UserController.class.php 93 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Controller;
  10. use Home\Model\OrderModel;
  11. class UserController extends CommonController {
  12. protected function _initialize(){
  13. parent::_initialize();
  14. }
  15. public function set_default_address()
  16. {
  17. $gpc = I('request.');
  18. $token = $gpc['token'];
  19. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  20. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  21. {
  22. echo json_encode( array('code' => 1) );
  23. die();
  24. }
  25. $member_id = $weprogram_token['member_id'];
  26. $id = $gpc['id'];//I('get.id', 0);
  27. M('ims_lionfish_comshop_address')->where( array('member_id' => $member_id ) )->save( $up_data );
  28. $up_data = array();
  29. $up_data['is_default'] = 1;
  30. M('ims_lionfish_comshop_address')->where( array('address_id' => $id ) )->save( $up_data );
  31. echo json_encode( array('code' => 0) );
  32. die();
  33. }
  34. public function group_orders()
  35. {
  36. $_GPC = I('request.');
  37. $token = $_GPC['token'];
  38. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  39. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  40. {
  41. echo json_encode( array('code' => 1) );
  42. die();
  43. }
  44. $member_id = $weprogram_token['member_id'];
  45. $type = isset($_GPC['type']) ? $_GPC['type']:'0';
  46. $page = isset($_GPC['page']) ? $_GPC['page']:'1';//当前第几页
  47. $pre_page = isset($_GPC['pre_page']) ? $_GPC['pre_page']:'10';//每页数量
  48. $offset = ($page -1) * $pre_page;
  49. $where = ' ';
  50. if($type == 1)
  51. {
  52. $where .= ' and p.state = 0 and p.end_time >'.time();
  53. } else if($type == 2){
  54. $where .= ' and p.state = 1 ';
  55. } else if($type == 3){
  56. $where .= ' and (o.order_status_id != 5 && o.order_status_id != 3) and (p.state = 2 or (p.state =0 and p.end_time <'.time().')) ';
  57. }else if($type == 0){
  58. //$where .= ' and o.order_status_id != 3 ';
  59. }
  60. $sql = "select og.goods_id as goods_id, og.name as name,og.goods_images,g.productprice as orign_price,o.voucher_credit,os.name as status_name,os.order_status_id,og.quantity,og.order_goods_id,p.need_count,p.state,p.is_lottery,p.lottery_state,p.end_time,o.delivery,o.lottery_win,o.total,o.shipping_fare,o.order_id,o.store_id,og.price,po.pin_id,o.order_status_id from ".C('DB_PREFIX')."lionfish_comshop_order as o, ".C('DB_PREFIX')."lionfish_comshop_order_goods as og,
  61. ".C('DB_PREFIX')."lionfish_comshop_pin as p,".C('DB_PREFIX')."lionfish_comshop_goods as g ,".C('DB_PREFIX')."lionfish_comshop_order_status as os ,".C('DB_PREFIX')."lionfish_comshop_pin_order as po
  62. where po.order_id = o.order_id and o.order_status_id = os.order_status_id and o.order_id = og.order_id and og.goods_id = g.id and po.pin_id = p.pin_id
  63. and o.member_id = ".$member_id." {$where} order by o.date_added desc limit {$offset},{$pre_page}";
  64. $list = M()->query($sql); //M()->query($sql);
  65. foreach($list as $key => $val)
  66. {
  67. $val['price'] = round($val['price'],2);
  68. //delivery
  69. if($val['order_status_id'] == 10)
  70. {
  71. $val['status_name'] = '等待退款';
  72. }
  73. else if($val['order_status_id'] == 4 && $val['delivery'] =='pickup')
  74. {
  75. //delivery 6
  76. $val['status_name'] = '待自提';
  77. //已自提
  78. }
  79. else if($val['order_status_id'] == 6 && $val['delivery'] =='pickup')
  80. {
  81. //delivery 6
  82. $val['status_name'] = '已自提';
  83. }else if($val['order_status_id'] == 10)
  84. {
  85. $val['status_name'] = '等待退款';
  86. }else if($val['order_status_id'] == 1 && $val['type'] == 'lottery')
  87. {
  88. //等待开奖
  89. //一等奖
  90. if($val['lottery_win'] == 1)
  91. {
  92. $val['status_name'] = '一等奖';
  93. }else {
  94. $val['status_name'] = '等待开奖';
  95. }
  96. }
  97. $pin_type = $val['state'];
  98. if($pin_type == 0 && $val['end_time'] <= time() )
  99. {
  100. $pin_type = 2;
  101. }
  102. switch($pin_type)
  103. {
  104. case 0:
  105. if($val['order_status_id'] == 2)
  106. {
  107. $val['status_name'] = $val['status_name'];
  108. }else{
  109. $val['status_name'] = '拼团中,'.$val['status_name'];
  110. }
  111. break;
  112. case 1:
  113. //7
  114. if($val['order_status_id'] == 7)
  115. {
  116. $val['status_name'] = '拼团成功,售后已退款';
  117. }else if($val['order_status_id'] == 1)
  118. {
  119. $val['status_name'] = '拼团成功,待发货';
  120. }
  121. else{
  122. $val['status_name'] = '拼团成功,'.$val['status_name'];
  123. }
  124. break;
  125. case 2:
  126. $val['status_name'] = '拼团失败,'.$val['status_name'];
  127. //order_status_id 2
  128. if($val['order_status_id'] == 2)
  129. {
  130. $val['status_name'] = '拼团失败';
  131. }
  132. break;
  133. }
  134. $val['goods_images'] = tomedia( $val['goods_images'] );
  135. $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' => $val['order_goods_id'] ) )->select();
  136. foreach($order_option_list as $option)
  137. {
  138. $val['option_str'][] = $option['value'];
  139. }
  140. if( !isset($val['option_str']) )
  141. {
  142. $val['option_str'] = '';
  143. }else{
  144. $val['option_str'] = implode(',', $val['option_str']);
  145. }
  146. $store_info = array('s_true_name' =>'','s_logo' => '');
  147. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  148. $store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
  149. $store_info['s_logo'] = tomedia($store_info['s_logo']);
  150. //$val['store_info'] = $store_info;
  151. //order_id pin_id
  152. $first_tuan = M('lionfish_comshop_pin_order')->where( array('pin_id' => $val['pin_id'] ) )->order('id asc')->find();
  153. if( $first_tuan['order_id'] == $val['order_id'] )
  154. {
  155. $val['me_is_head'] = 1;
  156. }else{
  157. $val['me_is_head'] = 0;
  158. }
  159. $val['price'] = round($val['price'],2);
  160. if($val['delivery'] == 'pickup')
  161. {
  162. $val['total'] = round($val['total'],2) - round($val['voucher_credit'],2);
  163. }else{
  164. $val['total'] = round($val['total'],2)+round($val['shipping_fare'],2) - round($val['voucher_credit'],2);
  165. }
  166. if($val['shipping_fare']<=0.001 || $val['delivery'] == 'pickup')
  167. {
  168. $val['shipping_fare'] = '免运费';
  169. }else{
  170. $val['shipping_fare'] = '运费:'.$val['shipping_fare'];
  171. }
  172. $val['orign_price'] = round($val['orign_price'],2);
  173. if($val['state'] == 0 && $val['end_time'] < time())
  174. {
  175. $val['state'] = 2;
  176. }
  177. $list[$key] = $val;
  178. }
  179. $need_data = array();
  180. $need_data['code'] = 1;
  181. if( !empty($list) )
  182. {
  183. $need_data['code'] = 0;
  184. $need_data['data'] = $list;
  185. }
  186. echo json_encode($need_data);
  187. die();
  188. }
  189. public function sub_user_shop()
  190. {
  191. $gpc = I('request.');
  192. $token = $gpc['token'];
  193. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  194. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  195. {
  196. echo json_encode( array('code' => 1) );
  197. die();
  198. }
  199. $member_id = $weprogram_token['member_id'];
  200. $id = $gpc['id'];
  201. $data = array();
  202. $data['member_id'] = $member_id;
  203. $data['shop_name'] = $gpc['head_name'];
  204. $data['shop_mobile'] = $gpc['head_mobile'];
  205. $data['imgGroup'] = $gpc['imgGroup'];
  206. $data['otherImgGroup'] = $gpc['otherImgGroup'];
  207. $data['state'] = 0;
  208. $data['addtime'] = time();
  209. //------
  210. $has_shopinfo = M('lionfish_comshop_member_shopinfo')->where( array('member_id' => $member_id ) )->find();
  211. if( !empty($has_shopinfo) )
  212. {
  213. echo json_encode( array('code' => 1, 'msg' => '您已经申请过了') );
  214. die();
  215. }else{
  216. M('lionfish_comshop_member_shopinfo')->add($data);
  217. echo json_encode( array('code' => 0) );
  218. die();
  219. }
  220. }
  221. public function user_index_shareqrcode()
  222. {
  223. $_GPC = I('request.');
  224. $token = $_GPC['token'];
  225. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  226. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  227. {
  228. $member_id = 0;
  229. }else{
  230. $member_id = $weprogram_token['member_id'];
  231. }
  232. $community_id = $_GPC['community_id'];
  233. //community_id: undefined
  234. $community_config_qrcode_json = D('Home/Front')->get_config_by_name('community_config_qrcode_'.$community_id );
  235. $community_config_qrcode_arr = unserialize($community_config_qrcode_json);
  236. $load_new = false;
  237. if( empty($community_config_qrcode_arr) )
  238. {
  239. $load_new = true;
  240. }else {
  241. if( $community_config_qrcode_arr['endtime'] < time() )
  242. {
  243. $load_new = true;
  244. }
  245. }
  246. //member_id
  247. $is_login_showprice = D('Home/Front')->get_config_by_name('is_login_showprice');
  248. if( !empty($is_login_showprice) && $is_login_showprice == 1 )
  249. {
  250. $load_new = true;
  251. }
  252. if( $load_new)
  253. {
  254. $goods_model = D('Home/Pingoods');
  255. $community_info = M('lionfish_community_head')->where( array('id' => $community_id) )->find();
  256. $tuanz_member_id = $community_info['member_id'];
  257. if(empty($member_id))
  258. {
  259. $member_id = $tuanz_member_id;
  260. }
  261. $qrcode_image = $goods_model->_get_index_wxqrcode($member_id,$community_id);
  262. $member_info = M('lionfish_comshop_member')->field('avatar,username,wepro_qrcode')
  263. ->where( array('member_id' => $tuanz_member_id) )->find();
  264. //fff562 get_weindex_share_image
  265. $avatar = $goods_model->get_user_avatar($member_info['avatar'], $tuanz_member_id,2);
  266. //is_hyaline Bool false
  267. $result = $goods_model->get_weindex_share_image($community_id,$qrcode_image,$avatar , $member_id);
  268. $data = array();
  269. $data['image_path'] = $result['full_path'];
  270. $ed_time = time() + 1800;
  271. $js_arr = array('endtime' => $ed_time,'image_path' => $data['image_path'] );
  272. $cd_key = 'community_config_qrcode_'.$community_id;
  273. D('Seller/Config')->update( array( $cd_key => serialize($js_arr) ) );
  274. }else{
  275. $data = array();
  276. $data['image_path'] = $community_config_qrcode_arr['image_path'];
  277. }
  278. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  279. $data['image_path'] = $shop_domain.'/'.$data['image_path'];
  280. $result = array('code' => 0, 'image_path' => $data['image_path'] );
  281. echo json_encode($result);
  282. die();
  283. }
  284. public function myvoucherlist()
  285. {
  286. $_GPC = I('request.');
  287. $type = isset($_GPC['type']) && !empty($_GPC['type']) ? $_GPC['type'] : 1;
  288. $page = isset($_GPC['page']) && !empty($_GPC['page']) ? $_GPC['page'] : 1;
  289. $pre_page = 20;
  290. $offset = ($page -1) * $pre_page;
  291. $token = $_GPC['token'];
  292. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  293. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  294. {
  295. echo json_encode( array('code' => 1) );
  296. die();
  297. }
  298. $member_id = $weprogram_token['member_id'];
  299. if( empty($member_id) )
  300. {
  301. $result['code'] = 3;
  302. $result['msg'] = '登录失效';
  303. echo json_encode($result);
  304. die();
  305. }
  306. $condition = "user_id=".$member_id;
  307. if($type == 1)
  308. {
  309. //未使用
  310. $condition .= " and consume= 'N' and end_time> ".time();
  311. } else if($type == 2){
  312. //已使用
  313. $condition .= " and (consume= 'Y' or end_time< ".time().")";
  314. }
  315. $list = M('lionfish_comshop_coupon_list')->where($condition)->order('add_time desc')->limit($offset,$pre_page)->select();
  316. $now_time = time();
  317. $category_list = M('lionfish_comshop_coupon_category')->field('id,name,status')->where( array('merchid' => 0) )->order('id desc')->select();
  318. $category = array();
  319. foreach($category_list as $val)
  320. {
  321. $category[$val['id']] = $val;
  322. }
  323. $k = 0;
  324. $result_list = array();
  325. foreach($list as $key => $val)
  326. {
  327. $couponid = $val['voucher_id'];
  328. $coupon = M('lionfish_comshop_coupon')->field('catid')->where( array('id' => $couponid) )->find();
  329. $val['tag'] = $category[$coupon['catid']]['name'];
  330. $store_info = array('s_true_name' =>'','s_logo' => '');
  331. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  332. $store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
  333. if( !empty($store_info['s_logo']))
  334. {
  335. $store_info['s_logo'] = tomedia($store_info['s_logo']);
  336. }else{
  337. $store_info['s_logo'] = '';
  338. }
  339. $val['store_name'] = $store_info['s_true_name'];
  340. $val['s_logo'] = $store_info['s_logo'];
  341. //now_time
  342. $val['is_over'] = 0;
  343. $val['is_use'] = 0;
  344. if($val['end_time'] < $now_time)
  345. {
  346. $val['is_over'] = 1;
  347. }
  348. if($val['consume'] == 'Y')
  349. {
  350. $val['is_use'] = 1;
  351. }
  352. $val['begin_time'] = date('Y.m.d H:i:s', $val['begin_time']);
  353. $val['end_time'] = date('Y.m.d H:i:s', $val['end_time']);
  354. $result_list[$k] = $val;
  355. $k++;
  356. }
  357. if( empty($result_list) )
  358. {
  359. echo json_encode( array('code' =>1) );
  360. }else {
  361. echo json_encode( array('code' =>0, 'list' => $result_list) );
  362. }
  363. }
  364. public function refunddetail()
  365. {
  366. $gpc = I('request.');
  367. $token = $gpc['token'];
  368. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  369. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  370. {
  371. echo json_encode( array('code' => 1) );
  372. die();
  373. }
  374. $member_id = $weprogram_token['member_id'];
  375. if( empty($member_id) )
  376. {
  377. $result['code'] = 0;
  378. $result['msg'] = '登录失效';
  379. echo json_encode($result);
  380. die();
  381. }
  382. $ref_id = $gpc['ref_id'];
  383. $order_refund = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  384. $order_id = $order_refund['order_id'];
  385. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id,'member_id' => $member_id) )->find();
  386. if(empty($order_info) )
  387. {
  388. $result['code'] = 0;
  389. $result['msg'] = '无此订单';
  390. echo json_encode($result);
  391. die();
  392. }
  393. if($order_refund['order_goods_id'] > 0)
  394. {
  395. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_refund['order_goods_id'] ,'order_id' =>$order_id ) )->find();
  396. }else{
  397. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->find();
  398. }
  399. if($order_refund['order_goods_id'] > 0)
  400. {
  401. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('type' => 2, 'order_goods_id' => $order_refund['order_goods_id'], 'order_id' =>$order_id ) )->order('addtime asc')->find();
  402. }else{
  403. $order_refund_history = M('lionfish_comshop_order_refund_history')->where( array('type' => 2,'order_id' => $order_id) )->order('addtime asc')->find();
  404. }
  405. $refund_reason = array(
  406. '97' =>'商品有质量问题',
  407. '98' =>'没有收到货',
  408. '99' =>'商品少发漏发发错',
  409. '100' =>'商品与描述不一致',
  410. '101' =>'收到商品时有划痕或破损',
  411. '102' =>'质疑假货',
  412. '111' =>'其他',
  413. );
  414. $order_refund['ref_type'] = $order_refund['ref_type'] ==1 ? '仅退款': '退款退货';
  415. $refund_state = array(
  416. 0 => '申请中',
  417. 1 => '商家拒绝',
  418. 2 => '平台介入',
  419. 3 => '退款成功',
  420. 4 => '退款失败',
  421. 5 => '撤销申请',
  422. );
  423. $order_refund['state'] = $refund_state[$order_refund['state']];
  424. $order_refund['addtime'] = date('Y-m-d H:i:s', $order_refund['addtime']);
  425. $order_refund_image = M('lionfish_comshop_order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->select();
  426. $url = D('Home/Front')->get_config_by_name('shop_domain');
  427. $refund_images = array();
  428. if(!empty($order_refund_image))
  429. {
  430. foreach($order_refund_image as $refund_image)
  431. {
  432. $refund_image['thumb_image'] = $refund_image['image'] ;
  433. $refund_images[] = $refund_image;
  434. }
  435. }
  436. if($order_refund['order_goods_id'] > 0)
  437. {
  438. $order_refund_historylist = M('lionfish_comshop_order_refund_history')->where( array('order_goods_id' => $order_refund['order_goods_id'],'order_id' => $order_id) )->order('addtime asc')->select();
  439. }else{
  440. $order_refund_historylist = M('lionfish_comshop_order_refund_history')->where( array('order_id' => $order_id) )->order('addtime asc')->select();
  441. }
  442. //ims_
  443. //.type ==3
  444. $pingtai_deal = 0;
  445. foreach($order_refund_historylist as $key => $val)
  446. {
  447. if($val['type'] ==3)
  448. {
  449. $pingtai_deal = 1;
  450. }
  451. $order_refund_history_image = M('lionfish_comshop_order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  452. if(!empty($order_refund_history_image))
  453. {
  454. foreach($order_refund_history_image as $kk => $vv)
  455. {
  456. $vv['thumb_image'] = $url. resize($vv['image'], 200,200) ;
  457. $order_refund_history_image[$kk] = $vv;
  458. }
  459. }
  460. $val['order_refund_history_image'] = $order_refund_history_image;
  461. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  462. $order_refund_historylist[$key] = $val;
  463. }
  464. echo json_encode( array('code' => 1,'pingtai_deal' => $pingtai_deal,'order_refund' =>$order_refund, 'order_id' => $order_id ,'order_refund_history' => $order_refund_history,'order_refund_historylist' => $order_refund_historylist, 'refund_images' => $refund_images,'order_goods' => $order_goods ,'order_info' => $order_info) );
  465. die();
  466. }
  467. public function cancel_refund()
  468. {
  469. $gpc = I('request.');
  470. $token = $gpc['token'];
  471. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  472. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  473. {
  474. echo json_encode( array('code' => 1) );
  475. die();
  476. }
  477. $member_id = $weprogram_token['member_id'];
  478. $ref_id = $gpc['ref_id'];
  479. $order_refund = M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->find();
  480. $order_id = $order_refund['order_id'];
  481. //$order_id = $gpc['order_id'];
  482. if( empty($member_id) )
  483. {
  484. $result['code'] = 0;
  485. $result['msg'] = '登录失效';
  486. echo json_encode($result);
  487. die();
  488. }
  489. $result = array('code' => 0);
  490. $order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->find();
  491. if(empty($order_info) )
  492. {
  493. $result['msg'] = '非法操作';
  494. echo json_encode($result);
  495. die();
  496. }
  497. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id) )->save( array('state' => 5) );
  498. //ims_
  499. $order_history = array();
  500. $order_history['order_id'] = $order_id;
  501. $order_history['order_goods_id'] = $order_refund['order_goods_id'];
  502. $order_history['order_status_id'] = 4;
  503. $order_history['notify'] = 0;
  504. $order_history['comment'] = '用户撤销退款';
  505. $order_history['date_added']=time();
  506. M('lionfish_comshop_order_history')->add($order_history);
  507. //ims_lionfish_comshop_order_goods
  508. if($order_refund['order_goods_id'] > 0)
  509. {
  510. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_refund['order_goods_id']) )->save( array('is_refund_state' => 0) );
  511. if($order_info['order_status_id'] == 12)
  512. {
  513. //检测 last_refund_order_status_id
  514. $order_gd_info = M('lionfish_comshop_order_goods')->where( array('is_refund_state' => 1, 'order_id' => $order_id ) )->find();
  515. if( empty($order_gd_info) )
  516. {
  517. if($order_info['last_refund_order_status_id'] > 0)
  518. {
  519. M('lionfish_comshop_order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->save( array('order_status_id' => $order_info['last_refund_order_status_id'] ) );
  520. }else{
  521. M('lionfish_comshop_order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->save( array('order_status_id' => 4) );
  522. }
  523. }
  524. }
  525. }else{
  526. if($order_info['last_refund_order_status_id'] > 0)
  527. {
  528. M('lionfish_comshop_order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->save( array('order_status_id' => $order_info['last_refund_order_status_id'] ) );
  529. }else{
  530. M('lionfish_comshop_order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->save( array('order_status_id' => 4) );
  531. }
  532. }
  533. $result['code'] = 1;
  534. echo json_encode($result);
  535. die();
  536. }
  537. public function refund_sub()
  538. {
  539. $gpc = I('request.');
  540. $token = $gpc['token'];
  541. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  542. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  543. {
  544. echo json_encode( array('code' => 1) );
  545. die();
  546. }
  547. $member_id = $weprogram_token['member_id'];
  548. if( empty($member_id) )
  549. {
  550. $result['code'] = 0;
  551. $result['msg'] = '登录失效';
  552. echo json_encode($result);
  553. die();
  554. }
  555. $data = array();
  556. $data['order_id'] = $gpc['order_id'];
  557. $data['complaint_type'] = $gpc['complaint_type'];
  558. $data['complaint_images'] = $gpc['complaint_images'];
  559. $data['complaint_desc'] = $gpc['complaint_desc'];
  560. $data['complaint_mobile'] = $gpc['complaint_mobile'];
  561. $data['complaint_reason'] = $gpc['complaint_reason'];
  562. $data['complaint_money'] = $gpc['complaint_money'];
  563. if( !empty($data['complaint_images']) )
  564. {
  565. $data['complaint_images'] = explode(',', $data['complaint_images']);
  566. }
  567. $order_id = $data['order_id'];
  568. $order_goods_id = $gpc['order_goods_id'];
  569. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id,'member_id' => $member_id) )->find();
  570. if(empty($order_info) )
  571. {
  572. $result['code'] = 0;
  573. $result['msg'] = '没有此订单';
  574. echo json_encode($result);
  575. die();
  576. }
  577. $result = array('code' => 0);
  578. $refdata = array();
  579. $refdata['order_id'] = intval($data['order_id']);
  580. $refdata['ref_type'] = intval($data['complaint_type']);
  581. $refdata['ref_money'] = floatval($data['complaint_money']);
  582. $refdata['ref_member_id'] = $member_id;
  583. $refdata['ref_name'] = htmlspecialchars($data['complaint_reason']);
  584. $refdata['ref_mobile'] = htmlspecialchars($data['complaint_mobile']);
  585. $refdata['ref_description'] = htmlspecialchars($data['complaint_desc']);
  586. $refdata['state'] = 0;
  587. $refdata['addtime'] = time();
  588. $order_info['total'] = round($order_info['total'],2)< 0.01 ? '0.00':round($order_info['total']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money'],2) ;
  589. if( !empty($order_goods_id) && $order_goods_id > 0 )
  590. {
  591. //ims_lionfish_comshop_order_goods
  592. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->find();
  593. $tp_total = round($order_goods_info['total'],2)< 0.01 ? '0.00':round($order_goods_info['total']+$order_goods_info['shipping_fare']-$order_goods_info['voucher_credit']-$order_goods_info['score_for_money']-$order_goods_info['fullreduction_money'],2) ;
  594. $order_info['total'] = $tp_total;
  595. }else{
  596. $tp_total = 0;
  597. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id, 'is_refund_state' => 0) )->select();
  598. foreach($order_goods_list as $order_goods_info)
  599. {
  600. $tp_total += round($order_goods_info['total'],2)< 0.01 ? '0.00':round($order_goods_info['total']+$order_goods_info['shipping_fare']-$order_goods_info['voucher_credit']-$order_goods_info['score_for_money']-$order_goods_info['fullreduction_money'],2) ;
  601. }
  602. $order_info['total'] = $tp_total;
  603. }
  604. if($order_info['total'] < 0)
  605. {
  606. $order_info['total'] = '0.00';
  607. }
  608. if($refdata['ref_money'] > $order_info['total'])
  609. {
  610. $result['msg'] = '退款金额不能大于订单总额';
  611. echo json_encode($result);
  612. die();
  613. }
  614. if(!empty($data['ref_id']))
  615. {
  616. $ref_id = intval($data['ref_id']);
  617. unset($refdata['order_id']);
  618. unset($refdata['ref_member_id']);
  619. unset($refdata['addtime']);
  620. M('lionfish_comshop_order_refund')->where( array('ref_id' => $ref_id ) )->save( $refdata );
  621. $order_history = array();
  622. $order_history['order_id'] = $order_id;
  623. $order_history['order_status_id'] = $order_info['order_status_id'];
  624. $order_history['notify'] = 0;
  625. $order_history['comment'] = '用户修改退款资料';
  626. $order_history['date_added']=time();
  627. // M('lionfish_comshop_order_history')->add($order_history);
  628. $order_refund_history = array();
  629. $order_refund_history['order_id'] = $order_id;
  630. $order_refund_history['order_goods_id'] = $order_goods_id;
  631. $order_refund_history['message'] = $refdata['ref_description'];
  632. $order_refund_history['type'] = 1;
  633. $order_refund_history['addtime'] = time();
  634. $orh_id = M('lionfish_comshop_order_refund_history')->add($order_refund_history);
  635. if(!empty($data['complaint_images']))
  636. {
  637. foreach($data['complaint_images'] as $complaint_images)
  638. {
  639. $img_data = array();
  640. $img_data['orh_id'] = $orh_id;
  641. $img_data['uniacid'] = $_W['uniacid'];
  642. $img_data['image'] = htmlspecialchars($complaint_images);
  643. $img_data['addtime'] = time();
  644. M('lionfish_comshop_order_refund_history_image')->add($img_data);
  645. }
  646. }
  647. }else {
  648. $refdata['order_goods_id'] = $order_goods_id;
  649. $ref_id = M('lionfish_comshop_order_refund')->add($refdata);
  650. $can_refund_order = true;
  651. if( !empty($order_goods_id) && $order_goods_id > 0 )
  652. {
  653. M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id ) )->save( array('is_refund_state' => 1) );
  654. //判断是否全部都退款了
  655. $gdall = M('lionfish_comshop_order_goods')->field('is_refund_state')->where( array('order_id' =>$order_id ) )->select();
  656. foreach( $gdall as $vv )
  657. {
  658. if( $vv['is_refund_state'] == 0 )
  659. {
  660. $can_refund_order = false;
  661. break;
  662. }
  663. }
  664. }else{
  665. M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->save( array('is_refund_state' => 1) );
  666. }
  667. /**
  668. 判断是否所有订单都在退款中
  669. **/
  670. if($can_refund_order)
  671. {
  672. $up_order = array();
  673. $up_order['order_status_id'] = 12;
  674. $up_order['last_refund_order_status_id'] = $order_info['order_status_id'];
  675. M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->save( $up_order );
  676. $order_history = array();
  677. $order_history['order_id'] = $order_id;
  678. $order_history['order_goods_id'] = $order_goods_id;
  679. $order_history['order_status_id'] = 12;
  680. $order_history['notify'] = 0;
  681. $order_history['comment'] = '用户前台申请退款中';
  682. $order_history['date_added']=time();
  683. M('lionfish_comshop_order_history')->add($order_history);
  684. }else{
  685. //部分商品退款
  686. $order_history = array();
  687. $order_history['order_id'] = $order_id;
  688. $order_history['order_goods_id'] = $order_goods_id;
  689. $order_history['order_status_id'] = 12;
  690. $order_history['notify'] = 0;
  691. $order_history['comment'] = '用户申请部分商品退款';
  692. $order_history['date_added']=time();
  693. M('lionfish_comshop_order_history')->add($order_history);
  694. }
  695. if(!empty($data['complaint_images']))
  696. {
  697. //complaint_images
  698. foreach($data['complaint_images'] as $complaint_images)
  699. {
  700. $img_data = array();
  701. $img_data['ref_id'] = $ref_id;
  702. $img_data['uniacid'] = $_W['uniacid'];
  703. $img_data['image'] = htmlspecialchars($complaint_images);
  704. $img_data['addtime'] = time();
  705. M('lionfish_comshop_order_refund_image')->add($img_data);
  706. }
  707. }
  708. }
  709. $result['code'] = 1;
  710. echo json_encode($result);
  711. die();
  712. }
  713. public function goods_express()//
  714. {
  715. $_GPC = I('request.');
  716. $token = $_GPC['token'];
  717. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  718. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  719. {
  720. echo json_encode( array('code' => 1) );
  721. die();
  722. }
  723. $member_id = $weprogram_token['member_id'];
  724. $order_id = $_GPC['order_id'];// I('get.order_id',0);
  725. if( empty($member_id) )
  726. {
  727. $result['code'] = 2;
  728. $result['msg'] = '登录失效';
  729. echo json_encode($result);
  730. die();
  731. }
  732. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  733. $now_time = time();
  734. if($now_time - $order_info['shipping_cha_time'] >= 43200)
  735. {
  736. //即时查询接口
  737. $seller_express = M('lionfish_comshop_express')->where( array('id' => $order_info['shipping_method'] ) )->find();
  738. if(!empty($seller_express['simplecode']))
  739. {
  740. //887406591556327434 YTO
  741. //TODO...
  742. $ebuss_info = D('Home/Front')->get_config_by_name('kdniao_id');
  743. $exappkey = D('Home/Front')->get_config_by_name('kdniao_api_key');
  744. $req_url = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
  745. $requestData= "{'OrderCode':'".$order_id."','ShipperCode':'".$seller_express['simplecode']."','LogisticCode':'". $order_info['shipping_no']."'}";
  746. $kdniao_freestatus = D('Home/Front')->get_config_by_name('kdniao_freestatus');
  747. $customerName = $order_info['shipping_tel'];
  748. $customerName = substr($customerName,7);
  749. $datas = array(
  750. 'EBusinessID' => $ebuss_info,
  751. 'RequestType' => '1002',
  752. 'RequestData' => urlencode($requestData) ,
  753. 'DataType' => '2',
  754. 'CustomerName'=>$customerName
  755. );
  756. if( isset($kdniao_freestatus) && $kdniao_freestatus ==1 )
  757. {
  758. $datas['RequestType'] = '8001';
  759. }
  760. $datas['DataSign'] = $this->encrypt($requestData, $exappkey);
  761. $result=$this->sendPost($req_url, $datas);
  762. $result = json_decode($result);
  763. // var_dump($result);
  764. //根据公司业务处理返回的信息......
  765. //Traces
  766. if(!empty($result->Traces))
  767. {
  768. $order_info['shipping_traces'] = serialize($result->Traces);
  769. $up_data = array('shipping_cha_time' => time(), 'shipping_traces' => $order_info['shipping_traces']);
  770. M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->save( $up_data );
  771. }
  772. }
  773. }
  774. //ims_
  775. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->find();
  776. $goods_info = array();
  777. $goods_info = D('Home/Pingoods')->get_goods_images($order_goods['goods_id']);
  778. $goods_info['image'] = tomedia($goods_info['image']);
  779. $seller_express = M('lionfish_comshop_express')->where( array('id' => $order_info['shipping_method'] ) )->find();
  780. $order_info['shipping_traces'] = unserialize($order_info['shipping_traces']) ;
  781. echo json_encode( array('code' => 0, 'seller_express' => $seller_express, 'goods_info' => $goods_info, 'order_info' => $order_info) );
  782. die();
  783. }
  784. public function get_order_money()
  785. {
  786. $gpc = I('request.');
  787. $token = $gpc['token'];
  788. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  789. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  790. {
  791. echo json_encode( array('code' => 1) );
  792. die();
  793. }
  794. $member_id = $weprogram_token['member_id'];
  795. if( empty($member_id) )
  796. {
  797. $result['code'] = 0;
  798. $result['msg'] = '登录失效';
  799. echo json_encode($result);
  800. die();
  801. }
  802. $order_id = $gpc['order_id'];
  803. $order_goods_id = $gpc['order_goods_id'];
  804. //total lionfish_comshop_order
  805. $total = 0;
  806. if( !empty($order_goods_id) && $order_goods_id > 0 )
  807. {
  808. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id , 'member_id' => $member_id ) )->find();
  809. $order_goods_all = M('lionfish_comshop_order_goods')->where( array('order_goods_id' => $order_goods_id,'order_id' => $order_id) )->select();
  810. foreach($order_goods_all as $val )
  811. {
  812. $total += $val['total'] + $val['shipping_fare']- $val['voucher_credit']- $val['fullreduction_money'] - $val['score_for_money'];
  813. }
  814. echo json_encode( array('code' =>1, 'total' => $total, 'order_status_id'=>$order_info['order_status_id']) );
  815. die();
  816. }else{
  817. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id,'member_id' =>$member_id ) )->find();
  818. $order_goods_all = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id, 'is_refund_state' => 0) )->select();
  819. foreach($order_goods_all as $val )
  820. {
  821. $total += $val['total'] + $val['shipping_fare']- $val['voucher_credit']- $val['fullreduction_money'] - $val['score_for_money'];
  822. }
  823. //$order_info['total'] = $order_info['total']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money']- $order_info['score_for_money'];
  824. //还要判断依据退款的
  825. if($total < 0){
  826. $total = 0;
  827. }
  828. $total = round($total, 2);
  829. echo json_encode( array('code' =>1, 'total' => $total, 'order_status_id'=>$order_info['order_status_id']) );
  830. die();
  831. }
  832. }
  833. function encrypt($data, $appkey) {
  834. return urlencode(base64_encode(md5($data.$appkey)));
  835. }
  836. function sendPost($url, $datas) {
  837. $temps = array();
  838. foreach ($datas as $key => $value) {
  839. $temps[] = sprintf('%s=%s', $key, $value);
  840. }
  841. $post_data = implode('&', $temps);
  842. $url_info = parse_url($url);
  843. if(empty($url_info['port']))
  844. {
  845. $url_info['port']=80;
  846. }
  847. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  848. $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  849. $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  850. $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  851. $httpheader.= "Connection:close\r\n\r\n";
  852. $httpheader.= $post_data;
  853. $fd = fsockopen($url_info['host'], $url_info['port']);
  854. fwrite($fd, $httpheader);
  855. $gets = "";
  856. $headerFlag = true;
  857. while (!feof($fd)) {
  858. if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  859. break;
  860. }
  861. }
  862. while (!feof($fd)) {
  863. $gets.= fread($fd, 128);
  864. }
  865. fclose($fd);
  866. return $gets;
  867. }
  868. //TODO.....next
  869. public function getaddress()
  870. {
  871. $gpc = I('request.');
  872. $token = $gpc['token'];
  873. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  874. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  875. {
  876. echo json_encode( array('code' => 1) );
  877. die();
  878. }
  879. $member_id = $weprogram_token['member_id'];
  880. $address_list = M('lionfish_comshop_address')->where( array('member_id' => $member_id) )->order('is_default desc , address_id desc')->select();
  881. foreach( $address_list as $key => $val )
  882. {
  883. //province_id city_id country_id
  884. $province_info = M('lionfish_comshop_area')->field('name')->where( array('id' => $val['province_id']) )->find();
  885. $city_info = M('lionfish_comshop_area')->field('name')->where( array('id' => $val['city_id']))->find();
  886. $country_info = M('lionfish_comshop_area')->field('name')->where( array('id' => $val['country_id'] ) )->find();
  887. $val['province_name'] = $province_info['name'];
  888. $val['city_name'] = $city_info['name'];
  889. $val['country_name'] = $country_info['name'];
  890. $address_list[$key] = $val;
  891. }
  892. if( !empty($address_list) )
  893. {
  894. echo json_encode( array('code' => 0, 'list' => $address_list) );
  895. die();
  896. }else{
  897. echo json_encode( array('code' => 1) );
  898. die();
  899. }
  900. }
  901. /**
  902. 收集订阅消息
  903. **/
  904. public function collect_subscriptmsg()
  905. {
  906. $_GPC = I('request.');
  907. $token = $_GPC['token'];
  908. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  909. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  910. {
  911. echo json_encode( array('code' => 1) );
  912. die();
  913. }
  914. $member_id = $weprogram_token['member_id'];
  915. //'pay_order','send_order','hexiao_success','apply_community','open_tuan','take_tuan','pin_tuansuccess','apply_tixian'
  916. $type_str = $_GPC['type'];
  917. $type_arr = explode(',', $type_str);
  918. foreach( $type_arr as $type )
  919. {
  920. $info = M('lionfish_comshop_subscribe')->where( array('member_id' => $member_id, 'type' => $type ) )->find();
  921. if( !empty($info) && false )
  922. {
  923. continue;
  924. }
  925. $template_id = "";
  926. switch( $type )
  927. {
  928. case 'pay_order':
  929. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pay_order');
  930. break;
  931. case 'send_order':
  932. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_send_order');
  933. break;
  934. case 'hexiao_success':
  935. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_hexiao_success');
  936. break;
  937. case 'apply_community':
  938. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_community');
  939. break;
  940. case 'open_tuan':
  941. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_open_tuan');
  942. break;
  943. case 'take_tuan':
  944. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_take_tuan');
  945. break;
  946. case 'pin_tuansuccess':
  947. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_pin_tuansuccess');
  948. break;
  949. case 'apply_tixian':
  950. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_apply_tixian');
  951. break;
  952. case 'presale_ordercan_continuepay':
  953. $template_id = D('Home/Front')->get_config_by_name('weprogram_subtemplate_presale_ordercan_continuepay');
  954. break;
  955. }
  956. if( empty($template_id) )
  957. {
  958. continue;
  959. }
  960. $ins_data = array();
  961. $ins_data['uniacid'] = 0;
  962. $ins_data['member_id'] = $member_id;
  963. $ins_data['template_id'] = $template_id;
  964. $ins_data['type'] = $type;
  965. $ins_data['addtime'] = time();
  966. M('lionfish_comshop_subscribe')->add( $ins_data );
  967. }
  968. echo json_encode( array('code' => 0) );
  969. die();
  970. }
  971. public function order_comment()
  972. {
  973. $gpc = I('request.');
  974. $token = $gpc['token'];
  975. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  976. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  977. {
  978. echo json_encode( array('code' => 1) );
  979. die();
  980. }
  981. $member_id = $weprogram_token['member_id'];
  982. $order_id = $gpc['order_id'];
  983. $goods_id = $gpc['goods_id'];
  984. if( empty($member_id) )
  985. {
  986. $result['code'] = 3;
  987. $result['msg'] = '登录失效';
  988. echo json_encode($result);
  989. die();
  990. }
  991. //ims_ lionfish_comshop_order_goods ims_lionfish_comshop_order_goods
  992. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' =>$order_id ,'goods_id' => $goods_id) )->find();
  993. $order_option_list =M('lionfish_comshop_order_option')->where( array('order_goods_id' => $order_goods['order_goods_id']) )->select();
  994. $order_goods['goods_images'] = tomedia($order_goods['goods_images']);
  995. $goods_filed = M('lionfish_comshop_goods')->field('productprice')->where( array('id' => $order_goods['goods_id']) )->find();
  996. $order_goods['orign_price'] = $goods_filed['productprice'];
  997. foreach($order_option_list as $option)
  998. {
  999. $order_goods['option_str'][] = $option['value'];
  1000. }
  1001. if( !isset($order_goods['option_str']) )
  1002. {
  1003. $order_goods['option_str'] = '';
  1004. }else{
  1005. $order_goods['option_str'] = implode(',', $order_goods['option_str']);
  1006. }
  1007. $order_goods['price'] = round($order_goods['price'],2);
  1008. $order_goods['orign_price'] = round($order_goods['orign_price'],2);
  1009. $image_info = D('Home/Pingoods')->get_goods_images( $order_goods['goods_id'] );
  1010. // M('goods')->field('image')->where( array('goods_id' => ) )->find();
  1011. $goods_image = tomedia($image_info['image']);
  1012. $open_comment_gift = D('Home/Front')->get_config_by_name('open_comment_gift');
  1013. $open_comment_gift = !empty($open_comment_gift) ? $open_comment_gift : 0;
  1014. //打到上限关闭
  1015. $commentresult = D('Seller/Order')->check_comment_gift_score($member_id);
  1016. if(!$commentresult['is_comment_gift']){
  1017. $open_comment_gift = 0;
  1018. }
  1019. $comment_gift_publish = D('Home/Front')->get_config_by_name('comment_gift_publish');
  1020. $comment_gift_publish = htmlspecialchars_decode($comment_gift_publish);
  1021. echo json_encode( array('code' => 0 ,'order_goods' =>$order_goods, 'goods_image' => $goods_image,'goods_id' =>$order_goods['goods_id']
  1022. ,'open_comment_gift' =>$open_comment_gift,'comment_gift_publish' =>$comment_gift_publish
  1023. ) );
  1024. die();
  1025. }
  1026. public function sub_comment()
  1027. {
  1028. $gpc = I('request.');
  1029. $token = $gpc['token'];
  1030. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1031. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  1032. {
  1033. echo json_encode( array('code' => 1) );
  1034. die();
  1035. }
  1036. $member_id = $weprogram_token['member_id'];
  1037. if( empty($member_id) )
  1038. {
  1039. $result['code'] = 3;
  1040. $result['msg'] = '登录失效';
  1041. echo json_encode($result);
  1042. die();
  1043. }
  1044. //cur_rel:cur_rel,cur2_rel:cur2_rel,cur3_rel:cur3_rel,imgs:imgs,
  1045. $data = array();
  1046. $data['order_id'] = $gpc['order_id'];
  1047. $data['goods_id'] = $gpc['goods_id'];
  1048. $data['cur_rel'] = 5;
  1049. $data['cur2_rel'] = 5;
  1050. $data['cur3_rel'] = 5;
  1051. $data['imgs'] = $gpc['imgs'];
  1052. $data['comment_content'] = $gpc['comment_content'];
  1053. $order_id = $data['order_id'];
  1054. $goods_id = $data['goods_id'];
  1055. $cur_rel = empty($data['cur_rel']) ? 5:$data['cur_rel'];
  1056. $cur2_rel = empty($data['cur2_rel']) ? 5:$data['cur2_rel'];
  1057. $cur3_rel = empty($data['cur3_rel']) ? 5:$data['cur3_rel'];
  1058. $imgs = $data['imgs'];
  1059. $comment_content = htmlspecialchars($data['comment_content']);
  1060. $order_goods = M('lionfish_comshop_order_goods')->field('name,goods_images')->where( array('goods_id' => $goods_id,'order_id' => $order_id) )->find();
  1061. $order_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $order_id) )->find();
  1062. $member_info = M('lionfish_comshop_member')->field('username as uname , avatar')->where( array('member_id' => $member_id) )->find();
  1063. //ims_
  1064. $data = array();
  1065. $data['member_id'] = $member_id;
  1066. $data['order_id'] = $order_id;
  1067. $data['goods_id'] = $goods_id;
  1068. $data['goods_name'] = $order_goods['name'];
  1069. $data['goods_image'] = $order_goods['goods_images'];
  1070. $data['order_num_alias'] = $order_info['order_num_alias'];
  1071. $data['avatar'] = $member_info['avatar'];
  1072. $data['user_name'] = $member_info['uname'];
  1073. //open_comment_shenhe state state
  1074. $open_comment_shenhe = D('Home/Front')->get_config_by_name('open_comment_shenhe');
  1075. if( empty($open_comment_shenhe) || $open_comment_shenhe == 0 )
  1076. {
  1077. $data['state'] = 1;
  1078. }
  1079. $data['star'] = $cur_rel;
  1080. $data['star2'] = $cur2_rel;
  1081. $data['star3'] = $cur3_rel;
  1082. $data['images'] = serialize($imgs);
  1083. $data['is_picture'] = empty($imgs) ? 0 :1;
  1084. $data['content'] = $comment_content;
  1085. $data['add_time'] = time();
  1086. $comment_id = M('lionfish_comshop_order_comment')->add($data);
  1087. if(isset($data['state']) && $data['state'] == 1){
  1088. //好评有礼送积分
  1089. D('Seller/Order')->sendCommentGift($comment_id);
  1090. M('lionfish_comshop_order_comment')->where(array('comment_id'=>$comment_id,'member_id'=>$member_id))->save(array('is_send_point'=>1));
  1091. }
  1092. //TOD...暂时屏蔽
  1093. // $goods_info = M('goods')->field('store_id')->where( array('goods_id' => $goods_id) )->find();
  1094. // $group_info = M('group')->field('seller_id')->where( array('seller_id' => $goods_info['store_id']) )->find();
  1095. //判断所有订单都评价了吗?
  1096. $comment_all_order = true;
  1097. //lionfish_comshop_order_goods
  1098. $order_goods_all = M('lionfish_comshop_order_goods')->field('goods_id')->where( array('order_id' => $order_id) )->select();
  1099. foreach($order_goods_all as $val)
  1100. {
  1101. $order_comment = M('lionfish_comshop_order_comment')->field('comment_id')->where( array('goods_id' => $val['goods_id'],'order_id' =>$order_id) )->find();
  1102. if(empty($order_comment))
  1103. {
  1104. $comment_all_order = false;
  1105. break;
  1106. }
  1107. }
  1108. if($comment_all_order)
  1109. {
  1110. $order_history = array();
  1111. $order_history['order_id'] = $order_id;
  1112. $order_history['order_status_id'] = 11;
  1113. $order_history['notify'] = 0;
  1114. $order_history['comment'] = '用户提交评论,订单完成。';
  1115. $order_history['date_added']=time();
  1116. M('lionfish_comshop_order_history')->add($order_history);
  1117. //ims_
  1118. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 11,'finishtime' => time()) );
  1119. }
  1120. echo json_encode( array('code' => 1) );
  1121. die();
  1122. }
  1123. //begin....
  1124. /**
  1125. 会员积分流水
  1126. controller: user.get_user_integral_flow
  1127. token,
  1128. page
  1129. 返回:
  1130. code=0 有数据,code=1 没有数据。
  1131. 金额:money,
  1132. 时间: charge_time
  1133. 状态 state:1 充值成功,3 余额支付
  1134. **/
  1135. public function get_user_integral_flow()
  1136. {
  1137. $_GPC = I('request.');
  1138. $token = $_GPC['token'];
  1139. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1140. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  1141. {
  1142. echo json_encode( array('code' => 1) );
  1143. die();
  1144. }
  1145. $member_id = $weprogram_token['member_id'];
  1146. if( empty($member_id) )
  1147. {
  1148. $result['code'] = 1;
  1149. $result['msg'] = '登录失效';
  1150. echo json_encode($result);
  1151. die();
  1152. }
  1153. $per_page = 20;
  1154. $page = isset($_GPC['page']) ? $_GPC['page'] : 1;
  1155. $offset = ($page - 1) * $per_page;
  1156. $list = array();
  1157. $list = M('lionfish_comshop_member_integral_flow')->where(" member_id = ".$member_id." ")->order('id desc')->limit($offset,$per_page)->select();
  1158. if( !empty($list) )
  1159. {
  1160. foreach($list as &$value)
  1161. {
  1162. $value['current_yuer'] = $value['after_operate_score'];
  1163. $value['addtime'] = date('Y-m-d H:i:s', $value['addtime']);
  1164. if( in_array($value['type'], array('goodsbuy','refundorder','orderbuy','pintuan_rebate') ))
  1165. {
  1166. $od_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $value['order_id'] ) )->find();
  1167. if( !empty($od_info) )
  1168. {
  1169. $value['trans_id'] = $od_info['order_num_alias'];
  1170. }
  1171. $order_goods_info = M('lionfish_comshop_order_goods')->field('name')->where( array('order_goods_id' => $value['order_goods_id']) )->find();
  1172. $value['goods_name'] = $order_goods_info['name'];
  1173. }
  1174. }
  1175. echo json_encode( array('code' => 0, 'data' => $list) );
  1176. die();
  1177. }else{
  1178. echo json_encode( array('code' => 1) );
  1179. die();
  1180. }
  1181. }
  1182. //end...
  1183. //----begin---
  1184. /**
  1185. 会员充值流水
  1186. controller: user.get_user_charge_flow
  1187. token,
  1188. page
  1189. 返回:
  1190. code=0 有数据,code=1 没有数据。
  1191. 金额:money,
  1192. 时间: charge_time
  1193. 状态 state:1 充值成功,3 余额支付
  1194. **/
  1195. public function get_user_charge_flow()
  1196. {
  1197. $_GPC = I('request.');
  1198. $token = $_GPC['token'];
  1199. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1200. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  1201. {
  1202. echo json_encode( array('code' => 1) );
  1203. die();
  1204. }
  1205. $member_id = $weprogram_token['member_id'];
  1206. $per_page = 20;
  1207. $page = isset($_GPC['page']) ? $_GPC['page'] : 1;
  1208. $offset = ($page - 1) * $per_page;
  1209. $list = array();
  1210. $sql = 'select * from '.C('DB_PREFIX')."lionfish_comshop_member_charge_flow
  1211. where member_id = ".$member_id." and state in (1,3,4,5,8,9,10,11,12,20,21) order by id desc limit {$offset},{$per_page}";
  1212. $list = M()->query($sql);
  1213. if( !empty($list) )
  1214. {
  1215. foreach($list as &$value)
  1216. {
  1217. $value['current_yuer'] = $value['operate_end_yuer'];
  1218. $value['charge_time'] = date('Y-m-d H:i:s', $value['charge_time']);
  1219. if($value['state'] == 3 || $value['state'] == 4 || $value['state'] == 21)
  1220. {
  1221. $od_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $value['trans_id'] ) )->find();
  1222. if( !empty($od_info) )
  1223. {
  1224. $value['trans_id'] = $od_info['order_num_alias'];
  1225. }
  1226. //6
  1227. if( $value['state'] == 4 && !empty($value['order_goods_id']) && $value['order_goods_id'] > 0 )
  1228. {
  1229. $value['state'] = 6;
  1230. }
  1231. }
  1232. }
  1233. echo json_encode( array('code' => 0, 'data' => $list) );
  1234. die();
  1235. }else{
  1236. echo json_encode( array('code' => 1) );
  1237. die();
  1238. }
  1239. }
  1240. //----end----
  1241. /**
  1242. 获取用户信息 can_yupay show_user_pin
  1243. **/
  1244. public function get_user_info()//
  1245. {
  1246. $gpc = I('request.');
  1247. $token = $gpc['token'];
  1248. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1249. $needAuth = false;
  1250. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  1251. {
  1252. $needAuth = true;
  1253. //echo json_encode( array('code' => 1) );
  1254. //die();
  1255. }
  1256. $member_id = $weprogram_token['member_id'];
  1257. if($member_id){
  1258. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1259. $member_info['full_user_name'] = base64_decode($member_info['full_user_name']);
  1260. // AFTER TO DO .
  1261. $member_level_list = array();
  1262. $level_name = '';
  1263. $is_show_member_level = D('Home/Front')->get_config_by_name('is_show_member_level');
  1264. $member_level_arr = array(
  1265. 0 => array('level_name' => '普通会员', 'discount' => 100),
  1266. );
  1267. $mb_level_list = M('lionfish_comshop_member_level')->where(1)->order('id asc')->select();
  1268. if( !empty($mb_level_list) )
  1269. {
  1270. foreach( $mb_level_list as $val )
  1271. {
  1272. $tmp = array();
  1273. $tmp['level_name'] = $val['levelname'];
  1274. $tmp['discount'] = $val['discount'];
  1275. $member_level_arr[$val['id']] = $tmp;
  1276. }
  1277. }
  1278. $member_info['is_show_member_level'] = $is_show_member_level;//是否显示会员等级信息
  1279. $member_info['member_level_info'] = $member_level_arr[ $member_info['level_id'] ];
  1280. $opencommiss = D('Home/Front')->get_config_by_name('commiss_level');
  1281. //待付款数量
  1282. $wait_pay_count = D('Home/Frontorder')->get_member_order_count($member_id," and order_status_id =3 ");
  1283. //待配送数量
  1284. $wait_send_count = D('Home/Frontorder')->get_member_order_count($member_id," and order_status_id = 1 and type <> 'ignore' ");
  1285. //待提货数量
  1286. $wait_get_count = D('Home/Frontorder')->get_member_order_count($member_id," and order_status_id =4 ");
  1287. //已提货数量
  1288. $has_get_count = D('Home/Frontorder')->get_member_order_count($member_id," and order_status_id in(6,11) ");
  1289. //售后退款
  1290. $refund_send_count = D('Home/Frontorder')->get_member_order_count($member_id," and order_status_id in(7,12,13) ");
  1291. $head_info = D('Home/Front')->get_member_community_info($member_id);
  1292. if( empty($head_info) )
  1293. {
  1294. $member_info['is_head'] = 0;
  1295. }else{
  1296. if($head_info['state'] == 1)
  1297. $member_info['is_head'] = 1;
  1298. else if($head_info['state'] == 0)
  1299. {
  1300. $member_info['is_head'] = 2;
  1301. }
  1302. else if($head_info['state'] == 2)
  1303. {
  1304. $member_info['is_head'] = 3;
  1305. }
  1306. }
  1307. $wechat_div = D('Home/Front')->get_config_by_name("wechat_div");
  1308. $wechat_div = $wechat_div?$wechat_div:"微信";
  1309. $member_info['wechat_div'] = $wechat_div;
  1310. $member_info['wait_pay_count'] = $wait_pay_count;
  1311. $member_info['wait_send_count'] = $wait_send_count;
  1312. $member_info['wait_get_count'] = $wait_get_count;
  1313. $member_info['has_get_count'] = $has_get_count;
  1314. //判断是否有提货码,没有就生成 hexiao_qrcod
  1315. // lionfish_comshop/moduleA/groupCenter/pendingDeliveryOrders?memberId=49
  1316. if( empty($member_info['hexiao_qrcod']))
  1317. {
  1318. $path = "lionfish_comshop/moduleA/groupCenter/pendingDeliveryOrders";
  1319. $hexiao_qrcod = D('Home/Pingoods')->_get_commmon_wxqrcode($path, $member_id);
  1320. if( empty($hexiao_qrcod) )
  1321. {
  1322. $member_info['hexiao_qrcod'] = '';
  1323. }else{
  1324. M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('hexiao_qrcod' => $hexiao_qrcod) );
  1325. $member_info['hexiao_qrcod'] = tomedia($hexiao_qrcod);
  1326. }
  1327. }else{
  1328. $member_info['hexiao_qrcod'] = tomedia($member_info['hexiao_qrcod']);
  1329. }
  1330. //判断是否是核销员
  1331. $salesroom_member_info = M('lionfish_comshop_salesroom_member')->where( array('member_id' => $member_id,'state'=>1) )->find();
  1332. if(!empty($salesroom_member_info)){
  1333. $member_info['is_hexiao_member'] = 1;
  1334. }else{
  1335. $member_info['is_hexiao_member'] = 0;
  1336. }
  1337. $is_show_member_id = D('Home/Front')->get_config_by_name('is_show_member_id');
  1338. $member_info['is_show_member_id'] = $is_show_member_id;
  1339. $supp_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  1340. $is_supply = 0; //未申请 2审核通过 1审核中
  1341. if( !empty($supp_info) ){
  1342. $is_supply = ($supp_info['state'] == 1) ? 2 : 1;
  1343. }
  1344. $is_show_auth_mobile = D('Home/Front')->get_config_by_name('is_show_auth_mobile');
  1345. if( empty($is_show_auth_mobile) )
  1346. {
  1347. $is_show_auth_mobile = 0;
  1348. }
  1349. //分销等级,如果是0,那么就是未开启分销
  1350. $commiss_level = D('Home/Front')->get_config_by_name('commiss_level');
  1351. if( empty($commiss_level) )
  1352. {
  1353. $commiss_level = 0;
  1354. }
  1355. //是否需要分享多少人成为分销
  1356. $commiss_sharemember_need = D('Home/Front')->get_config_by_name('commiss_sharemember_need');
  1357. //分享多少个人成为分销商
  1358. $commiss_share_member_update = D('Home/Front')->get_config_by_name('commiss_share_member_update');
  1359. //是否需要填写表单
  1360. $commiss_biaodan_need = D('Home/Front')->get_config_by_name('commiss_biaodan_need');
  1361. //是否需要审核
  1362. $commiss_become_condition = D('Home/Front')->get_config_by_name('commiss_become_condition');
  1363. //自定义表单格式
  1364. $commiss_diy_form = D('Home/Front')->get_config_by_name('commiss_diy_form');
  1365. $commiss_diy_name = D('Home/Front')->get_config_by_name('commiss_diy_name');
  1366. $share_member_count = M('lionfish_comshop_member')->where( "share_id={$member_id} and (agentid =0 or agentid={$member_id} )" )->count();
  1367. $create_time = strtotime( date('Y-m-d').' 00:00:00' );
  1368. $today_share_member_count = M('lionfish_comshop_member')->where( "share_id={$member_id} and (agentid =0 or agentid={$member_id}) and create_time>={$create_time}" )->count();
  1369. $create_y_time = $create_time - 86400;
  1370. $create_end_time = $create_time;
  1371. $yestoday_share_member_count = M('lionfish_comshop_member')->where( "share_id={$member_id} and (agentid =0 or agentid={$member_id}) and create_time>={$create_y_time} and create_time < {$create_end_time}" )->count();
  1372. //佣金团收益金额, 已结算多少钱,未结算多少钱
  1373. $pintuan_money = 0;
  1374. $pintuan_hasstatement_money = 0;
  1375. $pintuan_unstatement_money =0;
  1376. $pin_commiss = M('lionfish_comshop_pintuan_commiss')->where( array('member_id' => $member_id ) )->find();
  1377. if( !empty($pin_commiss) )
  1378. {
  1379. $pintuan_money = $pin_commiss['money'] + $pin_commiss['dongmoney']+ $pin_commiss['getmoney'];
  1380. }
  1381. $tp_hasstatement_money = M('lionfish_comshop_pintuan_commiss_order')->where( array('member_id' => $member_id, 'state' => 1) )->sum('money');
  1382. if( !empty($tp_hasstatement_money) && $tp_hasstatement_money > 0 )
  1383. {
  1384. $pintuan_hasstatement_money = $tp_hasstatement_money;
  1385. }
  1386. $tp_unstatement_money = M('lionfish_comshop_pintuan_commiss_order')->where( array('member_id' => $member_id,'state' => 0 ) )->sum('money');
  1387. if( !empty($tp_unstatement_money) && $tp_unstatement_money > 0 )
  1388. {
  1389. $pintuan_unstatement_money = $tp_unstatement_money;
  1390. }
  1391. $isopen_presale = D('Home/Front')->get_config_by_name('isopen_presale');
  1392. $isopen_presale = empty($isopen_presale) ? 0 : 1;
  1393. //是否开启礼品卡活动 begin
  1394. $isopen_virtualcard = D('Home/Front')->get_config_by_name('isopen_virtualcard');
  1395. $is_open_virtualcard_show = D('Home/Front')->get_config_by_name('is_open_virtualcard_show');
  1396. //礼品卡中心
  1397. $virtualcard_name_modify = D('Home/Front')->get_config_by_name('virtualcard_name_modify');
  1398. $virtualcard_name_modify = !isset($virtualcard_name_modify) || empty($virtualcard_name_modify) ? '礼品卡中心' : $virtualcard_name_modify;
  1399. if( isset($isopen_virtualcard) && $isopen_virtualcard == 1 )
  1400. {
  1401. $is_open_virtualcard_show = !isset($is_open_virtualcard_show) ? 0 : $is_open_virtualcard_show;
  1402. }else{
  1403. $is_open_virtualcard_show = 0;
  1404. }
  1405. //end
  1406. $result = array();
  1407. $result['code'] = 0;
  1408. $result['data'] = $member_info;
  1409. $result['is_supply'] = $is_supply;
  1410. $result['is_show_auth_mobile'] = $is_show_auth_mobile;
  1411. $result['commiss_level'] = $commiss_level;
  1412. $result['share_member_count'] = $share_member_count;
  1413. $result['today_share_member_count'] = $today_share_member_count;
  1414. $result['yestoday_share_member_count'] = $yestoday_share_member_count;
  1415. $result['commiss_sharemember_need'] = $commiss_sharemember_need;
  1416. $result['commiss_share_member_update'] = $commiss_share_member_update;
  1417. $result['commiss_biaodan_need'] = $commiss_biaodan_need;
  1418. $result['commiss_diy_form'] = unserialize($commiss_diy_form);
  1419. $result['commiss_become_condition'] = $commiss_become_condition;
  1420. $result['pintuan_money'] = $pintuan_money;
  1421. $result['pintuan_hasstatement_money'] = $pintuan_hasstatement_money;
  1422. $result['pintuan_unstatement_money'] = $pintuan_unstatement_money;
  1423. $result['isopen_presale'] = $isopen_presale;
  1424. $result['is_open_virtualcard_show'] = $is_open_virtualcard_show;//是否开启 礼品卡会员中心入口
  1425. $result['virtualcard_name_modify'] = $virtualcard_name_modify;//礼品卡中心名称自定义
  1426. //是否开启供应商手机端 member_id
  1427. $supply_is_open_mobilemanage = D('Home/Front')->get_config_by_name('supply_is_open_mobilemanage');
  1428. if( empty($supply_is_open_mobilemanage) || $supply_is_open_mobilemanage == 0 )
  1429. {
  1430. $supply_is_open_mobilemanage = 0;
  1431. }
  1432. $result['is_open_supplymobile'] = 0;
  1433. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  1434. if( !empty($supply_info) && $supply_info['state'] == 1 && $supply_info['type'] == 1 && $supply_info['is_open_mobilemanage'] == 1 )
  1435. {
  1436. $result['is_open_supplymobile'] = 1;
  1437. }
  1438. } else {
  1439. $result = array();
  1440. $result['code'] = 0;
  1441. $result['is_open_supplymobile'] = 0;
  1442. }
  1443. //判断是否开启了 会员卡 is_open_vipcard_buy
  1444. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  1445. $modify_vipcard_name = D('Home/Front')->get_config_by_name('modify_vipcard_name');
  1446. $modify_vipcard_logo = D('Home/Front')->get_config_by_name('modify_vipcard_logo');
  1447. $modify_vipcard_name = empty($modify_vipcard_name) ? '天机会员': $modify_vipcard_name;
  1448. if( !empty($modify_vipcard_logo) )
  1449. {
  1450. $modify_vipcard_logo = tomedia($modify_vipcard_logo);
  1451. }
  1452. $result['is_open_vipcard_buy'] = $is_open_vipcard_buy;
  1453. $result['modify_vipcard_name'] = $modify_vipcard_name;
  1454. $result['modify_vipcard_logo'] = $modify_vipcard_logo;
  1455. $result['is_vip_card_member'] = 0;
  1456. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  1457. {
  1458. //card_id //card_begin_time //card_end_time
  1459. $now_time = time();
  1460. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  1461. {
  1462. $result['is_vip_card_member'] = 1;//还有会员
  1463. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  1464. $result['is_vip_card_member'] = 2;//已过期
  1465. }
  1466. }
  1467. //判断是否开启了 会员卡 is_open_vipcard_buy
  1468. $is_open_vipcard_buy = D('Home/Front')->get_config_by_name('is_open_vipcard_buy');
  1469. $modify_vipcard_name = D('Home/Front')->get_config_by_name('modify_vipcard_name');
  1470. $modify_vipcard_logo = D('Home/Front')->get_config_by_name('modify_vipcard_logo');
  1471. $modify_vipcard_name = empty($modify_vipcard_name) ? '天机会员': $modify_vipcard_name;
  1472. if( !empty($modify_vipcard_logo) )
  1473. {
  1474. $modify_vipcard_logo = tomedia($modify_vipcard_logo);
  1475. }
  1476. $result['is_open_vipcard_buy'] = $is_open_vipcard_buy;
  1477. $result['modify_vipcard_name'] = $modify_vipcard_name;
  1478. $result['modify_vipcard_logo'] = $modify_vipcard_logo;
  1479. $result['is_vip_card_member'] = 0;
  1480. if( !empty($is_open_vipcard_buy) && $is_open_vipcard_buy == 1 )
  1481. {
  1482. //card_id //card_begin_time //card_end_time
  1483. $now_time = time();
  1484. if( $member_info['card_id'] >0 && $member_info['card_end_time'] > $now_time )
  1485. {
  1486. $result['is_vip_card_member'] = 1;//还有会员
  1487. }else if( $member_info['card_id'] >0 && $member_info['card_end_time'] < $now_time ){
  1488. $result['is_vip_card_member'] = 2;//已过期
  1489. }
  1490. }
  1491. //判断是否开启同城配送begin
  1492. $isopen_localtown_delivery = D('Home/Front')->get_config_by_name('isopen_localtown_delivery');
  1493. $isopen_localtown_delivery = isset($isopen_localtown_delivery) && $isopen_localtown_delivery > 0 ? $isopen_localtown_delivery: 0;
  1494. $result['is_localtown_distributionman'] = 0;//是否同城配送员,1是,0 不是
  1495. if( $isopen_localtown_delivery == 1 && $member_id > 0 )
  1496. {
  1497. $orderdistribution = M('lionfish_comshop_orderdistribution')->where( array('member_id' => $member_id ) )->find();
  1498. if( !empty($orderdistribution) )
  1499. {
  1500. $result['is_localtown_distributionman'] = 1;
  1501. }
  1502. }
  1503. //end
  1504. //签到奖励 begin
  1505. $isopen_signinreward = D('Home/Front')->get_config_by_name('isopen_signinreward');
  1506. $show_signinreward_icon = D('Home/Front')->get_config_by_name('show_signinreward_icon');
  1507. if( empty($isopen_signinreward) )
  1508. {
  1509. $isopen_signinreward = 0;
  1510. }
  1511. if( empty($show_signinreward_icon) )
  1512. {
  1513. $show_signinreward_icon = 0;
  1514. }
  1515. $result['show_user_tuan_mobile'] = D('Home/Front')->get_config_by_name('show_user_tuan_mobile');
  1516. $result['isopen_signinreward'] = $isopen_signinreward;
  1517. $result['show_signinreward_icon'] = $show_signinreward_icon;
  1518. //签到奖励 end
  1519. $result['commiss_diy_name'] = D('Home/Front')->get_config_by_name('commiss_diy_name');
  1520. $result['user_tool_showtype'] = D('Home/Front')->get_config_by_name('user_tool_showtype');
  1521. $result['needAuth'] = $needAuth;
  1522. //判断是否开启邀新有礼begin
  1523. $is_open_invite_invitation = D('Home/Front')->get_config_by_name('is_invite_open_status');
  1524. $is_open_invite_invitation = !empty($is_open_invite_invitation) ? $is_open_invite_invitation : 0;
  1525. $result['is_open_invite_invitation'] = $is_open_invite_invitation;
  1526. //end
  1527. //判断是否开启平台入口
  1528. $isopen_admin_managefront = D('Home/Front')->get_config_by_name('isopen_admin_managefront');
  1529. $isopen_admin_managefront = isset($isopen_admin_managefront) ? $isopen_admin_managefront : 0;
  1530. if($isopen_admin_managefront == 1)
  1531. {
  1532. //检测是否平台管理员
  1533. $platform_admin_member = D('Home/Front')->get_config_by_name('platform_admin_member');
  1534. $platform_admin_member_arr = explode(',', $platform_admin_member );
  1535. if( !empty($platform_admin_member_arr) && in_array( $member_id , $platform_admin_member_arr ) )
  1536. {
  1537. $isopen_admin_managefront = 1;
  1538. }else{
  1539. $isopen_admin_managefront = 0;
  1540. }
  1541. }
  1542. $result['isopen_admin_managefront'] = $isopen_admin_managefront;
  1543. //end..
  1544. echo json_encode( $result );
  1545. die();
  1546. }
  1547. public function supply_apply()
  1548. {
  1549. $gpc = I('request.');
  1550. $token = $gpc['token'];
  1551. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1552. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  1553. {
  1554. echo json_encode( array('code' => 1) );
  1555. die();
  1556. }
  1557. $member_id = $weprogram_token['member_id'];
  1558. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1559. $supp_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  1560. if( !empty($supp_info) )
  1561. {
  1562. echo json_encode( array('code' => 1,'msg' => '您已经申请过了') );
  1563. die();
  1564. }
  1565. $data = array();
  1566. $data['name'] = $gpc['name'];
  1567. $data['shopname'] = $gpc['shopname'];
  1568. $data['member_id'] = $member_id;
  1569. $data['logo'] = $gpc['logo'];
  1570. $data['mobile'] = $gpc['mobile'];
  1571. $data['product'] = $gpc['product'];
  1572. $data['apptime'] = 0;
  1573. $data['state'] = 0;
  1574. $data['addtime'] = time();
  1575. if( empty($data['name']) )
  1576. {
  1577. echo json_encode( array('code' => 1,'msg' => '供应商联系人不能为空') );
  1578. die();
  1579. }
  1580. if( empty($data['shopname']) )
  1581. {
  1582. echo json_encode( array('code' => 1,'msg' => '供应商名称不能为空') );
  1583. die();
  1584. }
  1585. if( empty($data['mobile']) )
  1586. {
  1587. echo json_encode( array('code' => 1,'msg' => '供应商手机号不能为空') );
  1588. die();
  1589. }
  1590. M('lionfish_comshop_supply')->add($data);
  1591. echo json_encode( array('code' => 0) );
  1592. die();
  1593. }
  1594. public function get_member_form_id()
  1595. {
  1596. $gpc = I('request.');
  1597. $token = $gpc['token']; //I('get.token');
  1598. $from_id = $gpc['from_id']; //I('get.from_id');
  1599. if($from_id != 'the formId is a mock one')
  1600. {
  1601. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1602. $member_id = $weprogram_token['member_id'];
  1603. $member_formid_data = array();
  1604. $member_formid_data['member_id'] = $member_id;
  1605. $member_formid_data['state'] = 0;
  1606. $member_formid_data['formid'] = $from_id;
  1607. $member_formid_data['addtime'] = time();
  1608. M('lionfish_comshop_member_formid')->add( $member_formid_data );
  1609. }
  1610. echo json_encode( array('code' => 1) );
  1611. die();
  1612. }
  1613. public function getPhoneNumber()
  1614. {
  1615. $_GPC = I('request.');
  1616. $iv = $_GPC['iv'];
  1617. $encryptedData = $_GPC['encryptedData'];
  1618. $token = $_GPC['token'];
  1619. $res = $this->decryptData($encryptedData, $iv, $token);
  1620. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1621. if(empty($weprogram_token) || empty($weprogram_token['member_id']))
  1622. {
  1623. echo json_encode( array('code' => 1) );
  1624. die();
  1625. }
  1626. $member_id = $weprogram_token['member_id'];
  1627. $phoneNumber = $res->phoneNumber;
  1628. if($phoneNumber){
  1629. $param = array();
  1630. $param['telephone'] = $phoneNumber;
  1631. M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save($param);
  1632. $result = array('code' => 0, 'phoneNumber' =>$phoneNumber);
  1633. } else{
  1634. $result = array('code' => 1, 'msg' => '获取失败,请手动输入手机号', 'error' => $res);
  1635. }
  1636. echo json_encode($result);
  1637. die();
  1638. }
  1639. // 小程序解密
  1640. public function decryptData($encryptedData, $iv, $token)
  1641. {
  1642. $caceh_data = S('wepro_'.$token);
  1643. $session_info = M('lionfish_comshop_weprogram_token')->where( array('token' => $token ) )->find();
  1644. $session_key = '';
  1645. if(!empty($session_info) && !empty($session_info['session_key'])) $session_key = $session_info['session_key'];
  1646. $appid_info = M('lionfish_comshop_config')->where( array('name' => 'wepro_appid') )->find();
  1647. if (strlen($session_key) != 24) {
  1648. return -41001;
  1649. }
  1650. $aesKey=base64_decode($session_key);
  1651. if (strlen($iv) != 24) {
  1652. return -41002;
  1653. }
  1654. $aesIV=base64_decode($iv);
  1655. $aesCipher=base64_decode($encryptedData);
  1656. $result=openssl_decrypt( $aesCipher, "AES-128-CBC", $aesKey, 1, $aesIV);
  1657. $dataObj=json_decode( $result );
  1658. if( $dataObj == NULL )
  1659. {
  1660. return -41003;
  1661. }
  1662. if( $dataObj->watermark->appid != $appid_info['value'] )
  1663. {
  1664. return -41003;
  1665. }
  1666. return $dataObj;
  1667. }
  1668. public function applogin()
  1669. {
  1670. $gpc = I('request.');
  1671. $code = $gpc['code'];
  1672. $appid_info = M('lionfish_comshop_config')->where( array('name' => 'wepro_appid') )->find();
  1673. $appsecret_info = M('lionfish_comshop_config')->where( array('name' => 'wepro_appsecret') )->find();
  1674. $appid = $appid_info['value'];
  1675. $appsecret = $appsecret_info['value'];
  1676. $url = "https://api.weixin.qq.com/sns/jscode2session?appid={$appid}&secret={$appsecret}&js_code={$code}&grant_type=authorization_code";
  1677. $open_str = http_request($url);
  1678. $data = json_decode($open_str, true);
  1679. $expires_time = time() + $data['expires_in'];
  1680. $token = md5($data['openid'].time());
  1681. $token_data = array();
  1682. $token_data['wepro_openid_'.$token] = $data['openid'];
  1683. $token_data['wepro_expires_time_'.$token] = $expires_time;
  1684. $token_data['wepro_session_key_'.$token] = $data['session_key'];
  1685. $token_data['wepro_unionid_'.$token] = $data['unionid'];
  1686. S('wepro_'.$token, $token_data);
  1687. $werp_data = array();
  1688. $werp_data['token'] = $token;
  1689. $result = array('code' => 0, 'token' => $token,'openid' =>$data['openid']);
  1690. echo json_encode($result);
  1691. die();
  1692. }
  1693. public function applogin_do()
  1694. {
  1695. $gpc = I('request.');
  1696. $token = $gpc['token'];
  1697. $nickName = $gpc['nickName'];
  1698. $avatarUrl = $gpc['avatarUrl'];
  1699. $share_id = $gpc['share_id'];
  1700. $community_id = $gpc['community_id'];
  1701. $caceh_data = S('wepro_'.$token);
  1702. $openid = $caceh_data['wepro_openid_'.$token];
  1703. $expires_time = $caceh_data['wepro_expires_time_'.$token];
  1704. $session_key = $caceh_data['wepro_session_key_'.$token];
  1705. $unionid = $caceh_data['wepro_unionid_'.$token];
  1706. $orign_nickname = $nickName;
  1707. $nickName = \Lib\Weixin\WeChatEmoji::clear($nickName);
  1708. $nickName = trim($nickName);
  1709. if( empty($openid) )
  1710. {
  1711. echo json_encode(array('code' =>1,'member_id' => 0));
  1712. die();
  1713. }
  1714. $member_info = M('lionfish_comshop_member')->where( array('we_openid' => $openid) )->find();
  1715. if( !empty($unionid) && empty($member_info) )
  1716. {
  1717. $member_info = M('lionfish_comshop_member')->where( array('unionid' => $unionid) )->find();
  1718. }
  1719. $isblack = 0;
  1720. //是否可以领取礼包: 1、可以,0、不可以,2、老用户, 3、老用户且有邀请人
  1721. $is_can_collect_gift = 0;
  1722. $is_invite_open_status = D('Home/Front')->get_config_by_name('is_invite_open_status');
  1723. if(!empty($member_info) )
  1724. {
  1725. $data = array();
  1726. $data['we_openid'] = trim($openid);
  1727. $data['avatar'] = trim($avatarUrl);
  1728. $data['username'] = trim($nickName);
  1729. $data['full_user_name'] = base64_encode($orign_nickname);
  1730. $data['last_login_time'] = time();
  1731. $data['last_login_ip'] = get_client_ip();
  1732. if(!empty($is_invite_open_status) && $is_invite_open_status == 1) {
  1733. //邀新有礼
  1734. if (empty($member_info['share_id'])) {
  1735. if (intval($share_id) > 0 && $share_id != $member_info['member_id']) {
  1736. $data['share_id'] = intval($share_id);
  1737. //保存邀请记录
  1738. $is_can_collect_gift = D('Home/Invitegift')->insertInvitegiftRecord($share_id, $member_info['member_id'], 1);
  1739. }
  1740. } else {
  1741. $is_can_collect_gift = 3;
  1742. }
  1743. }
  1744. M('lionfish_comshop_member')->where( array('member_id' => $member_info['member_id'] ) )->save( $data );
  1745. /**
  1746. ims_lionfish_comshop_car
  1747. **/
  1748. $old_token_info = M('lionfish_comshop_weprogram_token')->where( array('member_id' => $member_info['member_id'] ) )->find();
  1749. if( !empty($old_token_info) )
  1750. {
  1751. M('lionfish_comshop_car')->where( array('token' => $old_token_info['token'] ) )->delete();
  1752. }
  1753. M('lionfish_comshop_weprogram_token')->where( array('member_id' => $member_info['member_id']) )->delete();
  1754. $member_id = $member_info['member_id'];
  1755. $weprogram_token_data = array();
  1756. $weprogram_token_data['token'] = $token;
  1757. $weprogram_token_data['member_id'] = $member_id;
  1758. $weprogram_token_data['session_key'] = $session_key;
  1759. $weprogram_token_data['expires_in'] = $expires_time;
  1760. M('lionfish_comshop_weprogram_token')->add($weprogram_token_data);
  1761. $isblack = $member_info['isblack'];
  1762. }else {
  1763. $data = array();
  1764. $data['openid'] = $openid;
  1765. $data['we_openid'] = trim($openid);
  1766. $data['unionid'] = trim($unionid);
  1767. $data['reg_type'] = 'weprogram';
  1768. $data['username']=trim($nickName);
  1769. $data['avatar']=trim($avatarUrl);
  1770. $data['last_login_time']=time();
  1771. $data['create_time'] = time();
  1772. $data['last_login_ip'] = get_client_ip();
  1773. $data['full_user_name'] = base64_encode($orign_nickname);
  1774. $data['account_money'] = 0;
  1775. $data['score'] = 0;
  1776. if( $share_id > 0 )
  1777. {
  1778. $commiss_level = D('Home/Front')->get_config_by_name('commiss_level');
  1779. if( !empty($commiss_level) && $commiss_level > 0)
  1780. {
  1781. //开启分销,判断有没有开启分享,跟上级是否分销
  1782. $share_member_info = M('lionfish_comshop_member')->field('comsiss_flag,comsiss_state')->where( array('member_id' => $share_id ) )->find();
  1783. if( $share_member_info['comsiss_flag'] == 1 && $share_member_info['comsiss_state'] ==1 )
  1784. {
  1785. //是分销身份
  1786. $data['agentid'] = $share_id;
  1787. }else{
  1788. //看当前是否开启分享判断,如果没有开启,那么分享id就是0
  1789. $commiss_sharemember_need = D('Home/Front')->get_config_by_name('commiss_sharemember_need');
  1790. if( empty($commiss_sharemember_need) || $commiss_sharemember_need == 0 )
  1791. {
  1792. //$share_id = 0;
  1793. }
  1794. }
  1795. }else{
  1796. //未开启分销:
  1797. //$share_id = 0;
  1798. }
  1799. }
  1800. $data['share_id'] = intval($share_id);
  1801. //是否开启需要审核
  1802. $is_user_shenhe = D('Home/Front')->get_config_by_name('is_user_shenhe');
  1803. if( !empty($is_user_shenhe) && $is_user_shenhe > 0){
  1804. $data['is_comsiss_audit'] = 1;
  1805. }else{
  1806. $data['is_comsiss_audit'] = 0;
  1807. }
  1808. if( !empty($is_user_shenhe) && $is_user_shenhe == 1 )
  1809. {
  1810. $data['is_apply_state'] = 0;
  1811. }else{
  1812. $data['is_apply_state'] = 1;
  1813. }
  1814. $member_id = M('lionfish_comshop_member')->add( $data );
  1815. if($community_id > 0) {
  1816. D('Seller/Community')->in_community_history($member_id, $community_id);
  1817. }
  1818. $weprogram_token_data = array();
  1819. $weprogram_token_data['token'] = $token;
  1820. $weprogram_token_data['member_id'] = $member_id;
  1821. $weprogram_token_data['session_key'] = $session_key;
  1822. $weprogram_token_data['expires_in'] = $expires_time;
  1823. M('lionfish_comshop_weprogram_token')->add($weprogram_token_data);
  1824. if( $share_id > 0 )
  1825. {
  1826. $commiss_level = D('Home/Front')->get_config_by_name('commiss_level');
  1827. if( !empty($commiss_level) && $commiss_level > 0)
  1828. {
  1829. //如果上级已经是分销了。那么就直接划到上级的名下
  1830. //检测是否填写过表单
  1831. $share_member_info = M('lionfish_comshop_member')->field('is_writecommiss_form,comsiss_flag,comsiss_state')->where( array('member_id' =>$share_id ) )->find();
  1832. if( !empty($share_member_info) )
  1833. {
  1834. if( $share_member_info['comsiss_flag'] == 1 && $share_member_info['comsiss_state'] == 1 )
  1835. {
  1836. M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->save( array('agentid' => $share_id ) );
  1837. }
  1838. }
  1839. }
  1840. if(!empty($is_invite_open_status) && $is_invite_open_status == 1){
  1841. //保存邀请记录
  1842. $is_can_collect_gift = D('Home/Invitegift')->insertInvitegiftRecord($share_id,$member_id, 0);
  1843. }
  1844. }
  1845. /**
  1846. if($share_id > 0)
  1847. {
  1848. $share_member = M('member')->field('we_openid')->where( array('member' => $share_id) )->find();
  1849. $member_formid_info = M('member_formid')->where( array('member_id' => $share_id, 'state' => 0) )->find();
  1850. //更新
  1851. if(!empty($member_formid_info))
  1852. {
  1853. $template_data['keyword1'] = array('value' => $data['name'], 'color' => '#030303');
  1854. $template_data['keyword2'] = array('value' => '普通会员', 'color' => '#030303');
  1855. $template_data['keyword3'] = array('value' => date('Y-m-d H:i:s'), 'color' => '#030303');
  1856. $template_data['keyword4'] = array('value' => '恭喜你,获得一位新成员', 'color' => '#030303');
  1857. $pay_order_msg_info = M('config')->where( array('name' => 'wxprog_member_take_in') )->find();
  1858. $template_id = $pay_order_msg_info['value'];
  1859. $url =C('SITE_URL');
  1860. $pagepath = 'pages/dan/me';
  1861. send_wxtemplate_msg($template_data,$url,$pagepath,$share_member['we_openid'],$template_id,$member_formid_info['formid']);
  1862. M('member_formid')->where( array('id' => $member_formid_info['id']) )->save( array('state' => 1) );
  1863. }
  1864. }
  1865. **/
  1866. }
  1867. //如果开启当团长模式,那么就固定去这个团长
  1868. $open_danhead_model = D('Home/Front')->get_config_by_name('open_danhead_model');
  1869. if( empty($open_danhead_model) )
  1870. {
  1871. $open_danhead_model = 0;
  1872. }
  1873. if($open_danhead_model == 1 && $member_id > 0 )
  1874. {
  1875. $default_head = M('lionfish_community_head')->field('id')->where( array('is_default' => 1) )->find();
  1876. if( !empty($default_head) )
  1877. {
  1878. D('Seller/Community')->in_community_history($member_id, $default_head['id']);
  1879. }
  1880. }
  1881. //是否开启需要强制收集表单
  1882. //是否强制手机
  1883. $isparse_formdata = 0;
  1884. $is_get_formdata = D('Home/Front')->get_config_by_name('is_get_formdata');
  1885. if( isset($is_get_formdata) && $is_get_formdata == 1 )
  1886. {
  1887. $now_member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id))->find();
  1888. if( $now_member_info['is_apply_state'] != 1 && $now_member_info['is_write_form'] != 1 )
  1889. {
  1890. $isparse_formdata = 1;
  1891. }
  1892. }
  1893. echo json_encode(array('code' =>1,'member_id' => $member_id ,'isblack' => $isblack , 'isparse_formdata' => $isparse_formdata, 'is_can_collect_gift'=>$is_can_collect_gift ));
  1894. die();
  1895. }
  1896. /**
  1897. 获取版权信息
  1898. **/
  1899. public function get_copyright()
  1900. {
  1901. $gpc = I('request.');
  1902. $info = M('lionfish_comshop_config')->field('value')->where( array('name' => 'footer_copyright_desc') )->find();
  1903. $common_header_backgroundimage = D('Home/Front')->get_config_by_name('user_header_backgroundimage');
  1904. if( !empty($common_header_backgroundimage) )
  1905. {
  1906. $common_header_backgroundimage = tomedia($common_header_backgroundimage);
  1907. }
  1908. $is_show_about_us = D('Home/Front')->get_config_by_name('is_show_about_us');
  1909. // 余额开关
  1910. $is_open_yue_pay = D('Home/Front')->get_config_by_name('is_open_yue_pay');
  1911. if( empty($is_open_yue_pay) )
  1912. {
  1913. $is_open_yue_pay = 0;
  1914. }
  1915. // 积分开关
  1916. $is_show_score = D('Home/Front')->get_config_by_name('is_show_score');
  1917. if( empty($is_show_score) )
  1918. {
  1919. $is_show_score = 0;
  1920. }
  1921. // 订单图标
  1922. $user_order_menu_icons = D('Home/Front')->get_config_by_name('user_order_menu_icons');
  1923. if( !empty($user_order_menu_icons) )
  1924. {
  1925. $user_order_menu_icons = unserialize($user_order_menu_icons);
  1926. foreach ($user_order_menu_icons as &$v) {
  1927. if(!empty($v) )
  1928. $v = tomedia($v);
  1929. }
  1930. }
  1931. // 菜单图片
  1932. $user_tool_icons = D('Home/Front')->get_config_by_name('user_tool_icons');
  1933. if( !empty($user_tool_icons) )
  1934. {
  1935. $user_tool_icons = unserialize($user_tool_icons);
  1936. foreach ($user_tool_icons as &$v) {
  1937. if(!empty($v) )
  1938. $v = tomedia($v);
  1939. }
  1940. }
  1941. //是否关闭团长申请
  1942. $close_community_apply_enter = D('Home/Front')->get_config_by_name('close_community_apply_enter');
  1943. // 退出登录
  1944. $ishow_user_loginout_btn = D('Home/Front')->get_config_by_name('ishow_user_loginout_btn');
  1945. // 供应商自定义名称
  1946. $supply_diy_name = D('Home/Front')->get_config_by_name('supply_diy_name');
  1947. //供应商申请
  1948. $enabled_front_supply = D('Home/Front')->get_config_by_name('enabled_front_supply');
  1949. if( empty($enabled_front_supply) )
  1950. {
  1951. $enabled_front_supply = 0;
  1952. }
  1953. // 客服开关
  1954. $user_service_switch = D('Home/Front')->get_config_by_name('user_service_switch');
  1955. // 提货码显示方式
  1956. $fetch_coder_type = D('Home/Front')->get_config_by_name('fetch_coder_type');
  1957. // 我的拼单
  1958. $show_user_pin = D('Home/Front')->get_config_by_name('show_user_pin');
  1959. $commiss_diy_name = D('Home/Front')->get_config_by_name('commiss_diy_name');
  1960. $show_user_change_comunity = D('Home/Front')->get_config_by_name('show_user_change_comunity');
  1961. $show_user_change_comunity_map = D('Home/Front')->get_config_by_name('show_user_change_comunity_map');
  1962. //是否单团长模式begin
  1963. $open_danhead_model = D('Home/Front')->get_config_by_name('open_danhead_model');
  1964. if( empty($open_danhead_model) )
  1965. {
  1966. $open_danhead_model = 0;
  1967. }
  1968. $default_head_info = array();
  1969. if( $open_danhead_model == 1 )
  1970. {
  1971. $default_head = M('lionfish_community_head')->field('id')->where( array('is_default' => 1) )->find();
  1972. if( !empty($default_head) )
  1973. {
  1974. $default_head_info = D('Home/Front')->get_community_byid($default_head['id'], $where);
  1975. }
  1976. }
  1977. //是否单团长模式end
  1978. //会员中心群接龙开关begin
  1979. $is_open_solitaire = D('Home/Front')->get_config_by_name('is_open_solitaire');
  1980. if( empty($is_open_solitaire) )
  1981. {
  1982. $is_open_solitaire = 0;
  1983. }
  1984. //会员中心群接龙开关 end
  1985. $user_top_font_color = D('Home/Front')->get_config_by_name('user_top_font_color');
  1986. $excharge_nav_name = D('Home/Front')->get_config_by_name('excharge_nav_name');
  1987. $hide_community_change_btn = D('Home/Front')->get_config_by_name('hide_community_change_btn');
  1988. $hide_community_change_word = D('Home/Front')->get_config_by_name('hide_community_change_word');
  1989. $close_community_index = D('Home/Front')->get_config_by_name('close_community_index');
  1990. echo json_encode(
  1991. array(
  1992. 'code' => 0,
  1993. 'data' => $info['value'],
  1994. 'common_header_backgroundimage' => $common_header_backgroundimage,
  1995. 'is_show_about_us'=> $is_show_about_us,
  1996. 'is_show_score' => $is_show_score,
  1997. 'is_open_yue_pay' => $is_open_yue_pay,
  1998. 'user_order_menu_icons' => $user_order_menu_icons,
  1999. 'user_tool_icons' => $user_tool_icons,
  2000. 'close_community_apply_enter' => $close_community_apply_enter,
  2001. 'ishow_user_loginout_btn' => $ishow_user_loginout_btn,
  2002. 'supply_diy_name' => $supply_diy_name,
  2003. 'enabled_front_supply' => $enabled_front_supply,
  2004. 'user_service_switch' => $user_service_switch,
  2005. 'fetch_coder_type' => $fetch_coder_type,
  2006. 'show_user_pin' => $show_user_pin,
  2007. 'commiss_diy_name' => $commiss_diy_name,
  2008. 'show_user_change_comunity' => $show_user_change_comunity,
  2009. 'show_user_change_comunity_map' => $show_user_change_comunity_map,
  2010. 'open_danhead_model' => $open_danhead_model,
  2011. 'default_head_info' => $default_head_info,
  2012. 'is_open_solitaire' => $is_open_solitaire,
  2013. 'user_top_font_color' => $user_top_font_color,
  2014. 'excharge_nav_name' => $excharge_nav_name,
  2015. 'hide_community_change_btn' => $hide_community_change_btn,
  2016. 'hide_community_change_word' => $hide_community_change_word,
  2017. 'close_community_index' => $close_community_index
  2018. )
  2019. );
  2020. }
  2021. public function get_about_us(){
  2022. $about_us = D('Home/Front')->get_config_by_name('personal_center_about_us');
  2023. echo json_encode( array('code' =>0, 'data' => htmlspecialchars_decode( $about_us) ) );
  2024. die();
  2025. }
  2026. // 更新资料
  2027. public function update_user_info(){
  2028. $_GPC = I('request.');
  2029. $result = array();
  2030. $result['code'] = 1;
  2031. $token = $_GPC['token'];
  2032. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2033. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  2034. {
  2035. echo json_encode( array('code' => 1) );
  2036. die();
  2037. }
  2038. $member_id = $weprogram_token['member_id'];
  2039. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  2040. if( empty($member_info) )
  2041. {
  2042. // 未登录
  2043. echo json_encode( array('code' => 2) );
  2044. die();
  2045. }
  2046. $param = array();
  2047. $param['username'] = $_GPC['nickName'];
  2048. $param['avatar'] = $_GPC['avatarUrl'];
  2049. $member_id = $_GPC['memberId'];
  2050. if($member_id && !empty($param['username']) && !empty($param['avatar']) ){
  2051. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save($param);
  2052. $result['code'] = 0;
  2053. }
  2054. echo json_encode($result);
  2055. die();
  2056. }
  2057. //获取账户余额
  2058. public function get_account_money(){
  2059. $gpc = I('request.');
  2060. $result = array();
  2061. $result['code'] = 1;
  2062. $result['data'] = 0;
  2063. $result['msg'] = '';
  2064. $token = $gpc['token'];
  2065. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2066. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  2067. {
  2068. $result['msg'] = '未登录';
  2069. echo json_encode( $result ); //未登录
  2070. die();
  2071. }
  2072. $member_id = $weprogram_token['member_id'];
  2073. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  2074. $chargetype_list = M('lionfish_comshop_chargetype')->order( 'id asc' )->select();
  2075. if( empty($chargetype_list) )
  2076. {
  2077. $chargetype_list = array();
  2078. }
  2079. $excharge_nav_name = D('Home/Front')->get_config_by_name('excharge_nav_name');
  2080. $result['excharge_nav_name'] = $excharge_nav_name;
  2081. if(!empty($member_info)) {
  2082. $result['code'] = 0;
  2083. $result['data'] = $member_info['account_money'];
  2084. $result['chargetype_list'] = $chargetype_list;
  2085. $member_charge_publish = D('Home/Front')->get_config_by_name('member_charge_publish');
  2086. $result['member_charge_publish'] = htmlspecialchars_decode($member_charge_publish);
  2087. $result['recharge_get_money'] = D('Home/Front')->get_config_by_name('recharge_get_money');
  2088. }
  2089. echo json_encode($result);
  2090. die();
  2091. }
  2092. //end...
  2093. //----begin---
  2094. /**
  2095. 配送员收入明细
  2096. controller: user.get_user_distribution_order
  2097. token,
  2098. page
  2099. 返回:code=0 有数据,code=1 没有数据。
  2100. data 配送收入列表,
  2101. **/
  2102. public function get_user_distribution_order()
  2103. {
  2104. $_GPC = I('request.');
  2105. $token = $_GPC['token'];
  2106. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2107. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  2108. {
  2109. echo json_encode( array('code' => 1) );
  2110. die();
  2111. }
  2112. $member_id = $weprogram_token['member_id'];
  2113. $orderdistribution_id = D('Home/LocaltownSnatch')->get_distribution_id_by_member_id($member_id);
  2114. if( $orderdistribution_id <= 0 )
  2115. {
  2116. echo json_encode( array('code' => 3, 'msg' => '不是配送员' ) );
  2117. die();
  2118. }
  2119. $per_page = 20;
  2120. $page = isset($_GPC['page']) ? $_GPC['page'] : 1;
  2121. $offset = ($page - 1) * $per_page;
  2122. $list = array();
  2123. $sql = "select id,order_id,state,shipping_money,is_statement,addtime from ".C('DB_PREFIX')."lionfish_comshop_orderdistribution_order "
  2124. . " where orderdistribution_id = ".$orderdistribution_id." order by id desc limit {$offset},{$per_page}";
  2125. $list = M()->query($sql);
  2126. if( !empty($list) )
  2127. {
  2128. foreach($list as &$value)
  2129. {
  2130. $value['addtime'] = date('Y-m-d H:i:s', $value['addtime']);
  2131. $order_info = M('lionfish_comshop_order')->field('order_num_alias')->where( array('order_id' => $value['order_id'] ) )->find();
  2132. $value['order_num_alias'] = $order_info['order_num_alias'];
  2133. }
  2134. echo json_encode( array('code' => 0, 'data' => $list) );
  2135. die();
  2136. }else{
  2137. echo json_encode( array('code' => 1) );
  2138. die();
  2139. }
  2140. }
  2141. //会员保存 收集表单信息
  2142. public function save_formData()
  2143. {
  2144. $gpc = I('request.');
  2145. $token = $gpc['token'];
  2146. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2147. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  2148. {
  2149. echo json_encode( array('code' => 1) );
  2150. die();
  2151. }
  2152. $member_id = $weprogram_token['member_id'];
  2153. $form_username = I('request.form_username','','htmlspecialchars');
  2154. $form_mobile = I('request.form_mobile','','htmlspecialchars');
  2155. if( empty($form_username) )
  2156. {
  2157. echo json_encode( array('code' => 1, 'message' => '真实姓名不能为空') );
  2158. die();
  2159. }
  2160. if( empty($form_mobile) )
  2161. {
  2162. echo json_encode( array('code' => 1, 'message' => '手机号不能为空') );
  2163. die();
  2164. }
  2165. $form_info = array();
  2166. $form_info['username'] = $form_username;
  2167. $form_info['mobile'] = $form_mobile;
  2168. $up_data = array();
  2169. $up_data['is_write_form'] = 1;
  2170. $up_data['form_info'] = serialize( $form_info );
  2171. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save( $up_data );
  2172. echo json_encode( array('code' => 0) );
  2173. die();
  2174. }
  2175. /**
  2176. * 领券中心
  2177. */
  2178. public function collect_voucher()
  2179. {
  2180. $_GPC = I('request.');
  2181. $token = $_GPC['token'];
  2182. $coupon_id = $_GPC['coupon_id'];
  2183. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2184. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  2185. {
  2186. echo json_encode( array('code' => 1) );
  2187. die();
  2188. }
  2189. $member_id = $weprogram_token['member_id'];
  2190. if( empty($member_id) )
  2191. {
  2192. $result['code'] = 3;
  2193. $result['msg'] = '登录失效';
  2194. echo json_encode($result);
  2195. die();
  2196. }
  2197. if( empty($coupon_id) )
  2198. {
  2199. echo json_encode(array('code'=>1,'msg'=>'优惠券数据错误'));
  2200. die();
  2201. }
  2202. $category_list = M('lionfish_comshop_coupon_category')->field('id,name,status')->where( array('merchid' => 0) )->order('id desc')->select();
  2203. $category = array();
  2204. foreach($category_list as $val)
  2205. {
  2206. $category[$val['id']] = $val;
  2207. }
  2208. $params = "id in (".$coupon_id.") and ((timelimit=1 and end_time>".time().") or timelimit=0)";
  2209. $list = M('lionfish_comshop_coupon')->where($params)->order('add_time desc')->select();
  2210. $result_list = array();
  2211. $k = 0;
  2212. $nowtime = time();
  2213. foreach($list as $key => $val)
  2214. {
  2215. //验证买家是否有 优惠券
  2216. $count = M('lionfish_comshop_coupon_list')->where(array('voucher_id'=>$val['id'],'user_id'=>$member_id))->count();
  2217. if($count > 0){
  2218. $val['is_collect'] = 1;
  2219. }else{
  2220. $val['is_collect'] = 0;
  2221. }
  2222. //判断买家 是否未使用优惠券
  2223. //is_use 0 未使用,1、已使用,2 用户不存在优惠券数据
  2224. if($val['is_collect'] == 1){
  2225. $no_use_count = M('lionfish_comshop_coupon_list')->where(array('voucher_id'=>$val['id'],'user_id'=>$member_id,'consume'=>'N'))->count();
  2226. if($no_use_count > 0){
  2227. $val['is_use'] = 0;
  2228. }else{
  2229. $val['is_use'] = 1;
  2230. }
  2231. }else{
  2232. $val['is_use'] = 2;
  2233. }
  2234. //判断买家 获取的优惠券是否过期
  2235. //is_over 0、未过期,1、已过期,2 用户不存在优惠券数据
  2236. // if($val['end_time'] < $nowtime){
  2237. // $val['is_over'] = 1;
  2238. // }else{
  2239. if($val['is_collect'] == 1){
  2240. $no_over_count = M('lionfish_comshop_coupon_list')->where(array('voucher_id'=>$val['id'],'user_id'=>$member_id))->where('end_time > '.$nowtime)->count();
  2241. if($no_over_count > 0){
  2242. $val['is_over'] = 0;
  2243. }else{
  2244. $val['is_over'] = 1;
  2245. }
  2246. }else{
  2247. $val['is_over'] = 2;
  2248. }
  2249. // }
  2250. $val['tag'] = $category[$val['catid']]['name'];
  2251. $val['begin_time'] = date('Y.m.d H:i:s', $val['begin_time']);
  2252. $val['end_time'] = date('Y.m.d H:i:s', $val['end_time']);
  2253. $result_list[$k] = $val;
  2254. $k++;
  2255. }
  2256. if( empty($result_list) )
  2257. {
  2258. echo json_encode(array('code'=>1,'msg'=>'暂无优惠券数据'));
  2259. die();
  2260. }else {
  2261. echo json_encode( array('code' =>0, 'list' => $result_list) );
  2262. }
  2263. }
  2264. /**
  2265. * 获取用户真实姓名和手机号
  2266. */
  2267. public function get_realname_tel() {
  2268. $_GPC = I('request.');
  2269. $token = $_GPC['token'];
  2270. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2271. if(empty($weprogram_token) || empty($weprogram_token['member_id']))
  2272. {
  2273. echo json_encode( array('code' => 1) );
  2274. die();
  2275. }
  2276. $member_id = $weprogram_token['member_id'];
  2277. $member_info = M('lionfish_comshop_member')->field('realname,telephone')->where( array('member_id' => $member_id) )->find();
  2278. $result = array('code' => 0, 'data' =>$member_info);
  2279. echo json_encode($result);
  2280. die();
  2281. }
  2282. public function update_realname_tel() {
  2283. $_GPC = I('request.');
  2284. $token = $_GPC['token'];
  2285. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2286. if(empty($weprogram_token) || empty($weprogram_token['member_id']))
  2287. {
  2288. echo json_encode( array('code' => 1) );
  2289. die();
  2290. }
  2291. $member_id = $weprogram_token['member_id'];
  2292. $result['code'] = 2;
  2293. $param = array();
  2294. $param['realname'] = $_GPC['realname'];
  2295. $param['telephone'] = $_GPC['telephone'];
  2296. if( $member_id ){
  2297. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->save($param);
  2298. $result['code'] = 0;
  2299. } else {
  2300. $result['message'] = "用户不存在";
  2301. }
  2302. echo json_encode($result);
  2303. die();
  2304. }
  2305. }