ApiuserController.class.php 91 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. * ==========================================================================
  6. * @link http://www.liofis.com/
  7. * @copyright Copyright (c) 2015 liofis.com.
  8. * @license http://www.liofis.com/license.html License
  9. * ==========================================================================
  10. *
  11. * @author fish
  12. * 处理订单相关内容
  13. */
  14. namespace Home\Controller;
  15. class ApiuserController extends CommonController {
  16. protected function _initialize()
  17. {
  18. parent::_initialize();
  19. $this->cur_page = 'apicheckout';
  20. $this->member_id = 1;
  21. }
  22. public function get_user_info()
  23. {
  24. $token = I('get.token');
  25. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  26. $member_id = $weprogram_token['member_id'];
  27. $member_info = M('member')->field('name,avatar,score,member_id,comsiss_flag,level_id,account_money')->where( array('member_id' => $member_id) )->find();
  28. $opencommiss = C('opencommiss');
  29. $is_open_integral = C('is_open_integral'); $level_name = C('member_default_levelname'); $member_info['level'] = 0;
  30. if(!empty($member_info['level_id']) && $member_info['level_id'] > 0) { $level_info = M('member_level')->where( array('id' => $member_info['level_id']) )->find(); if( !empty($level_info) ) { $level_name = $level_info['levelname']; } //level $member_info['level'] = $level_info['level']; } $config_name = M('config')->where( array('name' => 'is_yue_open') )->find(); $member_level_is_open_arr = M('config')->where( array('name' => 'member_level_is_open') )->find(); $member_level_list = array(); if( $member_level_is_open_arr['value'] == 1) { $member_level_list = M('member_level')->order('id asc')->select(); if( !empty($member_level_list) ) { foreach( $member_level_list as $key => $val ) { $val['discount'] = $val['discount'] / 10; $member_level_list[$key] = $val; } } }
  31. echo json_encode( array('code' => 0,'member_level_list' => $member_level_list,'level_name' => $level_name,'member_level_is_open' => $member_level_is_open_arr['value'],'is_yue_open' => $config_name['value'], 'opencommiss' => $opencommiss,'data' =>$member_info ,'is_open_integral' => $is_open_integral) ); die();
  32. } public function myask_detail() { $id = I('get.id'); $blog_info = M('blog')->where( array('blog_id' => $id) )->find(); $blog_content = M('blog_content')->where( array('blog_id' => $id) )->find(); $info = array(); $info['title'] = $blog_info['title']; $info['update_time'] = $blog_info['update_time']; $info['image'] = C('SITE_URL').'/Uploads/image/'. $blog_info['image']; $qian = array( "/Uploads/image" ); $hou = array( C('SITE_URL') . "/Uploads/image" ); $blog_content['content'] = str_replace($qian, $hou, $blog_content['content']); $info['summary'] = $blog_content['summary']; $info['content'] = htmlspecialchars_decode($blog_content['content']); echo json_encode( array('code' => 0, 'info' => $info) ); die(); } public function myask_list() { $type = I('get.type',1); $page = I('get.page',1); $pre_page = I('get.pre_page',15); $offset = ($page -1) * $pre_page; $condition = array('type' => 'question'); $list = M('blog')->where($condition)->order('blog_id desc')->limit($offset,$pre_page)->select(); $now_time = time(); foreach($list as $key => $val) { $val['create_time'] = date('Y.m.d H:i:s', $val['create_time']); $list[$key] = $val; } $this->type = $type; $this->list = $list; if( empty($list) ) { echo json_encode( array('code' =>1) ); }else { echo json_encode( array('code' =>0, 'list' => $list) ); } } public function get_address_info() { $token = I('get.token'); $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find(); $member_id = $weprogram_token['member_id']; $id = I('get.id', 0); $address_info = M('address')->where( array('address_id' => $id) )->find(); $province_info = M('area')->field('area_name')->where( array('area_id' => $address_info['province_id']) )->find(); $city_info = M('area')->field('area_name')->where( array('area_id' => $address_info['city_id']) )->find(); $country_info = M('area')->field('area_name')->where( array('area_id' => $address_info['country_id']) )->find(); $address_info['province_name'] = $province_info['area_name']; $address_info['city_name'] = $city_info['area_name']; $address_info['country_name'] = $country_info['area_name']; echo json_encode( array('code' => 0 , 'info' =>$address_info) ); die(); } public function set_default_address() { $token = I('get.token'); $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find(); $member_id = $weprogram_token['member_id']; $id = I('get.id', 0); M('address')->where( array('member_id' => $member_id) )->save( array('is_default' => 0) ); M('address')->where( array('address_id' => $id) )->save( array('is_default' => 1) ); echo json_encode( array('code' => 0) ); die(); } public function del_address() { $token = I('get.token'); $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find(); $member_id = $weprogram_token['member_id']; $id = I('get.id', 0); M('address')->where( array('address_id' => $id) )->delete( ); echo json_encode( array('code' => 0) ); die(); } public function getaddress() { $token = I('get.token'); $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find(); $member_id = $weprogram_token['member_id']; $address_list = M('address')->where( array('member_id' => $member_id) )->order( "is_default desc , address_id desc " )->select(); foreach( $address_list as $key => $val ) { //province_id city_id country_id $province_info = M('area')->field('area_name')->where( array('area_id' => $val['province_id']) )->find(); $city_info = M('area')->field('area_name')->where( array('area_id' => $val['city_id']) )->find(); $country_info = M('area')->field('area_name')->where( array('area_id' => $val['country_id']) )->find(); $val['province_name'] = $province_info['area_name']; $val['city_name'] = $city_info['area_name']; $val['country_name'] = $country_info['area_name']; $address_list[$key] = $val; } if( !empty($address_list) ) { echo json_encode( array('code' => 0, 'list' => $address_list) ); die(); }else{ echo json_encode( array('code' => 1) ); die(); } }
  33. public function apply()
  34. {
  35. //token
  36. $token = I('get.token');
  37. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  38. $member_id = $weprogram_token['member_id'];
  39. $result = array('code' => 0);
  40. $member_commiss_apply = M('member_commiss_apply')->where(array('member_id' =>$member_id, 'state' =>0))->find();
  41. if(!empty($member_commiss_apply)) {
  42. $result['code'] = 1;
  43. $result['msg'] = '您已经申请,等待审核!';
  44. } else {
  45. $data = array();
  46. $data['member_id'] = $member_id;
  47. $data['state'] = 0;
  48. $data['addtime'] = time();
  49. $res = M('member_commiss_apply')->add($data);
  50. if($res){
  51. } else {
  52. $result['code'] = 1;
  53. $result['msg'] = '提交失败';
  54. }
  55. }
  56. echo json_encode($result);
  57. die();
  58. }
  59. //member_formid
  60. public function get_member_form_id()
  61. {
  62. //token/' + token + '/from_id/' + from_id
  63. $token = I('get.token');
  64. $from_id = I('get.from_id');
  65. if($from_id != 'the formId is a mock one')
  66. {
  67. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  68. $member_id = $weprogram_token['member_id'];
  69. $member_formid_data = array();
  70. $member_formid_data['member_id'] = $member_id;
  71. $member_formid_data['state'] = 0;
  72. $member_formid_data['formid'] = $from_id;
  73. $member_formid_data['addtime'] = time();
  74. M('member_formid')->add($member_formid_data);
  75. }
  76. echo json_encode( array('code' => 1) );
  77. die();
  78. }
  79. public function get_user_addresslist()
  80. {
  81. $token = I('get.token');
  82. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  83. $member_id = $weprogram_token['member_id'];
  84. //group ->group('user_id,test_time')
  85. $list=M('address')->where(array('member_id'=>$member_id))->group('province_id,country_id,city_id,address')->order('address_id desc ')->select();
  86. if(!empty($list)){
  87. foreach ($list as $k => $v) {
  88. $list[$k]['id'] = $v['address_id'];
  89. }
  90. }
  91. if(!empty($list))
  92. {
  93. foreach($list as &$address)
  94. {
  95. $province_info = M('area')->where( array('area_id' => $address['province_id']) )->find();
  96. $city_info = M('area')->where( array('area_id' => $address['city_id']) )->find();
  97. $country_info = M('area')->where( array('area_id' => $address['country_id']) )->find();
  98. $address['province_name'] = $province_info['area_name'];
  99. $address['city_name'] = $city_info['area_name'];
  100. $address['country'] = $country_info['area_name'];
  101. }
  102. }
  103. if( !empty($list) )
  104. {
  105. echo json_encode( array('code' => 0 , 'data' => $list) );
  106. die();
  107. } else{
  108. echo json_encode( array('code' => 1) );
  109. die();
  110. }
  111. }
  112. public function group_orders()
  113. {
  114. $token = I('get.token');
  115. $type = I('get.type',0);
  116. $page = I('get.page',0);//当前第几页
  117. $pre_page = I('get.pre_page',10);//每页数量
  118. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  119. $member_id = $weprogram_token['member_id'];
  120. $data_json = file_get_contents('php://input');
  121. $data = json_decode($data_json, true);
  122. $offset = ($page -1) * $pre_page;
  123. $where = ' ';
  124. if($type == 1)
  125. {
  126. $where .= ' and p.state = 0 and p.end_time >'.time();
  127. } else if($type == 2){
  128. $where .= ' and p.state = 1 ';
  129. } else if($type == 3){
  130. $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().')) ';
  131. }else if($type == 0){
  132. //$where .= ' and o.order_status_id != 3 ';
  133. }
  134. $sql = "select g.name,og.goods_images,g.price as orign_price,o.voucher_credit,g.fan_image,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')."order as o, ".C('DB_PREFIX')."order_goods as og,
  135. ".C('DB_PREFIX')."pin as p,".C('DB_PREFIX')."goods as g ,".C('DB_PREFIX')."order_status as os ,".C('DB_PREFIX')."pin_order as po
  136. 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.goods_id and po.pin_id = p.pin_id
  137. and o.member_id = ".$member_id." {$where} order by o.date_added desc limit {$offset},{$pre_page}";
  138. $list = M()->query($sql);
  139. foreach($list as $key => $val)
  140. {
  141. $val['price'] = round($val['price'],2);
  142. if($val['shipping_fare']<=0.001 || $val['delivery'] == 'pickup')
  143. {
  144. $val['shipping_fare'] = '免运费';
  145. }else{
  146. $val['shipping_fare'] = '运费:'.$val['shipping_fare'];
  147. }
  148. //delivery
  149. if($val['order_status_id'] == 10)
  150. {
  151. $val['status_name'] = '等待退款';
  152. }
  153. else if($val['order_status_id'] == 4 && $val['delivery'] =='pickup')
  154. {
  155. //delivery 6
  156. $val['status_name'] = '待自提';
  157. //已自提
  158. }
  159. else if($val['order_status_id'] == 6 && $val['delivery'] =='pickup')
  160. {
  161. //delivery 6
  162. $val['status_name'] = '已自提';
  163. }else if($val['order_status_id'] == 10)
  164. {
  165. $val['status_name'] = '等待退款';
  166. }else if($val['order_status_id'] == 1 && $val['type'] == 'lottery')
  167. {
  168. //等待开奖
  169. //一等奖
  170. if($val['lottery_win'] == 1)
  171. {
  172. $val['status_name'] = '一等奖';
  173. }else {
  174. $val['status_name'] = '等待开奖';
  175. }
  176. }
  177. //p.state,p.end_time
  178. $pin_type = $val['state'];
  179. if($pin_type == 0 && $val['end_time'] <= time() )
  180. {
  181. $pin_type = 2;
  182. }
  183. switch($pin_type)
  184. {
  185. case 0:
  186. if($val['order_status_id'] == 2)
  187. {
  188. $val['status_name'] = $val['status_name'];
  189. }else{
  190. $val['status_name'] = '拼团中,'.$val['status_name'];
  191. }
  192. break;
  193. case 1:
  194. //7
  195. if($val['order_status_id'] == 7)
  196. {
  197. $val['status_name'] = '拼团成功,售后已退款';
  198. }else if($val['order_status_id'] == 1)
  199. {
  200. $val['status_name'] = '拼团成功,待发货';
  201. }
  202. else{
  203. $val['status_name'] = '拼团成功,'.$val['status_name'];
  204. }
  205. break;
  206. case 2:
  207. $val['status_name'] = '拼团失败,'.$val['status_name'];
  208. //order_status_id 2
  209. if($val['order_status_id'] == 2)
  210. {
  211. $val['status_name'] = '拼团失败';
  212. }
  213. break;
  214. }
  215. $val['goods_images']= C('SITE_URL') .resize($val['goods_images'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  216. //s_true_name seller_id option_str
  217. $order_option_list = M('order_option')->where( array('order_goods_id' =>$val['order_goods_id']) )->select();
  218. foreach($order_option_list as $option)
  219. {
  220. $val['option_str'][] = $option['value'];
  221. }
  222. if( !isset($val['option_str']) )
  223. {
  224. $val['option_str'] = '';
  225. }else{
  226. $val['option_str'] = implode(',', $val['option_str']);
  227. }
  228. $store_info = M('seller')->field('s_true_name,s_logo')->where('s_id='.$val['store_id'])->find();
  229. $store_info['s_logo'] = C('SITE_URL').'/Uploads/image/'.$store_info['s_logo'];
  230. $val['store_info'] = $store_info;
  231. unset($val['fan_image']);
  232. //unset($val['goods_images']);
  233. $val['price'] = round($val['price'],2);
  234. $val['total'] = round($val['total'],2);
  235. if($val['delivery'] == 'pickup')
  236. {
  237. $val['total'] = round($val['total'],2) - round($val['voucher_credit'],2);
  238. }else{
  239. $val['total'] = round($val['total'],2)+round($val['shipping_fare'],2) - round($val['voucher_credit'],2);
  240. }
  241. $val['orign_price'] = round($val['orign_price'],2);
  242. if($val['state'] == 0 && $val['end_time'] < time())
  243. {
  244. $val['state'] = 2;
  245. }
  246. $list[$key] = $val;
  247. }
  248. $need_data = array();
  249. $need_data['code'] = 1;
  250. if( !empty($list) )
  251. {
  252. $need_data['code'] = 0;
  253. $need_data['data'] = $list;
  254. }
  255. echo json_encode($need_data);
  256. die();
  257. }
  258. function fav_toggle()
  259. {
  260. $token = I('get.token');
  261. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  262. $member_id = $weprogram_token['member_id'];
  263. if( empty($member_id) )
  264. {
  265. $result['code'] = 3;
  266. $result['msg'] = '登录失效';
  267. echo json_encode($result);
  268. die();
  269. }
  270. $goods_id = I('goods_id');
  271. $goods_model = D('Home/Goods');
  272. //1 取消收藏 2 添加收藏
  273. $code = $goods_model->user_fav_goods_toggle($goods_id, $member_id);
  274. echo json_encode( array('code' => $code) );
  275. die();
  276. }
  277. public function fav_storetoggle()
  278. {
  279. $token = I('get.token');
  280. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  281. $member_id = $weprogram_token['member_id'];
  282. if( empty($member_id) )
  283. {
  284. $result['code'] = 3;
  285. $result['msg'] = '登录失效';
  286. echo json_encode($result);
  287. die();
  288. }
  289. $store_id = I('store_id');
  290. $goods_model = D('Home/Goods');
  291. //1 取消收藏 2 添加收藏
  292. $code = $goods_model->user_fav_store_toggle($store_id, $member_id);
  293. echo json_encode( array('code' => $code) );
  294. die();
  295. }
  296. public function myfavshop()
  297. {
  298. $page = I('get.page',1);
  299. $pre_page = I('get.pre_page',6);
  300. $offset = ($page -1) * $pre_page;
  301. $token = I('get.token');
  302. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  303. $member_id = $weprogram_token['member_id'];
  304. $list = M('user_favstore')->where( array('member_id' => $member_id) )->order('add_time desc')->limit($offset,$pre_page)->select();
  305. foreach($list as $key => $val)
  306. {
  307. $tp_store = M('seller')->field('s_true_name,s_logo')->where( array('s_id' => $val['store_id']) )->find();
  308. $tp_store['logo'] = C('SITE_URL').'Uploads/image/'. $tp_store['s_logo'];
  309. unset($tp_store['s_logo']);
  310. $store_goods = M('goods')->field('goods_id,name,quantity,seller_count,virtual_count,image,price,danprice')->where( array('store_id' => $val['store_id'],'status'=>1,'quantity' =>array('gt',0)) )->order('is_index_show desc, seller_count desc')->limit(3)->select();
  311. foreach($store_goods as $kk => $vv)
  312. {
  313. $vv['image'] = C('SITE_URL').'Uploads/image/'. $vv['image'];
  314. $vv['seller_count'] = $vv['seller_count'] + $vv['virtual_count'];
  315. unset($vv['virtual_count']);
  316. $store_goods[$kk] = $vv;
  317. }
  318. $val['tp_store'] = $tp_store;
  319. $val['goods'] = $store_goods;
  320. //$val = $tp_goods;
  321. $list[$key] = $val;
  322. }
  323. if( empty($list) )
  324. {
  325. echo json_encode( array('code' => 1) );
  326. die();
  327. } else {
  328. echo json_encode( array('code' => 0 , 'data' => $list) );
  329. die();
  330. }
  331. }
  332. public function myvoucherlist()
  333. {
  334. $type = I('get.type',1);
  335. $page = I('get.page',1);
  336. $pre_page = I('get.pre_page',4);
  337. $offset = ($page -1) * $pre_page;
  338. $token = I('get.token');
  339. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  340. $member_id = $weprogram_token['member_id'];
  341. //$member_id = 1;
  342. //$type = 3;
  343. if( empty($member_id) )
  344. {
  345. $result['code'] = 3;
  346. $result['msg'] = '登录失效';
  347. echo json_encode($result);
  348. die();
  349. }
  350. $condition = "user_id=".$member_id;
  351. if($type == 1)
  352. {
  353. //未使用
  354. $condition .= " and consume= 'N' and end_time> ".time();
  355. } else if($type == 2){
  356. //已使用
  357. $condition .= " and (consume= 'Y' or end_time< ".time().")";
  358. }
  359. $list = M('voucher_list')->field('voucher_title,store_id,type,credit,limit_money,consume,begin_time,end_time')->where($condition)->order('add_time desc')->limit($offset,$pre_page)->select();
  360. $now_time = time();
  361. foreach($list as $key => $val)
  362. {
  363. $store_info = M('seller')->field('s_true_name,s_logo')->where( array('s_id' => $val['store_id']) )->find();
  364. $val['store_name'] = $store_info['s_true_name'];
  365. $store_info['s_logo'] = C('SITE_URL').'/Uploads/image/'.$store_info['s_logo'];
  366. $val['s_logo'] = $store_info['s_logo'];
  367. //now_time
  368. $val['is_over'] = 0;
  369. if($val['end_time'] < $now_time)
  370. {
  371. $val['is_over'] = 1;
  372. }
  373. if($val['consume'] == 'Y')
  374. {
  375. $val['is_over'] = 1;
  376. }
  377. $val['begin_time'] = date('Y.m.d H:i:s', $val['begin_time']);
  378. $val['end_time'] = date('Y.m.d H:i:s', $val['end_time']);
  379. $list[$key] = $val;
  380. }
  381. $this->type = $type;
  382. $this->list = $list;
  383. if( empty($list) )
  384. {
  385. echo json_encode( array('code' =>1) );
  386. }else {
  387. echo json_encode( array('code' =>0, 'list' => $list) );
  388. }
  389. }
  390. public function myscores() { $page = I('get.page',1); $type = I('get.type','all'); $pre_page = I('get.pre_page',10); $offset = ($page -1) * $pre_page; $token = I('get.token'); $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find(); $member_id = $weprogram_token['member_id']; if( empty($member_id) ) { $result['code'] = 3; $result['msg'] = '登录失效'; echo json_encode($result); die(); } $where = ""; if($type == 'all') { }else if($type =='in'){ $where = " and in_out = 'in' "; }else if($type == 'out'){ $where = " and in_out = 'out' "; } $sql ="select * from ".C('DB_PREFIX')."integral_flow where member_id = {$member_id} {$where} and state = 1 order by addtime desc limit {$offset},{$pre_page} "; $list = M()->query($sql); foreach($list as $key => $val) { //type //'goodsbuy','refundorder','system_add','system_del','orderbuy' $val['score'] = intval($val['score']); switch($val['type']) { case 'goodsbuy': $val['typename'] = '商品购买奖励积分'; $val['score'] = '+'.$val['score']; break; case 'orderbuy': $val['typename'] = '积分兑换商品'; $val['score'] = -$val['score']; break; case 'refundorder': $val['typename'] = '订单退款'; $val['score'] = -$val['score']; break; case 'system_add': $val['typename'] = '后台充值'; $val['score'] = '+'.$val['score']; break; case 'system_del': $val['typename'] = '后台扣除'; $val['score'] = -$val['score']; break; //score } $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']); $list[$key] = $val; } //myscores $integral_rules = C('integral_description'); $qian=array("\r\n"); $hou=array("@F@"); $integral_rules_str = str_replace($qian,$hou,$integral_rules); $integral_rules_str = explode('@F@',$integral_rules_str); if( empty($list) ) { echo json_encode( array('code' => 1,'integral_rules_str' => $integral_rules_str) ); die(); } else { echo json_encode( array('code' => 0 , 'data' => $list,'integral_rules_str' => $integral_rules_str) ); die(); } }
  391. public function myfavgoods()
  392. {
  393. $page = I('get.page',1);
  394. $pre_page = I('get.pre_page',6);
  395. $offset = ($page -1) * $pre_page;
  396. $token = I('get.token');
  397. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  398. $member_id = $weprogram_token['member_id'];
  399. //$member_id = 1;
  400. if( empty($member_id) )
  401. {
  402. $result['code'] = 3;
  403. $result['msg'] = '登录失效';
  404. echo json_encode($result);
  405. die();
  406. }
  407. $sql ="select g.goods_id,g.name,g.quantity,g.seller_count,g.virtual_count,g.image,g.price,g.danprice,f.* from
  408. ".C('DB_PREFIX')."user_favgoods as f , ".C('DB_PREFIX')."goods as g where f.goods_id = g.goods_id and ( g.type ='pintuan' or g.type = 'lottery' ) and f.member_id = {$member_id}
  409. order by f.add_time desc limit {$offset},{$pre_page} ";
  410. $list = M()->query($sql);
  411. //$list = M('user_favgoods')->where( array('member_id' => $member_id) )->order('add_time desc')->limit($offset,$pre_page)->select();
  412. $goods_model = D('Home/goods');
  413. foreach($list as $key => $val)
  414. {
  415. //$tp_goods = M('goods')->field('goods_id,name,quantity,seller_count,virtual_count,image,price,danprice')->where( array('goods_id' => $val['goods_id']) )->find();
  416. //if(empty($tp_goods))
  417. //{
  418. // continue;
  419. //}
  420. $price_arr = $goods_model->get_goods_price($val['goods_id']);
  421. $val['seller_count'] = $val['seller_count'] + $val['virtual_count'];
  422. //danprice
  423. $val['danprice'] = $price_arr['price'];
  424. $val['image'] = C('SITE_URL').'Uploads/image/'. $val['image'];
  425. //$val = $tp_goods;
  426. $list[$key] = $val;
  427. }
  428. if( empty($list) )
  429. {
  430. echo json_encode( array('code' => 1) );
  431. die();
  432. } else {
  433. echo json_encode( array('code' => 0 , 'data' => $list) );
  434. die();
  435. }
  436. }
  437. public function order_comment()
  438. {
  439. $order_id = I('get.order_id',0);
  440. $token = I('get.token');
  441. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  442. $member_id = $weprogram_token['member_id'];
  443. if( empty($member_id) )
  444. {
  445. $result['code'] = 3;
  446. $result['msg'] = '登录失效';
  447. echo json_encode($result);
  448. die();
  449. }
  450. $order_goods = M('order_goods')->where( array('order_id' => $order_id) )->find();
  451. $order_option_list = M('order_option')->where( array('order_goods_id' =>$order_goods['order_goods_id']) )->select();
  452. $order_goods['goods_images']= C('SITE_URL') .resize($order_goods['goods_images'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  453. //price orign_price
  454. $goods_filed = M('goods')->field('price')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  455. $order_goods['orign_price'] = $goods_filed['price'];
  456. foreach($order_option_list as $option)
  457. {
  458. $order_goods['option_str'][] = $option['value'];
  459. }
  460. if( !isset($order_goods['option_str']) )
  461. {
  462. $order_goods['option_str'] = '';
  463. }else{
  464. $order_goods['option_str'] = implode(',', $order_goods['option_str']);
  465. }
  466. $order_goods['price'] = round($order_goods['price'],2);
  467. $order_goods['orign_price'] = round($order_goods['orign_price'],2);
  468. $goods_info = M('goods')->field('image')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  469. $goods_image = resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  470. if(!empty($goods_image['fan_image'])){
  471. $goods_image = C('SITE_URL'). resize($goods_info['fan_image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  472. }else {
  473. $goods_image = C('SITE_URL').resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  474. }
  475. echo json_encode( array('code' => 0 ,'order_goods' =>$order_goods, 'goods_image' => $goods_image,'goods_id' =>$order_goods['goods_id']) );
  476. die();
  477. //$this->goods_image = $goods_image;
  478. //$this->order_goods = $order_goods;
  479. //$this->display();
  480. }
  481. /**
  482. * 提交评论信息
  483. */
  484. public function sub_comment()
  485. {
  486. //cur_rel:cur_rel,cur2_rel:cur2_rel,cur3_rel:cur3_rel,imgs:imgs,
  487. $data_json = file_get_contents('php://input');
  488. $data = json_decode($data_json, true);
  489. $order_id = $data['order_id'];
  490. $goods_id = $data['goods_id'];
  491. $cur_rel = empty($data['cur_rel']) ? 5:$data['cur_rel'];
  492. $cur2_rel = empty($data['cur2_rel']) ? 5:$data['cur2_rel'];
  493. $cur3_rel = empty($data['cur3_rel']) ? 5:$data['cur3_rel'];
  494. $imgs = $data['imgs'];
  495. $comment_content = htmlspecialchars($data['comment_content']);
  496. $token = I('get.token');
  497. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  498. $member_id = $weprogram_token['member_id'];
  499. if( empty($member_id) )
  500. {
  501. $result['code'] = 3;
  502. $result['msg'] = '登录失效';
  503. echo json_encode($result);
  504. die();
  505. }
  506. //goods_name
  507. //goods_image
  508. //order_num_alias
  509. //avatar
  510. //user_name
  511. $order_goods = M('order_goods')->field('name,goods_images')->where( array('order_id' => $order_id,'goods_id' => $goods_id) )->find();
  512. $order_info = M('order')->field('order_num_alias')->where( array('order_id' => $order_id) )->find();
  513. $member_info = M('member')->field('uname,avatar')->where( array('member_id' => $member_id) )->find();
  514. $data = array();
  515. $data['member_id'] = $member_id;
  516. $data['order_id'] = $order_id;
  517. $data['goods_id'] = $goods_id;
  518. $data['goods_name'] = $order_goods['name'];
  519. $data['goods_image'] = $order_goods['goods_images'];
  520. $data['order_num_alias'] = $order_info['order_num_alias'];
  521. $data['avatar'] = $member_info['avatar'];
  522. $data['user_name'] = $member_info['uname'];
  523. $data['star'] = $cur_rel;
  524. $data['star2'] = $cur2_rel;
  525. $data['star3'] = $cur3_rel;
  526. $data['images'] = serialize($imgs);
  527. $data['is_picture'] = empty($imgs) ? 0 :1;
  528. $data['content'] = $comment_content;
  529. $data['add_time'] = time();
  530. M('order_comment')->add($data);
  531. //order_comment $goods_info = M('goods')->field('store_id')->where( array('goods_id' => $goods_id) )->find(); $group_info = M('group')->field('seller_id')->where( array('seller_id' => $goods_info['store_id']) )->find(); if( !empty($group_info) ) { $quan_model = D('Home/Quan'); $post_data['member_id'] = $member_id; $post_data['group_id'] = $group_info['seller_id']; $post_data['goods_id'] = $goods_id; $post_data['title'] = $comment_content; $post_data['content'] = serialize($imgs); $rs = $quan_model->send_group_post($post_data); }
  532. $order_history = array();
  533. $order_history['order_id'] = $order_id;
  534. $order_history['order_status_id'] = 11;
  535. $order_history['notify'] = 0;
  536. $order_history['comment'] = '用户提交评论,订单完成。';
  537. $order_history['date_added']=time();
  538. M('order_history')->add($order_history);
  539. M('order')->where( array('order_id' =>$order_id ) )->save( array('order_status_id' => 11) );
  540. echo json_encode( array('code' => 1) );
  541. die();
  542. }
  543. /**
  544. 获取订单金额
  545. **/
  546. public function get_order_money()
  547. {
  548. $token = I('get.token');
  549. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  550. $member_id = $weprogram_token['member_id'];
  551. if( empty($member_id) )
  552. {
  553. $result['code'] = 0;
  554. $result['msg'] = '登录失效';
  555. echo json_encode($result);
  556. die();
  557. }
  558. $order_id = I('get.order_id');
  559. //total
  560. $order_info = M('order')->field('total')->where( array('order_id' => $order_id ,'member_id' => $member_id) )->find();
  561. $order_info['total'] = round($order_info['total'], 2);
  562. echo json_encode( array('code' =>1, 'total' => $order_info['total']) );
  563. die();
  564. }
  565. /**
  566. 退款提交
  567. **/
  568. public function refund_sub()
  569. {
  570. $token = I('get.token');
  571. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  572. $member_id = $weprogram_token['member_id'];
  573. if( empty($member_id) )
  574. {
  575. $result['code'] = 0;
  576. $result['msg'] = '登录失效';
  577. echo json_encode($result);
  578. die();
  579. }
  580. $data_json = file_get_contents('php://input');
  581. $data = json_decode($data_json, true);
  582. //$data = I('post.');
  583. $order_id = $data['order_id'];
  584. $order_info = M('order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->find();
  585. if(empty($order_info) )
  586. {
  587. $result['code'] = 0;
  588. $result['msg'] = '没有此订单';
  589. echo json_encode($result);
  590. die();
  591. }
  592. $result = array('code' => 0);
  593. $refdata = array();
  594. $refdata['order_id'] = intval($data['order_id']);
  595. $refdata['ref_type'] = intval($data['complaint_type']);
  596. $refdata['ref_money'] = floatval($data['complaint_money']);
  597. $refdata['ref_member_id'] = $member_id;
  598. $refdata['ref_name'] = htmlspecialchars($data['complaint_reason']);
  599. $refdata['ref_mobile'] = htmlspecialchars($data['complaint_mobile']);
  600. $refdata['ref_description'] = htmlspecialchars($data['complaint_desc']);
  601. $refdata['state'] = 0;
  602. $refdata['addtime'] = time();
  603. if($refdata['ref_money'] > $order_info['total'])
  604. {
  605. $result['msg'] = '退款金额不能大于订单总额';
  606. echo json_encode($result);
  607. die();
  608. }
  609. if(!empty($data['ref_id']))
  610. {
  611. $ref_id = intval($data['ref_id']);
  612. unset($refdata['order_id']);
  613. unset($refdata['ref_member_id']);
  614. unset($refdata['addtime']);
  615. M('order_refund')->where( array('ref_id' => $ref_id) )->save($refdata);
  616. $order_history = array();
  617. $order_history['order_id'] = $order_id;
  618. $order_history['order_status_id'] = $order_info['order_status_id'];
  619. $order_history['notify'] = 0;
  620. $order_history['comment'] = '用户修改退款资料';
  621. $order_history['date_added']=time();
  622. M('order_history')->add($order_history);
  623. $order_refund_history = array();
  624. $order_refund_history['order_id'] = $order_id;
  625. $order_refund_history['message'] = $refdata['ref_description'];
  626. $order_refund_history['type'] = 1;
  627. $order_refund_history['addtime'] = time();
  628. $orh_id = M('order_refund_history')->add($order_refund_history);
  629. if(!empty($data['complaint_images']))
  630. {
  631. foreach($data['complaint_images'] as $complaint_images)
  632. {
  633. $img_data = array();
  634. $img_data['orh_id'] = $orh_id;
  635. $img_data['image'] = htmlspecialchars($complaint_images);
  636. $img_data['addtime'] = time();
  637. M('order_refund_history_image')->add($img_data);
  638. }
  639. }
  640. }else {
  641. $ref_id = M('order_refund')->add($refdata);
  642. $up_order = array();
  643. $up_order['order_status_id'] = 12;
  644. M('order')->where( array('order_id' => $order_id) )->save($up_order);
  645. $order_history = array();
  646. $order_history['order_id'] = $order_id;
  647. $order_history['order_status_id'] = 12;
  648. $order_history['notify'] = 0;
  649. $order_history['comment'] = '用户申请退款中';
  650. $order_history['date_added']=time();
  651. M('order_history')->add($order_history);
  652. if(!empty($data['complaint_images']))
  653. {
  654. foreach($data['complaint_images'] as $complaint_images)
  655. {
  656. $img_data = array();
  657. $img_data['ref_id'] = $ref_id;
  658. $img_data['image'] = htmlspecialchars($complaint_images);
  659. $img_data['addtime'] = time();
  660. M('order_refund_image')->add($img_data);
  661. }
  662. }
  663. }
  664. $result['code'] = 1;
  665. echo json_encode($result);
  666. die();
  667. }
  668. /**
  669. 退款详情
  670. **/
  671. public function refunddetail()
  672. {
  673. $token = I('get.token');
  674. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  675. $member_id = $weprogram_token['member_id'];
  676. if( empty($member_id) )
  677. {
  678. $result['code'] = 0;
  679. $result['msg'] = '登录失效';
  680. echo json_encode($result);
  681. die();
  682. }
  683. $order_id = I('get.order_id',0);
  684. $order_info = M('order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->find();
  685. if(empty($order_info) )
  686. {
  687. $result['code'] = 0;
  688. $result['msg'] = '无此订单';
  689. echo json_encode($result);
  690. die();
  691. }
  692. $order_goods = M('order_goods')->where( array('order_id' => $order_id) )->find();
  693. $order_refund = M('order_refund')->where( array('order_id' => $order_id) )->find();
  694. $order_refund_history = M('order_refund_history')->where( array('order_id' => $order_id, 'type' => 2) )->order('addtime asc ')->find();
  695. $refund_reason = array(
  696. '97' =>'商品有质量问题',
  697. '98' =>'没有收到货',
  698. '99' =>'商品少发漏发发错',
  699. '100' =>'商品与描述不一致',
  700. '101' =>'收到商品时有划痕或破损',
  701. '102' =>'质疑假货',
  702. '111' =>'其他',
  703. );
  704. //ref_type
  705. $order_refund['ref_type'] = $order_refund['ref_type'] ==1 ? '仅退款': '退款退货';
  706. //$order_refund['ref_name'] = $refund_reason[$order_refund['ref_name']];
  707. $refund_state = array(
  708. 0 => '申请中',
  709. 1 => '商家拒绝',
  710. 2 => '平台介入',
  711. 3 => '退款成功',
  712. 4 => '退款失败',
  713. 5 => '撤销申请',
  714. );
  715. $order_refund['state'] = $refund_state[$order_refund['state']];
  716. $order_refund['addtime'] = date('Y-m-d H:i:s', $order_refund['addtime']);
  717. //$this->order_refund = $order_refund;
  718. $order_refund_image = M('order_refund_image')->where( array('ref_id' => $order_refund['ref_id']) )->select();
  719. $refund_images = array();
  720. if(!empty($order_refund_image))
  721. {
  722. foreach($order_refund_image as $refund_image)
  723. {
  724. $refund_image['thumb_image'] = C('SITE_URL').resize($refund_image['image'], 100, 100);
  725. $refund_images[] = $refund_image;
  726. }
  727. }
  728. $order_refund_historylist = M('order_refund_history')->where( array('order_id' => $order_id) )->order('addtime asc')->select();
  729. //.type ==3
  730. $pingtai_deal = 0;
  731. foreach($order_refund_historylist as $key => $val)
  732. {
  733. if($val['type'] ==3)
  734. {
  735. $pingtai_deal = 1;
  736. }
  737. $order_refund_history_image = M('order_refund_history_image')->where( array('orh_id' => $val['id']) )->select();
  738. if(!empty($order_refund_history_image))
  739. {
  740. foreach($order_refund_history_image as $kk => $vv)
  741. {
  742. $vv['thumb_image'] = resize($vv['image'], 100, 100);
  743. $order_refund_history_image[$kk] = $vv;
  744. }
  745. }
  746. $val['order_refund_history_image'] = $order_refund_history_image;
  747. $val['addtime'] = date('Y-m-d H:i:s', $val['addtime']);
  748. $order_refund_historylist[$key] = $val;
  749. }
  750. 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) );
  751. die();
  752. //$this->refund_images = $refund_images;
  753. //$this->order_goods = $order_goods;
  754. //$this->order_info = $order_info;
  755. //$this->order_refund_historylist = $order_refund_historylist;
  756. //$this->order_refund_history = $order_refund_history;
  757. //$this->order_id = $order_id;
  758. //$this->display();
  759. }
  760. /**
  761. 申请平台介入
  762. **/
  763. public function judgement_refund()
  764. {
  765. $result = array('code' => 0);
  766. $token = I('get.token');
  767. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  768. $member_id = $weprogram_token['member_id'];
  769. $order_id = I('get.order_id');
  770. $order_info = M('order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->find();
  771. if(empty($order_info) )
  772. {
  773. $result['msg'] = '非法操作';
  774. echo json_encode($result);
  775. die();
  776. }
  777. M('order_refund')->where( array('order_id' => $order_id) )->save( array('state' => 2) );
  778. M('order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->save( array('order_status_id' => 13) );
  779. $order_history = array();
  780. $order_history['order_id'] = $order_id;
  781. $order_history['order_status_id'] = 13;
  782. $order_history['notify'] = 0;
  783. $order_history['comment'] = '申请平台介入';
  784. $order_history['date_added']=time();
  785. M('order_history')->add($order_history);
  786. $order_refund_history = array();
  787. $order_refund_history['order_id'] = $order_id;
  788. $order_refund_history['message'] = '申请平台介入';
  789. $order_refund_history['type'] = 1;
  790. $order_refund_history['addtime'] = time();
  791. M('order_refund_history')->add($order_refund_history);
  792. $result['code'] = 1;
  793. echo json_encode($result);
  794. die();
  795. }
  796. /**
  797. 撤销退款
  798. **/
  799. public function cancel_refund()
  800. {
  801. $token = I('get.token');
  802. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  803. $member_id = $weprogram_token['member_id'];
  804. $order_id = I('get.order_id');
  805. if( empty($member_id) )
  806. {
  807. $result['code'] = 0;
  808. $result['msg'] = '登录失效';
  809. echo json_encode($result);
  810. die();
  811. }
  812. $result = array('code' => 0);
  813. $order_info = M('order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->find();
  814. if(empty($order_info) )
  815. {
  816. $result['msg'] = '非法操作';
  817. echo json_encode($result);
  818. die();
  819. }
  820. M('order_refund')->where( array('order_id' => $order_id) )->save( array('state' => 5) );
  821. $order_history = array();
  822. $order_history['order_id'] = $order_id;
  823. $order_history['order_status_id'] = 4;
  824. $order_history['notify'] = 0;
  825. $order_history['comment'] = '用户撤销退款';
  826. $order_history['date_added']=time();
  827. M('order_history')->add($order_history);
  828. // state
  829. M('order')->where( array('member_id' => $member_id, 'order_id' => $order_id) )->save( array('order_status_id' => 4) );
  830. $result['code'] = 1;
  831. echo json_encode($result);
  832. die();
  833. }
  834. /**
  835. 物流快递
  836. **/
  837. public function goods_express()
  838. {
  839. $token = I('get.token');
  840. $order_id = I('get.order_id',0);
  841. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  842. $member_id = $weprogram_token['member_id'];
  843. if( empty($member_id) )
  844. {
  845. $result['code'] = 2;
  846. $result['msg'] = '登录失效';
  847. echo json_encode($result);
  848. die();
  849. }
  850. $order_info = M('order')->where( array('order_id' => $order_id) )->find();
  851. //shipping_cha_time 86400 43200
  852. $now_time = time();
  853. if($now_time - $order_info['shipping_cha_time'] >= 43200)
  854. {
  855. //即时查询接口
  856. $seller_express = M('seller_express')->where( array('id' =>$order_info['shipping_method'] ) )->find();
  857. //$seller_express['jianma'] = 'YTO';
  858. //$order_info['shipping_no'] = '887406591556327434';
  859. if(!empty($seller_express['jianma']))
  860. {
  861. //887406591556327434 YTO
  862. //TODO...
  863. $ebuss_info = M('config')->where( array('name' => 'EXPRESS_EBUSS_ID') )->find();
  864. $exappkey = M('config')->where( array('name' => 'EXPRESS_APPKEY') )->find();
  865. $req_url = "http://api.kdniao.cc/Ebusiness/EbusinessOrderHandle.aspx";
  866. $this->ebusinessid = $ebuss_info['value'];
  867. $this->appkey = $exappkey['value'];
  868. $requestData= "{'OrderCode':'".$order_id."','ShipperCode':'".$seller_express['jianma']."','LogisticCode':'". $order_info['shipping_no']."'}";
  869. $datas = array(
  870. 'EBusinessID' => $ebuss_info['value'],
  871. 'RequestType' => '1002',
  872. 'RequestData' => urlencode($requestData) ,
  873. 'DataType' => '2',
  874. );
  875. $datas['DataSign'] = $this->encrypt($requestData, $exappkey['value']);
  876. $result=$this->sendPost($req_url, $datas);
  877. $result = json_decode($result);
  878. //根据公司业务处理返回的信息......
  879. //Traces
  880. if(!empty($result->Traces))
  881. {
  882. $order_info['shipping_traces'] = serialize($result->Traces);
  883. M('order')->where( array('order_id' => $order_id) )->save( array('shipping_cha_time' => time(), 'shipping_traces' => $order_info['shipping_traces']) );
  884. }
  885. }
  886. }
  887. $order_goods = M('order_goods')->where( array('order_id' => $order_id) )->find();
  888. $goods_info = M('goods')->field('image')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  889. $goods_info['image']=C('SITE_URL'). resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  890. $seller_express = M('seller_express')->where( array('id' =>$order_info['shipping_method'] ) )->find();
  891. //shipping_traces
  892. $order_info['shipping_traces'] = unserialize($order_info['shipping_traces']) ;
  893. echo json_encode( array('code' => 0, 'seller_express' => $seller_express, 'goods_info' => $goods_info, 'order_info' => $order_info) );
  894. die();
  895. //$this->seller_express = $seller_express;
  896. //$this->goods_info = $goods_info;
  897. //$this->order_info = $order_info;
  898. //$this->display();
  899. }
  900. /**
  901. * post提交数据
  902. * @param string $url 请求Url
  903. * @param array $datas 提交的数据
  904. * @return url响应返回的html
  905. */
  906. function sendPost($url, $datas) {
  907. $temps = array();
  908. foreach ($datas as $key => $value) {
  909. $temps[] = sprintf('%s=%s', $key, $value);
  910. }
  911. $post_data = implode('&', $temps);
  912. $url_info = parse_url($url);
  913. if(empty($url_info['port']))
  914. {
  915. $url_info['port']=80;
  916. }
  917. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  918. $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  919. $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  920. $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  921. $httpheader.= "Connection:close\r\n\r\n";
  922. $httpheader.= $post_data;
  923. $fd = fsockopen($url_info['host'], $url_info['port']);
  924. fwrite($fd, $httpheader);
  925. $gets = "";
  926. $headerFlag = true;
  927. while (!feof($fd)) {
  928. if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  929. break;
  930. }
  931. }
  932. while (!feof($fd)) {
  933. $gets.= fread($fd, 128);
  934. }
  935. fclose($fd);
  936. return $gets;
  937. }
  938. /**
  939. * 电商Sign签名生成
  940. * @param data 内容
  941. * @param appkey Appkey
  942. * @return DataSign签名
  943. */
  944. function encrypt($data, $appkey) {
  945. return urlencode(base64_encode(md5($data.$appkey)));
  946. }
  947. /**
  948. 订单确认收货接口
  949. **/
  950. function receive_order()
  951. {
  952. $token = I('get.token');
  953. $order_id = I('get.order_id');
  954. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  955. $member_id = $weprogram_token['member_id'];
  956. if( empty($member_id) )
  957. {
  958. $result['code'] = 2;
  959. $result['msg'] = '登录失效';
  960. echo json_encode($result);
  961. die();
  962. }
  963. $order_info = M('order')->where( array('member_id' => $member_id,'order_id' => $order_id) )->find();
  964. if(empty($order_info)){
  965. $result['code'] = 1;
  966. $result['msg'] = '非法操作,会员不存在该订单';
  967. echo json_encode($result);
  968. die();
  969. }
  970. $model = D('Home/Order');
  971. $model->receive_order($order_id);
  972. $result['code'] = 0;
  973. echo json_encode($result);
  974. die();
  975. }
  976. /**
  977. 取消订单操作
  978. **/
  979. public function cancel_order()
  980. {
  981. $token = I('get.token');
  982. $order_id = I('get.order_id');
  983. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  984. $member_id = $weprogram_token['member_id'];
  985. if( empty($member_id) )
  986. {
  987. $result['code'] = 2;
  988. $result['msg'] = '登录失效';
  989. echo json_encode($result);
  990. die();
  991. }
  992. $order_info = M('order')->where( array('member_id' => $member_id,'order_id' => $order_id) )->find();
  993. if(empty($order_info)){
  994. $result['code'] = 1;
  995. $result['msg'] = '非法操作,会员不存在该订单';
  996. echo json_encode($result);
  997. die();
  998. }
  999. $model = D('Home/Order');
  1000. $model->cancel_order($order_id);
  1001. $result['code'] = 0;
  1002. echo json_encode($result);
  1003. die();
  1004. }
  1005. function group_info()
  1006. {
  1007. $interface_get_time = time();
  1008. $token = I('get.token');
  1009. $order_id = I('get.order_id');
  1010. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1011. $member_id = $weprogram_token['member_id'];
  1012. $is_show = 0;
  1013. //获取拼团商品信息
  1014. $order_goods_sql = "select name,goods_id,price,total,goods_images,quantity from ".C('DB_PREFIX')."order_goods
  1015. where order_id = {$order_id} limit 1";
  1016. $order_goods_arr = M()->query($order_goods_sql);
  1017. if(empty($order_goods_arr))
  1018. {
  1019. //未找到
  1020. echo json_encode( array('code' =>1) );
  1021. die();
  1022. }
  1023. $order_goods = $order_goods_arr[0];
  1024. $order_goods['price'] = round($order_goods['price'],2);
  1025. $order_goods['total'] = round($order_goods['total'],2);
  1026. //"price": "0.0100",
  1027. //"total": "0.0100",
  1028. $order_info = M('order')->field('member_id')->where( array('order_id' => $order_id) )->find();
  1029. $order_goods['image']=C('SITE_URL'). resize($order_goods['goods_images'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  1030. $order_goods['goods_images'] = C('SITE_URL').'Uploads/image/'.$order_goods['goods_images'];
  1031. $goods_info = M('goods')->field('name,price,seller_count,virtual_count')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  1032. $goods_desc = M('goods_description')->field('share_group_title')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  1033. $goods_info['seller_count'] = $goods_info['seller_count'] + $goods_info['virtual_count'];
  1034. unset($goods_info['virtual_count']);
  1035. //pin_price
  1036. // $pin_goods = M('pin_goods')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  1037. //pin_price
  1038. //$pin_goods['pin_price_del'] = explode('.',$pin_goods['pin_price']);
  1039. //price
  1040. //unset($pin_goods['customer_id']);
  1041. $water_image = '';
  1042. $pin_order = M('pin_order')->where( array('order_id' =>$order_id) )->find();
  1043. //获取拼团信息
  1044. $pin_info = M('pin')->where( array('pin_id' => $pin_order['pin_id']) )->find();
  1045. if($pin_info['state'] == 0 && $pin_info['end_time'] < time()){
  1046. $pin_info['state'] = 2;
  1047. }
  1048. $tuanzhang_info = M('member')->where( array('member_id' => $pin_info['user_id']) )->find();
  1049. $pin_order_sql = "select po.add_time,m.member_id,m.name,m.telephone,m.avatar from ".C('DB_PREFIX')."pin_order as po,".C('DB_PREFIX')."order as o,
  1050. ".C('DB_PREFIX')."order_goods as og,".C('DB_PREFIX')."member as m
  1051. where po.pin_id = ".$pin_info['pin_id']." and o.order_status_id in(1,2,4,6,7,8,9,10,11)
  1052. and og.order_id = po.order_id and o.order_id = po.order_id and o.member_id= m.member_id order by po.add_time asc ";
  1053. $pin_order_arr = M()->query($pin_order_sql);
  1054. $me_take_in = 0;
  1055. foreach($pin_order_arr as $key =>$val)
  1056. {
  1057. if($member_id == $val['member_id'])
  1058. {
  1059. $me_take_in = 1;
  1060. }
  1061. $pin_order_arr[$key] = $val;
  1062. }
  1063. if($pin_info['is_jiqi'] == 1)
  1064. {
  1065. $jia_list = M('jiapinorder')->where( array('pin_id' => $pin_info['pin_id']) )->select();
  1066. foreach( $jia_list as $jia_val )
  1067. {
  1068. $tmp_arr = array();
  1069. $tmp_arr['add_time'] = $jia_val['addtime'];
  1070. $tmp_arr['member_id'] = 1;
  1071. $tmp_arr['name'] = $jia_val['uname'];
  1072. $tmp_arr['telephone'] = $jia_val['mobile'];
  1073. $tmp_arr['avatar'] = $jia_val['avatar'];
  1074. $pin_order_arr[] = $tmp_arr;
  1075. //po.add_time,m.member_id,m.name,m.telephone,m.avatar
  1076. }
  1077. }
  1078. $is_me = 0;
  1079. if($order_info['member_id'] == $member_id)
  1080. {
  1081. $is_me = 1;
  1082. }
  1083. $share_title = "不要错过~我".round($order_goods['price'],2)."元拼了".$goods_info['name'];
  1084. if(!empty($goods_desc['share_group_title']) )
  1085. {
  1086. $share_title = $goods_desc['share_group_title'];
  1087. $share_title = str_replace('{pin_price}',round($order_goods['price'],2),$share_title);
  1088. $share_title = str_replace('{name}',$goods_info['name'],$share_title);
  1089. }
  1090. $this->is_me = $is_me;
  1091. $this->goods_info = $goods_info;
  1092. //$this->pin_goods = $pin_goods;
  1093. $this->pin_order = $pin_order;
  1094. $this->me_take_in = $me_take_in;
  1095. $this->pin_info = $pin_info;
  1096. $this->share_title = $share_title;
  1097. $this->tuanzhang_info = $tuanzhang_info;
  1098. $this->pin_order_arr = $pin_order_arr;
  1099. $this->order_goods = $order_goods;
  1100. $this->order_id = $order_id;
  1101. $this->group_order_id = $group_order_id;
  1102. /* 商品规格begin */
  1103. //get_goods_options($goods_id)
  1104. $goods_model = D('Home/Goods');
  1105. //$this->options=$goods_model->get_goods_options($order_goods['goods_id']);
  1106. $goods_option_mult_value = M('goods_option_mult_value')->where( array('goods_id' =>$order_goods['goods_id']) )->order('id asc')->select();
  1107. $goods_option_mult_value_ref = array();
  1108. foreach($goods_option_mult_value as $key => $val)
  1109. {
  1110. $val['image'] = resize($val['image'],200,200);
  1111. $goods_option_mult_value[$key] = $val;
  1112. $goods_option_mult_value_ref[ $val['rela_goodsoption_valueid'] ] = $val;
  1113. }
  1114. $this->goods_option_mult_value_ref = $goods_option_mult_value_ref;
  1115. /* 商品规格end */
  1116. unset( $tuanzhang_info['reg_type'] );
  1117. unset( $tuanzhang_info['openid'] );
  1118. unset( $tuanzhang_info['we_openid'] );
  1119. unset( $tuanzhang_info['bindmobile'] );
  1120. unset( $tuanzhang_info['uname'] );
  1121. unset( $tuanzhang_info['email'] );
  1122. unset( $tuanzhang_info['pwd'] );
  1123. unset( $tuanzhang_info['address_id'] );
  1124. unset( $tuanzhang_info['share_id'] );
  1125. unset( $tuanzhang_info['comsiss_flag'] );
  1126. unset( $tuanzhang_info['bind_seller_id'] );
  1127. unset( $tuanzhang_info['bind_seller_pickup'] );
  1128. unset( $tuanzhang_info['cart'] );
  1129. unset( $tuanzhang_info['wishlist'] );
  1130. unset( $tuanzhang_info['id_cardreal_name'] );
  1131. unset( $tuanzhang_info['id_card'] );
  1132. unset( $tuanzhang_info['login_count'] );
  1133. unset( $tuanzhang_info['last_login_ip'] );
  1134. unset( $tuanzhang_info['last_ip_region'] );
  1135. unset( $tuanzhang_info['create_time'] );
  1136. unset( $tuanzhang_info['last_login_time'] );
  1137. unset( $tuanzhang_info['status'] );
  1138. $options = $goods_model->get_goods_options($order_goods['goods_id']);
  1139. if( empty($goods_option_mult_value))
  1140. {
  1141. $options= array('list' => array() );
  1142. }
  1143. $need_data = array();
  1144. $need_data['is_me'] = $is_me;
  1145. $need_data['goods_info'] = $goods_info;
  1146. //$need_data['pin_goods'] = $pin_goods;
  1147. $need_data['pin_order'] = $pin_order;
  1148. $need_data['me_take_in'] = $me_take_in;
  1149. $need_data['share_title'] = $share_title;
  1150. $need_data['pin_info'] = $pin_info;
  1151. $need_data['tuanzhang_info'] = $tuanzhang_info;
  1152. $need_data['pin_order_arr'] = $pin_order_arr;
  1153. $need_data['order_goods'] = $order_goods;
  1154. $need_data['order_id'] = $order_id;
  1155. $need_data['group_order_id'] = $group_order_id;
  1156. $need_data['options'] = $options;
  1157. $need_data['interface_get_time'] = $interface_get_time;
  1158. $need_data['del_count'] = $pin_info['need_count'] - count($pin_order_arr);
  1159. //$need_data['goods_option_mult_value_ref'] = $goods_option_mult_value_ref;
  1160. echo json_encode( array('code' =>0, 'data' => $need_data) );
  1161. die();
  1162. }
  1163. /**
  1164. 核销代码开始
  1165. **/
  1166. public function hexiao_pickup()
  1167. {
  1168. $token = I('get.token');
  1169. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1170. $member_id = $weprogram_token['member_id'];
  1171. //$member_id = is_login();
  1172. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1173. if($member_info['bind_seller_pickup'] <= 0)
  1174. {
  1175. echo json_encode( array('code' => 1,'msg' => '您不是核销人员') );
  1176. die();
  1177. }
  1178. $pick_sn = I('get.pick_sn');
  1179. $pick_order = M('pick_order')->where( array('pick_sn' => $pick_sn) )->find();
  1180. $pick_member_info = M('pick_member')->where( array('member_id' => $member_id) )->find();
  1181. if($pick_member_info['pick_up_id'] > 0 && $pick_member_info['pick_up_id'] != $pick_order['pick_id'])
  1182. {
  1183. echo json_encode( array('code' => 1,'msg' => '您无此门店核销权限') );
  1184. die();
  1185. }
  1186. //pick_id
  1187. //order_id pick_id
  1188. $order_id = $pick_order['order_id'];
  1189. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  1190. if($order_goods['store_id'] != $member_info['bind_seller_pickup'])
  1191. {
  1192. echo json_encode( array('code' => 1,'msg' => '您无此商家核销权限') );
  1193. die();
  1194. }
  1195. $store_info = M('seller')->where('s_id='.$order_goods['store_id'])->find();
  1196. $order_info = M('order')->where( array('order_id' => $order_id) )->find();
  1197. $pick_up_info = array();
  1198. $pick_order_info = array();
  1199. if( $order_info['delivery'] == 'pickup' )
  1200. {
  1201. //查询自提点
  1202. $pick_order_info = M('pick_order')->where( array('order_id' => $order_id) )->find();
  1203. $pick_id = $pick_order_info['pick_id'];
  1204. $pick_up_info = M('pick_up')->where( array('id' => $pick_id) )->find();
  1205. }
  1206. //$this->pick_up_info = $pick_up_info;
  1207. $order_status_info = M('order_status')->where( array('order_status_id' => $order_info['order_status_id']) )->find();
  1208. //10 name
  1209. if($order_info['order_status_id'] == 10)
  1210. {
  1211. $order_status_info['name'] = '等待退款';
  1212. }
  1213. else if($order_info['order_status_id'] == 1 && $order_info['type'] == 'lottery')
  1214. {
  1215. //等待开奖
  1216. //一等奖
  1217. if($order_info['lottery_win'] == 1)
  1218. {
  1219. $order_status_info['name'] = '一等奖';
  1220. }else {
  1221. $order_status_info['name'] = '等待开奖';
  1222. }
  1223. }
  1224. $shipping_province = M('area')->where( array('area_id' => $order_info['shipping_province_id']) )->find();
  1225. $shipping_city = M('area')->where( array('area_id' => $order_info['shipping_city_id']) )->find();
  1226. $shipping_country = M('area')->where( array('area_id' => $order_info['shipping_country_id']) )->find();
  1227. $order_goods_list = M('order_goods')->where( array('order_id' => $order_id) )->select();
  1228. foreach($order_goods_list as $key => $order_goods)
  1229. {
  1230. $order_option_info = M('order_option')->field('value')->where( array('order_id' =>$order_id,'order_goods_id' => $order_goods['order_goods_id']) )->select();
  1231. foreach($order_option_info as $option)
  1232. {
  1233. $vv['option_str'][] = $option['value'];
  1234. }
  1235. if(empty($vv['option_str']))
  1236. {
  1237. //option_str
  1238. $order_goods['option_str'] = '';
  1239. }else{
  1240. $order_goods['option_str'] = implode(',', $vv['option_str']);
  1241. }
  1242. //
  1243. $order_goods['shipping_fare'] = round($order_goods['shipping_fare'],2);
  1244. $order_goods['price'] = round($order_goods['price'],2);
  1245. $order_goods['total'] = round($order_goods['total'],2);
  1246. $order_goods['image']=C('SITE_URL').resize($order_goods['goods_images'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  1247. $order_goods['goods_images']= C('SITE_URL').'/Uploads/image/'.$order_goods['goods_images'];
  1248. $store_info = M('seller')->field('s_true_name,s_logo')->where('s_id='.$order_goods['store_id'])->find();
  1249. $store_info['s_logo'] = C('SITE_URL').'/Uploads/image/'.$store_info['s_logo'];
  1250. $order_goods['store_info'] = $store_info;
  1251. unset($order_goods['model']);
  1252. unset($order_goods['rela_goodsoption_valueid']);
  1253. unset($order_goods['comment']);
  1254. $order_goods_list[$key] = $order_goods;
  1255. }
  1256. unset($order_info['store_id']);
  1257. unset($order_info['type']);
  1258. unset($order_info['email']);
  1259. unset($order_info['shipping_city_id']);
  1260. unset($order_info['shipping_country_id']);
  1261. unset($order_info['shipping_province_id']);
  1262. unset($order_info['comment']);
  1263. unset($order_info['voucher_id']);
  1264. unset($order_info['voucher_credit']);
  1265. unset($order_info['is_balance']);
  1266. unset($order_info['lottery_win']);
  1267. unset($order_info['ip']);
  1268. unset($order_info['ip_region']);
  1269. unset($order_info['user_agent']);
  1270. $order_info['shipping_fare'] = round($order_info['shipping_fare'],2);
  1271. $order_info['total'] = round($order_info['total'],2);
  1272. $order_info['price'] = round($order_info['price'],2);
  1273. $order_info['date_added'] = date('Y-m-d H:i:s', $order_info['date_added']);
  1274. $need_data = array();
  1275. $need_data['order_info'] = $order_info;
  1276. $need_data['order_status_info'] = $order_status_info;
  1277. $need_data['shipping_province'] = $shipping_province;
  1278. $need_data['shipping_city'] = $shipping_city;
  1279. $need_data['shipping_country'] = $shipping_country;
  1280. $need_data['order_goods_list'] = $order_goods_list;
  1281. //$order_info['order_status_id'] 13 平台介入退款
  1282. $order_refund_historylist = array();
  1283. $pingtai_deal = 0;
  1284. //判断是否已经平台处理完毕
  1285. $order_refund_historylist = M('order_refund_history')->where( array('order_id' => $order_id) )->order('addtime asc')->select();
  1286. foreach($order_refund_historylist as $key => $val)
  1287. {
  1288. if($val['type'] ==3)
  1289. {
  1290. $pingtai_deal = 1;
  1291. }
  1292. }
  1293. //order_refund
  1294. $order_refund = M('order_refund')->where( array('order_id' => $order_id) )->find();
  1295. if(!empty($order_refund))
  1296. {
  1297. $order_refund['addtime'] = date('Y-m-d H:i:s', $order_refund['addtime']);
  1298. }
  1299. $need_data['pick_up'] = $pick_up_info;
  1300. $need_data['pick_order_info'] = $pick_order_info;
  1301. //https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
  1302. //https://api.weixin.qq.com/wxa/getwxacodeunlimit?access_token=ACCESS_TOKEN
  1303. echo json_encode( array('code' => 0,'data' => $need_data,'pingtai_deal' => $pingtai_deal,'order_refund' => $order_refund ) );
  1304. die();
  1305. }
  1306. /**
  1307. 核销
  1308. **/
  1309. public function pickup_pickage()
  1310. {
  1311. $token = I('get.token');
  1312. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1313. $member_id = $weprogram_token['member_id'];
  1314. //$member_id = is_login();
  1315. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1316. if($member_info['bind_seller_pickup'] <= 0)
  1317. {
  1318. echo json_encode( array('code' => 1,'msg' => '您不是核销人员') );
  1319. die();
  1320. }
  1321. $pick_sn = I('get.pick_sn');
  1322. $pick_order = M('pick_order')->where( array('pick_sn' => $pick_sn) )->find();
  1323. $pick_member_info = M('pick_member')->where( array('member_id' => $member_id) )->find();
  1324. if($pick_member_info['pick_up_id'] > 0 && $pick_member_info['pick_up_id'] != $pick_order['pick_id'])
  1325. {
  1326. echo json_encode( array('code' => 1,'msg' => '您无此门店核销权限') );
  1327. die();
  1328. }
  1329. //order_id pick_id
  1330. $order_id = $pick_order['order_id'];
  1331. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  1332. if($order_goods['store_id'] != $member_info['bind_seller_pickup'])
  1333. {
  1334. echo json_encode( array('code' => 1,'msg' => '您无此商家核销权限') );
  1335. die();
  1336. }
  1337. $pick_id = $pick_order['id'];
  1338. //$pick_id = I('get.pick_id');
  1339. $pick_order = M('pick_order')->where( array('id' => $pick_id) )->find();
  1340. $member_id = is_login();
  1341. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1342. $result = array('code' => 0,'msg' => '');
  1343. $order_goods = M('order_goods')->where( array('order_id' => $pick_order['order_id']) )->find();
  1344. //发送订单佣金
  1345. //pick_member_id
  1346. $res = M('pick_order')->where( array('id' => $pick_id) )->save( array('pick_member_id' => $member_id, 'state' => 1, 'tihuo_time' => time()) );
  1347. if($res)
  1348. {
  1349. M('order')->where( array('order_id' => $pick_order['order_id']) )->save( array('order_status_id' => 6) );
  1350. $fenxiao_model = D('Home/Fenxiao');
  1351. $fenxiao_model->send_order_commiss_money($pick_order['order_id']);
  1352. //准备发送订单的 send_order_score_dr($order_id) $integral_model = D('Seller/Integral'); $integral_model->send_order_score_dr($pick_order['order_id']);
  1353. $history_data = array();
  1354. $history_data['order_id'] = $pick_order['order_id'];
  1355. $history_data['order_status_id'] = 6;
  1356. $history_data['notify'] = 0;
  1357. $history_data['comment'] = '用户提货,核销';
  1358. $history_data['date_added'] = time();
  1359. M('order_history')->add($history_data);
  1360. $notify_model = D('Home/Weixinnotify');
  1361. $notify_model->sendPickupsuccessMsg($pick_order['order_id']);
  1362. $result['code'] = 0;
  1363. }
  1364. echo json_encode($result);
  1365. die();
  1366. }
  1367. /**
  1368. 绑定自提订单核销管理员
  1369. **/
  1370. public function bind_pickup_order()
  1371. {
  1372. $seller_store_id = I('get.seller_store_id');
  1373. $token = I('get.token');
  1374. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1375. $member_id = $weprogram_token['member_id'];
  1376. //$member_id = is_login();
  1377. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1378. if( empty($member_info) )
  1379. {
  1380. echo json_encode( array('code' => 1,'msg' => '您未登录') );
  1381. die();
  1382. }
  1383. $seller_store_arr = explode('_', $seller_store_id);
  1384. $seller_id = $seller_store_arr[0];
  1385. $pick_up_id = $seller_store_arr[1];
  1386. $seller_info = M('seller')->field('s_true_name')->where( array('s_id' => $seller_id) )->find();
  1387. $store_name = '所有门店';
  1388. if( $pick_up_id > 0 )
  1389. {
  1390. $pick_up_info = M('pick_up')->where( array('id' => $pick_up_id) )->find();
  1391. $store_name = $pick_up_info['pick_name'];
  1392. }
  1393. echo json_encode( array('code' => 0,'seller_name' => $seller_info['s_true_name'], 'store_name' => $store_name ) );
  1394. die();
  1395. }
  1396. /**
  1397. 解除绑定自提订单核销管理员
  1398. **/
  1399. public function unbind_pickup_order()
  1400. {
  1401. $seller_store_id = I('get.seller_store_id');
  1402. $token = I('get.token');
  1403. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1404. $member_id = $weprogram_token['member_id'];
  1405. //$member_id = is_login();
  1406. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1407. if( empty($member_info) )
  1408. {
  1409. echo json_encode( array('code' => 1,'msg' => '您未登录') );
  1410. die();
  1411. }
  1412. $seller_store_arr = explode('_', $seller_store_id);
  1413. $seller_id = $seller_store_arr[0];
  1414. $pick_up_id = $seller_store_arr[1];
  1415. $data = array();
  1416. $data['bind_seller_pickup'] = 0;
  1417. $res = M('member')->where( array('member_id' => $member_id) )->save($data);
  1418. $this->display();
  1419. }
  1420. public function bind_pickup_post()
  1421. {
  1422. $seller_store_id = I('get.seller_store_id');
  1423. $token = I('get.token');
  1424. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1425. $member_id = $weprogram_token['member_id'];
  1426. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1427. if( empty($member_info) )
  1428. {
  1429. echo json_encode( array('code' => 1,'msg' => '您未登录') );
  1430. die();
  1431. }
  1432. $seller_store_arr = explode('_', $seller_store_id);
  1433. $seller_id = $seller_store_arr[0];
  1434. $pick_up_id = $seller_store_arr[1];
  1435. $data = array();
  1436. $data['bind_seller_pickup'] = $seller_id;
  1437. $res = M('member')->where( array('member_id' => $member_id) )->save($data);
  1438. M('pick_member')->where( array('member_id' => $member_id) )->delete();
  1439. $pick_member_data = array();
  1440. $pick_member_data['member_id'] = $member_id;
  1441. $pick_member_data['pick_up_id'] = $pick_up_id;
  1442. $pick_member_data['state'] = 1;
  1443. $pick_member_data['store_id'] = $seller_id;
  1444. $pick_member_data['addtime'] = time();
  1445. M('pick_member')->add($pick_member_data);
  1446. $result = array('code' => 0);
  1447. echo json_encode($result);
  1448. die();
  1449. }
  1450. /**
  1451. 核销代码结束
  1452. **/
  1453. /**
  1454. groupleaderindex
  1455. 分销商资料获取
  1456. **/
  1457. public function groupleaderindex()
  1458. {
  1459. $token = I('get.token');
  1460. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1461. $member_id = $weprogram_token['member_id'];
  1462. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1463. if( empty($member_info) )
  1464. {
  1465. echo json_encode( array('code' => 1,'msg' => '您未登录') );
  1466. die();
  1467. }
  1468. //查找一级数量
  1469. $tuanyuan_arr = M('member')->field('member_id')->where( array('share_id' => $member_id) )->select();
  1470. $tuanyuan_count = count($tuanyuan_arr);// $tuanyuan_count;
  1471. //查找二级数量
  1472. $second_tuanyuan_count = 0;
  1473. $second_arr = array();
  1474. if( !empty($tuanyuan_arr) )
  1475. {
  1476. $ids_arr = array();
  1477. foreach($tuanyuan_arr as $val)
  1478. {
  1479. $ids_arr[] = $val['member_id'];
  1480. }
  1481. $second_arr = M('member')->field('member_id')->where( array('share_id' => array('in', $ids_arr) ) )->select();
  1482. $second_tuanyuan_count = count($second_arr);
  1483. }
  1484. $second_tuanyuan_count = $second_tuanyuan_count;
  1485. //查找三级数量
  1486. $three_tuanyuan_count = 0;
  1487. if( !empty($second_arr) )
  1488. {
  1489. $ids_arr = array();
  1490. foreach($second_arr as $val)
  1491. {
  1492. $ids_arr[] = $val['member_id'];
  1493. }
  1494. $three_tuanyuan_count = M('member')->field('member_id')->where( array('share_id' => array('in', $ids_arr) ) )->count();
  1495. }
  1496. $three_tuanyuan_count = $three_tuanyuan_count;
  1497. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  1498. //$this->member_commiss = $member_commiss;
  1499. $opencommiss_arr = M('config')->where( array('name' => 'opencommiss') )->find();
  1500. $is_open_commiss = $opencommiss_arr['value'];
  1501. $tuijian_ren = '平台';
  1502. if($member_info['share_id'] > 0)
  1503. {
  1504. $tui_member = M('member')->field('uname')->where( array('member_id' => $member_info['share_id']) )->find();
  1505. $tuijian_ren = $tui_member['uname'];
  1506. }
  1507. //$this->tuijian_ren = $tuijian_ren;
  1508. //{{user_info.member_commiss.getmoney}}
  1509. //dongmoney getmoney money
  1510. $member_model = D('Home/Member');
  1511. //待确认收入
  1512. $total_wait_where = array();
  1513. $total_wait_where['member_id'] = $member_id;
  1514. $total_wait_where['state'] = 0;
  1515. $total_wait_commiss = $member_model->sum_member_commiss($total_wait_where);
  1516. $all_commiss_money = $total_wait_commiss + $member_commiss['money'] +$member_commiss['getmoney']+$member_commiss['dongmoney'];
  1517. $need_data = array();
  1518. $need_data['tuanyuan_count'] = $tuanyuan_count;
  1519. $need_data['all_commiss_money'] = $all_commiss_money;
  1520. $need_data['second_tuanyuan_count'] = $second_tuanyuan_count;
  1521. $need_data['three_tuanyuan_count'] = $three_tuanyuan_count;
  1522. $need_data['member_commiss'] = $member_commiss;
  1523. $need_data['is_open_commiss'] = $is_open_commiss;
  1524. $need_data['tuijian_ren'] = $tuijian_ren;
  1525. $need_data['member_info'] = $member_info;
  1526. $need_data['commiss_level_num'] = C('commiss_level_num');
  1527. echo json_encode( array('code' =>0 , 'data' => $need_data) );
  1528. die();
  1529. }
  1530. /**
  1531. 获取佣金首页
  1532. **/
  1533. function tuanbonus_index()
  1534. {
  1535. $token = I('get.token');
  1536. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1537. $member_id = $weprogram_token['member_id'];
  1538. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1539. //sum_member_commiss($where = array())
  1540. $member_model = D('Home/Member');
  1541. //今日收入
  1542. $today_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  1543. $today_end_time = $today_begin_time + 86400;
  1544. //$map['id'] = array('between','1,8'); $map['id'] = array('neq',100);
  1545. $today_where = array();
  1546. $today_where['member_id'] = $member_id;
  1547. $today_where['state'] = array('neq',2);
  1548. $today_where['addtime'] = array('between',$today_begin_time.','.$today_end_time);
  1549. $today_commiss = $member_model->sum_member_commiss($today_where);
  1550. //本月收入
  1551. $month_begin_time = strtotime( date("Y-m-d ",mktime(0, 0 , 0,date("m"),1,date("Y"))).' 00:00:00' );
  1552. $month_end_time = strtotime( date("Y-m-d ",mktime(23,59,59,date("m"),date("t"),date("Y"))).' 00:00:00' ) +86400;
  1553. $month_where = array();
  1554. $month_where['member_id'] = $member_id;
  1555. $month_where['state'] = array('neq',2);
  1556. $month_where['addtime'] = array('between',$month_begin_time.','.$month_end_time);
  1557. $month_commiss = $member_model->sum_member_commiss($month_where);
  1558. //累计收入
  1559. $total_where = array();
  1560. $total_where['member_id'] = $member_id;
  1561. $total_where['state'] = array('neq',2);
  1562. $total_commiss = $member_model->sum_member_commiss($total_where);
  1563. //待确认收入
  1564. $total_wait_where = array();
  1565. $total_wait_where['member_id'] = $member_id;
  1566. $total_wait_where['state'] = 0;
  1567. $total_wait_commiss = $member_model->sum_member_commiss($total_wait_where);
  1568. //可提现金额
  1569. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  1570. $this->today_commiss = round($today_commiss, 2);
  1571. $this->month_commiss = round($month_commiss, 2);
  1572. $this->total_commiss = round($total_commiss, 2);
  1573. $this->total_wait_commiss = round($total_wait_commiss, 2);
  1574. $can_tixian_money = 0;
  1575. if(!empty($member_commiss)) {
  1576. $can_tixian_money = $member_commiss['money'];
  1577. }
  1578. $this->can_tixian_money = round($can_tixian_money, 2);
  1579. $comsiss_flag = $member_info['comsiss_flag'];
  1580. if($member_info['comsiss_flag'] == 0)
  1581. {
  1582. //state
  1583. $member_commiss_apply = M('member_commiss_apply')->where( array('member_id' =>$member_id, 'state' =>0) )
  1584. ->find();
  1585. if(!empty($member_commiss_apply)) {
  1586. $comsiss_flag = 2;
  1587. }
  1588. }
  1589. $this->comsiss_flag = $comsiss_flag;
  1590. $need_data = array();
  1591. $need_data['today_commiss'] = round($today_commiss, 2);
  1592. $need_data['month_commiss'] = round($month_commiss, 2);
  1593. $need_data['total_commiss'] = round($total_commiss, 2);
  1594. $need_data['total_wait_commiss'] = round($total_wait_commiss, 2);
  1595. $need_data['can_tixian_money'] = round($can_tixian_money, 2);
  1596. $need_data['comsiss_flag'] = $comsiss_flag;
  1597. echo json_encode( array('code' =>0, 'data' => $need_data ) );
  1598. die();
  1599. //$this->display();
  1600. }
  1601. /**
  1602. 获取账单详情
  1603. **/
  1604. public function listorder()
  1605. {
  1606. $token = I('get.token');
  1607. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1608. $member_id = $weprogram_token['member_id'];
  1609. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1610. //今日新增
  1611. $today_begin_time = strtotime( date('Y-m-d'.' 00:00:00') );
  1612. $today_end_time = $today_begin_time + 86400;
  1613. $today_where = array();
  1614. $today_where['member_id'] = $member_id;
  1615. $today_where['addtime'] = array('between',$today_begin_time.','.$today_end_time);
  1616. $today_count = M('member_commiss_order')->where( $today_where )->count();
  1617. //昨日新增
  1618. $yes_begin_time = $today_begin_time - 86400;
  1619. $yes_end_time = $today_begin_time;
  1620. $yes_where = array();
  1621. $yes_where['member_id'] = $member_id;
  1622. $yes_where['addtime'] = array('between',$yes_begin_time.','.$yes_end_time);
  1623. $yes_count = M('member_commiss_order')->where( $yes_where )->count();
  1624. //总订单量
  1625. $total_where = array();
  1626. $total_where['member_id'] = $member_id;
  1627. $total_count = M('member_commiss_order')->where( $total_where )->count();
  1628. $need_data = array();
  1629. $need_data['today_count'] = $today_count;
  1630. $need_data['yes_count'] = $yes_count;
  1631. $need_data['total_count'] = $total_count;
  1632. echo json_encode( array('code' =>0, 'data' => $need_data) );
  1633. die();
  1634. $this->display();
  1635. }
  1636. /**
  1637. 获取账单详情列表
  1638. **/
  1639. public function listorder_list()
  1640. {
  1641. $token = I('get.token');
  1642. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1643. $member_id = $weprogram_token['member_id'];
  1644. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1645. $per_page = 6;
  1646. $page = I('get.page',1);
  1647. $offset = ($page - 1) * $per_page;
  1648. $list = array();
  1649. $where = '';
  1650. $state = I('get.state',-1);
  1651. //state
  1652. if($state >=0)
  1653. {
  1654. $where = ' and mco.state = '.$state;
  1655. }
  1656. $commiss_level_num = C('commiss_level_num');
  1657. $where = ' and mco.level <= '.$commiss_level_num;
  1658. //$commiss_level_num = C('commiss_level_num'); level
  1659. $this->state = $state;
  1660. $sql = 'select mco.level, mco.money,mco.child_member_id,mco.addtime,mco.state,o.order_status_id,o.order_num_alias,o.total,og.goods_id,og.quantity,og.name,mco.store_id,m.uname from '.C('DB_PREFIX')."member_commiss_order as mco , ".C('DB_PREFIX')."order_goods as og, ".C('DB_PREFIX')."order as o , ".C('DB_PREFIX')."member as m
  1661. where mco.order_id=og.order_id and mco.order_id = o.order_id and m.member_id=mco.child_member_id and mco.member_id=".$member_id." {$where} order by mco.id desc limit {$offset},{$per_page}";
  1662. $list = M()->query($sql);
  1663. $order_status_list = M('order_status')->select();
  1664. $status_arr = array();
  1665. foreach($order_status_list as $vv)
  1666. {
  1667. $status_arr[$vv['order_status_id']] = $vv['name'];
  1668. }
  1669. foreach($list as $key =>$val)
  1670. {
  1671. $val['total'] = round($val['total'],2);
  1672. $val['money'] = round($val['money'],2);
  1673. $val['status_name'] = $status_arr[$val['order_status_id']];
  1674. $val['addtime'] = date('Y-m-d', $val['addtime']);
  1675. $goods_info = M('goods')->field('image')->where( array('goods_id' => $val['goods_id']) )->find();
  1676. $val['image']=C('SITE_URL'). resize($goods_info['image'], C('common_image_thumb_width'), C('common_image_thumb_height'));
  1677. $list[$key] = $val;
  1678. }
  1679. $this->list = $list;
  1680. if(empty($list))
  1681. {
  1682. echo json_encode( array('code' => 1) );
  1683. die();
  1684. }else {
  1685. echo json_encode( array('code' => 0, 'data' => $list) );
  1686. die();
  1687. }
  1688. }
  1689. /**
  1690. 检测是否绑定了银行卡
  1691. **/
  1692. public function check_tixian()
  1693. {
  1694. $token = I('get.token');
  1695. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1696. $member_id = $weprogram_token['member_id'];
  1697. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1698. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  1699. if( empty($member_commiss['bankname']) || empty($member_commiss['bankaccount']) || empty($member_commiss['bankusername']))
  1700. {
  1701. echo json_encode( array('code' =>0) );
  1702. die();
  1703. }else{
  1704. echo json_encode( array('code' => 1) );
  1705. die();
  1706. }
  1707. }
  1708. /**
  1709. 获取用户佣金信息
  1710. **/
  1711. public function get_tixian_info()
  1712. {
  1713. $token = I('get.token');
  1714. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1715. $member_id = $weprogram_token['member_id'];
  1716. $limit_money = C('commiss_money_limit');
  1717. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1718. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  1719. $member_commiss['limit_money'] = $limit_money;
  1720. echo json_encode( array('code' =>0,'data' => $member_commiss) );
  1721. die();
  1722. }
  1723. /**
  1724. 绑定银行卡
  1725. **/
  1726. public function bindcard()
  1727. {
  1728. $token = I('get.token');
  1729. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1730. $member_id = $weprogram_token['member_id'];
  1731. $data_json = file_get_contents('php://input');
  1732. $datas = json_decode($data_json, true);
  1733. $bankusername = $datas['bankusername'];//I('post.bankusername','','htmlspecialchars');
  1734. $bankname = $datas['bankname'];//I('post.bankname','','htmlspecialchars');
  1735. $bankaccount = $datas['bankaccount'];//I('post.bankaccount','','htmlspecialchars');
  1736. $data = array();
  1737. $data['bankusername'] = $bankusername;
  1738. $data['bankname'] = $bankname;
  1739. $data['bankaccount'] = $bankaccount;
  1740. M('member_commiss')->where( array('member_id' => $member_id) )->save($data);
  1741. echo json_encode( array('code' => 0) );
  1742. die();
  1743. }
  1744. public function tixian_sub()
  1745. {
  1746. $token = I('get.token');
  1747. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1748. $member_id = $weprogram_token['member_id'];
  1749. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1750. $result = array('code' => 1,'msg' => '提现失败');
  1751. $member_commiss = M('member_commiss')->where( array('member_id' => $member_id) )->find();
  1752. $data_json = file_get_contents('php://input');
  1753. $datas = json_decode($data_json, true);
  1754. $money = $datas['money'];//I('post.money',0,'floatval');
  1755. $commiss_money_limit = C('commiss_money_limit');
  1756. if(!empty($commiss_money_limit) && $commiss_money_limit >0)
  1757. {
  1758. if($member_commiss['money'] < $commiss_money_limit)
  1759. {
  1760. $result['msg'] = '佣金满'.$commiss_money_limit.'才能提现';
  1761. echo json_encode($result);
  1762. die();
  1763. }
  1764. }
  1765. if($money > 0 && $money <= $member_commiss['money'])
  1766. {
  1767. $data = array();
  1768. $data['member_id'] = $member_id;
  1769. $data['money'] = $money;
  1770. $data['state'] = 0;
  1771. $data['shentime'] = 0;
  1772. $data['addtime'] = time();
  1773. M('tixian_order')->add($data);
  1774. $com_arr = array();
  1775. $com_arr['money'] = $member_commiss['money'] - $money;
  1776. $com_arr['dongmoney'] = $member_commiss['dongmoney'] + $money;
  1777. M('member_commiss')->where( array('member_id' => $member_id) )->save($com_arr);
  1778. $result['code'] = 0;
  1779. }
  1780. echo json_encode($result);
  1781. die();
  1782. }
  1783. /**
  1784. 提现记录
  1785. **/
  1786. public function tixian_record()
  1787. {
  1788. $token = I('get.token');
  1789. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1790. $member_id = $weprogram_token['member_id'];
  1791. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1792. $per_page = 5;
  1793. $page = I('get.page',1);
  1794. $offset = ($page - 1) * $per_page;
  1795. $list = array();
  1796. $sql = "select * from ".C('DB_PREFIX')."tixian_order
  1797. where member_id=".$member_id." order by addtime desc limit {$offset},{$per_page}";
  1798. $list = M()->query($sql);
  1799. foreach($list as $key => $val)
  1800. {
  1801. $val['addtime'] = date('Y-m-d', $val['addtime']);
  1802. $list[$key] = $val;
  1803. }
  1804. if( !empty($list) )
  1805. {
  1806. echo json_encode( array('code' =>0, 'data'=>$list) );
  1807. die();
  1808. }else{
  1809. echo json_encode( array('code' => 1) );
  1810. die();
  1811. }
  1812. }
  1813. public function cons_member_common($member_id)
  1814. {
  1815. $member_common = array('member_id'=>$member_id,'qrcode_img' => '');
  1816. M('member_common')->add($member_common);
  1817. return $member_common;
  1818. }
  1819. /**
  1820. 团长二维码
  1821. **/
  1822. public function qrcode()
  1823. {
  1824. $member_common = M('member_common')->where( array('member_id' => UID) )->find();
  1825. if(empty($member_common))
  1826. {
  1827. $member_common = $this->cons_member_common(UID);
  1828. }
  1829. $is_tan = 1;
  1830. $hashids = new \Lib\Hashids(C('PWD_KEY'), C('URL_ID'));
  1831. $member_id = UID;
  1832. $hash_member_id = $hashids->encode($member_id);
  1833. $url = C('SITE_URL')."index.php?s=/index/index/rmid/{$hash_member_id}";
  1834. if(empty($member_common['qrcode_img']))
  1835. {
  1836. $content = $url;
  1837. $target = C('SITE_URL').'Uploads/image/'.C('user_qrcode_image');
  1838. $user_qrcodebg_x = C('user_qrcode_x');
  1839. $user_qrcodebg_y = C('user_qrcode_y');
  1840. if(empty($user_qrcodebg_x))
  1841. {
  1842. $user_qrcodebg_x = 0;
  1843. }
  1844. if(empty($user_qrcodebg_y))
  1845. {
  1846. $user_qrcodebg_y = 0;
  1847. }
  1848. $new_image = get_compare_qrcode($content,$target,$user_qrcodebg_x,$user_qrcodebg_y);
  1849. $uarray = array( 'qrcode_img'=>$new_image);
  1850. M('member_common')->where( array('member_id' => $member_id) )->save($uarray);
  1851. $member_common['qrcode_img'] = $new_image;
  1852. cookie('qrcode_tan', 1);
  1853. } else {
  1854. $tan_time = cookie('qrcode_tan');
  1855. if(empty($tan_time))
  1856. {
  1857. cookie('qrcode_tan', 1);
  1858. }else
  1859. {
  1860. cookie('qrcode_tan', $tan_time+1);
  1861. if($tan_time >=2)
  1862. {
  1863. $is_tan = 2;
  1864. }
  1865. }
  1866. $new_image = $login_user['qrcode'];
  1867. }
  1868. $this->member_common = $member_common;
  1869. $this->display();
  1870. }
  1871. function tuanyuan()
  1872. {
  1873. $token = I('get.token');
  1874. $weprogram_token = M('weprogram_token')->field('member_id')->where( array('token' =>$token) )->find();
  1875. $member_id = $weprogram_token['member_id'];
  1876. $member_info = M('member')->where( array('member_id' => $member_id) )->find();
  1877. $per_page = 6;
  1878. $page = I('get.page',1);
  1879. $offset = ($page - 1) * $per_page;
  1880. //type 1 2 3
  1881. $type = I('get.type',1);
  1882. //6
  1883. $list = array();
  1884. if($type == 1)
  1885. {
  1886. $sql = 'select * from '.C('DB_PREFIX')."member
  1887. where share_id = ".$member_id." order by member_id desc limit {$offset},{$per_page}";
  1888. $list = M()->query($sql);
  1889. //var_dump($list, $sql);die();
  1890. }else if( $type ==2 ){
  1891. $sql = 'select member_id from '.C('DB_PREFIX')."member
  1892. where share_id = ".$member_id;
  1893. $first_list = M()->query($sql);
  1894. $list = array();
  1895. if( !empty($first_list) )
  1896. {
  1897. $ids_arr = array();
  1898. foreach( $first_list as $val )
  1899. {
  1900. $ids_arr[] = $val['member_id'];
  1901. }
  1902. $ids_str = implode(',', $ids_arr);
  1903. $sql = 'select * from '.C('DB_PREFIX')."member
  1904. where share_id in (".$ids_str.") order by member_id desc limit {$offset},{$per_page}";
  1905. $list = M()->query($sql);
  1906. }
  1907. } else if( $type ==3 ){
  1908. $sql = 'select member_id from '.C('DB_PREFIX')."member
  1909. where share_id = ".$member_id;
  1910. $first_list = M()->query($sql);
  1911. $list = array();
  1912. if( !empty($first_list) )
  1913. {
  1914. $ids_arr = array();
  1915. foreach( $first_list as $val )
  1916. {
  1917. $ids_arr[] = $val['member_id'];
  1918. }
  1919. $ids_str = implode(',', $ids_arr);
  1920. $sql = 'select member_id from '.C('DB_PREFIX')."member
  1921. where share_id in (".$ids_str.") ";
  1922. $second_list = M()->query($sql);
  1923. if( !empty($second_list) )
  1924. {
  1925. $ids_arr = array();
  1926. foreach( $second_list as $val )
  1927. {
  1928. $ids_arr[] = $val['member_id'];
  1929. }
  1930. $ids_str = implode(',', $ids_arr);
  1931. $sql = 'select * from '.C('DB_PREFIX')."member
  1932. where share_id in (".$ids_str.") order by member_id desc limit {$offset},{$per_page}";
  1933. $list = M()->query($sql);
  1934. }
  1935. }
  1936. }
  1937. //{$member_info.uname}
  1938. foreach($list as $key => $val)
  1939. {
  1940. $parent_name = M('member')->field('name')->where( array('member_id' => $val['share_id']) )->find();
  1941. $val['parent_name'] = $parent_name['name'];
  1942. $val['create_time'] = date('Y-m-d H:i:s', $val['create_time']);
  1943. $list[$key] = $val;
  1944. }
  1945. if( empty($list) )
  1946. {
  1947. echo json_encode( array('code' => 1) );
  1948. die();
  1949. } else{
  1950. echo json_encode( array('code' =>0 , 'data' => $list) );
  1951. die();
  1952. }
  1953. }
  1954. public function yongjing()
  1955. {
  1956. $per_page = 10;
  1957. $page = I('get.page',1);
  1958. $gid = I('get.gid',0);
  1959. $offset = ($page - 1) * $per_page;
  1960. $where = "";
  1961. //danprice pin_price
  1962. if( !empty($gid) && $gid >0 )
  1963. {
  1964. $goods_ids_arr = M('goods_to_category')->where("class_id1 ={$gid} or class_id2 ={$gid} or class_id3 = {$gid} ")->field('goods_id')->select();
  1965. $ids_arr = array();
  1966. foreach($goods_ids_arr as $val){
  1967. $ids_arr[] = $val['goods_id'];
  1968. }
  1969. $ids_str = implode(',',$ids_arr);
  1970. if( !empty($ids_str) )
  1971. {
  1972. $where .= " and a.goods_id in ({$ids_str}) ";
  1973. //a.goods_id
  1974. }
  1975. }
  1976. $sql = " SELECT a.goods_id,a.name,a.quantity,a.danprice,b.pin_price,a.commiss_one_dan_disc,( b.commiss_one_pin_disc * b.pin_price ) as pin_yong_money,( a.commiss_one_dan_disc * a.danprice ) as dan_yong_money, a.price,a.image
  1977. FROM ".C('DB_PREFIX')."goods as a left join ".C('DB_PREFIX')."pin_goods as b on a.goods_id = b.goods_id WHERE (a.commiss_one_dan_disc >0 or b.commiss_one_pin_disc >0) and a.status = 1 {$where} and a.quantity >0 order by dan_yong_money desc, pin_yong_money desc
  1978. limit {$offset},{$per_page}";
  1979. /**
  1980. $sql = 'select g.goods_id,g.name,g.quantity,g.pinprice,g.commiss_one_pin_disc,( g.pinprice * g.commiss_one_pin_disc ) as yong_money, g.price,g.image from '.C('DB_PREFIX')."goods as g
  1981. where g.status =1 and g.quantity > 0 and g.commiss_one_pin_disc >0 order by yong_money desc limit {$offset},{$per_page}";
  1982. **/
  1983. $list = M()->query($sql);
  1984. foreach ($list as $k => $v) {
  1985. $v['image']=C('SITE_URL'). resize($v['image'], C('spike_thumb_width'), C('spike_thumb_height'));
  1986. $pin_yong_money = round( $v['pin_yong_money'] /100 , 2);
  1987. $dan_yong_money = round( $v['dan_yong_money'] /100 , 2);
  1988. if( $pin_yong_money > $dan_yong_money )
  1989. {
  1990. $v['yong_money'] = $pin_yong_money;
  1991. $v['price'] = $v['pin_price'];
  1992. } else {
  1993. $v['yong_money'] = $dan_yong_money;
  1994. $v['price'] = $v['danprice'];
  1995. }
  1996. //"danprice":"0.04","pin_price":"0.01",
  1997. $list[$k] = $v;
  1998. }
  1999. if( empty($list) )
  2000. {
  2001. echo json_encode( array('code' => 1) );
  2002. die();
  2003. } else {
  2004. echo json_encode( array('code' =>0, 'data' => $list) );
  2005. die();
  2006. }
  2007. /**
  2008. SELECT a.goods_id, a.commiss_one_dan_disc, b.commiss_one_pin_disc
  2009. FROM `oscshop_goods` as a left join oscshop_pin_goods as b on a.goods_id = b.goods_id WHERE a.commiss_one_dan_disc >0 and a.status = 1 and a.quantity >0 order by a.goods_id desc
  2010. **/
  2011. }
  2012. }