OrderModel.class.php 128 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Seller\Model;
  10. class OrderModel{
  11. public function do_tuanz_over($order_id, $title = '后台操作,确认送达团长')
  12. {
  13. //express_time
  14. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 4, 'express_tuanz_time' => time()) );
  15. //todo ... send member msg goods is ing
  16. $history_data = array();
  17. $history_data['order_id'] = $order_id;
  18. $history_data['order_status_id'] = 4;
  19. $history_data['notify'] = 0;
  20. $history_data['comment'] = $title;
  21. $history_data['date_added'] = time();
  22. M('lionfish_comshop_order_history')->add( $history_data );
  23. D('Home/Frontorder')->send_order_operate($order_id);
  24. }
  25. /**
  26. * @param $order_id
  27. * @param string 同城配送发货
  28. */
  29. public function do_send_localtown( $order_id, $title = '后台操作,开始配送货物' )
  30. {
  31. //express_time
  32. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 4,'express_time' => time(), 'express_tuanz_time' => time()) );
  33. //todo ... send member msg goods is ing
  34. $history_data = array();
  35. $history_data['order_id'] = $order_id;
  36. $history_data['order_status_id'] = 4;
  37. $history_data['notify'] = 0;
  38. $history_data['comment'] = $title;
  39. $history_data['date_added'] = time();
  40. M('lionfish_comshop_order_history')->add( $history_data );
  41. D('Home/LocaltownDelivery')->change_distribution_order_state( $order_id, 0, 1);
  42. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id) )->save( array('delivery_type' => 1) );
  43. D('Home/Frontorder')->send_order_operate($order_id);
  44. //给配送员发送公众号消息
  45. $count = D('Seller/Redisorder')->set_distribution_delivery_message($order_id);
  46. return $count;
  47. }
  48. public function do_send_tuanz($order_id, $title = '后台操作,确认开始配送货物')
  49. {
  50. //express_time
  51. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 14, 'express_time' => time()) );
  52. //todo ... send tuanz msg
  53. $history_data = array();
  54. $history_data['order_id'] = $order_id;
  55. $history_data['order_status_id'] = 14;
  56. $history_data['notify'] = 0;
  57. $history_data['comment'] = $title;
  58. $history_data['date_added'] = time();
  59. M('lionfish_comshop_order_history')->add($history_data);
  60. }
  61. /**
  62. * 后台自动送达团长
  63. * @param unknown $order
  64. * @param string $title
  65. */
  66. public function order_auto_service($order,$title="后台自动确认送达团长"){
  67. if($order['delivery'] == 'tuanz_send'){//团长配送订单
  68. $is_communityhead_auto_service = D('Home/Front')->get_config_by_name('is_communityhead_auto_service');
  69. if($is_communityhead_auto_service == 1){//团长订单自动确认送达团长
  70. D('Seller/Order')->do_tuanz_over($order['order_id'],'后台自动确认送达团长');
  71. D('Home/Frontorder')->send_order_operate($order['order_id']);
  72. }
  73. }else if($order['delivery'] == 'pickup'){//到点自提订单
  74. $is_ziti_auto_service = D('Home/Front')->get_config_by_name('is_ziti_auto_service');
  75. if($is_ziti_auto_service == 1){//到店自提订单自动确认送达团长
  76. D('Seller/Order')->do_tuanz_over($order['order_id'],'后台自动确认送达团长');
  77. D('Home/Frontorder')->send_order_operate($order['order_id']);
  78. }
  79. }
  80. }
  81. public function update($data)
  82. {
  83. $ins_data = array();
  84. $ins_data['tagname'] = $data['tagname'];
  85. $ins_data['tagcontent'] = serialize(array_filter($data['tagcontent']));
  86. $ins_data['state'] = $data['state'];
  87. $ins_data['sort_order'] = $data['sort_order'];
  88. $id = $data['id'];
  89. if( !empty($id) && $id > 0 )
  90. {
  91. M('lionfish_comshop_goods_tags')->where( array('id' => $id) )->save( $ins_data );
  92. }else{
  93. M('lionfish_comshop_goods_tags')->add( $ins_data );
  94. }
  95. }
  96. public function load_order_list($reorder_status_id = 0,$is_fenxiao =0,$is_pin =0,$integral =0,$is_soli=0)
  97. {
  98. $time = I('request.time');
  99. $s_time_start = I('request.time_start');
  100. $s_time_end = I('request.time_end');
  101. if( !isset($time['start']) )
  102. {
  103. $time['start'] = $s_time_start;
  104. $time['end'] = $s_time_end;
  105. }
  106. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  107. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  108. $order_status_id = I('request.order_status_id', 0);
  109. if($reorder_status_id >0)
  110. {
  111. $order_status_id = $reorder_status_id;
  112. }
  113. $searchtime = I('request.searchtime','');
  114. $searchfield = I('request.searchfield', '');
  115. $searchtype = I('request.type', 'normal');
  116. if( $is_pin == 1 )
  117. {
  118. $searchtype = 'pintuan';
  119. }
  120. if( $integral == 1 )
  121. {
  122. $searchtype = 'integral';
  123. }
  124. if(empty($searchtype)){
  125. $searchtype = 'normal';
  126. }
  127. $delivery = I('request.delivery', '');
  128. $count_where = "";
  129. $agentid = I('request.agentid', '');
  130. $head_id = I('request.headid', '');
  131. //$is_fenxiao = I('request.is_fenxiao', 0);
  132. $pindex = I('request.page', 1);
  133. $psize = 20;
  134. $paras =array();
  135. $sqlcondition = "";
  136. $condition = " 1 ";
  137. $is_soli_type = I('request.type', '');
  138. if($is_soli_type == 'soli')
  139. {
  140. $is_soli = 1;
  141. }
  142. if($is_soli > 0)
  143. {
  144. $condition .= " and o.soli_id > 0 ";
  145. }
  146. //begin 预售
  147. if( isset($_GET['presale_order']) && $_GET['presale_order'] == 1 )
  148. {
  149. $condition .= " and opr.order_id=o.order_id ";
  150. $sqlcondition .= ' inner join ' . C('DB_PREFIX').'lionfish_comshop_order_presale opr ';
  151. }
  152. //end 预售
  153. //begin 礼品卡
  154. if( isset($_GET['virtualcard_order']) && $_GET['virtualcard_order'] == 1 )
  155. {
  156. $condition .= " and vco.order_id=o.order_id ";
  157. $sqlcondition .= ' inner join ' . C('DB_PREFIX').'lionfish_comshop_order_virtualcard vco ';
  158. }
  159. //end 礼品卡
  160. if (defined('ROLE') && ROLE == 'agenter' )
  161. {
  162. $supper_info = get_agent_logininfo();
  163. $order_ids_list_tmp = M('lionfish_comshop_order_goods')->field('order_id')->where( array('supply_id' => $supper_info['id'] ) )->select();
  164. if( !empty($order_ids_list_tmp) )
  165. {
  166. $order_ids_tmp_arr = array();
  167. foreach($order_ids_list_tmp as $vv)
  168. {
  169. $order_ids_tmp_arr[] = $vv['order_id'];
  170. }
  171. $order_ids_tmp_str = implode(',', $order_ids_tmp_arr);
  172. $condition .= " and o.order_id in({$order_ids_tmp_str}) ";
  173. }
  174. else{
  175. $condition .= " and o.order_id in(0) ";
  176. }
  177. }
  178. if( $is_fenxiao == 1)
  179. {
  180. //分销订单
  181. $condition .= " and o.is_commission = 1 ";
  182. $count_where .= " and is_commission = 1 ";
  183. $commiss_member_id = I('request.commiss_member_id', '');
  184. if( $commiss_member_id > 0 )
  185. {
  186. $order_ids = M('lionfish_comshop_member_commiss_order')->field('order_id')->where( array('member_id' => $commiss_member_id ) )->select();
  187. if(!empty($order_ids))
  188. {
  189. $order_ids_arr = array();
  190. foreach($order_ids as $vv)
  191. {
  192. $order_ids_arr[] = $vv['order_id'];
  193. }
  194. $order_ids_str = implode(",",$order_ids_arr);
  195. $condition .= ' AND ( o.order_id in('.$order_ids_str.') ) ';
  196. $count_where .= ' AND ( order_id in('.$order_ids_str.') ) ';
  197. }else{
  198. $condition .= " and o.order_id in(0) ";
  199. $count_where .= ' AND order_id in(0) ';
  200. }
  201. }
  202. }
  203. if( !empty($searchtype) && in_array($searchtype, array('normal','pintuan','integral')) )
  204. {
  205. $condition .= " and o.type ='{$searchtype}' ";
  206. }
  207. if( !empty($delivery) )
  208. {
  209. if($delivery == 'cashon_delivery'){
  210. $condition .= " and o.payment_code = '{$delivery}' ";
  211. }else{
  212. $condition .= " and o.delivery ='{$delivery}' ";
  213. }
  214. }
  215. if( !empty($head_id) && $head_id >0 )
  216. {
  217. $condition .= " and o.head_id ='{$head_id}' ";
  218. $count_where .= " and head_id ='{$head_id}' ";
  219. }
  220. if($order_status_id > 0)
  221. {
  222. //$condition .= " and o.order_status_id={$order_status_id} ";
  223. if($order_status_id ==12 )
  224. {
  225. $condition .= " and (o.order_status_id={$order_status_id} or o.order_status_id=10 ) ";
  226. }else if($order_status_id ==11)
  227. {
  228. $condition .= " and (o.order_status_id={$order_status_id} or o.order_status_id=6 ) ";
  229. }
  230. else{
  231. $condition .= " and o.order_status_id={$order_status_id} ";
  232. }
  233. }
  234. //$is_fenxiao = I('request.is_fenxiao','intval',0);
  235. $keyword = I('request.keyword');
  236. if( !empty($searchfield) && !empty($keyword))
  237. {
  238. $keyword = trim($keyword);
  239. $keyword = htmlspecialchars_decode($keyword, ENT_QUOTES);
  240. switch($searchfield)
  241. {
  242. case 'ordersn':
  243. $condition .= ' AND locate("'.$keyword.'",o.order_num_alias)>0';
  244. break;
  245. case 'member':
  246. $condition .= ' AND (locate("'.$keyword.'",m.username)>0 or locate("'.$keyword.'",m.telephone)>0 or "'.$keyword.'"=o.member_id ) and o.member_id >0 ';
  247. $sqlcondition .= ' left join ' . C('DB_PREFIX') . 'lionfish_comshop_member m on m.member_id = o.member_id ';
  248. break;
  249. case 'member_id':
  250. $keyword = intval($keyword);
  251. $condition .= ' AND o.member_id = '.$keyword.' ';
  252. break;
  253. case 'address':
  254. $condition .= ' AND ( locate("'.$keyword.'",o.shipping_name)>0 )';
  255. //shipping_address
  256. break;
  257. case 'mobile':
  258. $condition .= ' AND ( locate("'.$keyword.'",o.shipping_tel)>0 )';
  259. //shipping_address
  260. break;
  261. case 'location':
  262. $condition .= ' AND (locate("'.$keyword.'",o.shipping_address)>0 )';
  263. break;
  264. case 'shipping_no':
  265. $condition .= ' AND (locate("'.$keyword.'",o.shipping_no)>0 )';
  266. break;
  267. case 'head_address':
  268. $head_ids = M('lionfish_community_head')->field('id')->where( 'community_name like "%'.$keyword.'%"' )->select();
  269. if(!empty($head_ids))
  270. {
  271. $head_ids_arr = array();
  272. foreach($head_ids as $vv)
  273. {
  274. $head_ids_arr[] = $vv['id'];
  275. }
  276. $head_ids_str = implode(",",$head_ids_arr);
  277. $condition .= ' AND ( o.head_id in('.$head_ids_str.') )';
  278. }else{
  279. $condition .= " and o.order_id in(0) ";
  280. }
  281. break;
  282. case 'head_name':
  283. // SELECT * FROM `ims_lionfish_community_head` WHERE `head_name` LIKE '%黄%'
  284. $head_ids = M('lionfish_community_head')->field('id')->where( 'head_name like "%'.$keyword.'%"' )->select();
  285. if(!empty($head_ids))
  286. {
  287. $head_ids_arr = array();
  288. foreach($head_ids as $vv)
  289. {
  290. $head_ids_arr[] = $vv['id'];
  291. }
  292. $head_ids_str = implode(",",$head_ids_arr);
  293. $condition .= ' AND ( o.head_id in('.$head_ids_str.') )';
  294. }else{
  295. $condition .= " and o.order_id in(0) ";
  296. }
  297. break;
  298. case 'goodstitle':
  299. $sqlcondition = ' inner join ( select DISTINCT(og.order_id) from ' . C('DB_PREFIX').'lionfish_comshop_order_goods og where (locate("'.$keyword.'",og.name)>0)) gs on gs.order_id=o.order_id';
  300. //var_dump($sqlcondition);
  301. //die();
  302. break;
  303. case 'supply_name':
  304. $supply_name_sql = 'SELECT id FROM ' . C('DB_PREFIX').
  305. 'lionfish_comshop_supply where shopname like "%'.$keyword.'%"';
  306. $supply_ids = M()->query($supply_name_sql);
  307. if(!empty($supply_ids))
  308. {
  309. $supply_ids_arr = array();
  310. foreach($supply_ids as $vv)
  311. {
  312. $supply_ids_arr[] = $vv['id'];
  313. }
  314. $supply_ids_str = implode(",",$supply_ids_arr);
  315. $order_ids_list_tmp = M('lionfish_comshop_order_goods')->field('order_id')->where( "supply_id in ({$supply_ids_str})" )->select();
  316. if( !empty($order_ids_list_tmp) )
  317. {
  318. $order_ids_tmp_arr = array();
  319. foreach($order_ids_list_tmp as $vv)
  320. {
  321. $order_ids_tmp_arr[] = $vv['order_id'];
  322. }
  323. $order_ids_tmp_str = implode(',', $order_ids_tmp_arr);
  324. $condition .= " and o.order_id in({$order_ids_tmp_str}) ";
  325. }else{
  326. $condition .= " and o.order_id in(0) ";
  327. }
  328. }else{
  329. $condition .= " and o.order_id in(0) ";
  330. }
  331. break;
  332. case 'trans_id':
  333. $condition .= ' AND (locate('.$keyword.',o.transaction_id)>0 )';
  334. break;
  335. }
  336. }
  337. if( !empty($searchtime) )
  338. {
  339. switch( $searchtime )
  340. {
  341. case 'create':
  342. //下单时间 date_added
  343. $condition .= " and o.date_added>={$starttime} and o.date_added <= {$endtime}";
  344. break;
  345. case 'pay':
  346. //付款时间
  347. $condition .= " and o.pay_time>={$starttime} and o.pay_time <= {$endtime}";
  348. break;
  349. case 'send':
  350. //发货时间
  351. $condition .= " and o.express_time>={$starttime} and o.express_time <= {$endtime}";
  352. break;
  353. case 'finish':
  354. //完成时间
  355. $condition .= " and o.receive_time>={$starttime} and o.receive_time <= {$endtime}";
  356. break;
  357. }
  358. }
  359. //----begin----
  360. if (defined('ROLE') && ROLE == 'agenter' ) {
  361. $supper_info = get_agent_logininfo();
  362. $total_where = " and supply_id= ".$supper_info['id'];
  363. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".
  364. C('DB_PREFIX')."lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id'] );
  365. $order_ids_arr = array();
  366. $order_ids_arr_dan = array();
  367. $total_money = 0;
  368. foreach($order_ids_list as $vv)
  369. {
  370. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  371. {
  372. $order_ids_arr[$vv['order_id']] = $vv;
  373. $order_ids_arr_dan[] = $vv['order_id'];
  374. }
  375. }
  376. if( !empty($order_ids_arr_dan) )
  377. {
  378. $sql = 'SELECT count(o.order_id) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_order as o '.$sqlcondition.' where ' . $condition." and o.order_id in (".implode(',', $order_ids_arr_dan).") " ;
  379. $total_arr = M()->query($sql);
  380. $total = $total_arr[0]['count'];
  381. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  382. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where {$condition} and og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." ");
  383. if( !empty($order_ids_list) )
  384. {
  385. foreach($order_ids_list as $vv)
  386. {
  387. $total_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  388. }
  389. }
  390. }else{
  391. $total = 0;
  392. }
  393. }else{
  394. $sql = 'SELECT count(o.order_id) as count FROM ' . C('DB_PREFIX'). 'lionfish_comshop_order as o '.$sqlcondition.' where ' . $condition ;
  395. $total_arr = M()->query( $sql );
  396. $total = $total_arr[0]['count'];
  397. $sql = 'SELECT sum(o.total+o.shipping_fare-o.voucher_credit-o.fullreduction_money) as total_money FROM ' . C('DB_PREFIX') . 'lionfish_comshop_order as o '.$sqlcondition.' where ' . $condition ;
  398. $total_money_arr = M()->query($sql);
  399. $total_money = $total_money_arr[0]['total_money'];
  400. }
  401. //---------end----
  402. if($total_money < 0)
  403. {
  404. $total_money = 0;
  405. }
  406. $total_money = number_format($total_money,2);
  407. $order_status_arr = $this->get_order_status_name();
  408. $export = I('request.export', 0);
  409. if ($export == 1 || $export == 2)
  410. {
  411. @set_time_limit(0);
  412. $is_can_look_headinfo = true;
  413. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  414. if (defined('ROLE') && ROLE == 'agenter' )
  415. {
  416. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  417. {
  418. $is_can_look_headinfo = false;
  419. }
  420. }
  421. $note_content = D('Home/Front')->get_config_by_name('order_note_name');
  422. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  423. $columns = array(
  424. array('title' => '订单流水号', 'field' => 'day_paixu', 'width' => 24),
  425. array('title' => '订单编号', 'field' => 'order_num_alias', 'width' => 36),
  426. array('title' => '昵称', 'field' => 'name', 'width' => 12),
  427. //array('title' => '会员姓名', 'field' => 'mrealname', 'width' => 12),
  428. array('title' => 'openid', 'field' => 'openid', 'width' => 24),
  429. array('title' => '会员手机号', 'field' => 'telephone', 'width' => 12),
  430. array('title' => '会员备注', 'field' => 'member_content', 'width' => 24),
  431. array('title' => '收货姓名(或自提人)', 'field' => 'shipping_name', 'width' => 12),
  432. array('title' => '联系电话', 'field' => 'shipping_tel', 'width' => 12),
  433. array('title' => '供应商名称/类型', 'field' => 'supply_name', 'width' => 12),
  434. //array('title' => '收货地址', 'field' => 'address_province', 'width' => 12),
  435. //array('title' => '', 'field' => 'address_city', 'width' => 12),
  436. //array('title' => '', 'field' => 'address_area', 'width' => 12),
  437. array('title' => '微信支付交易单号', 'field' => 'transaction_id', 'width' => 24),
  438. array('title' => '完整收货地址', 'field' => 'address_province_city_area', 'width' => 12),
  439. //array('title' => '', 'field' => 'address_street', 'width' => 12),
  440. array('title' => '提货详细地址', 'field' => 'address_address', 'width' => 12),
  441. array('title' => '团长配送送货详细地址', 'field' => 'tuan_send_address', 'width' => 22),
  442. array('title' => '商品名称', 'field' => 'goods_title', 'width' => 24),
  443. array('title' => '商品分类', 'field' => 'goods_category', 'width' => 24),
  444. array('title' => '商品编码', 'field' => 'goods_goodssn', 'width' => 12),
  445. array('title' => '商品规格', 'field' => 'goods_optiontitle', 'width' => 12),
  446. array('title' => '商品数量', 'field' => 'quantity', 'width' => 12),
  447. array('title' => '商品单价', 'field' => 'goods_price1', 'width' => 12),
  448. //array('title' => '商品单价(折扣后)', 'field' => 'goods_price2', 'width' => 12),
  449. //array('title' => '商品价格(折扣前)', 'field' => 'goods_rprice1', 'width' => 12),
  450. array('title' => '商品价格', 'field' => 'goods_rprice2', 'width' => 12),
  451. array('title' => '支付方式', 'field' => 'paytype', 'width' => 12),
  452. array('title' => '配送方式', 'field' => 'delivery', 'width' => 12),
  453. array('title' => '预计送达时间', 'field' => 'expected_delivery_time', 'width' => 24),
  454. //array('title' => '自提门店', 'field' => 'pickname', 'width' => 24),
  455. //array('title' => '商品小计', 'field' => 'goodsprice', 'width' => 12),
  456. array('title' => '运费', 'field' => 'dispatchprice', 'width' => 12),
  457. array('title' => '积分抵扣', 'field' => 'score_for_money', 'width' => 12),
  458. //array('title' => '余额抵扣', 'field' => 'deductcredit2', 'width' => 12),
  459. array('title' => '满额立减', 'field' => 'fullreduction_money', 'width' => 12),
  460. array('title' => '优惠券优惠', 'field' => 'voucher_credit', 'width' => 12),
  461. array('title' => '会员佣金', 'field' => 'member_commissmoney', 'width' => 12),
  462. //array('title' => '订单改价', 'field' => 'changeprice', 'width' => 12),
  463. //array('title' => '运费改价', 'field' => 'changedispatchprice', 'width' => 12),
  464. array('title' => '应收款(该笔订单总款)', 'field' => 'price', 'width' => 12),
  465. array('title' => '状态', 'field' => 'status', 'width' => 12),
  466. array('title' => '团长佣金', 'field' => 'head_money', 'width' => 12),
  467. array('title' => '下单时间', 'field' => 'createtime', 'width' => 24),
  468. array('title' => '付款时间', 'field' => 'paytime', 'width' => 24),
  469. array('title' => '发货时间', 'field' => 'sendtime', 'width' => 24),
  470. array('title' => '收货时间', 'field' => 'receive_time', 'width' => 24),
  471. array('title' => '退款商品数量', 'field' => 'has_refund_quantity', 'width' => 12),
  472. array('title' => '退款金额', 'field' => 'has_refund_money', 'width' => 12),
  473. array('title' => '完成时间', 'field' => 'finishtime', 'width' => 24),
  474. array('title' => '快递公司', 'field' => 'expresscom', 'width' => 24),
  475. array('title' => '快递单号', 'field' => 'expresssn', 'width' => 24),
  476. array('title' => '小区名称', 'field' => 'community_name', 'width' => 12),
  477. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 12),
  478. array('title' => '团长电话', 'field' => 'head_mobile', 'width' => 12),
  479. array('title' => '团长完整地址', 'field' => 'fullAddress', 'width' => 24),
  480. array('title' => '省市区', 'field' => 'province', 'width' => 24),
  481. array('title' => '订单备注', 'field' => 'remark', 'width' => 36),
  482. array('title' => '卖家订单备注', 'field' => 'remarksaler', 'width' => 36),
  483. array('title' => '商品成本价', 'field' => 'costprice', 'width' => 36),
  484. //array('title' => '核销员', 'field' => 'salerinfo', 'width' => 24),
  485. //array('title' => '核销门店', 'field' => 'storeinfo', 'width' => 36),
  486. //array('title' => '订单自定义信息', 'field' => 'order_diyformdata', 'width' => 36),
  487. //array('title' => '商品自定义信息', 'field' => 'goods_diyformdata', 'width' => 36)
  488. array('title' => '省', 'field' => 'address_province', 'width' => 36),
  489. array('title' => '市', 'field' => 'address_city', 'width' => 36),
  490. array('title' => '区', 'field' => 'address_country', 'width' => 36),
  491. array('title' => '商品重量(克)', 'field' => 'goods_weight', 'width' => 36),
  492. );
  493. if($order_note_open == 1){
  494. if(empty($note_content)){
  495. $note_content= '店名';
  496. }
  497. $columns[] = array('title' => $note_content, 'field' => 'note_content', 'width' => 24, 'sort' => 0, 'is_check' => 0);
  498. }
  499. //modify_explode_arr
  500. $modify_explode_arr = I('request.modify_explode_arr', '');
  501. $columns_keys = array();
  502. foreach($columns as $val)
  503. {
  504. $columns_keys[ $val['field'] ] = array('title' => $val['title'],'width' => $val['width'] );
  505. }
  506. if( !empty($modify_explode_arr) )
  507. {
  508. /**
  509. order_num_alias,
  510. name,telephone,member_content,shipping_name,shipping_tel,
  511. address_province_city_area,address_address,goods_title,goods_rprice2,quantity,paytype,
  512. delivery,tuan_send_address,goods_optiontitle,goods_price1,receive_time,expresssn,createtime,
  513. community_name,head_name,head_mobile
  514. **/
  515. $ziduan_arr = explode(',', $modify_explode_arr);
  516. $length = count($ziduan_arr);
  517. $columns = array();
  518. $save_columns = array();
  519. foreach( $ziduan_arr as $fields )
  520. {
  521. if($fields == 'province'){
  522. $columns[] = array('title' => $columns_keys['address_province']['title'], 'field' => 'address_province', 'width' => $columns_keys['address_province']['width'] );
  523. $columns[] = array('title' => $columns_keys['address_city']['title'], 'field' => 'address_city', 'width' => $columns_keys['address_city']['width'] );
  524. $columns[] = array('title' => $columns_keys['address_country']['title'], 'field' => 'address_country', 'width' => $columns_keys['address_country']['width'] );
  525. }else{
  526. $columns[] = array('title' => $columns_keys[$fields]['title'], 'field' => $fields, 'width' => $columns_keys[$fields]['width'] );
  527. }
  528. $save_columns[$fields] = $length;
  529. $length--;
  530. }
  531. //dump(777);die;
  532. D('Seller/Config')->update( array('modify_export_fields' => json_encode($save_columns) ) );
  533. }
  534. $exportlist = array();
  535. if (!(empty($total))) {
  536. //begin
  537. set_time_limit(0);
  538. $fileName = date('YmdHis', time());
  539. header('Content-Type: application/vnd.ms-execl');
  540. header('Content-Disposition: attachment;filename="订单数据' . $fileName . '.csv"');
  541. $begin = microtime(true);
  542. $fp = fopen('php://output', 'a');
  543. $step = 100;
  544. $nums = 10000;
  545. //设置标题
  546. //$title = array('ID', '用户名', '用户年龄', '用户描述', '用户手机', '用户QQ', '用户邮箱', '用户地址');
  547. $title = array();
  548. foreach($columns as $key => $item) {
  549. $title[$item['field']] = iconv('UTF-8', 'GBK', $item['title']);
  550. }
  551. fputcsv($fp, $title);
  552. //$page = ceil($total / 500);
  553. $sqlcondition .= ' left join ' .C('DB_PREFIX') . 'lionfish_comshop_order_goods ogc on ogc.order_id = o.order_id ';
  554. $sql_count = 'SELECT count(o.order_id) as count
  555. FROM ' . C('DB_PREFIX'). 'lionfish_comshop_order as o '.$sqlcondition.' where ' . $condition ;
  556. $total_arr = M()->query($sql_count);
  557. $total = $total_arr[0]['count'];
  558. $page = ceil($total / 500);
  559. for($s = 1; $s <= $page; $s++) {
  560. $offset = ($s-1)* 500;
  561. if ($_GPC['export'] == 1 ) {
  562. $sql = 'SELECT o.*,ogc.name as goods_title,ogc.supply_id,ogc.goods_id,ogc.order_goods_id ,ogc.quantity as ogc_quantity,ogc.price,ogc.statements_end_time,
  563. ogc.total as goods_total ,ogc.score_for_money as g_score_for_money, ogc.fullreduction_money as g_fullreduction_money,ogc.voucher_credit as g_voucher_credit ,ogc.has_refund_money,ogc.has_refund_quantity , ogc.shipping_fare as g_shipping_fare,ogc.model as model ,ogc.cost_price
  564. FROM ' . C('DB_PREFIX') . 'lionfish_comshop_order as o '.$sqlcondition.' where ' . $condition . ' ORDER BY o.head_id asc,ogc.goods_id desc, o.`order_id` DESC limit '."{$offset},500";
  565. }else{
  566. $sql = 'SELECT o.*,ogc.name as goods_title,ogc.supply_id,ogc.order_goods_id,ogc.goods_id,ogc.quantity as ogc_quantity,ogc.price,ogc.is_refund_state,ogc.statements_end_time,
  567. ogc.total as goods_total ,ogc.score_for_money as g_score_for_money, ogc.fullreduction_money as g_fullreduction_money,ogc.voucher_credit as g_voucher_credit ,ogc.has_refund_money,ogc.has_refund_quantity ,ogc.shipping_fare as g_shipping_fare,ogc.model as model ,ogc.cost_price
  568. FROM ' . C('DB_PREFIX') . 'lionfish_comshop_order as o '.$sqlcondition.' where ' . $condition . ' ORDER BY o.`order_id` DESC limit '."{$offset},500";
  569. }
  570. $list = M()->query( $sql );
  571. // var_dump($list);
  572. $look_member_arr = array();
  573. $area_arr = array();
  574. if( !empty($list) )
  575. {
  576. foreach($list as $val)
  577. {
  578. if (defined('ROLE') && ROLE == 'agenter' )
  579. {
  580. $supper_info = get_agent_logininfo();
  581. if($supper_info['id'] != $val['supply_id'])
  582. {
  583. continue;
  584. }
  585. }
  586. if( empty($look_member_arr) || !isset($look_member_arr[$val['member_id']]) )
  587. {
  588. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id']) )->find();
  589. $look_member_arr[$val['member_id']] = $member_info;
  590. }
  591. $category_name = "";
  592. $cate_list = M('lionfish_comshop_goods_to_category')->where( array('goods_id' => $val['goods_id'] ) )->select();
  593. $cate_arr = array();
  594. if( !empty($cate_list) )
  595. {
  596. foreach( $cate_list as $c_val )
  597. {
  598. $ct_info = M('lionfish_comshop_goods_category')->field('name')->where( array('id' => $c_val['cate_id'] ) )->find();
  599. if( !empty($ct_info) )
  600. {
  601. $cate_arr[] = $ct_info['name'];
  602. }
  603. }
  604. $category_name = implode('、', $cate_arr);
  605. }
  606. $tmp_exval= array();
  607. $tmp_exval['order_num_alias'] = $val['order_num_alias']."\t";
  608. $tmp_exval['day_paixu'] = '#'.$val['day_paixu'];
  609. $tmp_exval['name'] = $look_member_arr[$val['member_id']]['username'];
  610. $tmp_exval['goods_category'] = $category_name;
  611. //from_type
  612. if($val['from_type'] == 'wepro')
  613. {
  614. $tmp_exval['openid'] = $look_member_arr[$val['member_id']]['we_openid'];
  615. }else{
  616. $tmp_exval['openid'] = $look_member_arr[$val['member_id']]['openid'];
  617. }
  618. $tmp_exval['telephone'] = $look_member_arr[$val['member_id']]['telephone'];
  619. $tmp_exval['member_content'] = $look_member_arr[$val['member_id']]['content'];
  620. $tmp_exval['shipping_name'] = $val['shipping_name'];
  621. $tmp_exval['shipping_tel'] = $val['shipping_tel'];
  622. //area_arr
  623. if( empty($area_arr) || !isset($area_arr[$val['shipping_province_id']]) )
  624. {
  625. $area_arr[$val['shipping_province_id']] = D('Seller/Front')->get_area_info($val['shipping_province_id']);
  626. }
  627. if( empty($area_arr) || !isset($area_arr[$val['shipping_city_id']]) )
  628. {
  629. $area_arr[$val['shipping_city_id']] = D('Seller/Front')->get_area_info($val['shipping_city_id']);
  630. }
  631. if( empty($area_arr) || !isset($area_arr[$val['shipping_country_id']]) )
  632. {
  633. $area_arr[$val['shipping_country_id']] = D('Seller/Front')->get_area_info($val['shipping_country_id']);
  634. }
  635. $province_info = $area_arr[$val['shipping_province_id']];
  636. $city_info = $area_arr[$val['shipping_city_id']];
  637. $area_info = $area_arr[$val['shipping_country_id']];
  638. $tmp_exval['address_province_city_area'] = $province_info['name'].$city_info['name'].$area_info['name'].$val['shipping_address'];
  639. $tmp_exval['address_province'] = $province_info['name'];
  640. $tmp_exval['address_city'] = $city_info['name'];
  641. $tmp_exval['address_country'] = $area_info['name'];
  642. $tmp_exval['goods_goodssn'] = $val['model'];
  643. $tmp_exval['address_address'] = $val['shipping_address'];
  644. if( $val['delivery'] == 'tuanz_send'){
  645. // $tmp_exval['address_address'] = $val['tuan_send_address'];
  646. }
  647. $tmp_exval['tuan_send_address'] = $val['tuan_send_address'];
  648. $tmp_exval['goods_title'] = htmlspecialchars_decode(stripslashes($val['goods_title']));
  649. if($val['supply_id'] == 0){
  650. $tmp_exval['supply_name'] = '平台自营(自营)';
  651. }else{
  652. $supply_list = M('lionfish_comshop_supply')->where( array('id' => $val['supply_id'] ) )->find();
  653. $tmp_exval['supply_name'] = $supply_list['shopname'].'(独立供应商)';
  654. }
  655. $goods_optiontitle = $this->get_order_option_sku($val['order_id'], $val['order_goods_id']);
  656. $tmp_exval['goods_optiontitle'] = $goods_optiontitle;
  657. $tmp_exval['quantity'] = $val['ogc_quantity'];
  658. $tmp_exval['goods_price1'] = $val['price'];
  659. $tmp_exval['goods_rprice2'] = $val['goods_total'];
  660. $tmp_exval['has_refund_money'] = $val['has_refund_money'];
  661. $tmp_exval['has_refund_quantity'] = $val['has_refund_quantity'];
  662. $goods_weight = $this->get_order_option_weight($val['order_id'], $val['order_goods_id']);
  663. $tmp_exval['goods_weight'] = $goods_weight;
  664. $paytype = $val['payment_code'];
  665. switch($paytype)
  666. {
  667. case 'admin':
  668. $paytype='后台支付';
  669. break;
  670. case 'yuer':
  671. $paytype='余额支付';
  672. break;
  673. case 'weixin':
  674. $paytype='微信支付';
  675. break;
  676. default:
  677. $paytype = '未支付';
  678. }
  679. //has_refund_quantity has_refund_money
  680. //$val['order_id'], $val['order_goods_id']
  681. $has_refund_quantity = D('Seller/Commonorder')->refund_order_goods_quantity( $val['order_id'], $val['order_goods_id'] );
  682. $tmp_exval['has_refund_quantity'] = $has_refund_quantity;
  683. $has_refund_money = D('Seller/Commonorder')->get_order_goods_refund_money( $val['order_id'], $val['order_goods_id'] );
  684. $tmp_exval['has_refund_money'] = $has_refund_money;
  685. if(!empty($val['head_id'])){
  686. $community_info = D('Seller/Front')->get_community_byid($val['head_id']);
  687. $tmp_exval['community_name'] = $community_info['communityName'];
  688. if( $is_can_look_headinfo )
  689. {
  690. $tmp_exval['fullAddress'] = $community_info['fullAddress'];
  691. $tmp_exval['head_name'] = $community_info['disUserName'];
  692. $tmp_exval['head_mobile'] = $community_info['head_mobile'];
  693. }else{
  694. $tmp_exval['fullAddress'] = '';
  695. $tmp_exval['head_name'] = '';
  696. $tmp_exval['head_mobile'] = '';
  697. }
  698. }else{
  699. $tmp_exval['community_name'] = '';
  700. $tmp_exval['fullAddress'] = '';
  701. $tmp_exval['head_name'] = '';
  702. $tmp_exval['head_mobile'] = '';
  703. }
  704. $tmp_exval['paytype'] = $paytype;
  705. //express 快递, pickup 自提, tuanz_send 团长配送
  706. //$tmp_exval['delivery'] = $val['delivery'] == 'express'? '快递':'自提';
  707. if($val['delivery'] == 'express'){
  708. $tmp_exval['delivery'] = '快递';
  709. }elseif($val['delivery'] == 'pickup'){
  710. $tmp_exval['delivery'] = '自提';
  711. }elseif($val['delivery'] == 'tuanz_send'){
  712. $tmp_exval['delivery'] = '团长配送';
  713. }
  714. $tmp_exval['expected_delivery_time'] =$val['expected_delivery_time'];
  715. if ($_GPC['export'] == 1 ) {
  716. $tmp_exval['dispatchprice'] = $val['g_shipping_fare'];
  717. $val['total'] = $val['goods_total']+$val['g_shipping_fare']-$val['g_score_for_money']-$val['g_fullreduction_money'] - $val['g_voucher_credit'];
  718. if($val['total'] < 0)
  719. {
  720. $val['total'] = 0;
  721. }
  722. $tmp_exval['price'] = $val['total'];
  723. }else{
  724. //总运费
  725. $shipping_fare_sum = array();
  726. $shipping_fare_sum = M('lionfish_comshop_order')->where( array('order_id' => $val['order_id']) )->count('shipping_fare');
  727. $total = M('lionfish_comshop_order')->where( array('order_id' => $val['order_id']) )->field('total, shipping_fare, score_for_money,fullreduction_money, voucher_credit')->find();
  728. //
  729. $order_goods_id = M('lionfish_comshop_order_goods')->where( array('order_id' => $val['order_id']) )->field('order_goods_id')->order('order_goods_id asc')->find();
  730. $lionfish_comshop_order_goods = M('lionfish_comshop_order_goods')->where( array('goods_id' => $val['goods_id'],'order_id' => $val['order_id']) )->find();
  731. if($order_goods_id['order_goods_id'] == $val['order_goods_id'] ){
  732. $tmp_exval['dispatchprice'] = $shipping_fare_sum;
  733. $tmp_exval['price'] = $total['total']+$total['shipping_fare']-$total['score_for_money']-$total['fullreduction_money'] - $total['voucher_credit'];
  734. }else{
  735. $tmp_exval['dispatchprice'] = 0;
  736. $tmp_exval['price'] = 0;
  737. }
  738. }
  739. $tmp_exval['transaction_id'] = $val['transaction_id']."\t";
  740. $tmp_exval['note_content'] = $val['note_content'];
  741. $tmp_exval['score_for_money'] = $val['g_score_for_money'];
  742. $tmp_exval['fullreduction_money'] = $val['g_fullreduction_money'];
  743. $tmp_exval['voucher_credit'] = $val['g_voucher_credit'];
  744. $tmp_exval['changeprice'] = $val['changedtotal'];
  745. $tmp_exval['changedispatchprice'] = $val['changedshipping_fare'];
  746. $val['total'] = $val['goods_total']+$val['g_shipping_fare']-$val['g_score_for_money']-$val['g_fullreduction_money'] - $val['g_voucher_credit'];
  747. if($val['total'] < 0)
  748. {
  749. $val['total'] = 0;
  750. }
  751. $tmp_exval['price'] = $val['total'];
  752. $tmp_exval['head_money'] = 0;
  753. $head_commiss_order = M('lionfish_community_head_commiss_order')->where( array('order_id' => $val['order_id'],'order_goods_id' => $val['order_goods_id'],'type' => 'orderbuy') )->select();
  754. if( !empty($head_commiss_order) )
  755. {
  756. $head_money = 0;
  757. foreach($head_commiss_order as $k=>$v){
  758. $head_money = $head_money + $v['money'];
  759. }
  760. $tmp_exval['head_money'] = $head_money;
  761. //$tmp_exval['head_money'] = $head_commiss_order['money'];
  762. }
  763. $tmp_exval['member_commissmoney'] = 0;
  764. //array('title' => '会员佣金', 'field' => 'member_commissmoney', 'width' => 12),
  765. $member_commissmoney = M('lionfish_comshop_member_commiss_order')->where( array('order_id' => $val['order_id'], 'order_goods_id' => $val['order_goods_id'] ) )->sum('money');
  766. if( !empty($member_commissmoney) && $member_commissmoney > 0 )
  767. {
  768. $tmp_exval['member_commissmoney'] = $member_commissmoney;
  769. }
  770. if($val['has_refund_quantity'] > 0){
  771. $tmp_exval['status'] = $order_status_arr[7];
  772. }else{
  773. $tmp_exval['status'] = $order_status_arr[$val['order_status_id']];
  774. }
  775. $tmp_exval['createtime'] = date('Y-m-d H:i:s', $val['date_added']);
  776. $tmp_exval['paytime'] = empty($val['pay_time']) ? '' : date('Y-m-d H:i:s', $val['pay_time']);
  777. $tmp_exval['sendtime'] = empty($val['express_time']) ? '': date('Y-m-d H:i:s', $val['express_time']);
  778. $tmp_exval['finishtime'] = empty($val['finishtime']) ? '' : date('Y-m-d H:i:s', $val['finishtime']);
  779. $tmp_exval['receive_time'] = empty($val['receive_time']) ? '' : date('Y-m-d H:i:s', $val['receive_time']);
  780. $tmp_exval['expresscom'] = $val['dispatchname'];
  781. $tmp_exval['expresssn'] = $val['shipping_no'];
  782. $tmp_exval['remark'] = $val['comment'];
  783. $tmp_exval['remarksaler'] = $val['remarksaler'];
  784. $tmp_exval['costprice'] = 0;
  785. $lionfish_comshop_goods = M('lionfish_comshop_goods')->where( array('id' => $val['goods_id']) )->find();
  786. if(!empty($lionfish_comshop_goods)){
  787. if ($lionfish_comshop_goods['hasoption'] == 1){
  788. $lionfish_comshop_order_goods = M('lionfish_comshop_order_goods')->where( array('goods_id' => $val['goods_id'],'order_id' => $val['order_id']) )->find();
  789. if (!empty($lionfish_comshop_order_goods)){
  790. $lionfish_comshop_goods_option_item_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' => $lionfish_comshop_order_goods['rela_goodsoption_valueid'],'goods_id' => $val['goods_id']) )->find();
  791. $tmp_exval['costprice'] = isset($lionfish_comshop_goods_option_item_value['costprice'])?$lionfish_comshop_goods_option_item_value['costprice'] : 0;
  792. }
  793. }else{
  794. $tmp_exval['costprice'] = $lionfish_comshop_goods['costprice'];
  795. }
  796. }
  797. $tmp_exval['costprice'] = isset($val['cost_price'])?$val['cost_price'] : 0;
  798. $exportlist[] = $tmp_exval;
  799. $row_arr = array();
  800. foreach($columns as $key => $item) {
  801. $row_arr[$item['field']] = iconv('UTF-8', 'GBK//IGNORE', $tmp_exval[$item['field']]);
  802. }
  803. //var_dump($row_arr);die;
  804. fputcsv($fp, $row_arr);
  805. }
  806. ob_flush();
  807. flush();
  808. unset($list);
  809. }
  810. }
  811. die();
  812. //D('Seller/Excel')->export($exportlist, array('title' => '订单数据', 'columns' => $columns));
  813. }
  814. }
  815. if (!(empty($total))) {
  816. $sql = 'SELECT o.* FROM ' .C('DB_PREFIX'). 'lionfish_comshop_order as o '.$sqlcondition.' where ' . $condition . ' ORDER BY o.`order_id` DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  817. $list = M()->query($sql);
  818. $need_list = array();
  819. foreach ($list as $key => &$value ) {
  820. $sql_goods = "select og.* from ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  821. where og.order_id = {$value[order_id]} ";
  822. $goods = M()->query($sql_goods);
  823. $value['is_virtualcard'] = 0;
  824. if( $value['delivery'] == 'express' )
  825. {
  826. $virtualcard_result = D('Seller/VirtualCard')->getVirtualCardOrderInfO( $value['order_id'] );
  827. if( $virtualcard_result['code'] == 0 ) {
  828. $value['is_virtualcard'] = 1;
  829. }
  830. }
  831. $need_goods = array();
  832. $shipping_fare = 0;
  833. $fullreduction_money = 0;
  834. $voucher_credit = 0;
  835. $totals = 0;
  836. if( $value['delivery'] == 'localtown_delivery' && ($value['order_status_id'] != 3 && $value['order_status_id'] != 5 ) )
  837. {
  838. $value['orderdistribution_order'] = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $value['order_id'] ) )->find();
  839. if( !empty($value['orderdistribution_order']) && $value['orderdistribution_order'] > 0 )
  840. {
  841. $orderdistribution = M('lionfish_comshop_orderdistribution')->where( array('id' => $value['orderdistribution_order']['orderdistribution_id'] ) )->find();
  842. $value['orderdistribution_order']['username'] = $orderdistribution['username'];
  843. }
  844. $imdada_data = M('lionfish_comshop_orderdistribution_thirth_query')->where( array('order_id' => $value['order_id'], 'third_distribution_type'=>'imdada' ) )->find();
  845. if($imdada_data['status'] == 1){
  846. $value['pre_imdada_delivery_fee'] = "¥".$imdada_data['shipping_fee'];
  847. }else{
  848. $value['pre_imdada_delivery_fee'] = $imdada_data['message'];
  849. }
  850. $mk_data = M('lionfish_comshop_orderdistribution_thirth_query')->where( array('order_id' => $value['order_id'], 'third_distribution_type'=>'mk' ) )->find();
  851. if($mk_data['status'] == 1){
  852. $value['pre_mk_delivery_fee'] = "¥".$mk_data['shipping_fee'];
  853. }else{
  854. $value['pre_mk_delivery_fee'] = $mk_data['message'];
  855. }
  856. $sf_data = M('lionfish_comshop_orderdistribution_thirth_query')->where( array('order_id' => $value['order_id'], 'third_distribution_type'=>'sf' ) )->find();
  857. if($sf_data['status'] == 1){
  858. $value['pre_sf_delivery_fee'] = "¥".$sf_data['shipping_fee'];
  859. }else{
  860. $value['pre_sf_delivery_fee'] = $sf_data['message'];
  861. }
  862. //达达配送是否已发过
  863. $imdada_count = M('lionfish_comshop_orderdistribution_thirth_log')->where(array('order_id'=>$value['order_id'],'third_distribution_type'=>'imdada'))->count();
  864. $imdada_has_send = 0;
  865. if($imdada_count > 0){
  866. $imdada_has_send = 1;
  867. }
  868. $value['imdada_has_send'] = $imdada_has_send;
  869. //顺丰配送是否已发过
  870. $sf_count = M('lionfish_comshop_orderdistribution_thirth_log')->where(array('order_id'=>$value['order_id'],'third_distribution_type'=>'sf'))->count();
  871. $sf_has_send = 0;
  872. if($sf_count > 0){
  873. $sf_has_send = 1;
  874. }
  875. $value['sf_has_send'] = $sf_has_send;
  876. }
  877. foreach($goods as $key =>$goods_val)
  878. {
  879. $goods_val['name'] = htmlspecialchars_decode(stripslashes($goods_val['name']));
  880. if( $goods_val['is_statements_state'] == 1 )
  881. {
  882. $value['is_statements_state'] = 1;
  883. }
  884. $goods_val['option_sku'] = $this->get_order_option_sku($value['order_id'], $goods_val['order_goods_id']);
  885. $goods_val['commisson_info'] = array();//load_model_class('commission')->get_order_goods_commission( $value['order_id'], $goods_val['order_goods_id']);
  886. //供应商名称
  887. $goods_val['shopname'] = M('lionfish_comshop_supply')->field('shopname,type')->where( array('id' => $goods_val['supply_id'] ) )->find();
  888. //商品类型
  889. $goods_val['goods_type'] = M('lionfish_comshop_goods')->field('type')->where( array('id' => $goods_val['goods_id'] ) )->find();
  890. if( $goods_val['is_refund_state'] == 1 )
  891. {
  892. $refund_info = M('lionfish_comshop_order_refund')->where( array('order_id' => $value['order_id'] ,'order_goods_id' => $goods_val['order_goods_id']) )->order('ref_id desc')->find();
  893. $goods_val['refund_info'] = $refund_info;
  894. }
  895. if (defined('ROLE') && ROLE == 'agenter' )
  896. {
  897. $supper_info = get_agent_logininfo();
  898. if($supper_info['id'] != $goods_val['supply_id'])
  899. {
  900. continue;
  901. }
  902. }
  903. $shipping_fare += $goods_val['shipping_fare'];
  904. $fullreduction_money += $goods_val['fullreduction_money'];
  905. $voucher_credit += $goods_val['voucher_credit'];
  906. $totals += $goods_val['total'];
  907. if($value['delivery'] == 'hexiao'){
  908. $goods_val['hexiao_info'] = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' => $value['order_id'] ,'order_goods_id' => $goods_val['order_goods_id']) )->find();
  909. }
  910. $need_goods[$key] = $goods_val;
  911. }
  912. if (defined('ROLE') && ROLE == 'agenter' )
  913. {
  914. $value['shipping_fare'] = $shipping_fare;
  915. $value['fullreduction_money'] = $fullreduction_money;
  916. $value['voucher_credit'] = $voucher_credit;
  917. $value['total'] = $totals;
  918. }
  919. //member_id ims_ nickname
  920. $nickname_info = M('lionfish_comshop_member')->field('username as nickname,content')->where( array('member_id' => $value['member_id']) )->find();
  921. $nickname = $nickname_info['nickname'];
  922. $value['nickname'] = $nickname;
  923. $value['member_content'] = $nickname_info['content'];
  924. $value['goods'] = $need_goods;
  925. if($value['head_id'] <=0 )
  926. {
  927. $value['community_name'] = '';
  928. $value['head_name'] = '';
  929. $value['head_mobile'] = '';
  930. $value['province'] = '';
  931. $value['city'] = '';
  932. }else{
  933. $community_info = D('Seller/Front')->get_community_byid($value['head_id']);
  934. $value['community_name'] = $community_info['communityName'];
  935. $value['head_name'] = $community_info['disUserName'];
  936. $value['head_mobile'] = $community_info['head_mobile'];
  937. if (defined('ROLE') && ROLE == 'agenter' )
  938. {
  939. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  940. if($supply_can_look_headinfo != 1){
  941. $value['community_name'] = D('Seller/Order')->desensitize($community_info['communityName'],0,-1);
  942. $value['head_name'] = D('Seller/Order')->desensitize($community_info['disUserName'],1,1);
  943. $value['head_mobile'] = D('Seller/Order')->desensitize($community_info['head_mobile'],3,4);
  944. }
  945. }
  946. $value['province'] = $community_info['province'];
  947. $value['city'] = $community_info['city'];
  948. }
  949. }
  950. $pager = pagination2($total, $pindex, $psize);
  951. }
  952. //get_order_count($where = '',$uniacid = 0)
  953. if( !empty($searchtype) )
  954. {
  955. $count_where .= " and type = '{$searchtype}' ";
  956. }
  957. if (defined('ROLE') && ROLE == 'agenter' )
  958. {
  959. $supper_info = get_agent_logininfo();
  960. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  961. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." ");
  962. $order_ids_arr = array();
  963. $seven_refund_money= 0;
  964. foreach($order_ids_list as $vv)
  965. {
  966. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  967. {
  968. $order_ids_arr[$vv['order_id']] = $vv['order_id'];
  969. }
  970. }
  971. if( !empty($order_ids_arr) )
  972. {
  973. $count_where .= " and order_id in (".implode(',', $order_ids_arr).")";
  974. }else{
  975. $count_where .= " and order_id in (0)";
  976. }
  977. }
  978. $all_count = $this->get_order_count($count_where);
  979. $count_status_1 = $this->get_order_count(" {$count_where} and order_status_id = 1 ");
  980. $count_status_3 = $this->get_order_count(" {$count_where} and order_status_id = 3 ");
  981. $count_status_4 = $this->get_order_count(" {$count_where} and order_status_id = 4 ");
  982. $count_status_5 = $this->get_order_count(" {$count_where} and order_status_id = 5 ");
  983. $count_status_7 = $this->get_order_count(" {$count_where} and order_status_id = 7 ");
  984. $count_status_11 = $this->get_order_count(" {$count_where} and (order_status_id = 11 or order_status_id = 6) ");
  985. $count_status_14 = $this->get_order_count(" {$count_where} and order_status_id = 14 ");
  986. $count_status_express = $this->get_order_count(" {$count_where} and order_status_id = 1 and delivery = 'express'");
  987. return array('total' => $total, 'total_money' => $total_money,'pager' => $pager, 'all_count' => $all_count,
  988. 'list' =>$list,
  989. 'count_status_1' => $count_status_1,'count_status_3' => $count_status_3,'count_status_4' => $count_status_4,
  990. 'count_status_5' => $count_status_5, 'count_status_7' => $count_status_7, 'count_status_11' => $count_status_11,
  991. 'count_status_14' => $count_status_14,'count_status_express'=>$count_status_express
  992. );
  993. }
  994. //---copy begin
  995. public function load_afterorder_list($is_pintuan = 0)
  996. {
  997. $time = I('request.time');
  998. $starttime = isset($time['start']) ? strtotime($time['start']) : strtotime(date('Y-m-d'.' 00:00:00'));
  999. $endtime = isset($time['end']) ? strtotime($time['end']) : strtotime(date('Y-m-d'.' 23:59:59'));
  1000. $order_status_id = I('request.order_status_id', 0);
  1001. $state = I('request.state', -1);
  1002. if($reorder_status_id >0)
  1003. {
  1004. $order_status_id = $reorder_status_id;
  1005. }
  1006. $searchtime = I('request.searchtime','');
  1007. $searchfield = I('request.searchfield', '');
  1008. $searchtype = I('request.type', '');
  1009. if( $is_pintuan == 1 && empty($searchtype) )
  1010. {
  1011. $searchtype = 'pintuan';
  1012. }
  1013. $delivery = I('request.delivery', '');
  1014. $count_where = "";
  1015. $agentid = I('request.agentid', '');
  1016. $head_id = I('request.headid', '');
  1017. $pindex = I('request.page', 1);
  1018. $psize = 20;
  1019. $paras =array();
  1020. $sqlcondition = "";
  1021. $condition = " 1 ";
  1022. if( defined('ROLE') && ROLE == 'agenter' )
  1023. {
  1024. $supper_info = session('agent_auth');
  1025. $supper_info['id'] = $supper_info['uid'];
  1026. $order_ids_list_tmp = M('lionfish_comshop_order_goods')->field('order_id')->where( array('supply_id' => $supper_info['id'] ) )->select();
  1027. if( !empty($order_ids_list_tmp) )
  1028. {
  1029. $order_ids_tmp_arr = array();
  1030. foreach($order_ids_list_tmp as $vv)
  1031. {
  1032. $order_ids_tmp_arr[] = $vv['order_id'];
  1033. }
  1034. $order_ids_tmp_str = implode(',', $order_ids_tmp_arr);
  1035. $condition .= " and o.order_id in({$order_ids_tmp_str}) ";
  1036. }
  1037. else{
  1038. $condition .= " and o.order_id in(0) ";
  1039. }
  1040. }
  1041. if( !empty($searchtype) )
  1042. {
  1043. $condition .= " and o.type ='{$searchtype}' ";
  1044. }
  1045. if( !empty($delivery) )
  1046. {
  1047. $condition .= " and o.delivery ='{$delivery}' ";
  1048. }
  1049. if( !empty($head_id) && $head_id >0 )
  1050. {
  1051. $condition .= " and o.head_id ='{$head_id}' ";
  1052. $count_where .= " and head_id ='{$head_id}' ";
  1053. }
  1054. if( $state >= 0 )
  1055. {
  1056. $condition .= " and ore.state ='{$state}' ";
  1057. }
  1058. if($order_status_id > 0)
  1059. {
  1060. if($order_status_id ==12 )
  1061. {
  1062. $condition .= " and (o.order_status_id={$order_status_id} or o.order_status_id=10 ) ";
  1063. }else if($order_status_id ==11)
  1064. {
  1065. $condition .= " and (o.order_status_id={$order_status_id} or o.order_status_id=6 ) ";
  1066. }
  1067. else{
  1068. $condition .= " and o.order_status_id={$order_status_id} ";
  1069. }
  1070. }
  1071. if( $is_fenxiao == 1)
  1072. {
  1073. //分销订单
  1074. $condition .= " and o.is_commission = 1 ";
  1075. $count_where = " and is_commission = 1 ";
  1076. }
  1077. $keyword = I('request.keyword');
  1078. if( !empty($searchfield) && !empty($keyword))
  1079. {
  1080. $keyword = trim($keyword);
  1081. $keyword = htmlspecialchars_decode($keyword, ENT_QUOTES);
  1082. switch($searchfield)
  1083. {
  1084. case 'ordersn':
  1085. $condition .= ' AND locate("'.$keyword.'",o.order_num_alias)>0';
  1086. break;
  1087. case 'member':
  1088. $condition .= ' AND (locate("'.$keyword.'",m.username)>0 or locate("'.$keyword.'",m.telephone)>0 or "'.$keyword.'"=o.member_id )';
  1089. $sqlcondition .= ' left join ' . C('DB_PREFIX') . 'lionfish_comshop_member m on m.member_id = o.member_id ';
  1090. break;
  1091. case 'address':
  1092. $condition .= ' AND ( locate("'.$keyword.'",o.shipping_name)>0 )';
  1093. //shipping_address
  1094. break;
  1095. case 'mobile':
  1096. $condition .= ' AND ( locate("'.$keyword.'",o.shipping_tel)>0 )';
  1097. //shipping_address
  1098. break;
  1099. case 'location':
  1100. $condition .= ' AND (locate("'.$keyword.'",o.shipping_address)>0 )';
  1101. break;
  1102. case 'shipping_no':
  1103. $condition .= ' AND (locate("'.$keyword.'",o.shipping_no)>0 )';
  1104. break;
  1105. case 'head_address':
  1106. $head_ids = M('lionfish_community_head')->field('id')->where( 'community_name like "%'.$keyword.'%"' )->select();
  1107. if(!empty($head_ids))
  1108. {
  1109. $head_ids_arr = array();
  1110. foreach($head_ids as $vv)
  1111. {
  1112. $head_ids_arr[] = $vv['id'];
  1113. }
  1114. $head_ids_str = implode(",",$head_ids_arr);
  1115. $condition .= ' AND ( o.head_id in('.$head_ids_str.') )';
  1116. }else{
  1117. $condition .= " and o.order_id in(0) ";
  1118. }
  1119. break;
  1120. case 'head_name':
  1121. // SELECT * FROM `ims_lionfish_community_head` WHERE `head_name` LIKE '%黄%'
  1122. $head_ids = M('lionfish_community_head')->field('id')->where( 'head_name like "%'.$keyword.'%"' )->select();
  1123. if(!empty($head_ids))
  1124. {
  1125. $head_ids_arr = array();
  1126. foreach($head_ids as $vv)
  1127. {
  1128. $head_ids_arr[] = $vv['id'];
  1129. }
  1130. $head_ids_str = implode(",",$head_ids_arr);
  1131. $condition .= ' AND ( o.head_id in('.$head_ids_str.') )';
  1132. }else{
  1133. $condition .= " and o.order_id in(0) ";
  1134. }
  1135. break;
  1136. case 'goodstitle':
  1137. $sqlcondition = ' inner join ( select DISTINCT(og.order_id) from ' . C('DB_PREFIX').'lionfish_comshop_order_goods og where (locate("'.$keyword.'",og.name)>0)) gs on gs.order_id=o.order_id';
  1138. //var_dump($sqlcondition);
  1139. //die();
  1140. break;
  1141. case 'supply_name':
  1142. $supply_name_sql = 'SELECT id FROM ' . C('DB_PREFIX').
  1143. 'lionfish_comshop_supply where shopname like "%'.$keyword.'%"';
  1144. $supply_ids = M()->query($supply_name_sql);
  1145. if(!empty($supply_ids))
  1146. {
  1147. $supply_ids_arr = array();
  1148. foreach($supply_ids as $vv)
  1149. {
  1150. $supply_ids_arr[] = $vv['id'];
  1151. }
  1152. $supply_ids_str = implode(",",$supply_ids_arr);
  1153. $order_ids_list_tmp = M('lionfish_comshop_order_goods')->field('order_id')->where( "supply_id in ({$supply_ids_str})" )->select();
  1154. if( !empty($order_ids_list_tmp) )
  1155. {
  1156. $order_ids_tmp_arr = array();
  1157. foreach($order_ids_list_tmp as $vv)
  1158. {
  1159. $order_ids_tmp_arr[] = $vv['order_id'];
  1160. }
  1161. $order_ids_tmp_str = implode(',', $order_ids_tmp_arr);
  1162. $condition .= " and o.order_id in({$order_ids_tmp_str}) ";
  1163. }else{
  1164. $condition .= " and o.order_id in(0) ";
  1165. }
  1166. }else{
  1167. $condition .= " and o.order_id in(0) ";
  1168. }
  1169. break;
  1170. case 'trans_id':
  1171. $condition .= ' AND (locate('.$keyword.',o.transaction_id)>0 )';
  1172. break;
  1173. }
  1174. }
  1175. if( !empty($searchtime) )
  1176. {
  1177. switch( $searchtime )
  1178. {
  1179. case 'create':
  1180. //下单时间 date_added
  1181. $condition .= " and o.date_added>={$starttime} and o.date_added <= {$endtime}";
  1182. break;
  1183. case 'pay':
  1184. //付款时间
  1185. $condition .= " and o.pay_time>={$starttime} and o.pay_time <= {$endtime}";
  1186. break;
  1187. case 'send':
  1188. //发货时间
  1189. $condition .= " and o.express_time>={$starttime} and o.express_time <= {$endtime}";
  1190. break;
  1191. case 'finish':
  1192. //完成时间
  1193. $condition .= " and o.finishtime>={$starttime} and o.finishtime <= {$endtime}";
  1194. break;
  1195. }
  1196. }
  1197. if (defined('ROLE') && ROLE == 'agenter' ) {
  1198. $supper_info = get_agent_logininfo();
  1199. $total_where = " and supply_id= ".$supper_info['id'];
  1200. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".
  1201. C('DB_PREFIX')."lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id'] );
  1202. $order_ids_arr = array();
  1203. $order_ids_arr_dan = array();
  1204. $total_money = 0;
  1205. foreach($order_ids_list as $vv)
  1206. {
  1207. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  1208. {
  1209. $order_ids_arr[$vv['order_id']] = $vv;
  1210. $order_ids_arr_dan[] = $vv['order_id'];
  1211. }
  1212. }
  1213. if( !empty($order_ids_arr_dan) )
  1214. {
  1215. $sql = 'SELECT count(o.order_id) as count FROM '.C('DB_PREFIX')."lionfish_comshop_order_refund as ore, " . C('DB_PREFIX'). 'lionfish_comshop_order as o
  1216. '.$sqlcondition.' where ' . $condition." and ore.order_id = o.order_id and o.order_id in (".implode(',', $order_ids_arr_dan).") " ;
  1217. $total_arr = M()->query($sql);
  1218. $total = $total_arr[0]['count'];
  1219. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money
  1220. from ".C('DB_PREFIX')."lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o ,".C('DB_PREFIX')."lionfish_comshop_order_refund as ore
  1221. where {$condition} and ore.order_id = o.order_id and og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." ");
  1222. if( !empty($order_ids_list) )
  1223. {
  1224. foreach($order_ids_list as $vv)
  1225. {
  1226. $total_money += $vv['total']+$vv['shipping_fare']-$vv['voucher_credit']-$vv['fullreduction_money'];
  1227. }
  1228. }
  1229. }else{
  1230. $total = 0;
  1231. }
  1232. }else{
  1233. $sql = 'SELECT count(o.order_id) as count FROM '.C('DB_PREFIX')."lionfish_comshop_order_refund as ore,
  1234. " . C('DB_PREFIX'). 'lionfish_comshop_order as o '.$sqlcondition.' where ore.order_id = o.order_id and ' . $condition ;
  1235. $total_arr = M()->query($sql);
  1236. $total = $total_arr[0]['count'];
  1237. }
  1238. $order_status_arr = $this->get_order_status_name();
  1239. $export = I('request.export', 0);
  1240. if ($export == 1)
  1241. {
  1242. $is_can_look_headinfo = true;
  1243. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1244. if (defined('ROLE') && ROLE == 'agenter' )
  1245. {
  1246. if( isset($supply_can_look_headinfo) && $supply_can_look_headinfo == 2 )
  1247. {
  1248. $is_can_look_headinfo = false;
  1249. }
  1250. }
  1251. @set_time_limit(0);
  1252. $columns = array(
  1253. array('title' => '订单编号', 'field' => 'order_num_alias', 'width' => 36),
  1254. array('title' => '订单流水号', 'field' => 'day_paixu', 'width' => 24),
  1255. array('title' => '昵称', 'field' => 'name', 'width' => 12),
  1256. //array('title' => '会员姓名', 'field' => 'mrealname', 'width' => 12),
  1257. array('title' => 'openid', 'field' => 'openid', 'width' => 24),
  1258. array('title' => '会员手机号', 'field' => 'telephone', 'width' => 12),
  1259. array('title' => '会员备注', 'field' => 'member_content', 'width' => 24),
  1260. array('title' => '收货姓名(或自提人)', 'field' => 'shipping_name', 'width' => 12),
  1261. array('title' => '联系电话', 'field' => 'shipping_tel', 'width' => 12),
  1262. array('title' => '收货地址', 'field' => 'address_province', 'width' => 12),
  1263. array('title' => '', 'field' => 'address_city', 'width' => 12),
  1264. array('title' => '', 'field' => 'address_area', 'width' => 12),
  1265. //array('title' => '', 'field' => 'address_street', 'width' => 12),
  1266. array('title' => '提货详细地址', 'field' => 'address_address', 'width' => 12),
  1267. array('title' => '团长配送送货详细地址', 'field' => 'tuan_send_address', 'width' => 22),
  1268. array('title' => '商品名称', 'field' => 'goods_title', 'width' => 24),
  1269. array('title' => '商品编码', 'field' => 'goods_goodssn', 'width' => 12),
  1270. array('title' => '商品规格', 'field' => 'goods_optiontitle', 'width' => 12),
  1271. array('title' => '商品数量', 'field' => 'quantity', 'width' => 12),
  1272. array('title' => '商品单价', 'field' => 'goods_price1', 'width' => 12),
  1273. //array('title' => '商品单价(折扣后)', 'field' => 'goods_price2', 'width' => 12),
  1274. //array('title' => '商品价格(折扣前)', 'field' => 'goods_rprice1', 'width' => 12),
  1275. array('title' => '商品价格', 'field' => 'goods_rprice2', 'width' => 12),
  1276. array('title' => '支付方式', 'field' => 'paytype', 'width' => 12),
  1277. array('title' => '配送方式', 'field' => 'delivery', 'width' => 12),
  1278. array('title' => '预计送达时间', 'field' => 'expected_delivery_time', 'width' => 24),
  1279. //array('title' => '自提门店', 'field' => 'pickname', 'width' => 24),
  1280. //array('title' => '商品小计', 'field' => 'goodsprice', 'width' => 12),
  1281. array('title' => '运费', 'field' => 'dispatchprice', 'width' => 12),
  1282. array('title' => '积分抵扣', 'field' => 'score_for_money', 'width' => 12),
  1283. //array('title' => '余额抵扣', 'field' => 'deductcredit2', 'width' => 12),
  1284. array('title' => '满额立减', 'field' => 'fullreduction_money', 'width' => 12),
  1285. array('title' => '优惠券优惠', 'field' => 'voucher_credit', 'width' => 12),
  1286. //array('title' => '订单改价', 'field' => 'changeprice', 'width' => 12),
  1287. //array('title' => '运费改价', 'field' => 'changedispatchprice', 'width' => 12),
  1288. array('title' => '应收款(该笔订单总款)', 'field' => 'price', 'width' => 12),
  1289. array('title' => '状态', 'field' => 'status', 'width' => 12),
  1290. array('title' => '团长佣金', 'field' => 'head_money', 'width' => 12),
  1291. array('title' => '下单时间', 'field' => 'createtime', 'width' => 24),
  1292. array('title' => '付款时间', 'field' => 'paytime', 'width' => 24),
  1293. array('title' => '发货时间', 'field' => 'sendtime', 'width' => 24),
  1294. array('title' => '完成时间', 'field' => 'finishtime', 'width' => 24),
  1295. array('title' => '快递公司', 'field' => 'expresscom', 'width' => 24),
  1296. array('title' => '快递单号', 'field' => 'expresssn', 'width' => 24),
  1297. array('title' => '小区名称', 'field' => 'community_name', 'width' => 12),
  1298. array('title' => '团长姓名', 'field' => 'head_name', 'width' => 12),
  1299. array('title' => '团长电话', 'field' => 'head_mobile', 'width' => 12),
  1300. array('title' => '完整地址', 'field' => 'fullAddress', 'width' => 24),
  1301. array('title' => '订单备注', 'field' => 'remark', 'width' => 36),
  1302. array('title' => '卖家订单备注', 'field' => 'remarksaler', 'width' => 36),
  1303. //array('title' => '核销员', 'field' => 'salerinfo', 'width' => 24),
  1304. //array('title' => '核销门店', 'field' => 'storeinfo', 'width' => 36),
  1305. //array('title' => '订单自定义信息', 'field' => 'order_diyformdata', 'width' => 36),
  1306. //array('title' => '商品自定义信息', 'field' => 'goods_diyformdata', 'width' => 36)
  1307. );
  1308. $exportlist = array();
  1309. set_time_limit(0);
  1310. $fileName = date('YmdHis', time());
  1311. header('Content-Type: application/vnd.ms-execl');
  1312. header('Content-Disposition: attachment;filename="退款订单数据' . $fileName . '.csv"');
  1313. $begin = microtime(true);
  1314. $fp = fopen('php://output', 'a');
  1315. $step = 100;
  1316. $nums = 10000;
  1317. //设置标题
  1318. //$title = array('ID', '用户名', '用户年龄', '用户描述', '用户手机', '用户QQ', '用户邮箱', '用户地址');
  1319. $title = array();
  1320. foreach($columns as $key => $item) {
  1321. $title[$item['field']] = iconv('UTF-8', 'GBK', $item['title']);
  1322. }
  1323. fputcsv($fp, $title);
  1324. $sql_count = 'SELECT count(o.order_id) as count FROM '.C('DB_PREFIX')."lionfish_comshop_order_refund as ore, "
  1325. . C('DB_PREFIX'). 'lionfish_comshop_order as o '.$sqlcondition.' where ore.order_id = o.order_id and '
  1326. . $condition . ' ORDER BY ore.`ref_id` DESC ';
  1327. $total_arr = M()->query($sql_count);
  1328. $total = $total_arr[0]['count'];
  1329. $sqlcondition .= ' left join ' .C('DB_PREFIX') . 'lionfish_comshop_order_goods ogc on ogc.order_id = o.order_id ';
  1330. $page = ceil($total / 500);
  1331. if (!(empty($total))) {
  1332. //searchfield goodstitle goods_goodssn
  1333. for($s = 1; $s <= $page; $s++) {
  1334. $offset = ($s-1)* 500;
  1335. $sql = 'SELECT o.*,ogc.name as goods_title,ogc.supply_id,ogc.order_goods_id ,ogc.quantity as ogc_quantity,ogc.price,ogc.model as model,
  1336. ogc.total as goods_total ,ogc.score_for_money as g_score_for_money,ogc.fullreduction_money as g_fullreduction_money,ogc.voucher_credit as g_voucher_credit ,ogc.shipping_fare as g_shipping_fare FROM '.C('DB_PREFIX').
  1337. "lionfish_comshop_order_refund as ore, " . C('DB_PREFIX'). 'lionfish_comshop_order as o '.$sqlcondition.' where ore.order_id = o.order_id and ' .
  1338. $condition . ' ORDER BY ore.`ref_id` DESC limit ' . "{$offset}, 500";
  1339. $list = M()->query($sql);
  1340. $look_member_arr = array();
  1341. $area_arr = array();
  1342. foreach($list as $val)
  1343. {
  1344. if (defined('ROLE') && ROLE == 'agenter' )
  1345. {
  1346. $supper_info = get_agent_logininfo();
  1347. if($supper_info['id'] != $val['supply_id'])
  1348. {
  1349. continue;
  1350. }
  1351. }
  1352. if( empty($look_member_arr) || !isset($look_member_arr[$val['member_id']]) )
  1353. {
  1354. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $val['member_id']) )->find();
  1355. $look_member_arr[$val['member_id']] = $member_info;
  1356. }
  1357. $tmp_exval= array();
  1358. $tmp_exval['order_num_alias'] = $val['order_num_alias']."\t";
  1359. $tmp_exval['day_paixu'] = $val['day_paixu'];
  1360. $tmp_exval['name'] = $look_member_arr[$val['member_id']]['username'];
  1361. //from_type
  1362. if($val['from_type'] == 'wepro')
  1363. {
  1364. $tmp_exval['openid'] = $look_member_arr[$val['member_id']]['we_openid'];
  1365. }else{
  1366. $tmp_exval['openid'] = $look_member_arr[$val['member_id']]['openid'];
  1367. }
  1368. $tmp_exval['telephone'] = $look_member_arr[$val['member_id']]['telephone'];
  1369. $tmp_exval['member_content'] = $look_member_arr[$val['member_id']]['content'];
  1370. $tmp_exval['shipping_name'] = $val['shipping_name'];
  1371. $tmp_exval['shipping_tel'] = $val['shipping_tel'];
  1372. //area_arr
  1373. if( empty($area_arr) || !isset($area_arr[$val['shipping_province_id']]) )
  1374. {
  1375. $area_arr[$val['shipping_province_id']] = D('Seller/Front')->get_area_info($val['shipping_province_id']);
  1376. }
  1377. if( empty($area_arr) || !isset($area_arr[$val['shipping_city_id']]) )
  1378. {
  1379. $area_arr[$val['shipping_city_id']] = D('Seller/Front')->get_area_info($val['shipping_city_id']);
  1380. }
  1381. if( empty($area_arr) || !isset($area_arr[$val['shipping_country_id']]) )
  1382. {
  1383. $area_arr[$val['shipping_country_id']] = D('Seller/Front')->get_area_info($val['shipping_country_id']);
  1384. }
  1385. $province_info = $area_arr[$val['shipping_province_id']];
  1386. $city_info = $area_arr[$val['shipping_city_id']];
  1387. $area_info = $area_arr[$val['shipping_country_id']];
  1388. $tmp_exval['address_province'] = $province_info['name'];
  1389. $tmp_exval['address_city'] = $city_info['name'];
  1390. $tmp_exval['address_area'] = $area_info['name'];
  1391. $tmp_exval['goods_goodssn'] = $val['model'];
  1392. $tmp_exval['address_address'] = $val['shipping_address'];
  1393. if( $val['delivery'] == 'tuanz_send'){
  1394. //$tmp_exval['address_address'] = $val['tuan_send_address'];
  1395. }
  1396. $tmp_exval['tuan_send_address'] = $val['tuan_send_address'];
  1397. $tmp_exval['goods_title'] = htmlspecialchars_decode(stripslashes($val['goods_title']));
  1398. $goods_optiontitle = $this->get_order_option_sku($val['order_id'], $val['order_goods_id']);
  1399. $tmp_exval['goods_optiontitle'] = $goods_optiontitle;
  1400. $tmp_exval['quantity'] = $val['ogc_quantity'];
  1401. $tmp_exval['goods_price1'] = $val['price'];
  1402. $tmp_exval['goods_rprice2'] = $val['goods_total'];
  1403. $paytype = $val['payment_code'];
  1404. switch($paytype)
  1405. {
  1406. case 'admin':
  1407. $paytype='后台支付';
  1408. break;
  1409. case 'yuer':
  1410. $paytype='余额支付';
  1411. break;
  1412. case 'weixin':
  1413. $paytype='微信支付';
  1414. break;
  1415. default:
  1416. $paytype = '未支付';
  1417. }
  1418. $community_info = D('Seller/Front')->get_community_byid($val['head_id']);
  1419. $tmp_exval['community_name'] = $community_info['communityName'];
  1420. if($is_can_look_headinfo){
  1421. $tmp_exval['fullAddress'] = $community_info['fullAddress'];
  1422. $tmp_exval['head_name'] = $community_info['disUserName'];
  1423. $tmp_exval['head_mobile'] = $community_info['head_mobile'];
  1424. }else{
  1425. $tmp_exval['fullAddress'] = '';
  1426. $tmp_exval['head_name'] = '';
  1427. $tmp_exval['head_mobile'] = '';
  1428. }
  1429. $tmp_exval['paytype'] = $paytype;
  1430. if($val['delivery'] == 'express'){
  1431. $tmp_exval['delivery'] = '快递';
  1432. }elseif($val['delivery'] == 'pickup'){
  1433. $tmp_exval['delivery'] = '自提';
  1434. }elseif($val['delivery'] == 'tuanz_send'){
  1435. $tmp_exval['delivery'] = '团长配送';
  1436. }
  1437. $tmp_exval['expected_delivery_time'] =$val['expected_delivery_time']; //date("Y-m-d H:i:s",time())
  1438. $tmp_exval['dispatchprice'] = $val['g_shipping_fare'];
  1439. $tmp_exval['score_for_money'] = $val['g_score_for_money'];
  1440. $tmp_exval['fullreduction_money'] = $val['g_fullreduction_money'];
  1441. $tmp_exval['voucher_credit'] = $val['g_voucher_credit'];
  1442. $tmp_exval['changeprice'] = $val['changedtotal'];
  1443. $tmp_exval['changedispatchprice'] = $val['changedshipping_fare'];
  1444. $val['total'] = $val['goods_total']+$val['g_shipping_fare']-$val['g_score_for_money']-$val['g_fullreduction_money'] - $val['g_voucher_credit'];
  1445. if($val['total'] < 0)
  1446. {
  1447. $val['total'] = 0;
  1448. }
  1449. $tmp_exval['price'] = $val['total'];
  1450. $tmp_exval['head_money'] = 0;
  1451. $head_commiss_order = M('lionfish_community_head_commiss_order')->where( array('order_id' => $val['order_id'],'order_goods_id' => $val['order_goods_id']) )->find();
  1452. if( !empty($head_commiss_order) )
  1453. {
  1454. $tmp_exval['head_money'] = $head_commiss_order['money'];
  1455. }
  1456. $tmp_exval['status'] = $order_status_arr[$val['order_status_id']];
  1457. $tmp_exval['createtime'] = date('Y-m-d H:i:s', $val['date_added']);
  1458. $tmp_exval['paytime'] = empty($val['pay_time']) ? '' : date('Y-m-d H:i:s', $val['pay_time']);
  1459. $tmp_exval['sendtime'] = empty($val['express_time']) ? '': date('Y-m-d H:i:s', $val['express_time']);
  1460. $tmp_exval['finishtime'] = empty($val['finishtime']) ? '' : date('Y-m-d H:i:s', $val['finishtime']);
  1461. $tmp_exval['expresscom'] = $val['dispatchname'];
  1462. $tmp_exval['expresssn'] = $val['shipping_no'];
  1463. $tmp_exval['remark'] = $val['comment'];
  1464. $tmp_exval['remarksaler'] = $val['remarksaler'];
  1465. $exportlist[] = $tmp_exval;
  1466. $row_arr = array();
  1467. foreach($columns as $key => $item) {
  1468. $row_arr[$item['field']] = iconv('UTF-8', 'GBK//IGNORE', $tmp_exval[$item['field']]);
  1469. }
  1470. fputcsv($fp, $row_arr);
  1471. }
  1472. ob_flush();
  1473. flush();
  1474. unset($list);
  1475. }
  1476. die();
  1477. // dump($exportlist);die;
  1478. //D('Seller/Excel')->export($exportlist, array('title' => '订单数据', 'columns' => $columns));
  1479. }
  1480. }
  1481. if (!(empty($total))) {
  1482. $sql = 'SELECT ore.ref_id, ore.order_goods_id,ore.state as ore_state, o.* FROM '.
  1483. C('DB_PREFIX')."lionfish_comshop_order_refund as ore, " . C('DB_PREFIX') . 'lionfish_comshop_order as o '.
  1484. $sqlcondition.' where ore.order_id = o.order_id and ' . $condition .
  1485. ' ORDER BY ore.`ref_id` DESC LIMIT ' . (($pindex - 1) * $psize) . ',' . $psize;
  1486. $list = M()->query($sql);
  1487. $need_list = array();
  1488. foreach ($list as $key => &$value ) {
  1489. $sql_goods = "select og.* from ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  1490. where og.order_id = {$value[order_id]} ";
  1491. if( !empty($value['order_goods_id']) && $value['order_goods_id'] > 0 )
  1492. {
  1493. $sql_goods = "select og.* from ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  1494. where og.order_goods_id = ".$value['order_goods_id']." and og.order_id = {$value[order_id]} ";
  1495. }
  1496. $goods = M()->query($sql_goods);
  1497. $need_goods = array();
  1498. $shipping_fare = 0;
  1499. $fullreduction_money = 0;
  1500. $voucher_credit = 0;
  1501. $totals = 0;
  1502. //ref_id
  1503. $refund_disable = M('lionfish_comshop_order_refund_disable')->where( array('ref_id' => $value['ref_id'] ) )->find();
  1504. if( !empty($refund_disable) )
  1505. {
  1506. $value['is_forbidden'] = 1;
  1507. }else{
  1508. $value['is_forbidden'] = 0;
  1509. }
  1510. foreach($goods as $key =>$goods_val)
  1511. {
  1512. $goods_val['name'] = htmlspecialchars_decode(stripslashes($goods_val['name']));
  1513. $goods_val['option_sku'] = $this->get_order_option_sku($value['order_id'], $goods_val['order_goods_id']);
  1514. $goods_val['commisson_info'] = array();
  1515. if (defined('ROLE') && ROLE == 'agenter' )
  1516. {
  1517. $supper_info = get_agent_logininfo();
  1518. if($supper_info['id'] != $goods_val['supply_id'])
  1519. {
  1520. continue;
  1521. }
  1522. }
  1523. $shipping_fare += $goods_val['shipping_fare'];
  1524. $fullreduction_money += $goods_val['fullreduction_money'];
  1525. $voucher_credit += $goods_val['voucher_credit'];
  1526. $totals += $goods_val['total'];
  1527. $need_goods[$key] = $goods_val;
  1528. }
  1529. //if( $_W['role'] == 'agenter' )
  1530. //{
  1531. $value['shipping_fare'] = $shipping_fare;
  1532. $value['fullreduction_money'] = $fullreduction_money;
  1533. $value['voucher_credit'] = $voucher_credit;
  1534. $value['total'] = $totals;
  1535. // }
  1536. //member_id ims_ nickname
  1537. $nickname_row = M('lionfish_comshop_member')->field('username as nickname,content')->where( array('member_id' =>$value['member_id'] ) )->find();
  1538. $value['nickname'] = $nickname_row['nickname'];
  1539. $value['member_content'] = $nickname_row['content'];
  1540. $value['goods'] = $need_goods;
  1541. $community_info = D('Seller/Front')->get_community_byid($value['head_id']);
  1542. $value['community_name'] = $community_info['communityName'];
  1543. $value['head_name'] = $community_info['disUserName'];
  1544. $value['head_mobile'] = $community_info['head_mobile'];
  1545. if (defined('ROLE') && ROLE == 'agenter' )
  1546. {
  1547. $supply_can_look_headinfo = D('Home/Front')->get_config_by_name('supply_can_look_headinfo');
  1548. if($supply_can_look_headinfo != 1){
  1549. $value['community_name'] = D('Seller/Order')->desensitize($community_info['communityName'],0,-1);
  1550. $value['head_name'] = D('Seller/Order')->desensitize($community_info['disUserName'],1,1);
  1551. $value['head_mobile'] = D('Seller/Order')->desensitize($community_info['head_mobile'],3,4);
  1552. }
  1553. }
  1554. $value['province'] = $community_info['province'];
  1555. $value['city'] = $community_info['city'];
  1556. }
  1557. $pager = pagination2($total, $pindex, $psize);
  1558. }
  1559. //get_order_count($where = '',$uniacid = 0)
  1560. if( !empty($searchtype) )
  1561. {
  1562. $count_where = " and type = '{$searchtype}' ";
  1563. }
  1564. if (defined('ROLE') && ROLE == 'agenter' )
  1565. {
  1566. $supper_info = get_agent_logininfo();
  1567. $order_ids_list = M()->query("select og.order_id,og.total,og.shipping_fare,og.voucher_credit,og.fullreduction_money from ".C('DB_PREFIX').
  1568. "lionfish_comshop_order_goods as og , ".C('DB_PREFIX')."lionfish_comshop_order as o where og.order_id =o.order_id and og.supply_id = ".$supper_info['id']." ");
  1569. $order_ids_arr = array();
  1570. $seven_refund_money= 0;
  1571. foreach($order_ids_list as $vv)
  1572. {
  1573. if( empty($order_ids_arr) || !isset($order_ids_arr[$vv['order_id']]) )
  1574. {
  1575. $order_ids_arr[$vv['order_id']] = $vv['order_id'];
  1576. }
  1577. }
  1578. if( !empty($order_ids_arr) )
  1579. {
  1580. $count_where .= " and order_id in (".implode(',', $order_ids_arr).")";
  1581. }else{
  1582. $count_where .= " and order_id in (0)";
  1583. }
  1584. }
  1585. $all_count = $this->get_order_count($count_where);
  1586. $count_status_1 = $this->get_order_count(" {$count_where} and order_status_id = 1 ");
  1587. $count_status_3 = $this->get_order_count(" {$count_where} and order_status_id = 3 ");
  1588. $count_status_4 = $this->get_order_count(" {$count_where} and order_status_id = 4 ");
  1589. $count_status_5 = $this->get_order_count(" {$count_where} and order_status_id = 5 ");
  1590. $count_status_7 = $this->get_order_count(" {$count_where} and order_status_id = 7 ");
  1591. $count_status_11 = $this->get_order_count(" {$count_where} and (order_status_id = 11 or order_status_id = 6) ");
  1592. $count_status_14 = $this->get_order_count(" {$count_where} and order_status_id = 14 ");
  1593. return array('total' => $total, 'total_money' => $total_money,'pager' => $pager, 'all_count' => $all_count,
  1594. 'list' =>$list,
  1595. 'count_status_1' => $count_status_1,'count_status_3' => $count_status_3,'count_status_4' => $count_status_4,
  1596. 'count_status_5' => $count_status_5, 'count_status_7' => $count_status_7, 'count_status_11' => $count_status_11,
  1597. 'count_status_14' => $count_status_14
  1598. );
  1599. }
  1600. //---copy end
  1601. /**
  1602. * @param $order_id
  1603. * @param int $is_supply 1、供应商手机付款,0、后台付款
  1604. * @return array
  1605. */
  1606. public function admin_pay_order($order_id,$is_supply = 0)
  1607. {
  1608. $order = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  1609. $member_id = $order['member_id'];
  1610. //支付才减库存,才需要判断
  1611. $kucun_method = D('Home/Front')->get_config_by_name('kucun_method');
  1612. if( empty($kucun_method) )
  1613. {
  1614. $kucun_method = 0;
  1615. }
  1616. $error_msg = '';
  1617. if($kucun_method == 1)
  1618. {
  1619. /*** 检测商品库存begin **/
  1620. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id'] ) )->select();
  1621. //goods_id
  1622. foreach($order_goods_list as $val)
  1623. {
  1624. $quantity = $val['quantity'];
  1625. $goods_id = $val['goods_id'];
  1626. $can_buy_count = D('Home/Front')->check_goods_user_canbuy_count($member_id, $goods_id);
  1627. //TODO.这里有问题
  1628. $goods_description = D('Home/Front')->get_goods_common_field($goods_id , 'total_limit_count');
  1629. if($can_buy_count == -1)
  1630. {
  1631. $error_msg = '每人最多购买'.$goods_description['total_limit_count'].'个哦';
  1632. }else if($can_buy_count >0 && $quantity >$can_buy_count)
  1633. {
  1634. $error_msg = '您还能购买'.$can_buy_count.'份';
  1635. }
  1636. $goods_quantity= D('Home/Car')->get_goods_quantity($goods_id);
  1637. if($goods_quantity<$quantity){
  1638. if ($goods_quantity==0) {
  1639. $error_msg ='已抢光';
  1640. }else{
  1641. $error_msg ='商品数量不足,剩余'.$goods_quantity.'个!!';
  1642. }
  1643. }
  1644. //rela_goodsoption_valueid
  1645. if(!empty($val['rela_goodsoption_valueid']))
  1646. {
  1647. $mul_opt_arr = array();
  1648. $goods_option_mult_value = M('lionfish_comshop_goods_option_item_value')->where( array('option_item_ids' => $val['rela_goodsoption_valueid'],'goods_id' => $goods_id) )->find();
  1649. if( !empty($goods_option_mult_value) )
  1650. {
  1651. if($goods_option_mult_value['stock']<$quantity){
  1652. $error_msg = '商品数量不足,剩余'.$goods_option_mult_value['stock'].'个!!';
  1653. }
  1654. }
  1655. }
  1656. }
  1657. /*** 检测商品库存end **/
  1658. }
  1659. if( !empty($error_msg) )
  1660. {
  1661. return array('code' => 0,'msg' => $error_msg);
  1662. }else{
  1663. if( $order && $order['order_status_id'] == 3)
  1664. {
  1665. $o = array();
  1666. if($is_supply == 1){
  1667. $o['payment_code'] = 'supply_mobile';
  1668. $o['transaction_id'] = '供应商手机付款';
  1669. }else{
  1670. $o['payment_code'] = 'admin';
  1671. $o['transaction_id'] ='后台付款';
  1672. }
  1673. $o['order_id']=$order['order_id'];
  1674. $o['order_status_id'] = $order['is_pin'] == 1 ? 2:1;
  1675. $o['date_modified']=time();
  1676. $o['pay_time']=time();
  1677. if($order['delivery'] == 'hexiao'){//核销订单 支付完成状态改成 已发货待收货
  1678. $o['order_status_id'] = 4;
  1679. }
  1680. //ims_
  1681. M('lionfish_comshop_order')->where( array('order_id' => $order['order_id']) )->save($o);
  1682. $kucun_method = D('Home/Front')->get_config_by_name('kucun_method', $_W['uniacid']);
  1683. if( empty($kucun_method) )
  1684. {
  1685. $kucun_method = 0;
  1686. }
  1687. if($kucun_method == 1)
  1688. {//支付完减库存,增加销量
  1689. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->select();
  1690. foreach($order_goods_list as $order_goods)
  1691. {
  1692. D('Home/Pingoods')->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
  1693. }
  1694. }
  1695. $oh = array();
  1696. $oh['order_id']=$order['order_id'];
  1697. $oh['order_status_id']= $order['is_pin'] == 1 ? 2:1;
  1698. if($is_supply == 1){
  1699. $oh['comment']='供应商手机端付款';
  1700. }else{
  1701. $oh['comment']='后台付款';
  1702. }
  1703. $oh['date_added']=time();
  1704. $oh['notify']=1;
  1705. M('lionfish_comshop_order_history')->add($oh);
  1706. D('Home/Weixinnotify')->orderBuy($order['order_id'],true);
  1707. //发送购买通知
  1708. //TODO 先屏蔽,等待调试这个消息
  1709. //$weixin_nofity = D('Home/Weixinnotify');
  1710. //$weixin_nofity->orderBuy($order['order_id']);
  1711. if($order['type'] == 'pintuan'){
  1712. $pin_order = M('lionfish_comshop_pin_order')->where( array('order_id' => $order['order_id']) )->find();
  1713. $pin_id = $pin_order['pin_id'];
  1714. $pin_model = D('Home/Pin');
  1715. $is_pin_success = $pin_model->checkPinSuccess($pin_id);
  1716. if($is_pin_success) {
  1717. //todo send pintuan success notify
  1718. $pin_model->updatePintuanSuccess($pin_id);
  1719. }
  1720. }
  1721. return array('code' => 1);
  1722. }
  1723. }
  1724. }
  1725. public function admin_pay_order2($order_id)
  1726. {
  1727. $order = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  1728. if( $order && $order['order_status_id'] == 3)
  1729. {
  1730. $o = array();
  1731. $o['payment_code'] = 'admin';
  1732. $o['order_id']=$order['order_id'];
  1733. $o['order_status_id'] = $order['is_pin'] == 1 ? 2:1;
  1734. $o['date_modified']=time();
  1735. $o['pay_time']=time();
  1736. $o['transaction_id'] = $is_integral ==1? '积分兑换':'余额支付';
  1737. //ims_
  1738. M('lionfish_comshop_order')->where( array('order_id' => $order['order_id']) )->save($o);
  1739. //暂时屏蔽
  1740. //$kucun_method = C('kucun_method');
  1741. //$kucun_method = empty($kucun_method) ? 0 : intval($kucun_method);
  1742. $kucun_method = 0;
  1743. //$goods_model = D('Home/Goods');
  1744. if($kucun_method == 1)
  1745. {//支付完减库存,增加销量
  1746. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order['order_id']) )->select();
  1747. foreach($order_goods_list as $order_goods)
  1748. {
  1749. D('Home/Pingoods')->del_goods_mult_option_quantity($order['order_id'],$order_goods['rela_goodsoption_valueid'],$order_goods['goods_id'],$order_goods['quantity'],1);
  1750. }
  1751. }
  1752. $oh = array();
  1753. $oh['order_id']=$order['order_id'];
  1754. $oh['order_status_id']= $order['is_pin'] == 1 ? 2:1;
  1755. $oh['comment']='后台付款';
  1756. $oh['date_added']=time();
  1757. $oh['notify']=1;
  1758. M('lionfish_comshop_order_history')->add($oh);
  1759. //发送购买通知
  1760. //TODO 先屏蔽,等待调试这个消息
  1761. //$weixin_nofity = D('Home/Weixinnotify');
  1762. //$weixin_nofity->orderBuy($order['order_id']);
  1763. }
  1764. }
  1765. //检查订单是否能确认收货(存在售后未完成无法确认收货)
  1766. public function check_order_receive($order_id){
  1767. $result = array();
  1768. $status = 1;//1、可以确认收货,0、不能确认收货
  1769. $sql_goods = "select og.* from ".C('DB_PREFIX')."lionfish_comshop_order_goods as og
  1770. where og.order_id = {$order_id} ";
  1771. $goods = M()->query($sql_goods);
  1772. foreach($goods as $key =>$goods_val)
  1773. {
  1774. if( $goods_val['is_refund_state'] == 1 )
  1775. {
  1776. $refund_info = M('lionfish_comshop_order_refund')->field('state')->where( array('order_id' => $order_id ,'order_goods_id' => $goods_val['order_goods_id']) )->find();
  1777. if(!empty($refund_info)){
  1778. if($refund_info['state'] == 0 || $refund_info['state'] == 2){
  1779. $status = 0;
  1780. break;
  1781. }
  1782. }
  1783. }
  1784. }
  1785. $result['status'] = $status;
  1786. return $result;
  1787. }
  1788. //检查订单是否能确认收货(同城配送订单) 该订单未有配送员接单或还未指定配送员,无法确认收货
  1789. public function check_localtown_order_receive($order_id){
  1790. $result = array();
  1791. $status = 1;//1、可以确认收货,0、不能确认收货
  1792. $order_distribution = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id) )->find();
  1793. if(empty($order_distribution['orderdistribution_id']) && ($order_distribution['state'] == 1 || $order_distribution['state'] == 0)){
  1794. $status = 0;
  1795. }
  1796. if(empty($order_distribution['third_distribution_type']) && ($order_distribution['state'] == 1 || $order_distribution['state'] == 0)){
  1797. $status = 0;
  1798. }
  1799. $result['status'] = $status;
  1800. return $result;
  1801. }
  1802. public function receive_order($order_id)
  1803. {
  1804. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 6, 'receive_time' => time()) );
  1805. D('Home/Frontorder')->receive_order($order_id);
  1806. }
  1807. /**
  1808. 获取订单规格值
  1809. **/
  1810. public function get_order_option_sku($order_id, $order_goods_id)
  1811. {
  1812. $option_list = M('lionfish_comshop_order_option')->field('name,value')->where( array('order_goods_id' => $order_goods_id,'order_id' => $order_id) )->select();
  1813. $sku_str = "";
  1814. if( !empty($option_list) )
  1815. {
  1816. $tmp_arr = array();
  1817. foreach($option_list as $val)
  1818. {
  1819. $tmp_arr[] = $val['name'].",".$val['value'];
  1820. }
  1821. $sku_str = implode(' ', $tmp_arr);
  1822. }
  1823. return $sku_str;
  1824. }
  1825. /**
  1826. 获取订单商品重量
  1827. **/
  1828. public function get_order_option_weight($order_id, $order_goods_id)
  1829. {
  1830. $weight_str = "";
  1831. $order_goods_info = M('lionfish_comshop_order_goods')->field('goods_id,rela_goodsoption_valueid')->where( array('order_goods_id' => $order_goods_id,'order_id' => $order_id) )->find();
  1832. if(!empty($order_goods_info) && !empty($order_goods_info['rela_goodsoption_valueid'])){
  1833. $godos_option_info = M('lionfish_comshop_goods_option_item_value')->field('goods_id,weight')->where( array('goods_id' => $order_goods_info['goods_id'],'option_item_ids' => $order_goods_info['rela_goodsoption_valueid']) )->find();
  1834. if(!empty($godos_option_info) && !empty($godos_option_info['weight'])){
  1835. $weight_str = $godos_option_info['weight'];
  1836. }
  1837. }else{
  1838. $goods_info = M('lionfish_comshop_goods')->field('id,weight')->where( array('id' => $order_goods_info['goods_id']) )->find();
  1839. if(!empty($goods_info) && !empty($goods_info['weight'])){
  1840. $weight_str = $goods_info['weight'];
  1841. }
  1842. }
  1843. return $weight_str;
  1844. }
  1845. public function get_order_status_name()
  1846. {
  1847. $data = S('order_status_name');
  1848. if (empty($data)) {
  1849. $all_list = M('lionfish_comshop_order_status')->select();
  1850. if (empty($all_list)) {
  1851. $data = array();
  1852. }else{
  1853. $data = array();
  1854. foreach($all_list as $val)
  1855. {
  1856. $data[$val['order_status_id']] = $val['name'];
  1857. }
  1858. }
  1859. S('order_status_name', $data);
  1860. }
  1861. return $data;
  1862. }
  1863. /**
  1864. 获取商品数量
  1865. **/
  1866. public function get_order_count($where = '')
  1867. {
  1868. //begin 预售
  1869. if( isset($_GET['presale_order']) && $_GET['presale_order'] == 1 )
  1870. {
  1871. $sql = "select count(1) as count from ".C('DB_PREFIX')."lionfish_comshop_order inner join ".C('DB_PREFIX').'lionfish_comshop_order_presale opr on '.C("DB_PREFIX").'lionfish_comshop_order.order_id =opr.order_id ';
  1872. $sql .= " where 1 {$where} ";
  1873. $count_arr = M()->query( $sql );
  1874. $total = $count_arr[0]['count'];
  1875. }else if( isset($_GET['virtualcard_order']) && $_GET['virtualcard_order'] == 1 )
  1876. {
  1877. //礼品卡订单
  1878. $sql = "select count(1) as count from ".C('DB_PREFIX')."lionfish_comshop_order inner join ".C('DB_PREFIX').'lionfish_comshop_order_virtualcard vco on '.C("DB_PREFIX").'lionfish_comshop_order.order_id =vco.order_id ';
  1879. $sql .= " where 1 {$where} ";
  1880. $count_arr = M()->query( $sql );
  1881. $total = $count_arr[0]['count'];
  1882. }
  1883. else{
  1884. $total = M('lionfish_comshop_order')->where("1 ".$where)->count();
  1885. }
  1886. //end 预售
  1887. return $total;
  1888. }
  1889. public function get_wait_shen_order_comment()
  1890. {
  1891. $total = M('lionfish_comshop_order_comment')->where( array('state' => 0, 'type' =>0) )->count();
  1892. return $total;
  1893. }
  1894. /**
  1895. 获取商品数量
  1896. **/
  1897. public function get_order_sum($field=' sum(total) as total ' , $where = '',$uniacid = 0)
  1898. {
  1899. $info = M('lionfish_comshop_order')->field($field)->where("1 ".$where )->find();
  1900. return $info;
  1901. }
  1902. /**
  1903. **/
  1904. public function get_order_goods_group_paihang($where = '',$uniacid = 0)
  1905. {
  1906. //total
  1907. //SELECT name , sum(`quantity`) as total_quantity , goods_id FROM `ims_lionfish_comshop_order_goods` GROUP by goods_id order by total_quantity desc
  1908. $sql ="SELECT name , sum(`quantity`) as total_quantity, sum(`total`) as m_total , goods_id FROM ".
  1909. C('DB_PREFIX') ."lionfish_comshop_order_goods where 1 {$where} GROUP by goods_id
  1910. order by total_quantity desc limit 10 ";
  1911. $list = M()->query($sql);
  1912. return $list;
  1913. }
  1914. public function goods_express()
  1915. {
  1916. $_GPC = I('request.');
  1917. $order_id = $_GPC['order_id'];// I('get.order_id',0);
  1918. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1919. $now_time = time();
  1920. if($now_time - $order_info['shipping_cha_time'] >= 43200 || true)
  1921. {
  1922. //即时查询接口
  1923. $seller_express = M('lionfish_comshop_express')->where( array('id' => $order_info['shipping_method'] ) )->find();
  1924. if(!empty($seller_express['simplecode']))
  1925. {
  1926. //887406591556327434 YTO
  1927. //TODO...
  1928. $ebuss_info = D('Home/Front')->get_config_by_name('kdniao_id');
  1929. $exappkey = D('Home/Front')->get_config_by_name('kdniao_api_key');
  1930. $req_url = "http://api.kdniao.com/Ebusiness/EbusinessOrderHandle.aspx";
  1931. //shipping_tel
  1932. if($seller_express['simplecode'] == 'SF'){
  1933. $shipping_tel = substr($order_info['shipping_tel'],-4);
  1934. $requestData= "{'OrderCode':'".$order_id."','ShipperCode':'".$seller_express['simplecode']."','CustomerName':'".$shipping_tel."','LogisticCode':'". $order_info['shipping_no']."'}";
  1935. }else{
  1936. $requestData= "{'OrderCode':'".$order_id."','ShipperCode':'".$seller_express['simplecode']."','LogisticCode':'". $order_info['shipping_no']."'}";
  1937. }
  1938. $customerName = $order_info['shipping_tel'];
  1939. $customerName = substr($customerName,7);
  1940. $datas = array(
  1941. 'EBusinessID' => $ebuss_info,
  1942. 'RequestType' => '1002',
  1943. 'RequestData' => urlencode($requestData) ,
  1944. 'DataType' => '2',
  1945. 'CustomerName'=>$customerName
  1946. );
  1947. $kdniao_freestatus = D('Home/Front')->get_config_by_name('kdniao_freestatus');
  1948. if( isset($kdniao_freestatus) && $kdniao_freestatus ==1 )
  1949. {
  1950. $datas['RequestType'] = '8001';
  1951. //$datas['RequestType'] = '8002';
  1952. }
  1953. if($kdniao_freestatus == 0 ){
  1954. //申通、中通、圆通
  1955. if($seller_express['simplecode'] !='STO' && $seller_express['simplecode'] !='ZTO' && $seller_express['simplecode'] !='YTO' ){
  1956. $order_express = array('code' => 2, 'Reason' => "物流接口(快递鸟)-'免费模式'只支持查询申通、中通、圆通物流轨迹");
  1957. return $order_express;
  1958. }
  1959. }
  1960. $datas['DataSign'] = $this->encrypt($requestData, $exappkey);
  1961. $result_old=$this->sendPost($req_url, $datas);
  1962. $result = json_decode($result_old);
  1963. //array(8) { ["LogisticCode"]=> string(14) "75395511326146" ["ShipperCode"]=> string(3) "ZTO" ["Traces"]=> array(0) { } ["State"]=> string(1) "0" ["OrderCode"]=> string(4) "5884" ["EBusinessID"]=> string(7) "1636513" ["Reason"]=> string(50) "业务错误[不支持当前快递公司的查询]" ["Success"]=> bool(false) }
  1964. $result2 = json_decode($result_old,true);
  1965. if($result2["Success"] == false){
  1966. $order_express = array('code' => 2, 'Reason' => $result2["Reason"]);
  1967. return $order_express;
  1968. }
  1969. //根据公司业务处理返回的信息......
  1970. //Traces
  1971. if(!empty($result->Traces))
  1972. {
  1973. $order_info['shipping_traces'] = serialize($result->Traces);
  1974. $up_data = array('shipping_cha_time' => time(), 'shipping_traces' => $order_info['shipping_traces']);
  1975. M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->save( $up_data );
  1976. }else{
  1977. $order_express = array('code' => 2, 'Reason' => $result2["Reason"]);
  1978. return $order_express;
  1979. }
  1980. }
  1981. }
  1982. //ims_
  1983. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->find();
  1984. $goods_info = array();
  1985. $goods_info = D('Home/Pingoods')->get_goods_images($order_goods['goods_id']);
  1986. $goods_info['image'] = tomedia($goods_info['image']);
  1987. $seller_express = M('lionfish_comshop_express')->where( array('id' => $order_info['shipping_method'] ) )->find();
  1988. $order_info['shipping_traces'] = unserialize($order_info['shipping_traces']) ;
  1989. $order_express = array('code' => 0, 'seller_express' => $seller_express, 'goods_info' => $goods_info, 'order_info' => $order_info);
  1990. return $order_express;
  1991. }
  1992. function encrypt($data, $appkey) {
  1993. return urlencode(base64_encode(md5($data.$appkey)));
  1994. }
  1995. function sendPost($url, $datas) {
  1996. $temps = array();
  1997. foreach ($datas as $key => $value) {
  1998. $temps[] = sprintf('%s=%s', $key, $value);
  1999. }
  2000. $post_data = implode('&', $temps);
  2001. $url_info = parse_url($url);
  2002. if(empty($url_info['port']))
  2003. {
  2004. $url_info['port']=80;
  2005. }
  2006. $httpheader = "POST " . $url_info['path'] . " HTTP/1.0\r\n";
  2007. $httpheader.= "Host:" . $url_info['host'] . "\r\n";
  2008. $httpheader.= "Content-Type:application/x-www-form-urlencoded\r\n";
  2009. $httpheader.= "Content-Length:" . strlen($post_data) . "\r\n";
  2010. $httpheader.= "Connection:close\r\n\r\n";
  2011. $httpheader.= $post_data;
  2012. $fd = fsockopen($url_info['host'], $url_info['port']);
  2013. fwrite($fd, $httpheader);
  2014. $gets = "";
  2015. $headerFlag = true;
  2016. while (!feof($fd)) {
  2017. if (($header = @fgets($fd)) && ($header == "\r\n" || $header == "\n")) {
  2018. break;
  2019. }
  2020. }
  2021. while (!feof($fd)) {
  2022. $gets.= fread($fd, 128);
  2023. }
  2024. fclose($fd);
  2025. return $gets;
  2026. }
  2027. /**
  2028. * 好评有礼送积分
  2029. * @param array $comment_info 评价信息
  2030. */
  2031. public function sendCommentGift($comment_id){
  2032. $comment_info = M('lionfish_comshop_order_comment')->where(array('comment_id'=>$comment_id))->find();
  2033. $open_comment_gift = D('Home/Front')->get_config_by_name('open_comment_gift');
  2034. //开启好评有礼
  2035. if($open_comment_gift == 1){
  2036. //评价奖励积分数
  2037. $comment_gift_score = D('Home/Front')->get_config_by_name('comment_gift_score');
  2038. $type = "goodscomment";
  2039. $result = D('Seller/Order')->check_comment_gift_score($comment_info['member_id']);
  2040. if($result['is_comment_gift']){
  2041. $this->charge_member_score( $comment_info['member_id'] , $comment_gift_score,'in', $type, $comment_info['order_id']);
  2042. }
  2043. /*if($send_all_score < $comment_gift_max_score){//已赠送积分小于好评奖励积分上限
  2044. $this->charge_member_score( $comment_info['member_id'] , $comment_gift_score,'in', $type, $comment_info['order_id']);
  2045. }*/
  2046. }
  2047. }
  2048. /**
  2049. * 验证评价有礼积分是否达到上限
  2050. * 返回boolean true 还没达到上限,false 已经达到上限
  2051. */
  2052. public function check_comment_gift_score($member_id){
  2053. $result = array();
  2054. //好评奖励积分上限周期
  2055. $comment_gift_time = D('Home/Front')->get_config_by_name('comment_gift_time');
  2056. //好评奖励积分上限
  2057. $comment_gift_max_score = D('Home/Front')->get_config_by_name('comment_gift_max_score');
  2058. $type = "goodscomment";
  2059. $where = " 1 and member_id=".$member_id;
  2060. $where = $where. " and in_out='in' and type='".$type."' ";
  2061. if($comment_gift_time == 1){//每天
  2062. $begin_time = strtotime(date('Y-m-d 00:00:00'));
  2063. $end_time = strtotime(date('Y-m-d 23:59:59'));
  2064. $where = $where. " and addtime >= ".$begin_time." and addtime <= ".$end_time;
  2065. }else if($comment_gift_time == 2){//每周
  2066. $today = date('Y-m-d');
  2067. $first = 1;
  2068. $w = date('w',strtotime($today));
  2069. $begin_time = strtotime(date('Y-m-d',strtotime("$today -" . ($w ? $w - $first : 6) . ' days')));
  2070. $begin = date('Y-m-d',strtotime("$today -" . ($w ? $w - $first : 6) . ' days'));
  2071. $end_time = strtotime(date('Y-m-d',strtotime("$begin +6 days")));
  2072. $where = $where. " and addtime >= ".$begin_time." and addtime <= ".$end_time;
  2073. }else if($comment_gift_time == 3){//每月
  2074. $begin_time = strtotime(date('Y-m-01', strtotime(date("Y-m-d"))));
  2075. $begin = date('Y-m-01', strtotime(date("Y-m-d")));
  2076. $end_time = strtotime(date('Y-m-d', strtotime("$begin +1 month -1 day")));
  2077. $where = $where. " and addtime >= ".$begin_time." and addtime <= ".$end_time;
  2078. }
  2079. $send_all_score = M('lionfish_comshop_member_integral_flow')->where($where)->sum('score');
  2080. /*$result['where'] = $where;
  2081. $result['all_score'] = $send_all_score;*/
  2082. if(empty($send_all_score)){
  2083. $send_all_score = 0;
  2084. }
  2085. /*$result['send_all_score'] = $send_all_score;
  2086. $result['comment_gift_max_score'] = $comment_gift_max_score;*/
  2087. if($comment_gift_max_score > 0){
  2088. if($send_all_score < $comment_gift_max_score){//已赠送积分小于好评奖励积分上限
  2089. $result['is_comment_gift'] = true;
  2090. }else{
  2091. $result['is_comment_gift'] = false;
  2092. }
  2093. }else{
  2094. $result['is_comment_gift'] = true;
  2095. }
  2096. return $result;
  2097. }
  2098. public function charge_member_score($member_id, $score,$in_out, $type, $order_id=0){
  2099. $log_data = array();
  2100. $log_data['member_id'] = $member_id;
  2101. $log_data['in_out'] = $in_out;
  2102. $log_data['score'] = $score;
  2103. $log_data['type'] = $type;
  2104. $log_data['order_id'] = $order_id;
  2105. $log_data['addtime'] = time();
  2106. $member_score_info = M('lionfish_comshop_member')->field('score')->where( array('member_id' => $member_id) )->find();
  2107. $member_score = $member_score_info['score'];
  2108. if(empty($member_score)){
  2109. $member_score = 0;
  2110. }
  2111. if($in_out == 'in'){
  2112. $log_data['after_operate_score'] = $member_score+$score;
  2113. if($type == 'goodscomment'){
  2114. //增加积分
  2115. $log_data['state'] = 1;
  2116. $log_data['remark'] = "评价有礼,增加积分";
  2117. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->setInc('score',$score);
  2118. }else if($type == 'invitegift'){
  2119. //邀请者赠送积分
  2120. $log_data['state'] = 1;
  2121. $log_data['remark'] = "邀请者邀请成功,增加积分".$score;
  2122. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->setInc('score',$score);
  2123. }else if($type == 'invitegift_new'){
  2124. //被邀请者赠送积分
  2125. $log_data['state'] = 1;
  2126. $log_data['remark'] = "被邀请者邀请成功,增加积分".$score;
  2127. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->setInc('score',$score);
  2128. }else if($type == 'pintuan_rebate'){
  2129. //拼团返利
  2130. $log_data['state'] = 1;
  2131. $log_data['remark'] = "拼团返利,赠送积分".$score;
  2132. M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->setInc('score',$score);
  2133. }
  2134. }
  2135. M('lionfish_comshop_member_integral_flow')->add($log_data);
  2136. }
  2137. public function send_delivery_msg($order_info,$we_openid){
  2138. //同城配送是否开启
  2139. $isopen_localtown_delivery = D('Home/Front')->get_config_by_name('isopen_localtown_delivery' );
  2140. if(!empty($isopen_localtown_delivery)){
  2141. $weixin_template_order =array();
  2142. $weixin_appid = D('Home/Front')->get_config_by_name('weixin_appid');
  2143. $weixin_template_order_riders_receive = D('Home/Front')->get_config_by_name('weixin_template_order_riders_receive');
  2144. $shop_domain = D('Home/Front')->get_config_by_name('shop_domain');
  2145. $url = $shop_domain;
  2146. if( !empty($weixin_appid) && !empty($weixin_template_order_riders_receive) )
  2147. {
  2148. $template_id = $weixin_template_order_riders_receive;
  2149. $head_pathinfo = "lionfish_comshop/moudleB/rider/grap";
  2150. $weixin_template_order = array(
  2151. 'appid' => $weixin_appid,
  2152. 'template_id' => $weixin_template_order_riders_receive,
  2153. 'pagepath' => $head_pathinfo,
  2154. 'data' => array(
  2155. //详细内容
  2156. 'first' => array('value' => '您好,有新的同城配送订单,请您尽快接单!','color' => '#030303'),
  2157. //买家名称
  2158. 'keyword1' => array('value' => $order_info['shipping_name'],'color' => '#030303'),
  2159. //买家电话
  2160. 'keyword2' => array('value' => $order_info['shipping_tel'],'color' => '#030303'),
  2161. //配送地址
  2162. 'keyword3' => array('value' => $order_info['shipping_address'],'color' => '#030303'),
  2163. //商品内容
  2164. 'keyword4' => array('value' => $order_info['goods_name'],'color' => '#030303'),
  2165. //下单时间
  2166. 'keyword5' => array('value' => $order_info['create_time'],'color' => '#030303'),
  2167. 'remark' => array('value' => '请骑手们尽快接单','color' => '#030303'),
  2168. )
  2169. );
  2170. $res = D('Seller/User')->send_wxtemplate_msg(array() , $url ,$head_pathinfo,$we_openid,$template_id,"", 0,$weixin_template_order);
  2171. //print_r($res);
  2172. }
  2173. }
  2174. }
  2175. /**
  2176. * 获取同城配送订单信息
  2177. * @param $order_id
  2178. */
  2179. public function get_order_delivery_detail($order_id){
  2180. $order_delivery = array();
  2181. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  2182. //买家名称
  2183. $order_delivery['shipping_name'] = $order_info['shipping_name'];
  2184. //买家电话
  2185. $order_delivery['shipping_tel'] = $order_info['shipping_tel'];
  2186. //配送地址
  2187. $province_info = D('Seller/Area')->get_area_info($order_info['shipping_province_id']);
  2188. $city_info = D('Seller/Area')->get_area_info($order_info['shipping_city_id']);
  2189. $country_info = D('Seller/Area')->get_area_info($order_info['shipping_country_id']);
  2190. $shipping_address = $province_info.$city_info.$country_info.$order_info['shipping_address'];
  2191. $order_delivery['shipping_address'] = $shipping_address;
  2192. //商品内容
  2193. $goods_name = "";
  2194. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->select();
  2195. foreach($order_goods as $k=>$v)
  2196. {
  2197. if(empty($goods_name)){
  2198. $goods_name = $v['name'];
  2199. }else{
  2200. $goods_name = $goods_name.';'.$v['name'];
  2201. }
  2202. }
  2203. $order_delivery['goods_name'] = $goods_name;
  2204. //下单时间
  2205. $order_delivery['create_time'] = date('Y-m-d H:i:s',$order_info['date_added']);
  2206. return $order_delivery;
  2207. }
  2208. /**
  2209. * 同城配送第三方公司配送
  2210. * @param $order_id 订单号
  2211. * @param $data_type 第三方公司
  2212. * @param $express_info 第三方公司返回数据
  2213. */
  2214. public function do_send_localtown_thirth_delivery( $order_id, $data_type, $express_info)
  2215. {
  2216. $title = ",开始配送货物";
  2217. $delivery_company = "";
  2218. if($data_type == 'imdada'){
  2219. $delivery_company = "第三方达达";
  2220. }else if($data_type == 'sf'){
  2221. $delivery_company = "第三方顺丰同城";
  2222. }else if($data_type == 'make'){
  2223. $delivery_company = "码科配送";
  2224. }else if($data_type == 'ele'){
  2225. $delivery_company = "蜂鸟即配";
  2226. }
  2227. $title = $delivery_company.$title;
  2228. //express_time
  2229. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 4,'express_time' => time(), 'express_tuanz_time' => time(), 'third_distribution_type'=>$data_type) );
  2230. //todo ... send member msg goods is ing
  2231. $history_data = array();
  2232. $history_data['order_id'] = $order_id;
  2233. $history_data['order_status_id'] = 4;
  2234. $history_data['notify'] = 0;
  2235. $history_data['comment'] = $title;
  2236. $history_data['date_added'] = time();
  2237. M('lionfish_comshop_order_history')->add( $history_data );
  2238. $other_data = array();
  2239. $other_data['delivery_company'] = $delivery_company;
  2240. $other_data['data_type'] = $data_type;
  2241. if($data_type == 'imdada'){
  2242. $other_data['delivery_fee'] = $express_info['delivery_fee'];
  2243. }else if($data_type == 'sf'){
  2244. $other_data['delivery_fee'] = $express_info['delivery_fee'];
  2245. $other_data['delivery_order_id'] = $express_info['delivery_order_id'];
  2246. $other_data['delivery_bill_id'] = $express_info['delivery_bill_id'];
  2247. }else if( $data_type == 'make' ){
  2248. $other_data['delivery_fee'] = $express_info['delivery_fee'];
  2249. $other_data['delivery_order_id'] = $express_info['delivery_order_id'];
  2250. }else if( $data_type == 'ele' ){
  2251. $other_data['delivery_fee'] = $express_info['delivery_fee'];
  2252. $other_data['delivery_order_id'] = $express_info['delivery_order_id'];
  2253. }
  2254. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 1, $other_data);
  2255. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $data_type , 1 ,'已创建订单' );
  2256. D('Home/Frontorder')->send_order_operate($order_id);
  2257. }
  2258. /**
  2259. * @param $order_id
  2260. * @param $order_status_id 0、状态未改变,4、已发货,待收货,6、已签收
  2261. * @param $other_data
  2262. */
  2263. public function do_localtown_thirth_delivery_return( $order_sn, $order_status_id, $other_data)
  2264. {
  2265. $order_info = M('lionfish_comshop_order')->field('order_id,order_num_alias,total,member_id,order_status_id')->where( array('order_num_alias' => $order_sn) )->find();
  2266. if(!empty($order_info)){
  2267. $order_id = $order_info['order_id'];
  2268. $delivery_company = "";
  2269. if($other_data['data_type'] == 'imdada'){
  2270. $delivery_company = "第三方达达";
  2271. }else if($other_data['data_type'] == 'sf'){
  2272. $delivery_company = "第三方顺丰同城";
  2273. }else if( $other_data['data_type'] == 'make' )
  2274. {
  2275. $delivery_company = "第三方码科配送";
  2276. }else if( $other_data['data_type'] == 'ele' )
  2277. {
  2278. $delivery_company = "第三方蜂鸟即配";
  2279. }
  2280. if($order_status_id > 0){
  2281. if($order_status_id == 6 && $order_info['order_status_id'] == 4){
  2282. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 6, 'receive_time' => time()) );
  2283. D('Home/Frontorder')->receive_order($order_id, 1, $delivery_company);
  2284. //M('lionfish_comshop_order_history')->where( array('order_id' => $order_id,'order_status_id' => 6) )->save( array( 'comment' => $delivery_company.',确认收货') );
  2285. }
  2286. }
  2287. $other_data['delivery_company'] = $delivery_company;
  2288. if($other_data['data_type'] == 'imdada'){//达达平台配送
  2289. if($other_data['order_status'] == 2){//待取货
  2290. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 2, $other_data);
  2291. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['dm_name'].'已抢单,待取货' );
  2292. }else if($other_data['order_status'] == 3){//配送中
  2293. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 3, $other_data);
  2294. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['dm_name'].'配送中' );
  2295. }else if($other_data['order_status'] == 4){//已完成
  2296. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 4, $other_data);
  2297. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['dm_name'].'配送完成' );
  2298. }else if($other_data['order_status'] == 5){//已取消
  2299. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 5, $other_data);
  2300. $cancel_reason = "";
  2301. if($other_data['cancel_from'] == 11){//达达骑手取消订单
  2302. $cancel_reason = "骑士取消订单:".$other_data['cancel_reason'];
  2303. }else{
  2304. $cancel_reason = "订单取消原因:".$other_data['cancel_reason'];
  2305. }
  2306. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] , $cancel_reason );
  2307. $this->cancel_third_delviery_order_notice($order_info,$other_data);
  2308. }else if($other_data['order_status'] == 9){//妥投异常之物品返回中
  2309. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 5, $other_data);
  2310. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['cancel_reason'] );
  2311. $this->cancel_third_delviery_order_notice($order_info,$other_data);
  2312. }else if($other_data['order_status'] == 10){//妥投异常之物品返回完成
  2313. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 5, $other_data);
  2314. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['cancel_reason'] );
  2315. $this->cancel_third_delviery_order_notice($order_info,$other_data);
  2316. }else if($other_data['order_status'] == 100){//创建达达运单失败
  2317. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 5, $other_data);
  2318. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['cancel_reason'] );
  2319. }
  2320. }else if( $other_data['data_type'] == 'make' ){
  2321. //2 3/ 4
  2322. if($other_data['order_status'] == 2){//待取货
  2323. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 2, $other_data);
  2324. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['dm_name'].'已抢单,待取货' );
  2325. }else if($other_data['order_status'] == 3){//配送中
  2326. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 3, $other_data);
  2327. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['dm_name'].'配送中' );
  2328. }else if($other_data['order_status'] == 4){//已完成
  2329. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 4, $other_data);
  2330. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['dm_name'].'配送完成' );
  2331. }
  2332. }else if($other_data['data_type'] == 'sf'){//顺丰同城配送
  2333. if($other_data['order_status'] == 2){//已取消
  2334. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 5, $other_data);
  2335. $cancel_reason = "订单取消,操作人:".$other_data['operator_name'].",取消原因:".$other_data['status_desc'];
  2336. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , 5 ,$cancel_reason );
  2337. $other_data['cancel_reason'] = $other_data['status_desc'];
  2338. $this->cancel_third_delviery_order_notice($order_info,$other_data);
  2339. }else if($other_data['order_status'] == 10 || $other_data['order_status'] == 12 || $other_data['order_status'] == 15){
  2340. //10-配送员确认;12:配送员到店;15:配送员配送中
  2341. $operator_action = $other_data['status_desc'];
  2342. $operator_txt = "";
  2343. if(!empty($other_data['operator_name'])){
  2344. $operator_txt = "(".$other_data['operator_name'].','.$other_data['operator_phone'].")";
  2345. }
  2346. if($other_data['order_status'] == 10){
  2347. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 2, $other_data);
  2348. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , 2 ,$operator_action.$operator_txt);
  2349. }else if($other_data['order_status'] == 12){
  2350. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 2, $other_data);
  2351. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , 2 ,$operator_action.$operator_txt);
  2352. }else if($other_data['order_status'] == 15){
  2353. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 3, $other_data);
  2354. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , 3 ,$operator_action.$operator_txt);
  2355. }
  2356. }else if($other_data['order_status'] == 0){
  2357. //0-订单异常
  2358. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 5, $other_data);
  2359. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , 11 ,'订单异常,异常详情:'.$other_data['ex_content'] );
  2360. }else if($other_data['order_status'] == 17){//已完成
  2361. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 4, $other_data);
  2362. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , 4 , '配送员点击完成' );
  2363. }
  2364. }else if( $other_data['data_type'] == 'ele' ){//蜂鸟即配
  2365. if($other_data['order_status'] == 2){//待取货
  2366. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 2, $other_data);
  2367. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] , $other_data['desc'] );
  2368. }else if($other_data['order_status'] == 3){//配送中
  2369. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 3, $other_data);
  2370. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] , $other_data['desc'] );
  2371. }else if($other_data['order_status'] == 4){//已完成
  2372. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 4, $other_data);
  2373. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] , $other_data['desc'] );
  2374. }else if($other_data['order_status'] == 100){//异常订单
  2375. D('Home/LocaltownDelivery')->change_thirth_distribution_order_state( $order_id, 5, $other_data);
  2376. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $other_data['data_type'] , $other_data['order_status'] ,$other_data['desc'] );
  2377. }
  2378. }
  2379. }
  2380. }
  2381. /**
  2382. * 商家取消第三方配送订单
  2383. * @param $order_id
  2384. * @param $data_type
  2385. * @param $other_data
  2386. */
  2387. public function do_cancel_thirth_delivery_order($order_id,$data_type,$other_data){
  2388. /*$delivery_company = "";
  2389. if($other_data['data_type'] == 'imdada'){
  2390. $delivery_company = "第三方达达";
  2391. }else if($other_data['data_type'] == 'sf'){
  2392. $delivery_company = "第三方顺丰同城";
  2393. }*/
  2394. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(
  2395. array('state' => 5,'cancel_reason'=>$other_data['cancel_reason'],'deduct_fee'=>$other_data['deduct_fee'])
  2396. );
  2397. //违约金
  2398. if(!empty($other_data['now_deduct_fee']) && $other_data['now_deduct_fee'] > 0){
  2399. $log_mgs = "";
  2400. if($data_type == 'imdada'){
  2401. $log_mgs = "第三方达达取消订单,产生违约费:¥".$other_data['now_deduct_fee'];
  2402. }else if($data_type == 'sf'){
  2403. $log_mgs = "第三方顺丰取消订单,产生违约费:¥".$other_data['now_deduct_fee'];
  2404. }else if($data_type == 'make'){
  2405. $log_mgs = "码科配送取消订单,产生违约费:¥".$other_data['now_deduct_fee'];
  2406. }else if($data_type == 'ele'){
  2407. $log_mgs = "蜂鸟即配取消订单,产生违约费:¥".$other_data['now_deduct_fee'];
  2408. }
  2409. $oh = array();
  2410. $oh['order_id'] = $order_id;
  2411. $oh['order_status_id'] = 4;
  2412. $oh['comment'] = $log_mgs;
  2413. $oh['date_added'] = time();
  2414. $oh['notify'] = 1;
  2415. M('lionfish_comshop_order_history')->add($oh);
  2416. //扣除违约金
  2417. D('Seller/Supply')->update_supply_commission($order_id,$other_data['now_deduct_fee']);
  2418. }
  2419. if($data_type == 'sf'){
  2420. $delivery_company = "第三方顺丰同城";
  2421. $remark = $delivery_company.'订单已取消,取消原因:'.$other_data['cancel_reason'];
  2422. D('Home/LocaltownDelivery')->write_distribution_log( $order_id, 0 , 5 ,$remark );
  2423. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id ) )->save(
  2424. array('delivery_type'=>0)
  2425. );
  2426. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $data_type , 5 ,'订单已取消,取消原因:'.$other_data['cancel_reason'] );
  2427. }if($data_type == 'make'){
  2428. $delivery_company = "码科配送";
  2429. $remark = $delivery_company.'订单已取消,取消原因:'.$other_data['cancel_reason'];
  2430. D('Home/LocaltownDelivery')->write_distribution_log( $order_id, 0 , 5 ,$remark );
  2431. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $data_type , 5 ,'订单已取消,取消原因:'.$other_data['cancel_reason'] );
  2432. }if($data_type == 'ele'){
  2433. $delivery_company = "蜂鸟即配";
  2434. $remark = $delivery_company.'订单已取消,取消原因:'.$other_data['cancel_reason'];
  2435. D('Home/LocaltownDelivery')->write_distribution_log( $order_id, 0 , 5 ,$remark );
  2436. D('Home/LocaltownDelivery')->save_orderdistribution_thirth_log( $order_id, $data_type , 5 ,'订单已取消,取消原因:'.$other_data['cancel_reason'] );
  2437. }
  2438. }
  2439. /**
  2440. * 第三方配送取消订单通知
  2441. */
  2442. public function cancel_third_delviery_order_notice($order_info,$other_data){
  2443. $delivery_company = "";
  2444. if($other_data['data_type'] == 'imdada'){
  2445. $delivery_company = "达达";
  2446. }else if($other_data['data_type'] == 'sf'){
  2447. $delivery_company = "顺丰同城";
  2448. }else if($other_data['data_type'] == 'ele'){
  2449. $delivery_company = "蜂鸟即配";
  2450. }if($other_data['data_type'] == 'make') {
  2451. $delivery_company = "码科配送";
  2452. }
  2453. $order_member_name = M('lionfish_comshop_member')->where( array('member_id' => $order_info['member_id'] ) )->find();
  2454. //6、发送取消通知订单给平台
  2455. $weixin_template_cancle_order = D('Home/Front')->get_config_by_name('weixin_template_cancle_order');
  2456. $platform_send_info_member_id = D('Home/Front')->get_config_by_name('platform_send_info_member');
  2457. if( !empty($weixin_template_cancle_order) && !empty($platform_send_info_member_id) )
  2458. {
  2459. $weixin_template_order =array();
  2460. $weixin_appid = D('Home/Front')->get_config_by_name('weixin_appid' );
  2461. if( !empty($weixin_appid) && !empty($weixin_template_cancle_order) )
  2462. {
  2463. $head_pathinfo = "lionfish_comshop/pages/index/index";
  2464. $pl_member_id = explode(",", $platform_send_info_member_id);
  2465. foreach($pl_member_id as $m_id){
  2466. $weopenid = M('lionfish_comshop_member')->where( array('member_id' => $m_id ) )->find();
  2467. $weixin_template_order = array(
  2468. 'appid' => $weixin_appid,
  2469. 'template_id' => $weixin_template_cancle_order,
  2470. 'pagepath' => $head_pathinfo,
  2471. 'data' => array(
  2472. 'first' => array('value' => '您好,您收到了一个'.$delivery_company.'配送取消订单,请尽快处理','color' => '#030303'),
  2473. 'keyword1' => array('value' => $order_info['order_num_alias'],'color' => '#030303'),
  2474. 'keyword2' => array('value' => '取消订单','color' => '#030303'),
  2475. 'keyword3' => array('value' => sprintf("%01.2f", $order_info['total']),'color' => '#030303'),
  2476. 'keyword4' => array('value' => date('Y-m-d H:i:s'),'color' => '#030303'),
  2477. 'keyword5' => array('value' => $order_member_name['username'],'color' => '#030303'),
  2478. 'remark' => array('value' => '此订单已于'.date('Y-m-d H:i:s').'被'.$delivery_company.'配送取消,取消原因:'.$other_data['cancel_reason'].',请尽快处理','color' => '#030303'),
  2479. )
  2480. );
  2481. D('Seller/User')->just_send_wxtemplate($weopenid['we_openid'], 0, $weixin_template_order );
  2482. }
  2483. }
  2484. }
  2485. }
  2486. /**
  2487. * 核销订单
  2488. * @param $order_id 订单号
  2489. * @return array
  2490. */
  2491. public function hexiao_all_orders($order_id){
  2492. //订单信息
  2493. $field = "order_id,order_num_alias,member_id,ziti_name,ziti_mobile,shipping_name,shipping_tel";
  2494. $order_info = M('lionfish_comshop_order')->where(array('order_id'=>$order_id))->field($field)->find();
  2495. //订单要核销商品(未核销完,剩余核销数量大于0)
  2496. $order_goods_saleshexiao_list = M('lionfish_comshop_order_goods_saleshexiao')->where(array('order_id'=>$order_info['order_id'],'is_hexiao_over'=>0))->select();
  2497. if(count($order_goods_saleshexiao_list) > 0){
  2498. foreach($order_goods_saleshexiao_list as $k=>$v){
  2499. //核销商品
  2500. $this->hexiao_order_goods($v,0);
  2501. }
  2502. $this->hexiao_finished($order_id,'后台整单点击“确认使用”,订单完成');
  2503. }
  2504. }
  2505. /**
  2506. * 核销完成
  2507. * @param $order_id
  2508. */
  2509. public function hexiao_finished($order_id,$hx_msg){
  2510. $is_finished = true;
  2511. $hexiao_list = M('lionfish_comshop_order_goods_saleshexiao')->where(array('order_id'=>$order_id))->select();
  2512. foreach($hexiao_list as $k=>$v){
  2513. if($v['hexiao_type'] == 0 && $v['is_hexiao_over'] == 0){//按订单核销
  2514. $is_finished = false;
  2515. }
  2516. if($v['hexiao_type'] == 1 && $v['is_hexiao_over'] == 0){//按次核销
  2517. if($v['hexiao_count'] > 0 && $v['remain_hexiao_count'] > 0){
  2518. $is_finished = false;
  2519. }
  2520. if($v['hexiao_count'] == 0){
  2521. $is_finished = false;
  2522. }
  2523. }
  2524. }
  2525. if($is_finished){
  2526. $order_history = array();
  2527. $order_history['order_id'] = $order_id;
  2528. $order_history['order_status_id'] = 11;
  2529. $order_history['notify'] = 0;
  2530. $order_history['comment'] = $hx_msg;
  2531. $order_history['date_added']=time();
  2532. M('lionfish_comshop_order_history')->add($order_history);
  2533. //ims_
  2534. $time = time();
  2535. M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->save( array('order_status_id' => 11,'receive_time' => $time,'finishtime' => $time) );
  2536. $open_aftersale = D('Home/Front')->get_config_by_name('open_aftersale');
  2537. $open_aftersale_time = D('Home/Front')->get_config_by_name('open_aftersale_time');
  2538. $statements_end_time = $time;
  2539. if( !empty($open_aftersale) && !empty($open_aftersale_time) && $open_aftersale_time > 0 )
  2540. {
  2541. $statements_end_time = $statements_end_time + 86400 * $open_aftersale_time;
  2542. }
  2543. $up_order_data = array();
  2544. $up_order_data['statements_end_time'] = $statements_end_time;
  2545. M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->save( $up_order_data );
  2546. }
  2547. }
  2548. /**
  2549. * 核销商品
  2550. * @param $order_goods_saleshexiao 订单商品核销信息表
  2551. * @param $hx_time 0、按订单核销,大于0、按次数核销
  2552. * @return 1、核销商品成功,0、核销商品失败,-1 核销次数大于剩余次数
  2553. */
  2554. public function hexiao_order_goods($order_goods_saleshexiao,$hx_time){
  2555. //订单核销信息表id
  2556. $hx_id = $order_goods_saleshexiao['id'];
  2557. //剩余核销数量
  2558. $remain_hexiao_count = $order_goods_saleshexiao['remain_hexiao_count'];
  2559. if($order_goods_saleshexiao['hexiao_count'] > 0){
  2560. $hexiao_count = 0;
  2561. if($hx_time > 0){
  2562. if($hx_time > $remain_hexiao_count){
  2563. return -1;
  2564. }else{
  2565. $hexiao_count = $hx_time;
  2566. }
  2567. }else{
  2568. $hexiao_count = $remain_hexiao_count;
  2569. }
  2570. $hexiao_data = array();
  2571. if($hexiao_count == $remain_hexiao_count){
  2572. $hexiao_data['remain_hexiao_count'] = 0;
  2573. $hexiao_data['is_hexiao_over'] = 1;
  2574. }else{
  2575. $hexiao_data['remain_hexiao_count'] = $remain_hexiao_count - $hexiao_count;
  2576. }
  2577. $hx_result = M('lionfish_comshop_order_goods_saleshexiao')->where(array('id'=>$hx_id))->save($hexiao_data);
  2578. }else{
  2579. if($hx_time == 0){
  2580. $hexiao_data = array();
  2581. $hexiao_data['is_hexiao_over'] = 1;
  2582. $hexiao_count = 1;
  2583. $hx_result = M('lionfish_comshop_order_goods_saleshexiao')->where(array('id'=>$hx_id))->save($hexiao_data);
  2584. }else{
  2585. $hx_result = 1;
  2586. $hexiao_count = $hx_time;
  2587. }
  2588. }
  2589. if($hx_result !== false){
  2590. //添加订单核销记录表
  2591. $hexiao_record = array();
  2592. $hexiao_record['order_id'] = $order_goods_saleshexiao['order_id'];
  2593. $hexiao_record['order_goods_id'] = $order_goods_saleshexiao['order_goods_id'];
  2594. $hexiao_record['goods_id'] = $order_goods_saleshexiao['goods_id'];
  2595. $hexiao_record['hexiao_count'] = $hexiao_count;
  2596. $hexiao_record['smember_name'] = "后台操作";
  2597. $hexiao_record['is_admin'] = 1;
  2598. $hexiao_record['addtime'] = time();
  2599. M('lionfish_comshop_order_goods_saleshexiao_record')->add($hexiao_record);
  2600. return 1;
  2601. }else{
  2602. return 0;
  2603. }
  2604. }
  2605. /**
  2606. * 获取订单商品核销记录
  2607. */
  2608. public function get_goods_hexiao_record(){
  2609. $data = array();
  2610. $order_id = I('request.id','');
  2611. $order_goods_id = I('request.order_goods_id','');
  2612. $hx_count = 0;
  2613. $list = M('lionfish_comshop_order_goods_saleshexiao_record')->where(array('order_id'=>$order_id,'order_goods_id'=>$order_goods_id))->order('addtime desc')->select();
  2614. foreach($list as $k=>$v){
  2615. $hx_count = $hx_count + $v['hexiao_count'];
  2616. }
  2617. $data['hx_count'] = $hx_count;
  2618. $data['hx_list'] = $list;
  2619. return $data;
  2620. }
  2621. /**
  2622. * 商品指定核销信息
  2623. * @param unknown $goods_id
  2624. */
  2625. public function get_goods_assign_salesroom($goods_id){
  2626. $data = array();
  2627. //核销员
  2628. $item_smember = array();
  2629. //核销门店
  2630. $item_salesroom = M()->query("SELECT gs.*,sr.room_name,sr.room_logo FROM " . C('DB_PREFIX') .
  2631. "lionfish_comshop_goods_relative_salesroom as gs left join " . C('DB_PREFIX') ."lionfish_comshop_salesroom as sr on gs.salesroom_id=sr.id WHERE gs.goods_id=".$goods_id." order by gs.id asc" );
  2632. foreach($item_salesroom as $k=>$v){
  2633. $item_salesroom_smember = M()->query("SELECT grs.smember_id,sm.username FROM " . C('DB_PREFIX') .
  2634. "lionfish_comshop_goods_relative_smember as grs left join " . C('DB_PREFIX') ."lionfish_comshop_salesroom_member as sm on grs.smember_id=sm.id ".
  2635. " left join " . C('DB_PREFIX') ."lionfish_comshop_member as m on sm.member_id=m.member_id ".
  2636. " WHERE grs.gr_id=".$v['id']." order by sm.id asc" );
  2637. foreach($item_salesroom_smember as $mk=>$mv){
  2638. $item_smember[$mv['smember_id']] = $mv['username'];
  2639. }
  2640. }
  2641. $data['salesroom_list'] = $item_salesroom;
  2642. $data['smember_list'] = $item_smember;
  2643. return $data;
  2644. }
  2645. //脱敏代码
  2646. public function desensitize($string, $start = 0, $length = 0, $re = '*'){
  2647. if(empty($string) || empty($length) || empty($re)) return $string;
  2648. $end = $start + $length;
  2649. $strlen = mb_strlen($string);
  2650. $str_arr = array();
  2651. for($i=0; $i<$strlen; $i++) {
  2652. if($i>=$start && $i<$end)
  2653. $str_arr[] = $re;
  2654. else
  2655. $str_arr[] = mb_substr($string, $i, 1);
  2656. }
  2657. return implode('',$str_arr);
  2658. }
  2659. public function num_to_rmb($num){
  2660. $c1 = "零壹贰叁肆伍陆柒捌玖";
  2661. $c2 = "分角元拾佰仟万拾佰仟亿";
  2662. //精确到分后面就不要了,所以只留两个小数位
  2663. $num = round($num, 2);
  2664. //将数字转化为整数
  2665. $num = $num * 100;
  2666. if (strlen($num) > 10) {
  2667. return "金额太大,请检查";
  2668. }
  2669. $i = 0;
  2670. $c = "";
  2671. while (1) {
  2672. if ($i == 0) {
  2673. //获取最后一位数字
  2674. $n = substr($num, strlen($num)-1, 1);
  2675. } else {
  2676. $n = $num % 10;
  2677. }
  2678. //每次将最后一位数字转化为中文
  2679. $p1 = substr($c1, 3 * $n, 3);
  2680. $p2 = substr($c2, 3 * $i, 3);
  2681. if ($n != '0' || ($n == '0' && ($p2 == '亿' || $p2 == '万' || $p2 == '元'))) {
  2682. $c = $p1 . $p2 . $c;
  2683. } else {
  2684. $c = $p1 . $c;
  2685. }
  2686. $i = $i + 1;
  2687. //去掉数字最后一位了
  2688. $num = $num / 10;
  2689. $num = (int)$num;
  2690. //结束循环
  2691. if ($num == 0) {
  2692. break;
  2693. }
  2694. }
  2695. $j = 0;
  2696. $slen = strlen($c);
  2697. while ($j < $slen) {
  2698. //utf8一个汉字相当3个字符
  2699. $m = substr($c, $j, 6);
  2700. //处理数字中很多0的情况,每次循环去掉一个汉字“零”
  2701. if ($m == '零元' || $m == '零万' || $m == '零亿' || $m == '零零') {
  2702. $left = substr($c, 0, $j);
  2703. $right = substr($c, $j + 3);
  2704. $c = $left . $right;
  2705. $j = $j-3;
  2706. $slen = $slen-3;
  2707. }
  2708. $j = $j + 3;
  2709. }
  2710. //这个是为了去掉类似23.0中最后一个“零”字
  2711. if (substr($c, strlen($c)-3, 3) == '零') {
  2712. $c = substr($c, 0, strlen($c)-3);
  2713. }
  2714. //将处理的汉字加上“整”
  2715. if (empty($c)) {
  2716. return "零元整";
  2717. }else{
  2718. return $c . "整";
  2719. }
  2720. }
  2721. }
  2722. ?>