OrderModel.class.php 128 KB

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