OrderController.class.php 112 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466
  1. <?php
  2. /**
  3. * lionfish 商城系统
  4. *
  5. *
  6. * @author fish
  7. *
  8. */
  9. namespace Home\Controller;
  10. use Home\Model\OrderModel;
  11. class OrderController extends CommonController {
  12. protected function _initialize(){
  13. parent::_initialize();
  14. // 获取当前用户ID
  15. }
  16. /**
  17. 直接取消订单
  18. 1、已付款待发货 状态
  19. 2、是不是自己的订单
  20. 3、判断后台是否开启了状态
  21. 4、记录日志
  22. 5、处理订单,
  23. 6、处理退款,
  24. 7、打印小票
  25. 结束
  26. **/
  27. public function del_cancle_order()
  28. {
  29. $gpc = I('request.');
  30. $_GPC = I('request.');
  31. $token = $gpc['token'];
  32. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  33. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  34. {
  35. echo json_encode( array('code' => 2) );
  36. die();
  37. }
  38. $member_id = $weprogram_token['member_id'];
  39. $order_id = $_GPC['order_id'];
  40. $order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'order_id' => $order_id) )->find();
  41. $order_member_name = M('lionfish_comshop_member')->where( array('member_id' => $member_id ) )->find();
  42. if( empty($order_info) )
  43. {
  44. echo json_encode( array('code' => 1, 'msg' => '订单不存在') );
  45. die();
  46. }
  47. if( $order_info['order_status_id'] == 1)
  48. {
  49. $order_can_del_cancle = D('Home/Front')->get_config_by_name('order_can_del_cancle');
  50. if( empty($order_can_del_cancle) || $order_can_del_cancle == 0 )
  51. {
  52. //4、记录日志
  53. $order_history = array();
  54. $order_history['order_id'] = $order_id;
  55. $order_history['order_status_id'] = 5;
  56. $order_history['notify'] = 0;
  57. $order_history['comment'] = '会员前台申请,直接取消已支付待发货订单';
  58. $order_history['date_added'] = time();
  59. M('lionfish_comshop_order_history')->add($order_history);
  60. //5、处理订单
  61. $result = D('Home/Weixin')->del_cancle_order($order_id);
  62. //6、发送取消通知订单给平台
  63. $weixin_template_cancle_order = D('Home/Front')->get_config_by_name('weixin_template_cancle_order');
  64. $platform_send_info_member_id = D('Home/Front')->get_config_by_name('platform_send_info_member');
  65. if( !empty($weixin_template_cancle_order) && !empty($platform_send_info_member_id) )
  66. {
  67. $weixin_template_order =array();
  68. $weixin_appid = D('Home/Front')->get_config_by_name('weixin_appid' );
  69. if( !empty($weixin_appid) && !empty($weixin_template_cancle_order) )
  70. {
  71. $head_pathinfo = "lionfish_comshop/pages/index/index";
  72. $pl_member_id = explode(",", $platform_send_info_member_id);
  73. foreach($pl_member_id as $m_id){
  74. $weopenid = M('lionfish_comshop_member')->where( array('member_id' => $m_id ) )->find();
  75. $weixin_template_order = array(
  76. 'appid' => $weixin_appid,
  77. 'template_id' => $weixin_template_cancle_order,
  78. 'pagepath' => $head_pathinfo,
  79. 'data' => array(
  80. 'first' => array('value' => '您好,您收到了一个取消订单,请尽快处理','color' => '#030303'),
  81. 'keyword1' => array('value' => $order_info['order_num_alias'],'color' => '#030303'),
  82. 'keyword2' => array('value' => '取消订单','color' => '#030303'),
  83. 'keyword3' => array('value' => sprintf("%01.2f", $order_info['total']),'color' => '#030303'),
  84. 'keyword4' => array('value' => date('Y-m-d H:i:s'),'color' => '#030303'),
  85. 'keyword5' => array('value' => $order_member_name['username'],'color' => '#030303'),
  86. 'remark' => array('value' => '此订单已于'.date('Y-m-d H:i:s').'被用户取消,请尽快处理','color' => '#030303'),
  87. )
  88. );
  89. D('Seller/User')->just_send_wxtemplate($weopenid['we_openid'], 0, $weixin_template_order );
  90. }
  91. }
  92. }
  93. if( $result['code'] == 0 && $order_info['type'] != 'integral')
  94. {
  95. $is_print_cancleorder = D('Home/Front')->get_config_by_name('is_print_cancleorder');
  96. if( isset($is_print_cancleorder) && $is_print_cancleorder == 1 )
  97. {
  98. D('Seller/Printaction')->check_print_order($order_id,'用户取消订单');
  99. D('Seller/Printaction')->check_print_order2($order_id,'用户取消订单');
  100. }
  101. echo json_encode( array('code' => 0 ) );
  102. die();
  103. }
  104. else if($result['code'] == 0 && $order_info['type'] == 'integral')
  105. {
  106. echo json_encode( array('code' => 0 ) );
  107. die();
  108. }
  109. else{
  110. echo json_encode( array('code' => 1, 'msg' => $result['msg'] ) );
  111. die();
  112. }
  113. }else{
  114. echo json_encode( array('code' => 1, 'msg' => '未开启此项功能') );
  115. die();
  116. }
  117. }else{
  118. echo json_encode( array('code' => 1, 'msg' => '订单状态不正确,只有已支付,未发货的订单才能取消') );
  119. die();
  120. }
  121. }
  122. public function order_info()
  123. {
  124. $gpc = I('request.');
  125. $token = $gpc['token'];
  126. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  127. if( empty($weprogram_token) || empty($weprogram_token['member_id']) )
  128. {
  129. echo json_encode( array('code' => 2) );
  130. die();
  131. }
  132. $member_id = $weprogram_token['member_id'];
  133. $order_id = $gpc['id'];
  134. $is_supply = isset($gpc['is_supply']) ? $gpc['is_supply'] :'';
  135. if( $is_supply > 0 )
  136. {
  137. $supply_is_open_mobilemanage = D('Home/Front')->get_config_by_name('supply_is_open_mobilemanage');
  138. if( empty($supply_is_open_mobilemanage) || $supply_is_open_mobilemanage == 0 )
  139. {
  140. $supply_is_open_mobilemanage = 0;
  141. }
  142. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  143. if( !empty($supply_info) && $supply_info['state'] == 1 && $supply_info['type'] == 1 && $supply_info['is_open_mobilemanage'] == 1 )
  144. {
  145. $ck_order_goods = M('lionfish_comshop_order_goods')->where( array('supply_id' => $supply_info['id'], 'order_id' => $order_id ) )->find();
  146. if( !empty($ck_order_goods) )
  147. {
  148. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $ck_order_goods['order_id']) )->find();
  149. }else{
  150. echo json_encode( array('code' => 2 , 'msg' => '非法操作') );
  151. die();
  152. }
  153. }else{
  154. echo json_encode( array('code' => 2, 'msg' => '非法操作') );
  155. die();
  156. }
  157. }else{
  158. $order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'order_id' => $order_id) )->find();
  159. }
  160. //gpc
  161. if($order_info['is_change_price'] == 1){
  162. $order_info['admin_change_price'] = $order_info['total'] - $order_info['old_price'];
  163. }
  164. $pick_up_info = array();
  165. $pick_order_info = array();
  166. if( $order_info['delivery'] == 'pickup' )
  167. {
  168. //查询自提点
  169. $pick_order_info = array();
  170. $pick_id = 0;
  171. $pick_up_info = array();
  172. }
  173. if( $order_info['delivery'] == 'localtown_delivery' && ($order_info['order_status_id'] != 3 && $order_info['order_status_id'] != 5 ) )
  174. {
  175. $order_info['orderdistribution_order'] = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_info['order_id'] ) )->find();
  176. if( !empty($order_info['orderdistribution_order']) && $order_info['orderdistribution_order'] > 0 )
  177. {
  178. $orderdistribution = M('lionfish_comshop_orderdistribution')->where( array('id' => $order_info['orderdistribution_order']['orderdistribution_id'] ) )->find();
  179. $order_info['orderdistribution_order']['username'] = $orderdistribution['username'];
  180. }
  181. }
  182. $order_status_info = M('lionfish_comshop_order_status')->where( array('order_status_id' => $order_info['order_status_id'] ) )->find();
  183. //10 name
  184. if($order_info['order_status_id'] == 10)
  185. {
  186. $order_status_info['name'] = '等待退款';
  187. }
  188. else if($order_info['order_status_id'] == 4 && $order_info['delivery'] =='pickup')
  189. {
  190. //delivery 6
  191. $order_status_info['name'] = '待自提';
  192. //已自提
  193. }
  194. else if($order_info['order_status_id'] == 6 && $order_info['delivery'] =='pickup')
  195. {
  196. //delivery 6
  197. $order_status_info['name'] = '已自提';
  198. }
  199. else if($order_info['order_status_id'] == 1 && $order_info['type'] == 'lottery')
  200. {
  201. //等待开奖
  202. //一等奖
  203. if($order_info['lottery_win'] == 1)
  204. {
  205. $order_status_info['name'] = '一等奖';
  206. }else {
  207. $order_status_info['name'] = '等待开奖';
  208. }
  209. }
  210. //核销订单
  211. if( $order_info['delivery'] == 'hexiao' ){
  212. if($order_info['store_id'] == 0){
  213. $order_info['shopname'] = '平台自营';
  214. }else{
  215. $store_info = M('lionfish_comshop_supply')->where( array('id' => $order_info['store_id'] ) )->find();
  216. $order_info['shopname'] = $store_info['shopname'];
  217. }
  218. //订单卷码
  219. $order_info['hexiao_volume_code'] = $order_info['hexiao_volume_code'];
  220. //二维码
  221. if(empty($order_info['hexiao_qr_code'])){
  222. $order_info['hexiao_qr_code'] = D('Home/Salesroom')->_get_ordergoods_hxqrcode($order_id,'',$order_info['hexiao_volume_code']);
  223. }else{
  224. $order_info['hexiao_qr_code'] = tomedia($order_info['hexiao_qr_code']);
  225. }
  226. //门店列表
  227. $salesroom_list = D('Home/Salesroom')->get_order_salesroom($order_id,0);
  228. foreach($salesroom_list as $slk=>$slv){
  229. $member_lon = $gpc['longitude'];
  230. $member_lat = $gpc['latitude'];
  231. $salesroom_list[$slk]['distance'] = D('Home/Salesroom')->cal_salesroom_distance($slv,$member_lon,$member_lat);
  232. }
  233. $distances = array_column($salesroom_list,'distance');
  234. array_multisort($distances,SORT_ASC,$salesroom_list);
  235. $order_info['salesroom_list'] = $salesroom_list;
  236. }
  237. //$order_info['type']
  238. //open_auto_delete
  239. if($order_info['order_status_id'] == 3)
  240. {
  241. $open_auto_delete = D('Home/Front')->get_config_by_name('open_auto_delete');
  242. $auto_cancle_order_time = D('Home/Front')->get_config_by_name('auto_cancle_order_time');
  243. $order_info['open_auto_delete'] = $open_auto_delete;
  244. //date_added
  245. if($open_auto_delete == 1)
  246. {
  247. $order_info['over_buy_time'] = $order_info['date_added'] + 3600 * $auto_cancle_order_time;
  248. $order_info['cur_time'] = time();
  249. }
  250. }
  251. $shipping_province = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_province_id'] ) )->find();
  252. $shipping_city = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_city_id'] ) )->find();
  253. $shipping_country = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_country_id'] ) )->find();
  254. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->select();
  255. $shiji_total_money = 0;
  256. $member_youhui = 0.00;
  257. $pick_up_time = "";
  258. $pick_up_type = -1;
  259. $pick_up_weekday = '';
  260. $today_time = $order_info['pay_time'];
  261. $arr = array('天','一','二','三','四','五','六');
  262. $url = D('Home/Front')->get_config_by_name('shop_domain').'/';
  263. $attachment_type = D('Home/Front')->get_config_by_name('attachment_type');
  264. $qiniu_url = D('Home/Front')->get_config_by_name('qiniu_url');
  265. $is_can_received = 1;//是否可以收货,1、可以,0、不可以
  266. $hx_receive_info = array();//核销订单已收到待收货情况
  267. $receive_count = 0;//已收货
  268. $wait_count = 0;//待收货
  269. $goods_quantity = 0;//商品数量
  270. $refund_goods_quantity = 0;//退款商品数量
  271. $volume_code_list = array();//卷码列表
  272. $hx_order_count = 0;//按订单核销商品订单数
  273. $hx_time_count = 0;//按次数核销商品订单数
  274. $vi = 0;
  275. foreach($order_goods_list as $key => $order_goods)
  276. {
  277. $order_goods['name'] = htmlspecialchars_decode(stripslashes($order_goods['name']));
  278. $order_refund_goods = M('lionfish_comshop_order_refund')->where( array('order_id' =>$order_id,'order_goods_id' => $order_goods['order_goods_id'] ) )->order('ref_id desc')->find();
  279. if(!empty($order_refund_goods))
  280. {
  281. $order_refund_goods['addtime'] = date('Y-m-d H:i:s', $order_refund_goods['addtime']);
  282. if($order_refund_goods['state'] == 0 || $order_refund_goods['state'] == 2){
  283. $is_can_received = 0;
  284. }
  285. }
  286. $order_option_info = M('lionfish_comshop_order_option')->field('value')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_id) )->select();
  287. $order_goods['order_refund_goods'] = $order_refund_goods;
  288. foreach($order_option_info as $option)
  289. {
  290. $order_goods['option_str'][] = $option['value'];
  291. }
  292. if(empty($order_goods['option_str']))
  293. {
  294. //option_str
  295. $order_goods['option_str'] = '';
  296. }else{
  297. $order_goods['option_str'] = implode(',', $order_goods['option_str']);
  298. }
  299. //
  300. $order_goods['shipping_fare'] = round($order_goods['shipping_fare'],2);
  301. $order_goods['price'] = round($order_goods['price'],2);
  302. $order_goods['total'] = round($order_goods['total'],2);
  303. if( $order_goods['is_vipcard_buy'] == 1 || $order_goods['is_level_buy'] ==1 )
  304. {
  305. $order_goods['price'] = round($order_goods['oldprice'],2);
  306. }
  307. $order_goods['real_total'] = round($order_goods['quantity'] * $order_goods['price'],2);
  308. /**
  309. $goods_images = file_image_thumb_resize($vv['goods_images'],400);
  310. if(is_array($goods_images))
  311. {
  312. $vv['goods_images'] = $vv['goods_images'];
  313. }else{
  314. $vv['goods_images']= tomedia( file_image_thumb_resize($vv['goods_images'],400) );
  315. }
  316. **/
  317. if($attachment_type == 1)
  318. {
  319. $goods_images = $qiniu_url.resize($order_goods['goods_images'],400,400);
  320. }else{
  321. $goods_images = $url.resize($order_goods['goods_images'],400,400);
  322. }
  323. if( !is_array($goods_images) )
  324. {
  325. $order_goods['image']= tomedia( $goods_images );
  326. $order_goods['goods_images']= tomedia( $goods_images );
  327. }else{
  328. $order_goods['image']= $order_goods['goods_images'];
  329. }
  330. $order_goods['hascomment'] = 0;
  331. $order_goods_comment_info = M('lionfish_comshop_order_comment')->field('comment_id')->where( array('goods_id' => $order_goods['goods_id'],'order_id' =>$order_id) )->find();
  332. if( !empty($order_goods_comment_info) )
  333. {
  334. $order_goods['hascomment'] = 1;
  335. }
  336. $order_goods['can_ti_refund'] = 1;
  337. $disable_info = M('lionfish_comshop_order_refund_disable')->where( array('order_id' => $order_id, 'order_goods_id' => $order_goods['order_goods_id']) )->find();
  338. if( !empty($disable_info) )
  339. {
  340. $order_goods['can_ti_refund'] = 0;
  341. }
  342. if($order_goods['is_refund_state'] == 1)
  343. {
  344. //已经再申请退款中了。或者已经退款了。
  345. $order_refund_info = M('lionfish_comshop_order_refund')->field('state')->where( array('order_id' => $order_id,'order_goods_id' => $order_goods['order_goods_id'] ) )->find();
  346. if( $order_refund_info['state'] == 3 )
  347. {
  348. $order_goods['is_refund_state'] = 2;
  349. }
  350. }
  351. //无售后期
  352. $open_aftersale = D('Home/Front')->get_config_by_name('open_aftersale');
  353. if( empty($open_aftersale) )
  354. {
  355. $order_goods['is_statements_state'] = 1;
  356. }
  357. //ims_
  358. $goods_info = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $order_goods['goods_id']) )->find();
  359. $goods_cm_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify,goods_share_image')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  360. if($pick_up_type == -1 || $goods_cm_info['pick_up_type'] > $pick_up_type)
  361. {
  362. $pick_up_type = $goods_cm_info['pick_up_type'];
  363. if($pick_up_type == 0)
  364. {
  365. $pick_up_time = date('m-d', $today_time);
  366. //$pick_up_weekday = '周'.$arr[date('w',$today_time)];
  367. }else if( $pick_up_type == 1 ){
  368. $pick_up_time = date('m-d', $today_time+86400);
  369. //$pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  370. }else if( $pick_up_type == 2 )
  371. {
  372. $pick_up_time = date('m-d', $today_time+86400*2);
  373. //$pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  374. }else if($pick_up_type == 3)
  375. {
  376. $pick_up_time = $goods_cm_info['pick_up_modify'];
  377. }
  378. }
  379. if( !empty($goods_cm_info['goods_share_image']) )
  380. {
  381. $order_goods['goods_share_image']= tomedia( $goods_cm_info['goods_share_image'] );
  382. }else{
  383. $order_goods['goods_share_image'] = $order_goods['image'];
  384. }
  385. $order_goods['shop_price'] = $goods_info['price'];
  386. $store_info = array('s_true_name' =>'','s_logo' => '');
  387. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  388. //$store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
  389. if( !empty($store_info['s_logo']) )
  390. {
  391. $store_info['s_logo'] = tomedia($store_info['s_logo']);
  392. }else{
  393. $store_info['s_logo'] = '';
  394. }
  395. $order_goods['store_info'] = $store_info;
  396. //核销订单
  397. if( $order_info['delivery'] == 'hexiao' ){
  398. $order_goods_saleshexiao = M('lionfish_comshop_order_goods_saleshexiao')->where( array('order_id' =>$order_id,'order_goods_id' => $order_goods['order_goods_id'] ) )->find();
  399. //有效期截止
  400. $order_goods['effect_end_time'] = date('Y-m-d H:i:s',$order_goods_saleshexiao['effect_end_time']);
  401. // 是否核销过期:0 否,1、是
  402. $order_goods['is_hexiao_expire'] = $order_goods_saleshexiao['effect_end_time']>time()?0:1;
  403. //总核销次数
  404. $order_goods['hexiao_count'] = $order_goods_saleshexiao['hexiao_count'];
  405. //剩余核销次数
  406. $order_goods['remain_hexiao_count'] = $order_goods_saleshexiao['remain_hexiao_count'];
  407. //核销方式:0 订单核销,1、自定义核销次数
  408. $order_goods['hexiao_type'] = $order_goods_saleshexiao['hexiao_type'];
  409. //商品核销卷码
  410. $order_goods['hexiao_volume_code'] = $order_goods_saleshexiao['hexiao_volume_code'];
  411. //商品核销二维码
  412. if(empty($order_goods['hexiao_qr_code'])){
  413. $order_goods['hexiao_qr_code'] = D('Home/Salesroom')->_get_ordergoods_hxqrcode($order_id,$order_goods['order_goods_id'],$order_goods['hexiao_volume_code']);
  414. }else{
  415. $order_goods['hexiao_qr_code'] = tomedia($order_goods['hexiao_qr_code']);
  416. }
  417. //是否核销完毕:0 否,1、是
  418. $order_goods['is_hexiao_over'] = $order_goods_saleshexiao['is_hexiao_over'];
  419. //核销过期操作时间
  420. $order_goods['expire_act_time'] = $order_goods_saleshexiao['expire_act_time'];
  421. $volume_code_list[$vi]['hexiao_volume_code'] = $order_goods['hexiao_volume_code'];
  422. if($order_goods['is_hexiao_over'] == 1){
  423. $receive_count = $receive_count + $order_goods_saleshexiao['goods_quantity'] - $order_goods_saleshexiao['refund_quantity'];
  424. $volume_code_list[$vi]['is_use'] = 1;
  425. }else{
  426. $receive_count = $receive_count + floor(($order_goods_saleshexiao['hexiao_count'] - $order_goods_saleshexiao['refund_quantity']*$order_goods_saleshexiao['one_hexiao_count'] - $order_goods_saleshexiao['remain_hexiao_count'])/$order_goods_saleshexiao['one_hexiao_count']);
  427. $volume_code_list[$vi]['is_use'] = 0;
  428. }
  429. // 是否核销过期:0 否,1、是
  430. $volume_code_list[$vi]['is_hexiao_expire'] = $order_goods_saleshexiao['effect_end_time']>time()?0:1;
  431. $volume_code_list[$vi]['effect_end_time'] = date('Y-m-d H:i:s',$order_goods_saleshexiao['effect_end_time']);
  432. $volume_code_list[$vi]['refund_quantity'] = $order_goods_saleshexiao['refund_quantity'];
  433. if($order_goods['hexiao_type'] == 0){
  434. $hx_order_count = $hx_order_count + 1;
  435. }else{
  436. $hx_time_count = $hx_time_count + 1;
  437. }
  438. //核销商品门店信息
  439. $salesroom_list = D('Home/Salesroom')->get_order_goods_salesroom($order_goods['order_goods_id'],$gpc['longitude'],$gpc['latitude'],0);
  440. $order_goods['salesroom_list'] = $salesroom_list;
  441. $vi++;
  442. }
  443. if( $order_goods['is_refund_state'] == 1 || ($order_goods['has_refund_money'] > 0 && $order_goods['has_refund_quantity'] > 0) )
  444. {
  445. $order_goods['is_refund_state'] = 1;
  446. $where = " order_id = '".$order_goods['order_id']."' and order_goods_id = '".$order_goods['order_goods_id']."' and state in (0,2,3) ";
  447. $refund_info = M('lionfish_comshop_order_refund')->field('ref_id,order_id,ref_money,real_refund_quantity,state')->where( $where )->find();
  448. if(!empty($refund_info)){
  449. $order_goods['refund_info'] = $refund_info;
  450. }else{
  451. $refund_info = array();
  452. $refund_info['order_id'] = $order_goods['order_id'];
  453. $refund_info['ref_money'] = $order_goods['has_refund_money'];
  454. $refund_info['real_refund_quantity'] = $order_goods['has_refund_quantity'];
  455. $refund_info['state'] = 3;
  456. $order_goods['refund_info'] = $refund_info;
  457. }
  458. }
  459. unset($order_goods['model']);
  460. unset($order_goods['rela_goodsoption_valueid']);
  461. unset($order_goods['comment']);
  462. //ims_ ims_lionfish_comshop_order_goods_refund addtime
  463. $order_goods_refund_list = M('lionfish_comshop_order_goods_refund')->field('real_refund_quantity,money,addtime')->where( "order_goods_id=".$order_goods['order_goods_id'] )->order('id asc')->select();
  464. if( empty($order_goods_refund_list) )
  465. {
  466. $order_goods_refund_list = array();
  467. }else{
  468. foreach( $order_goods_refund_list as $kre => $rval )
  469. {
  470. $rval['addtime'] = date('Y-m-d H:i:s', $rval['addtime']);
  471. $order_goods_refund_list[$kre] = $rval;
  472. $refund_goods_quantity = $refund_goods_quantity + $rval['real_refund_quantity'];
  473. }
  474. }
  475. $order_goods['order_goods_refund_list'] = $order_goods_refund_list;
  476. $goods_quantity = $goods_quantity + $order_goods['quantity'];
  477. $order_goods_list[$key] = $order_goods;
  478. $shiji_total_money += $order_goods['quantity'] * $order_goods['price'];
  479. $member_youhui += ($order_goods['real_total'] - $order_goods['total']);
  480. }
  481. //核销订单
  482. if( $order_info['delivery'] == 'hexiao' ){
  483. $hx_receive_info['goods_count'] = count($order_goods_list);//商品种类
  484. $hx_receive_info['goods_quantity'] = $goods_quantity;//商品总数量
  485. $hx_receive_info['receive_count'] = $receive_count;//已收货商品数量
  486. $hx_receive_info['wait_count'] = $goods_quantity-$receive_count-$refund_goods_quantity;//待收货商品数量
  487. $hx_receive_info['refund_goods_quantity'] = $refund_goods_quantity;//已退款商品数量
  488. $hx_receive_info['volume_code_list'] = $volume_code_list;//商品卷码列表
  489. $hx_record = D('Home/Salesroom')->get_last_ordergoods_hexiaorecord($order_id);
  490. if(!empty($hx_record)){
  491. //使用地址
  492. if(empty($hx_record['salesroom_name'])){
  493. $hx_receive_info['salesroom_name'] = $hx_record['smember_name'];
  494. }else{
  495. $hx_receive_info['salesroom_name'] = $hx_record['salesroom_name'];
  496. }
  497. //使用时间
  498. $hx_receive_info['use_time'] = date('Y-m-d H:i:s',$hx_record['addtime']);
  499. }
  500. if($hx_order_count > 0 && $hx_time_count > 0){//混合订单
  501. $order_info['order_hexiao_type'] = 2;
  502. }else if($hx_order_count > 0 && $hx_time_count == 0){//按订单核销
  503. $order_info['order_hexiao_type'] = 0;
  504. }else if($hx_order_count == 0 && $hx_time_count > 0){//按次数核销
  505. $order_info['order_hexiao_type'] = 1;
  506. }
  507. $order_info['hx_receive_info'] = $hx_receive_info;//核销订单已收到待收货情况
  508. }
  509. unset($order_info['store_id']);
  510. unset($order_info['email']);
  511. unset($order_info['shipping_city_id']);
  512. unset($order_info['shipping_country_id']);
  513. unset($order_info['shipping_province_id']);
  514. //unset($order_info['comment']);
  515. unset($order_info['voucher_id']);
  516. unset($order_info['is_balance']);
  517. unset($order_info['lottery_win']);
  518. unset($order_info['ip']);
  519. unset($order_info['ip_region']);
  520. unset($order_info['user_agent']);
  521. $order_info['is_can_received'] = $is_can_received;
  522. $order_info['shipping_fare'] = round($order_info['shipping_fare'],2) < 0.01 ? '0.00':round($order_info['shipping_fare'],2) ;
  523. $order_info['voucher_credit'] = round($order_info['voucher_credit'],2) < 0.01 ? '0.00':round($order_info['voucher_credit'],2) ;
  524. $order_info['fullreduction_money'] = round($order_info['fullreduction_money'],2) < 0.01 ? '0.00':round($order_info['fullreduction_money'],2) ;
  525. $need_data = array();
  526. if($order_info['type'] == 'integral')
  527. {
  528. //暂时屏蔽积分商城
  529. $order_info['score'] = round($order_info['total'],2);
  530. }
  531. $order_info['total'] = round($order_info['total'] + $order_info['packing_fare'] +$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money'] - $order_info['score_for_money'] + $order_info['localtown_add_shipping_fare'] - $order_info['fare_shipping_free'],2);
  532. if($order_info['total'] < 0)
  533. {
  534. $order_info['total'] = '0.00';
  535. }
  536. $order_info['real_total'] = round($shiji_total_money,2)+$order_info['shipping_fare'];
  537. $order_info['price'] = round($order_info['price'],2);
  538. $order_info['member_youhui'] = round($member_youhui,2) < 0.01 ? '0.00':round($member_youhui,2);
  539. $order_info['pick_up_time'] = $pick_up_time;
  540. $order_info['shipping_fare'] = sprintf("%.2f",$order_info['shipping_fare']);
  541. $order_info['voucher_credit'] = sprintf("%.2f",$order_info['voucher_credit']);
  542. $order_info['fullreduction_money'] = sprintf("%.2f",$order_info['fullreduction_money']);
  543. $order_info['total'] = sprintf("%.2f",$order_info['total']);
  544. $order_info['real_total'] = sprintf("%.2f",$order_info['real_total']);
  545. $order_info['date_added'] = date('Y-m-d H:i:s', $order_info['date_added']);
  546. if($order_info['delivery'] =='pickup')
  547. {
  548. }else{
  549. }
  550. if( !empty($order_info['pay_time']) && $order_info['pay_time'] >0 )
  551. {
  552. $order_info['pay_date'] = date('Y-m-d H:i:s', $order_info['pay_time']);
  553. }else{
  554. $order_info['pay_date'] = '';
  555. }
  556. $order_info['express_tuanz_date'] = date('Y-m-d H:i:s', $order_info['express_tuanz_time']);
  557. $order_info['receive_date'] = date('Y-m-d H:i:s', $order_info['receive_time']);
  558. //"delivery": "pickup", enum('express', 'pickup', 'tuanz_send')
  559. if($order_info['delivery'] == 'express')
  560. {
  561. $placeorder_trans_name = D('Home/Front')->get_config_by_name('placeorder_trans_name' );
  562. $order_info['delivery_name'] = $placeorder_trans_name?$placeorder_trans_name:'快递';
  563. }else if($order_info['delivery'] == 'pickup')
  564. {
  565. $delivery_ziti_name = D('Home/Front')->get_config_by_name('delivery_ziti_name' );
  566. $order_info['delivery_name'] = $delivery_ziti_name?$delivery_ziti_name:'自提';
  567. }else if($order_info['delivery'] == 'tuanz_send'){
  568. $delivery_tuanzshipping_name = D('Home/Front')->get_config_by_name('delivery_tuanzshipping_name' );
  569. $order_info['delivery_name'] = $delivery_tuanzshipping_name?$delivery_tuanzshipping_name:'团长配送';
  570. }
  571. $pin_rebate = [];
  572. //拼团获取返利信息
  573. if($order_info['type'] == 'pintuan'){
  574. $pin_rebate['reward_amount'] = 0;
  575. $pin_rebate['rebate_reward'] = 0;
  576. $pin_order = M('lionfish_comshop_pin_order')->where( array('order_id' => $order_id ) )->find();
  577. //获取拼团信息
  578. $pin_info = M('lionfish_comshop_pin')->where( array('pin_id' =>$pin_order['pin_id'] ) )->find();
  579. if($pin_info['is_pintuan_rebate'] == 1){
  580. if($pin_info['rebate_reward'] == 1){//积分
  581. $integral_flow = M('lionfish_comshop_member_integral_flow')->where( array('order_id' => $order_id,'type'=>'pintuan_rebate') )->find();
  582. if(!empty($integral_flow)){
  583. $pin_rebate['reward_amount'] = $integral_flow['score'];
  584. $pin_rebate['rebate_reward'] = 1;
  585. }
  586. }else if($pin_info['rebate_reward'] == 2){//余额
  587. $charge_flow = M('lionfish_comshop_member_charge_flow')->where( array('trans_id' => $order_id,'state'=>21) )->find();
  588. if(!empty($charge_flow)){
  589. $pin_rebate['reward_amount'] = $charge_flow['money'];
  590. $pin_rebate['rebate_reward'] = 2;
  591. }
  592. }
  593. }
  594. }
  595. //获取订单表单信息
  596. $order_form = D('Home/Allform')->getOrderFormInfo($order_id, $member_id);
  597. $need_data['order_form'] = $order_form;
  598. $need_data['order_info'] = $order_info;
  599. $need_data['order_status_info'] = $order_status_info;
  600. $need_data['shipping_province'] = $shipping_province;
  601. $need_data['shipping_city'] = $shipping_city;
  602. $need_data['shipping_country'] = $shipping_country;
  603. $need_data['order_goods_list'] = $order_goods_list;
  604. $need_data['goods_count'] = count($order_goods_list);
  605. $need_data['pin_rebate'] = $pin_rebate;
  606. //$order_info['order_status_id'] 13 平台介入退款
  607. $order_refund_historylist = array();
  608. $pingtai_deal = 0;
  609. //判断是否已经平台处理完毕
  610. $order_refund_historylist = M('lionfish_comshop_order_refund_history')->where( array('order_id' => $order_id) )->order('addtime asc')->select();
  611. foreach($order_refund_historylist as $key => $val)
  612. {
  613. if($val['type'] ==3)
  614. {
  615. $pingtai_deal = 1;
  616. }
  617. }
  618. $order_refund = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id) )->find();
  619. if(!empty($order_refund))
  620. {
  621. $order_refund['addtime'] = date('Y-m-d H:i:s', $order_refund['addtime']);
  622. }
  623. $need_data['pick_up'] = $pick_up_info;
  624. if( empty($pick_order_info['qrcode']) && false)
  625. {
  626. }
  627. $need_data['pick_order_info'] = $pick_order_info;
  628. $order_pay_after_share = D('Home/Front')->get_config_by_name('order_pay_after_share');
  629. if($order_pay_after_share==1){
  630. $order_pay_after_share_title = D('Home/Front')->get_config_by_name('order_pay_after_share_title');
  631. $order_pay_after_share_img = D('Home/Front')->get_config_by_name('order_pay_after_share_img');
  632. $order_pay_after_share_img = !empty($order_pay_after_share_img) ? tomedia($order_pay_after_share_img) : '';
  633. $need_data['share_img'] = empty($order_pay_after_share_img) ? $need_data['order_goods_list'][0]['image']: $order_pay_after_share_img;
  634. $need_data['share_title'] = $order_pay_after_share_title;
  635. }else{
  636. if(empty($need_data['order_goods_list'][0]['goods_share_image']))
  637. {
  638. $need_data['share_img'] = $need_data['order_goods_list'][0]['image'];
  639. }
  640. }
  641. $order_can_del_cancle = D('Home/Front')->get_config_by_name('order_can_del_cancle');
  642. $order_can_del_cancle = empty($order_can_del_cancle) || $order_can_del_cancle == 0 ? 1 : 0;
  643. $is_hidden_orderlist_phone = D('Home/Front')->get_config_by_name('is_hidden_orderlist_phone');
  644. $is_show_guess_like = D('Home/Front')->get_config_by_name('is_show_order_guess_like');
  645. $user_service_switch = D('Home/Front')->get_config_by_name('user_service_switch');
  646. $common_header_backgroundimage = D('Home/Front')->get_config_by_name('common_header_backgroundimage');
  647. if($common_header_backgroundimage){
  648. $common_header_backgroundimage = tomedia($common_header_backgroundimage);
  649. }
  650. $order_can_shen_refund = D('Home/Front')->get_config_by_name('is_score_can_refund');
  651. if( $order_info['type'] == 'integral' )
  652. {
  653. if( !isset($order_can_shen_refund) || empty($order_can_shen_refund) )
  654. {
  655. $order_can_shen_refund = 0;
  656. }else{
  657. $order_can_shen_refund = 1;
  658. }
  659. }else{
  660. $order_can_shen_refund = 1;
  661. }
  662. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  663. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  664. if( !isset($order_note_open) || $order_note_open == 0)
  665. {
  666. $order_note_open = 0;
  667. }
  668. if( !isset($order_note_name) || empty($order_note_name) )
  669. {
  670. $order_note_name = '店名';
  671. }
  672. $open_comment_gift = D('Home/Front')->get_config_by_name('open_comment_gift');
  673. $open_comment_gift = !empty($open_comment_gift) ? $open_comment_gift : 0;
  674. $result = D('Seller/Order')->check_comment_gift_score($member_id);
  675. if(!$result['is_comment_gift']){
  676. $open_comment_gift = 0;
  677. }
  678. //预售信息数组 begin
  679. $presale_info = [];
  680. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $order_id );
  681. if( $presale_result['code'] == 0 )
  682. {
  683. $presale_info = $presale_result['data'];
  684. }
  685. //end
  686. //礼品卡订单信息 begin
  687. $virtualcard_result = D('Seller/VirtualCard')->getVirtualCardOrderInfO( $order_id );
  688. $virtualcard_info = [];
  689. if( $virtualcard_result['code'] == 0 && $virtualcard_result['data']['state'] > 0 )
  690. {
  691. $virtualcard_info = $virtualcard_result['data'];
  692. }
  693. //end
  694. echo json_encode(
  695. array(
  696. 'code' => 0,
  697. 'data' => $need_data,
  698. 'order_note_open' => $order_note_open,
  699. 'order_note_name' => $order_note_name,
  700. 'pingtai_deal' => $pingtai_deal,
  701. 'order_refund' => $order_refund,
  702. 'order_can_shen_refund' => $order_can_shen_refund,
  703. 'order_can_del_cancle' => $order_can_del_cancle,
  704. 'order_pay_after_share' => $order_pay_after_share,
  705. 'is_hidden_orderlist_phone' => $is_hidden_orderlist_phone,
  706. 'is_show_guess_like' => $is_show_guess_like,
  707. 'user_service_switch' => $user_service_switch,
  708. 'open_comment_gift' => $open_comment_gift,
  709. 'common_header_backgroundimage' => $common_header_backgroundimage,
  710. 'presale_info' => $presale_info,//预售信息
  711. 'virtualcard_info' => $virtualcard_info,//礼品卡信息
  712. )
  713. );
  714. }
  715. public function sign_dan_order()
  716. {
  717. $gpc = I('request.');
  718. $token = $gpc['token'];
  719. $order_id = $gpc['order_id'];
  720. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  721. $member_id = $weprogram_token['member_id'];
  722. $community_info = D('Home/Front')->get_member_community_info($member_id);
  723. $order_info = M('lionfish_comshop_order')->where( array('head_id' => $community_info['id'],'order_id' => $order_id) )->find();
  724. if(!empty($order_info) && $order_info['order_status_id'] == 14)
  725. {
  726. $oh = array();
  727. $oh['order_id']=$order_id;
  728. $oh['order_status_id']= 4;
  729. $oh['comment']='团长签收货物';
  730. $oh['date_added']=time();
  731. $oh['notify']= $order_info['order_status_id'];
  732. M('lionfish_comshop_order_history')->add( $oh );
  733. //更改订单为已发货
  734. D('Home/Frontorder')->send_order_operate($order_id);
  735. echo json_encode( array('code' => 0) );
  736. }else{
  737. echo json_encode( array('code' => 1) );
  738. }
  739. }
  740. public function order_commission()
  741. {
  742. $gpc = I('request.');
  743. $token = $gpc['token'];
  744. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  745. $member_id = $weprogram_token['member_id'];
  746. if( empty($member_id) )
  747. {
  748. echo json_encode( array('code' => 1) );
  749. die();
  750. }
  751. $community_info = D('Home/Front')->get_member_community_info($member_id);
  752. $head_id = $community_info['id'];
  753. $choose_date = $gpc['chooseDate'];
  754. $choose_date = str_replace('年','-', $choose_date);
  755. $choose_date = str_replace('月','-', $choose_date);
  756. $choose_date = $choose_date.'01 00:00:00';
  757. $BeginDate=date('Y-m-d', strtotime($choose_date));
  758. $end_date = date('Y-m-d', strtotime("$BeginDate +1 month -1 day")).' 23:59:59';
  759. $begin_time = strtotime($BeginDate.' 00:00:00');
  760. $end_time = strtotime($end_date);
  761. $where = " and addtime >= {$begin_time} and addtime < {$end_time} ";
  762. $money = M('lionfish_community_head_commiss_order')->where("head_id={$head_id} and state=0 {$where}")->sum('money');
  763. if( empty($money))
  764. {
  765. $money = 0;
  766. }
  767. echo json_encode( array('code' => 0, 'money' => $money) );
  768. die();
  769. }
  770. public function refundorderlist()
  771. {
  772. $gpc = I('request.');
  773. $is_tuanz = isset($gpc['is_tuanz']) ? $gpc['is_tuanz'] :0;
  774. $token = $gpc['token'];
  775. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  776. $member_id = $weprogram_token['member_id'];
  777. $page = isset($gpc['page']) ? $gpc['page']:'1';
  778. $size = isset($gpc['size']) ? $gpc['size']:'6';
  779. $offset = ($page - 1)* $size;
  780. $type = isset($gpc['type']) ? $gpc['type']:'';
  781. $where = ' and o.member_id = '.$member_id;
  782. $fields = " orf.state as refund_state ,orf.order_goods_id as r_order_goods_id, ";
  783. $currentTab = isset($gpc['currentTab']) ? $gpc['currentTab']:0;
  784. if($currentTab == 0)
  785. {
  786. }else if($currentTab == 1){
  787. //售后
  788. $where .= ' and o.order_status_id = 12 ';
  789. }else if($currentTab == 2){
  790. $where .= ' and orf.state =3 ';
  791. }else if($currentTab == 3)
  792. {
  793. $where .= ' and orf.state =1 ';
  794. }
  795. $sql = "select orf.ref_id,orf.state,orf.order_goods_id,o.order_id,o.order_num_alias,o.date_added,o.delivery,o.is_pin,{$fields} o.is_zhuli,o.shipping_fare,o.shipping_tel,o.shipping_name,o.voucher_credit,o.fullreduction_money,o.store_id,o.total,o.order_status_id,o.lottery_win,o.type from ".C('DB_PREFIX')."lionfish_comshop_order_refund as orf left join " .C('DB_PREFIX')."lionfish_comshop_order as o on orf.order_id = o.order_id
  796. where 1 {$where}
  797. order by orf.addtime desc limit {$offset},{$size}";
  798. $list = M()->query($sql);
  799. $lionfish_comshop_order_status_list = M('lionfish_comshop_order_status')->select();
  800. $url = D('Home/Front')->get_config_by_name('shop_domain');
  801. $status_arr = array();
  802. foreach( $lionfish_comshop_order_status_list as $kk => $val )
  803. {
  804. $status_arr[ $val['order_status_id'] ] = $val['name'];
  805. }
  806. //createTime
  807. foreach($list as $key => $val)
  808. {
  809. $val['createTime'] = date('Y-m-d H:i:s', $val['date_added']);
  810. switch( $val['state'] )
  811. {
  812. case 0:
  813. $val['status_name'] = '申请中';
  814. break;
  815. case 1:
  816. $val['status_name'] = '商家拒绝';
  817. break;
  818. case 2:
  819. break;
  820. case 3:
  821. $val['status_name'] = '退款成功';
  822. break;
  823. case 4:
  824. $val['status_name'] = '退款失败';
  825. break;
  826. case 5:
  827. $val['status_name'] = '撤销申请';
  828. break;
  829. }
  830. if($val['shipping_fare']<=0.001 || $val['delivery'] == 'pickup')
  831. {
  832. $val['shipping_fare'] = '免运费';
  833. }else{
  834. $val['shipping_fare'] = ''.$val['shipping_fare'];
  835. }
  836. if($val['order_status_id'] == 10)
  837. {
  838. $val['status_name'] = '等待退款';
  839. }
  840. else if($val['order_status_id'] == 4 && $val['delivery'] =='pickup')
  841. {
  842. //delivery 6
  843. $val['status_name'] = '待自提';
  844. //已自提
  845. }
  846. else if($val['order_status_id'] == 6 && $val['delivery'] =='pickup')
  847. {
  848. //delivery 6
  849. $val['status_name'] = '已自提';
  850. //已自提
  851. }
  852. else if($val['order_status_id'] == 1 && $val['type'] == 'lottery')
  853. {
  854. //等待开奖
  855. //一等奖
  856. if($val['lottery_win'] == 1)
  857. {
  858. $val['status_name'] = '一等奖';
  859. }else {
  860. $val['status_name'] = '等待开奖';
  861. }
  862. }
  863. else if($val['order_status_id'] == 2 && $val['type'] == 'lottery')
  864. {
  865. //等待开奖
  866. $val['status_name'] = '等待开奖';
  867. }
  868. $quantity = 0;
  869. if( $val['order_goods_id'] > 0 )
  870. {
  871. $goods_sql = "select order_goods_id,head_disc,member_disc,level_name,goods_id,is_pin,shipping_fare,name,goods_images,quantity,price,total,rela_goodsoption_valueid
  872. from ".C('DB_PREFIX')."lionfish_comshop_order_goods where order_goods_id=".$val['order_goods_id']." and order_id= ".$val['order_id']."";
  873. }else{
  874. $goods_sql = "select order_goods_id,head_disc,member_disc,level_name,goods_id,is_pin,shipping_fare,name,goods_images,quantity,price,total,rela_goodsoption_valueid
  875. from ".C('DB_PREFIX')."lionfish_comshop_order_goods where order_id= ".$val['order_id']."";
  876. }
  877. $goods_list = M()->query($goods_sql); //M()->query($goods_sql);
  878. $total_commision = 0;
  879. if($val['delivery'] =='tuanz_send')
  880. {
  881. $total_commision += $val['shipping_fare'];
  882. }
  883. foreach($goods_list as $kk => $vv)
  884. {
  885. //commision
  886. $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' =>$vv['order_goods_id'] ) )->select();
  887. if( !empty($vv['goods_images']))
  888. {
  889. $goods_images = $url. '/'.resize($vv['goods_images'],400,400);
  890. if(is_array($goods_images))
  891. {
  892. $vv['goods_images'] = $vv['goods_images'];
  893. }else{
  894. $vv['goods_images']= $url.'/'.resize($vv['goods_images'],400,400) ;
  895. }
  896. }else{
  897. $vv['goods_images']= '';
  898. }
  899. $goods_filed = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $vv['goods_id'] ) )->find();
  900. $vv['orign_price'] = $goods_filed['price'];
  901. $quantity += $vv['quantity'];
  902. foreach($order_option_list as $option)
  903. {
  904. $vv['option_str'][] = $option['value'];
  905. }
  906. if( !isset($vv['option_str']) )
  907. {
  908. $vv['option_str'] = '';
  909. }else{
  910. $vv['option_str'] = implode(',', $vv['option_str']);
  911. }
  912. // $vv['price'] = round($vv['price'],2);
  913. $vv['price'] = sprintf("%.2f",$vv['price']);
  914. $vv['orign_price'] = sprintf("%.2f",$vv['orign_price']);
  915. $vv['total'] = sprintf("%.2f",$vv['total']);
  916. $goods_list[$kk] = $vv;
  917. }
  918. $val['total_commision'] = $total_commision;
  919. $val['quantity'] = $quantity;
  920. if( empty($val['store_id']) )
  921. {
  922. $val['store_id'] = 1;
  923. }
  924. $store_info = array('s_true_name' =>'','s_logo' => '');
  925. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  926. $store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
  927. if( !empty($store_info['s_logo']))
  928. {
  929. $store_info['s_logo'] = tomedia($store_info['s_logo']);
  930. }else{
  931. $store_info['s_logo'] = '';
  932. }
  933. $order_goods['store_info'] = $store_info;
  934. $val['store_info'] = $store_info;
  935. $val['goods_list'] = $goods_list;
  936. $val['total'] = $val['total'] + $val['shipping_fare']-$val['voucher_credit']-$val['fullreduction_money'];
  937. if($val['total'] < 0)
  938. {
  939. $val['total'] = 0;
  940. }
  941. $val['total'] = sprintf("%.2f",$val['total']);
  942. $list[$key] = $val;
  943. }
  944. $need_data = array('code' => 0);
  945. if( !empty($list) )
  946. {
  947. $need_data['data'] = $list;
  948. }else {
  949. $need_data = array('code' => 1);
  950. }
  951. echo json_encode( $need_data );
  952. die();
  953. }
  954. public function orderlist()
  955. {
  956. $gpc = I('request.');
  957. $_GPC = $gpc;
  958. $is_tuanz = isset($gpc['is_tuanz']) ? $gpc['is_tuanz'] :0;
  959. $is_supply = isset($gpc['is_supply']) ? $gpc['is_supply'] :0;
  960. $token = $gpc['token'];
  961. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  962. $member_id = $weprogram_token['member_id'];
  963. $sqlcondition = "";
  964. $left_join = "";
  965. $page = isset($gpc['page']) ? $gpc['page']:'1';
  966. $size = isset($gpc['size']) ? $gpc['size']:'6';
  967. $offset = ($page - 1)* $size;
  968. $type = isset($gpc['type']) ? $gpc['type']:'';
  969. $order_status = isset($gpc['order_status']) ? $gpc['order_status']:'-1';
  970. $soli_id = isset($_GPC['soli_id']) ? $_GPC['soli_id'] : 0;//是否群接龙
  971. if($is_tuanz == 1)
  972. {
  973. $community_info = D('Home/Front')->get_member_community_info($member_id);
  974. if( isset($_GPC['chooseDate']) && !empty($_GPC['chooseDate']) )
  975. {
  976. $where = ' and o.head_id = '.$community_info['id'] ;
  977. }else{
  978. //$where = ' and o.head_id = '.$community_info['id'].' and o.delivery != "express" ';
  979. $where = ' and o.head_id = '.$community_info['id'].' ';
  980. }
  981. $searchfield = isset($_GPC['searchfield']) && !empty($_GPC['searchfield']) ? $_GPC['searchfield'] : '';
  982. if( !empty($searchfield) && !empty($_GPC['keyword']))
  983. {
  984. $keyword = $_GPC['keyword'];
  985. switch($searchfield)
  986. {
  987. case 'ordersn':
  988. $where .= ' AND locate("'.$keyword.'",o.order_num_alias)>0';
  989. break;
  990. case 'member':
  991. $where .= ' AND (locate("'.$keyword.'",m.username)>0 or "'.$keyword.'"=o.member_id )';
  992. $left_join .= ' left join ' . C('DB_PREFIX'). 'lionfish_comshop_member as m on m.member_id = o.member_id ';
  993. break;
  994. case 'address':
  995. $where .= ' AND ( locate("'.$keyword.'",o.shipping_name)>0 )';
  996. break;
  997. case 'mobile':
  998. $where .= ' AND ( locate("'.$keyword.'",o.shipping_tel)>0 )';
  999. break;
  1000. case 'location':
  1001. $where .= ' AND (locate("'.$keyword.'",o.shipping_address)>0 )';
  1002. break;
  1003. case 'shipping_no':
  1004. $where .= ' AND (locate("'.$keyword.'",o.shipping_no)>0 )';
  1005. break;
  1006. case 'goodstitle':
  1007. $left_join = ' inner join ( select DISTINCT(og.order_id) from ' . C('DB_PREFIX') . 'lionfish_comshop_order_goods as og where (locate("'.$keyword.'",og.name)>0)) gs on gs.order_id=o.order_id';
  1008. break;
  1009. case 'trans_id':
  1010. $where .= ' AND (locate("'.$keyword.'",o.transaction_id)>0 )';
  1011. break;
  1012. }
  1013. }
  1014. }
  1015. else if( $is_supply == 1 )
  1016. {
  1017. $supply_is_open_mobilemanage = D('Home/Front')->get_config_by_name('supply_is_open_mobilemanage');
  1018. if( empty($supply_is_open_mobilemanage) || $supply_is_open_mobilemanage == 0 )
  1019. {
  1020. $supply_is_open_mobilemanage = 0;
  1021. }
  1022. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  1023. if( !empty($supply_info) && $supply_info['state'] == 1 && $supply_info['type'] == 1 && $supply_info['is_open_mobilemanage'] == 1 )
  1024. {
  1025. $keyword = $_GPC['keyword'];
  1026. if( !empty($keyword) )
  1027. {
  1028. $left_join = ' inner join ( select DISTINCT(og.order_id) from ' . C('DB_PREFIX') . 'lionfish_comshop_order_goods as og where (locate("'.$keyword.'",og.name)>0) and og.supply_id = '.$supply_info['id'].' ) gs on gs.order_id=o.order_id';
  1029. }else{
  1030. $left_join = ' inner join ( select DISTINCT(og.order_id) from ' . C('DB_PREFIX') . 'lionfish_comshop_order_goods as og where og.supply_id = '.$supply_info['id'].' ) gs on gs.order_id=o.order_id';
  1031. }
  1032. //$where = " and o.delivery != 'hexiao'";
  1033. }else{
  1034. echo json_encode( array('code' => 2, 'msg' => '未开启此项功能') );
  1035. die();
  1036. }
  1037. }
  1038. else{
  1039. $where = ' and o.member_id = '.$member_id;
  1040. }
  1041. if( isset($gpc['chooseDate']) && !empty($gpc['chooseDate']) )
  1042. {
  1043. $choose_date = $gpc['chooseDate'];
  1044. $choose_date = str_replace('年','-', $choose_date);
  1045. $choose_date = str_replace('月','-', $choose_date);
  1046. $choose_date = $choose_date.'01 00:00:00';
  1047. $BeginDate=date('Y-m-d', strtotime($choose_date));
  1048. $end_date = date('Y-m-d', strtotime("$BeginDate +1 month -1 day")).' 23:59:59';
  1049. $begin_time = strtotime($BeginDate.' 00:00:00');
  1050. $end_time = strtotime($end_date);
  1051. $where .= ' and o.date_added >= '.$begin_time.' and o.date_added < '.$end_time;
  1052. }
  1053. //全部 -1 待付款 3 待配送1 待提货4 已提货6
  1054. //order_status $order_status
  1055. $join = "";
  1056. $fields = "";
  1057. switch($order_status)
  1058. {
  1059. case -1:
  1060. //全部 -1
  1061. break;
  1062. case 3:
  1063. //待付款 3
  1064. $where .= ' and o.order_status_id = 3 ';
  1065. break;
  1066. case 1:
  1067. //待配送1
  1068. $where .= ' and o.order_status_id = 1 ';
  1069. break;
  1070. case 4:
  1071. //待提货4
  1072. $where .= ' and o.order_status_id = 4 ';
  1073. break;
  1074. case 14:
  1075. //待提货4
  1076. $where .= ' and o.order_status_id = 14 ';
  1077. break;
  1078. case 22:
  1079. //待确认佣金的
  1080. $where .= ' and o.order_status_id in (1,4,14) ';
  1081. break;
  1082. case 357:
  1083. //待确认佣金的
  1084. $where .= ' and o.order_status_id in (3,5,7) ';
  1085. break;
  1086. case 6:
  1087. //已提货6
  1088. $where .= ' and o.order_status_id in (6,11) ';
  1089. break;
  1090. case 11:
  1091. //已完成
  1092. $where .= ' and o.order_status_id = 11 ';
  1093. break;
  1094. case 12:
  1095. $fields = " orf.state as refund_state , ";
  1096. $currentTab = isset($gpc['currentTab']) ? $gpc['currentTab']:0;
  1097. $join = " ".C('DB_PREFIX').'lionfish_comshop_order_refund as orf, ';
  1098. $where .= ' and o.order_id = orf.order_id ';
  1099. if($currentTab == 0)
  1100. {
  1101. }else if($currentTab == 1){
  1102. //售后
  1103. $where .= ' and o.order_status_id = 12 ';
  1104. }else if($currentTab == 2){
  1105. $where .= ' and orf.state =3 ';
  1106. }else if($currentTab == 3)
  1107. {
  1108. $where .= ' and orf.state =1 ';
  1109. }
  1110. break;
  1111. case 7:
  1112. //已退款
  1113. $where .= ' and o.order_status_id = 7 ';
  1114. break;
  1115. }
  1116. $where .= ' and o.type != "ignore" ';
  1117. if( isset($soli_id) && $soli_id > 0 )
  1118. {
  1119. $where .= " and o.soli_id = {$soli_id} ";
  1120. }
  1121. if( !empty($type) )
  1122. {
  1123. //$where .= ' and o.type != "ignore" ';
  1124. }
  1125. $sql = "select o.order_id,o.order_num_alias,o.date_added,o.delivery,o.is_pin,{$fields} o.is_zhuli,o.packing_fare,o.shipping_fare,o.shipping_tel,o.shipping_name,o.voucher_credit,o.score_for_money,o.fullreduction_money,o.store_id,o.total,o.order_status_id,o.lottery_win,o.type,os.name as status_name,o.ziti_mobile,o.localtown_add_shipping_fare,o.fare_shipping_free,o.third_distribution_type,o.payment_code "
  1126. . " from ".C('DB_PREFIX')."lionfish_comshop_order as o {$left_join}, {$join}
  1127. ".C('DB_PREFIX')."lionfish_comshop_order_status as os ".$sqlcondition."
  1128. where o.order_status_id = os.order_status_id {$where}
  1129. order by o.date_added desc limit {$offset},{$size}";
  1130. $list = M()->query($sql);
  1131. $open_auto_delete = D('Home/Front')->get_config_by_name('open_auto_delete');
  1132. $cancle_hour = D('Home/Front')->get_config_by_name('auto_cancle_order_time');
  1133. $cancle_hour_time = time() - 3600 * $cancle_hour;
  1134. $url = D('Home/Front')->get_config_by_name('shop_domain');
  1135. //createTime
  1136. foreach($list as $key => $val)
  1137. {
  1138. //判断是否需要取消订单
  1139. //order_status_id 3 open_auto_delete
  1140. if($open_auto_delete == 1 && $val['order_status_id'] == 3 && $val['date_added'] < $cancle_hour_time )
  1141. {
  1142. D('Home/Frontorder')->cancel_order($val['order_id'], true);
  1143. $val['order_status_id'] == 5;
  1144. }
  1145. $presale_result = D('Home/PresaleGoods')->getOrderPresaleInfo( $val['order_id'] );
  1146. if( $presale_result['code'] == 0 )
  1147. {
  1148. $val['is_presale'] = 1;
  1149. }else{
  1150. $val['is_presale'] = 0;
  1151. }
  1152. if($val['delivery'] == 'pickup')
  1153. {
  1154. //$val['total'] = round($val['total'],2) - round($val['voucher_credit'],2);
  1155. }else{
  1156. //$val['total'] = round($val['total'],2)+round($val['shipping_fare'],2) - round($val['voucher_credit'],2);
  1157. }
  1158. $val['createTime'] = date('Y-m-d H:i:s', $val['date_added']);
  1159. // $val['delivery'] =='pickup'
  1160. if($val['shipping_fare']<=0.001 || $val['delivery'] == 'pickup')
  1161. {
  1162. $val['shipping_fare'] = 0.00;
  1163. }else{
  1164. $val['shipping_fare'] = ''.$val['shipping_fare'];
  1165. }
  1166. if($val['order_status_id'] == 10)
  1167. {
  1168. $val['status_name'] = '等待退款';
  1169. }
  1170. else if($val['order_status_id'] == 4 && $val['delivery'] =='pickup')
  1171. {
  1172. //delivery 6
  1173. $val['status_name'] = '待自提';
  1174. //已自提
  1175. }
  1176. else if($val['order_status_id'] == 6 && $val['delivery'] =='pickup')
  1177. {
  1178. //delivery 6
  1179. $val['status_name'] = '已自提';
  1180. //已自提
  1181. }
  1182. else if($val['order_status_id'] == 1 && $val['type'] == 'lottery')
  1183. {
  1184. //等待开奖
  1185. //一等奖
  1186. if($val['lottery_win'] == 1)
  1187. {
  1188. $val['status_name'] = '一等奖';
  1189. }else {
  1190. $val['status_name'] = '等待开奖';
  1191. }
  1192. }
  1193. else if($val['order_status_id'] == 2 && $val['type'] == 'lottery')
  1194. {
  1195. //等待开奖
  1196. $val['status_name'] = '等待开奖';
  1197. }
  1198. $quantity = 0;
  1199. $goods_list = M('lionfish_comshop_order_goods')->field('order_id,order_goods_id,head_disc,member_disc,level_name,goods_id,is_pin,shipping_fare,name,goods_images,quantity,price,total,old_total,fullreduction_money,voucher_credit,rela_goodsoption_valueid,is_refund_state,has_refund_money,has_refund_quantity')->where( array('order_id' => $val['order_id']) )->select();
  1200. $total_commision = 0;
  1201. if($val['delivery'] =='tuanz_send')
  1202. {
  1203. $total_commision += $val['shipping_fare'];
  1204. }
  1205. foreach($goods_list as $kk => $vv)
  1206. {
  1207. //commision
  1208. if($is_tuanz == 1){
  1209. $community_order_info = M('lionfish_community_head_commiss_order')->where( array('head_id' => $community_info['id'],'order_goods_id' => $vv['order_goods_id']) )->find();
  1210. if(!empty($community_order_info))
  1211. {
  1212. $vv['commision'] = $community_order_info['money']-$community_order_info['add_shipping_fare'];
  1213. $vv['commision'] = sprintf("%.2f",$vv['commision']);
  1214. if($community_order_info['state'] == 2){
  1215. $vv['commision'] = 0;
  1216. }
  1217. $total_commision += $vv['commision'];
  1218. }else{
  1219. $vv['commision'] = "0.00";
  1220. }
  1221. $vv['head_shipping_fare'] = $community_order_info['add_shipping_fare'];//团长配送费
  1222. $vv['old_commision'] = $vv['commision'];
  1223. $vv['del_commision'] = 0;
  1224. //fen_type
  1225. $vv['fen_type'] = $community_order_info['fen_type'];// 0 按照比例, 1按照金额
  1226. $vv['fen_bili'] = $community_order_info['bili'];//比例
  1227. $vv['fen_gumoney'] = $community_order_info['bili'];//按照金额
  1228. $order_jishu = $vv['total'] -$vv['fullreduction_money']-$vv['voucher_credit']-$vv['has_refund_money'];
  1229. $vv['order_jishu'] = $order_jishu;//有效金额:(基数)
  1230. //has_refund_commission = 0
  1231. $order_goods_refund_list = M('lionfish_comshop_order_goods_refund')->where( array('order_id' => $val['order_id'],'order_goods_id' => $vv['order_goods_id'] ) )->select();
  1232. if( !empty($order_goods_refund_list) )
  1233. {
  1234. $kvbal_total_back_head_orderbuycommiss = 0;//合计退掉佣金
  1235. foreach( $order_goods_refund_list as $kvval )
  1236. {
  1237. $kvbal_total_back_head_orderbuycommiss += $kvval['back_head_orderbuycommiss'];
  1238. }
  1239. $vv['del_commision'] = $kvbal_total_back_head_orderbuycommiss;
  1240. $vv['old_commision'] += $vv['del_commision'];
  1241. }
  1242. }
  1243. $order_option_list = M('lionfish_comshop_order_option')->where( array('order_goods_id' => $vv['order_goods_id']) )->select();
  1244. if( !empty($vv['goods_images']))
  1245. {
  1246. $goods_images = $url. '/'.resize($vv['goods_images'],400,400);
  1247. if(is_array($goods_images))
  1248. {
  1249. $vv['goods_images'] = $vv['goods_images'];
  1250. }else{
  1251. $vv['goods_images']= $url.'/'.resize($vv['goods_images'],400,400) ;
  1252. }
  1253. }else{
  1254. $vv['goods_images']= '';
  1255. }
  1256. $goods_filed = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $vv['goods_id']) )->find();
  1257. $vv['orign_price'] = $goods_filed['price'];
  1258. $quantity += $vv['quantity'];
  1259. foreach($order_option_list as $option)
  1260. {
  1261. $vv['option_str'][] = $option['value'];
  1262. }
  1263. if( !isset($vv['option_str']) )
  1264. {
  1265. $vv['option_str'] = '';
  1266. }else{
  1267. $vv['option_str'] = implode(',', $vv['option_str']);
  1268. }
  1269. // $vv['price'] = round($vv['price'],2);
  1270. $vv['price'] = sprintf("%.2f",$vv['price']);
  1271. $vv['orign_price'] = sprintf("%.2f",$vv['orign_price']);
  1272. //$vv['total'] = sprintf("%.2f",$vv['total']);
  1273. $vv['total'] = sprintf("%.2f",$vv['old_total']);
  1274. if( $vv['is_refund_state'] == 1 || ($vv['has_refund_money'] > 0 && $vv['has_refund_quantity'] > 0) )
  1275. {
  1276. $vv['is_refund_state'] = 1;
  1277. $where = " order_id = '".$vv['order_id']."' and order_goods_id = '".$vv['order_goods_id']."' and state in (0,2,3) ";
  1278. $refund_info = M('lionfish_comshop_order_refund')->field('ref_id,order_id,ref_money,real_refund_quantity,state')->where( $where )->find();
  1279. if(!empty($refund_info)){
  1280. $vv['refund_info'] = $refund_info;
  1281. }else{
  1282. $refund_info = array();
  1283. $refund_info['order_id'] = $val['order_id'];
  1284. $refund_info['ref_money'] = $vv['has_refund_money'];
  1285. $refund_info['real_refund_quantity'] = $vv['has_refund_quantity'];
  1286. $refund_info['state'] = 3;
  1287. $vv['refund_info'] = $refund_info;
  1288. }
  1289. }
  1290. $goods_list[$kk] = $vv;
  1291. }
  1292. $val['total_commision'] = $total_commision;
  1293. $val['quantity'] = $quantity;
  1294. if( empty($val['store_id']) )
  1295. {
  1296. $val['store_id'] = 1;
  1297. }
  1298. $store_info = array('s_true_name' =>'','s_logo' => '');
  1299. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  1300. $store_info['s_logo'] = D('Home/Front')->get_config_by_name('shoplogo');
  1301. if( !empty($store_info['s_logo']))
  1302. {
  1303. $store_info['s_logo'] = tomedia($store_info['s_logo']);
  1304. }else{
  1305. $store_info['s_logo'] = '';
  1306. }
  1307. $order_goods['store_info'] = $store_info;
  1308. $val['store_info'] = $store_info;
  1309. $val['goods_list'] = $goods_list;
  1310. if($val['type'] == 'integral')
  1311. {
  1312. //暂时屏蔽积分
  1313. $val['score'] = round($val['total'],2);
  1314. }
  1315. $val['total'] = $val['total'] + $val['packing_fare'] + $val['shipping_fare']-$val['voucher_credit']-$val['fullreduction_money']-$val['score_for_money']+$val['localtown_add_shipping_fare']-$val['fare_shipping_free'];
  1316. if($val['total'] < 0)
  1317. {
  1318. $val['total'] = 0;
  1319. }
  1320. $val['total'] = sprintf("%.2f",$val['total']);
  1321. if( $val['delivery'] == 'localtown_delivery' && ($val['order_status_id'] != 3 && $val['order_status_id'] != 5 ) )
  1322. {
  1323. $val['orderdistribution_order'] = M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $val['order_id'] ) )->find();
  1324. if( !empty($val['orderdistribution_order']) && $val['orderdistribution_order'] > 0 )
  1325. {
  1326. $orderdistribution = M('lionfish_comshop_orderdistribution')->where( array('id' => $val['orderdistribution_order']['orderdistribution_id'] ) )->find();
  1327. $val['orderdistribution_order']['username'] = $orderdistribution['username'];
  1328. }
  1329. }
  1330. $list[$key] = $val;
  1331. }
  1332. $need_data = array('code' => 0);
  1333. if( !empty($list) )
  1334. {
  1335. $need_data['data'] = $list;
  1336. }else {
  1337. $need_data = array('code' => 1);
  1338. }
  1339. $open_aftersale = D('Home/Front')->get_config_by_name('open_aftersale');
  1340. if( empty($open_aftersale) )
  1341. {
  1342. $open_aftersale = 0;
  1343. }
  1344. $open_aftersale_time = D('Home/Front')->get_config_by_name('open_aftersale_time');
  1345. if( empty($open_aftersale_time) )
  1346. {
  1347. $open_aftersale_time = 0;
  1348. }
  1349. $need_data['open_aftersale'] = $open_aftersale;
  1350. $need_data['open_aftersale_time'] = $open_aftersale_time;
  1351. echo json_encode( $need_data );
  1352. die();
  1353. }
  1354. function receive_order_list()
  1355. {
  1356. $gpc = I('request.');
  1357. $order_data = $gpc['order_data'];
  1358. $token = $gpc['token'];
  1359. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1360. $member_id = $weprogram_token['member_id'];
  1361. $member_info = M('lionfish_comshop_member')->where( array('member_id' => $member_id) )->find();
  1362. if( empty($member_info) )
  1363. {
  1364. echo json_encode( array('code' => 1) );
  1365. die();
  1366. }
  1367. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1368. $is_member_hexiao = false;
  1369. if( empty($community_info) && $member_info['pickup_id'] > 0 )
  1370. {
  1371. $parent_community_info = M('lionfish_comshop_community_pickup_member')->where( array('member_id' =>$member_id ) )->find();
  1372. if(!empty($parent_community_info))
  1373. {
  1374. $is_member_hexiao = true;
  1375. $community_info = M('lionfish_community_head')->where( array('id' => $parent_community_info['community_id'] ) )->find();
  1376. }
  1377. }
  1378. if( empty($community_info) || $community_info['state'] != 1 )
  1379. {
  1380. echo json_encode( array('code' => 1) );
  1381. die();
  1382. }
  1383. if( is_array($order_data) )
  1384. {
  1385. $order_data_str = implode(',', $order_data);
  1386. }else{
  1387. $order_data_str = $order_data;
  1388. }
  1389. $where = ' and o.head_id = '.$community_info['id'];
  1390. $where .= ' and o.order_status_id = 4 and order_id in ('.$order_data_str.') ';
  1391. $sql = "select o.order_id,o.order_num_alias
  1392. from ".C('DB_PREFIX')."lionfish_comshop_order as o ,
  1393. ".C('DB_PREFIX')."lionfish_comshop_order_status as os
  1394. where o.order_status_id = os.order_status_id {$where}
  1395. order by o.date_added desc ";
  1396. $list = M()->query($sql);
  1397. if( !empty($list) )
  1398. {
  1399. foreach($list as $val)
  1400. {
  1401. D('Home/Frontorder')->receive_order($val['order_id']);
  1402. if($is_member_hexiao)
  1403. {
  1404. $pickup_member_record_data = array();
  1405. $pickup_member_record_data['order_id'] = $val['order_id'];
  1406. $pickup_member_record_data['order_sn'] = $val['order_num_alias'];
  1407. $pickup_member_record_data['community_id'] = $community_info['id'];
  1408. $pickup_member_record_data['member_id'] = $member_id;
  1409. $pickup_member_record_data['addtime'] = time();
  1410. M('lionfish_comshop_community_pickup_member_record')->add( $pickup_member_record_data );
  1411. }
  1412. }
  1413. echo json_encode( array('code' => 0) );
  1414. die();
  1415. }else{
  1416. echo json_encode( array('code' => 1) );
  1417. die();
  1418. }
  1419. //load_model_class('frontorder')->receive_order($order_id);
  1420. //string(15) "35,34,31,19,5,2"
  1421. //string(32) "b55feabc517fa686f79c1bbd303cdeda"
  1422. }
  1423. function receive_order()
  1424. {
  1425. $gpc = I('request.');
  1426. $token = $gpc['token'];
  1427. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1428. $member_id = $weprogram_token['member_id'];
  1429. $order_id = $gpc['order_id'];
  1430. if( empty($member_id) )
  1431. {
  1432. $result['code'] = 2;
  1433. $result['msg'] = '登录失效';
  1434. echo json_encode($result);
  1435. die();
  1436. }
  1437. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id,'member_id' => $member_id) )->find();
  1438. if(empty($order_info)){
  1439. $result['code'] = 1;
  1440. $result['msg'] = '非法操作,会员不存在该订单';
  1441. echo json_encode($result);
  1442. die();
  1443. }
  1444. //检查订单是否能确认收货(存在售后未完成无法确认收货)
  1445. $result = D('Seller/Order')->check_order_receive($order_id);
  1446. if($result['status'] == 0){
  1447. $result['code'] = 1;
  1448. $result['msg'] = '您的订单处于售后处理中,请完成后再确认收货!';
  1449. echo json_encode($result);
  1450. die();
  1451. }
  1452. if($order_info['delivery'] == 'localtown_delivery'){
  1453. $result = D('Seller/Order')->check_localtown_order_receive($order_id);
  1454. if($result['status'] == 0){
  1455. $result['code'] = 1;
  1456. $result['msg'] = '该订单未有配送员接单或还未指定配送员,无法确认收货!';
  1457. echo json_encode($result);
  1458. die();
  1459. }
  1460. M('lionfish_comshop_orderdistribution_order')->where( array('order_id' => $order_id) )->save( array('state' => 4) );
  1461. D('Home/LocaltownDelivery')->write_distribution_log( $order_id, 0 , 4 , "用户确认收货" );
  1462. }
  1463. D('Home/Frontorder')->receive_order($order_id);
  1464. $result['code'] = 0;
  1465. echo json_encode($result);
  1466. die();
  1467. }
  1468. /**
  1469. 取消订单操作
  1470. **/
  1471. public function cancel_order()
  1472. {
  1473. $gpc = I('request.');
  1474. $token = $gpc['token'];
  1475. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1476. $member_id = $weprogram_token['member_id'];
  1477. $order_id = $gpc['order_id'];
  1478. if( empty($member_id) )
  1479. {
  1480. $result['code'] = 2;
  1481. $result['msg'] = '登录失效';
  1482. echo json_encode($result);
  1483. die();
  1484. }
  1485. $order_info = M('lionfish_comshop_order')->where( array('member_id' => $member_id,'order_id' => $order_id) )->find();
  1486. if(empty($order_info)){
  1487. $result['code'] = 1;
  1488. $result['msg'] = '非法操作,会员不存在该订单';
  1489. echo json_encode($result);
  1490. die();
  1491. }
  1492. //order_status_id == 3
  1493. if($order_info['order_status_id'] != 3)
  1494. {
  1495. $result['code'] = 1;
  1496. $result['msg'] = '订单可能已取消,请刷新页面';
  1497. echo json_encode($result);
  1498. die();
  1499. }
  1500. D('Home/Frontorder')->cancel_order($order_id);
  1501. $result['code'] = 0;
  1502. echo json_encode($result);
  1503. die();
  1504. }
  1505. public function order_head_info()
  1506. {
  1507. $_GPC = I('request.');
  1508. $token = $_GPC['token'];
  1509. $is_share = $_GPC['is_share'];
  1510. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1511. $member_id = $weprogram_token['member_id'];
  1512. $order_id = $_GPC['id'];
  1513. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  1514. if($order_info['is_change_price'] == 1){
  1515. $order_info['admin_change_price'] = $order_info['total'] - $order_info['old_price'];
  1516. }
  1517. $pick_up_info = array();
  1518. $pick_order_info = array();
  1519. $community_info = D('Home/Front')->get_member_community_info($member_id);
  1520. if($is_share){
  1521. $userInfo = M('lionfish_comshop_member')->field('avatar')->where( array('member_id' => $order_info['member_id'] ) )->find();
  1522. $order_info['avatar'] = $userInfo['avatar'];
  1523. }
  1524. if( $order_info['delivery'] == 'pickup' )
  1525. {
  1526. //查询自提点
  1527. //$pick_order_info = M('lionfish_comshop_pick_order')->where( array('order_id' => $order_id) )->find();
  1528. //$pick_id = $pick_order_info['pick_id'];
  1529. //$pick_up_info = M('lionfish_comshop_pick_up')->where( array('id' => $pick_id ) )->find();
  1530. }
  1531. $order_status_info = M('lionfish_comshop_order_status')->where( array('order_status_id' => $order_info['order_status_id']) )->find();
  1532. //10 name
  1533. if($order_info['order_status_id'] == 10)
  1534. {
  1535. $order_status_info['name'] = '等待退款';
  1536. }
  1537. else if($order_info['order_status_id'] == 4 && $order_info['delivery'] =='pickup')
  1538. {
  1539. //delivery 6
  1540. $order_status_info['name'] = '待自提';
  1541. //已自提
  1542. }
  1543. else if($order_info['order_status_id'] == 6 && $order_info['delivery'] =='pickup')
  1544. {
  1545. //delivery 6
  1546. $order_status_info['name'] = '已自提';
  1547. }
  1548. else if($order_info['order_status_id'] == 1 && $order_info['type'] == 'lottery')
  1549. {
  1550. //等待开奖
  1551. //一等奖
  1552. if($order_info['lottery_win'] == 1)
  1553. {
  1554. $order_status_info['name'] = '一等奖';
  1555. }else {
  1556. $order_status_info['name'] = '等待开奖';
  1557. }
  1558. }
  1559. //$order_info['type']
  1560. //open_auto_delete
  1561. if($order_info['order_status_id'] == 3)
  1562. {
  1563. $open_auto_delete = D('Home/Front')->get_config_by_name('open_auto_delete');
  1564. $auto_cancle_order_time = D('Home/Front')->get_config_by_name('auto_cancle_order_time');
  1565. $order_info['open_auto_delete'] = $open_auto_delete;
  1566. //date_added
  1567. if($open_auto_delete == 1)
  1568. {
  1569. $order_info['over_buy_time'] = $order_info['date_added'] + 3600 * $auto_cancle_order_time;
  1570. $order_info['cur_time'] = time();
  1571. }
  1572. }
  1573. $shipping_province = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_province_id'] ) )->find();
  1574. $shipping_city = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_city_id'] ) )->find();
  1575. $shipping_country = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_country_id']) )->find();
  1576. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->select();
  1577. $shiji_total_money = 0;
  1578. $member_youhui = 0.00;
  1579. $pick_up_time = "";
  1580. $pick_up_type = -1;
  1581. $pick_up_weekday = '';
  1582. $today_time = $order_info['pay_time'];
  1583. $arr = array('天','一','二','三','四','五','六');
  1584. foreach($order_goods_list as $key => $order_goods)
  1585. {
  1586. $order_goods['name'] = htmlspecialchars_decode($order_goods['name']);
  1587. $order_option_info = M('lionfish_comshop_order_option')->field('value')->where( array('order_goods_id' => $order_goods['order_goods_id'],'order_id' => $order_id) )->select();
  1588. foreach($order_option_info as $option)
  1589. {
  1590. $order_goods['option_str'][] = $option['value'];
  1591. }
  1592. if(empty($order_goods['option_str']))
  1593. {
  1594. //option_str
  1595. $order_goods['option_str'] = '';
  1596. }else{
  1597. $order_goods['option_str'] = implode(',', $order_goods['option_str']);
  1598. }
  1599. //
  1600. $order_goods['shipping_fare'] = round($order_goods['shipping_fare'],2);
  1601. //$order_goods['price'] = round($order_goods['price'],2);
  1602. $order_goods['price'] = round($order_goods['price'],2);
  1603. $order_goods['total'] = round($order_goods['total'],2);
  1604. $order_goods['old_total'] = round($order_goods['old_total'],2);
  1605. if( $order_goods['is_vipcard_buy'] == 1 || $order_goods['is_level_buy'] ==1 )
  1606. {
  1607. $order_goods['price'] = round($order_goods['oldprice'],2);
  1608. }
  1609. $order_goods['real_total'] = round($order_goods['quantity'] * $order_goods['price'],2);
  1610. $community_order_info = M('lionfish_community_head_commiss_order')->where( array('head_id' => $community_info['id'],'order_goods_id' => $order_goods['order_goods_id']) )->find();
  1611. if(!empty($community_order_info))
  1612. {
  1613. $order_goods['commision'] = $community_order_info['money']-$community_order_info['add_shipping_fare'];
  1614. if($community_order_info['state'] == 2){
  1615. $order_goods['commision'] = 0;
  1616. }
  1617. }else{
  1618. $order_goods['commision'] = 0;
  1619. }
  1620. $order_goods['old_commision'] = $order_goods['commision'];
  1621. $order_goods['del_commision'] = 0;
  1622. $order_goods['statements_end_date'] = date('Y-m-d H:i:s', $order_goods['statements_end_time']);
  1623. //has_refund_commission = 0
  1624. $order_goods_refund_list = M('lionfish_comshop_order_goods_refund')->where( "order_id={$order_id} and order_goods_id=".$order_goods['order_goods_id'] )->select();
  1625. $refund_shipping_fare = 0;//退配送费
  1626. if( !empty($order_goods_refund_list) )
  1627. {
  1628. $kvbal_total_back_head_orderbuycommiss = 0;//合计退掉佣金
  1629. foreach( $order_goods_refund_list as $kvval )
  1630. {
  1631. $kvbal_total_back_head_orderbuycommiss += $kvval['back_head_orderbuycommiss'];
  1632. $refund_shipping_fare += $kvval['refund_shipping_fare'];
  1633. }
  1634. $order_goods['del_commision'] = $kvbal_total_back_head_orderbuycommiss;
  1635. $order_goods['old_commision'] += $order_goods['del_commision'];
  1636. }
  1637. //fen_type
  1638. $order_goods['fen_type'] = $community_order_info['fen_type'];// 0 按照比例, 1按照金额
  1639. $order_goods['fen_bili'] = $community_order_info['bili'];//比例
  1640. $order_goods['fen_gumoney'] = $community_order_info['bili'];//按照金额
  1641. $order_jishu = $order_goods['total'] -$order_goods['fullreduction_money']-$order_goods['voucher_credit']-$order_goods['has_refund_money'];
  1642. $order_goods['order_jishu'] = $order_jishu;//有效金额:(基数)
  1643. $order_goods['head_shipping_fare'] = $community_order_info['add_shipping_fare'];//团长配送费
  1644. /**
  1645. $goods_images = file_image_thumb_resize($vv['goods_images'],400);
  1646. if(is_array($goods_images))
  1647. {
  1648. $vv['goods_images'] = $vv['goods_images'];
  1649. }else{
  1650. $vv['goods_images']= tomedia( file_image_thumb_resize($vv['goods_images'],400) );
  1651. }
  1652. **/
  1653. $goods_images = $order_goods['goods_images'];
  1654. if( !is_array($goods_images) )
  1655. {
  1656. $order_goods['image']= tomedia( $goods_images );
  1657. $order_goods['goods_images']= tomedia( $goods_images );
  1658. }else{
  1659. $order_goods['image']= $order_goods['goods_images'];
  1660. }
  1661. $order_goods['hascomment'] = 0;
  1662. $order_goods_comment_info = M('lionfish_comshop_order_comment')->field('comment_id')->where( array('goods_id' => $order_goods['goods_id'],'order_id' => $order_id) )->find();
  1663. if( !empty($order_goods_comment_info) )
  1664. {
  1665. $order_goods['hascomment'] = 1;
  1666. }
  1667. //ims_
  1668. $goods_info = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $order_goods['goods_id']) )->find();
  1669. $goods_cm_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify')->where( array('goods_id' => $order_goods['goods_id']) )->find();
  1670. if($pick_up_type == -1 || $goods_cm_info['pick_up_type'] > $pick_up_type)
  1671. {
  1672. $pick_up_type = $goods_cm_info['pick_up_type'];
  1673. if($pick_up_type == 0)
  1674. {
  1675. $pick_up_time = date('m-d', $today_time);
  1676. //$pick_up_weekday = '周'.$arr[date('w',$today_time)];
  1677. }else if( $pick_up_type == 1 ){
  1678. $pick_up_time = date('m-d', $today_time+86400);
  1679. //$pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  1680. }else if( $pick_up_type == 2 )
  1681. {
  1682. $pick_up_time = date('m-d', $today_time+86400*2);
  1683. //$pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  1684. }else if($pick_up_type == 3)
  1685. {
  1686. $pick_up_time = $goods_cm_info['pick_up_modify'];
  1687. }
  1688. }
  1689. $order_goods['shop_price'] = $goods_info['price'];
  1690. $store_info = array('s_true_name' =>'','s_logo' => '');
  1691. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  1692. if( !empty($store_info['s_logo']) )
  1693. {
  1694. $store_info['s_logo'] = tomedia($store_info['s_logo']);
  1695. }else{
  1696. $store_info['s_logo'] = '';
  1697. }
  1698. if( $order_goods['is_refund_state'] == 1 || ($order_goods['has_refund_money'] > 0 && $order_goods['has_refund_quantity'] > 0) )
  1699. {
  1700. $order_goods['is_refund_state'] = 1;
  1701. $where = " order_id = '".$order_goods['order_id']."' and order_goods_id = '".$order_goods['order_goods_id']."' and state in (0,2,3) ";
  1702. $refund_info = M('lionfish_comshop_order_refund')->field('ref_id,order_id,ref_money,real_refund_quantity,state')->where( $where )->find();
  1703. if(!empty($refund_info)){
  1704. $order_goods['refund_info'] = $refund_info;
  1705. }else{
  1706. $refund_info = array();
  1707. $refund_info['order_id'] = $order_goods['order_id'];
  1708. $refund_info['ref_money'] = $order_goods['has_refund_money'];
  1709. $refund_info['real_refund_quantity'] = $order_goods['has_refund_quantity'];
  1710. $refund_info['state'] = 3;
  1711. $order_goods['refund_info'] = $refund_info;
  1712. }
  1713. }
  1714. $order_goods['store_info'] = $store_info;
  1715. unset($order_goods['model']);
  1716. unset($order_goods['rela_goodsoption_valueid']);
  1717. unset($order_goods['comment']);
  1718. $order_goods_list[$key] = $order_goods;
  1719. $shiji_total_money += $order_goods['quantity'] * $order_goods['price'];
  1720. $member_youhui += ($order_goods['real_total'] - $order_goods['total']);
  1721. }
  1722. unset($order_info['store_id']);
  1723. unset($order_info['email']);
  1724. unset($order_info['shipping_city_id']);
  1725. unset($order_info['shipping_country_id']);
  1726. unset($order_info['shipping_province_id']);
  1727. //unset($order_info['comment']);
  1728. unset($order_info['voucher_id']);
  1729. unset($order_info['is_balance']);
  1730. unset($order_info['lottery_win']);
  1731. unset($order_info['ip']);
  1732. unset($order_info['ip_region']);
  1733. unset($order_info['user_agent']);
  1734. $order_info['shipping_fare'] = round($order_info['shipping_fare'],2) < 0.01 ? '0.00':round($order_info['shipping_fare'],2) ;
  1735. $order_info['voucher_credit'] = round($order_info['voucher_credit'],2) < 0.01 ? '0.00':round($order_info['voucher_credit'],2) ;
  1736. $order_info['fullreduction_money'] = round($order_info['fullreduction_money'],2) < 0.01 ? '0.00':round($order_info['fullreduction_money'],2) ;
  1737. $order_info['total'] = round($order_info['total'],2)< 0.01 ? '0.00':round($order_info['total']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money']+$order_info['localtown_add_shipping_fare']+$order_info['packing_fare'],2)-$order_info['fare_shipping_free'] ;
  1738. if($order_info['total'] < 0)
  1739. {
  1740. $order_info['total'] = '0.00';
  1741. }
  1742. $order_info['total'] = round($order_info['total'],2)< 0.01 ? '0.00':round($order_info['total'],2) ;
  1743. $order_info['real_total'] = round($shiji_total_money,2)+$order_info['shipping_fare'];
  1744. $order_info['price'] = round($order_info['price'],2);
  1745. $order_info['member_youhui'] = round($member_youhui,2) < 0.01 ? '0.00':round($member_youhui,2);
  1746. $order_info['pick_up_time'] = $pick_up_time;
  1747. $order_info['shipping_fare'] = sprintf("%.2f",$order_info['shipping_fare']);
  1748. $order_info['voucher_credit'] = sprintf("%.2f",$order_info['voucher_credit']);
  1749. $order_info['fullreduction_money'] = sprintf("%.2f",$order_info['fullreduction_money']);
  1750. $order_info['total'] = sprintf("%.2f",$order_info['total']);
  1751. $order_info['real_total'] = sprintf("%.2f",$order_info['real_total']);
  1752. $order_note_open = D('Home/Front')->get_config_by_name('order_note_open');
  1753. $order_note_name = D('Home/Front')->get_config_by_name('order_note_name');
  1754. if( !isset($order_note_open) || $order_note_open == 0)
  1755. {
  1756. $order_note_open = 0;
  1757. }
  1758. if( !isset($order_note_name) || empty($order_note_name) )
  1759. {
  1760. $order_note_name = '店名';
  1761. }
  1762. $order_info['order_note_open'] = $order_note_open;
  1763. $order_info['order_note_name'] = $order_note_name;
  1764. $order_info['note_content'] = $order_info['note_content']!='null' ? $order_info['note_content'] : '';
  1765. $order_info['date_added'] = date('Y-m-d H:i:s', $order_info['date_added']);
  1766. $need_data = array();
  1767. if($order_info['delivery'] =='pickup')
  1768. {
  1769. }else{
  1770. }
  1771. if($order_info['type'] == 'integral')
  1772. {
  1773. //暂时屏蔽积分商城
  1774. //$integral_order = M('integral_order')->field('score')->where( array('order_id' => $order_id) )->find();
  1775. //$need_data['score'] = intval($integral_order['score']);
  1776. }
  1777. if( !empty($order_info['pay_time']) && $order_info['pay_time'] >0 )
  1778. {
  1779. $order_info['pay_date'] = date('Y-m-d H:i:s', $order_info['pay_time']);
  1780. }else{
  1781. $order_info['pay_date'] = '';
  1782. }
  1783. $order_info['express_tuanz_date'] = empty($order_info['express_tuanz_time']) ? '' : date('Y-m-d H:i:s', $order_info['express_tuanz_time']);
  1784. $order_info['receive_date'] = date('Y-m-d H:i:s', $order_info['receive_time']);
  1785. if($is_share==1){ $order_info['shipping_tel'] = substr_replace($order_info['shipping_tel'],'****',3,4); }
  1786. //货到付款订单
  1787. if($order_info['payment_code'] == 'cashon_delivery'){
  1788. $order_info['cashondelivery_code_img'] = D('Home/Front')->getCashonDeliveryCode();
  1789. }
  1790. $need_data['order_info'] = $order_info;
  1791. $need_data['order_status_info'] = $order_status_info;
  1792. $need_data['shipping_province'] = $shipping_province;
  1793. $need_data['shipping_city'] = $shipping_city;
  1794. $need_data['shipping_country'] = $shipping_country;
  1795. $need_data['order_goods_list'] = $order_goods_list;
  1796. $need_data['goods_count'] = count($order_goods_list);
  1797. //$order_info['order_status_id'] 13 平台介入退款
  1798. $order_refund_historylist = array();
  1799. $pingtai_deal = 0;
  1800. //判断是否已经平台处理完毕
  1801. $order_refund_historylist = M('lionfish_comshop_order_refund_history')->where( array('order_id' => $order_id) )->order('addtime asc')->select();
  1802. foreach($order_refund_historylist as $key => $val)
  1803. {
  1804. if($val['type'] ==3)
  1805. {
  1806. $pingtai_deal = 1;
  1807. }
  1808. }
  1809. $order_refund = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id) )->find();
  1810. if(!empty($order_refund))
  1811. {
  1812. $order_refund['addtime'] = date('Y-m-d H:i:s', $order_refund['addtime']);
  1813. }
  1814. $need_data['pick_up'] = $pick_up_info;
  1815. if( empty($pick_order_info['qrcode']) && false)
  1816. {
  1817. }
  1818. $need_data['pick_order_info'] = $pick_order_info;
  1819. $open_aftersale = D('Home/Front')->get_config_by_name('open_aftersale');
  1820. if( empty($open_aftersale) )
  1821. {
  1822. $open_aftersale = 0;
  1823. }
  1824. $open_aftersale_time = D('Home/Front')->get_config_by_name('open_aftersale_time');
  1825. if( empty($open_aftersale_time) )
  1826. {
  1827. $open_aftersale_time = 0;
  1828. }
  1829. echo json_encode( array('code' => 0,'data' => $need_data,'pingtai_deal' => $pingtai_deal,'order_refund' => $order_refund, 'open_aftersale' => $open_aftersale, 'open_aftersale_time' => $open_aftersale_time ) );
  1830. die();
  1831. }
  1832. public function order_share_info(){
  1833. $_GPC = I('request.');
  1834. $is_share = $_GPC['is_share'];
  1835. $token = $_GPC['token'];
  1836. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  1837. $member_id = $weprogram_token['member_id'];
  1838. $order_id = $_GPC['id'];
  1839. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id ) )->find();
  1840. if($is_share){
  1841. $userInfo = M('lionfish_comshop_member')->field('avatar')->where( array('member_id' => $order_info['member_id'] ) )->find();
  1842. $order_info['avatar'] = $userInfo['avatar'];
  1843. }
  1844. $pick_up_info = array();
  1845. $pick_order_info = array();
  1846. if( $order_info['delivery'] == 'pickup' )
  1847. {
  1848. //查询自提点
  1849. // $pick_order_info = M('lionfish_comshop_pick_order')->where( array('order_id' => $order_id ) )->find();
  1850. // $pick_id = $pick_order_info['pick_id'];
  1851. // $pick_up_info = M('lionfish_comshop_pick_up')->where( array('id' => $pick_id ) )->find();
  1852. }
  1853. $order_status_info = M('lionfish_comshop_order_status')->where( array('order_status_id' => $order_info['order_status_id'] ) )->find();
  1854. //10 name
  1855. if($order_info['order_status_id'] == 10)
  1856. {
  1857. $order_status_info['name'] = '等待退款';
  1858. }
  1859. else if($order_info['order_status_id'] == 4 && $order_info['delivery'] =='pickup')
  1860. {
  1861. //delivery 6
  1862. $order_status_info['name'] = '待自提';
  1863. //已自提
  1864. }
  1865. else if($order_info['order_status_id'] == 6 && $order_info['delivery'] =='pickup')
  1866. {
  1867. //delivery 6
  1868. $order_status_info['name'] = '已自提';
  1869. }
  1870. else if($order_info['order_status_id'] == 1 && $order_info['type'] == 'lottery')
  1871. {
  1872. //等待开奖
  1873. //一等奖
  1874. if($order_info['lottery_win'] == 1)
  1875. {
  1876. $order_status_info['name'] = '一等奖';
  1877. }else {
  1878. $order_status_info['name'] = '等待开奖';
  1879. }
  1880. }
  1881. //$order_info['type']
  1882. //open_auto_delete
  1883. if($order_info['order_status_id'] == 3)
  1884. {
  1885. $open_auto_delete = D('Home/Front')->get_config_by_name('open_auto_delete');
  1886. $auto_cancle_order_time = D('Home/Front')->get_config_by_name('auto_cancle_order_time');
  1887. $order_info['open_auto_delete'] = $open_auto_delete;
  1888. //date_added
  1889. if($open_auto_delete == 1)
  1890. {
  1891. $order_info['over_buy_time'] = $order_info['date_added'] + 3600 * $auto_cancle_order_time;
  1892. $order_info['cur_time'] = time();
  1893. }
  1894. }
  1895. $shipping_province = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_province_id'] ) )->find();
  1896. $shipping_city = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_city_id'] ) )->find();
  1897. $shipping_country = M('lionfish_comshop_area')->where( array('id' => $order_info['shipping_country_id'] ) )->find();
  1898. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->select();
  1899. $shiji_total_money = 0;
  1900. $member_youhui = 0.00;
  1901. $pick_up_time = "";
  1902. $pick_up_type = -1;
  1903. $pick_up_weekday = '';
  1904. $today_time = $order_info['pay_time'];
  1905. $arr = array('天','一','二','三','四','五','六');
  1906. foreach($order_goods_list as $key => $order_goods)
  1907. {
  1908. $order_goods['name'] = htmlspecialchars_decode($order_goods['name']);
  1909. $order_refund_goods = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id, 'order_goods_id' => $order_goods['order_goods_id'] ) )->order('ref_id desc')->find();
  1910. if(!empty($order_refund_goods))
  1911. {
  1912. $order_refund_goods['addtime'] = date('Y-m-d H:i:s', $order_refund_goods['addtime']);
  1913. }
  1914. $order_option_info = M('lionfish_comshop_order_option')->field('value')->where( array('order_id' => $order_id ,'order_goods_id' => $order_goods['order_goods_id'] ) )->select();
  1915. $order_goods['order_refund_goods'] = $order_refund_goods;
  1916. foreach($order_option_info as $option)
  1917. {
  1918. $order_goods['option_str'][] = $option['value'];
  1919. }
  1920. if(empty($order_goods['option_str']))
  1921. {
  1922. //option_str
  1923. $order_goods['option_str'] = '';
  1924. }else{
  1925. $order_goods['option_str'] = implode(',', $order_goods['option_str']);
  1926. }
  1927. //
  1928. $order_goods['shipping_fare'] = round($order_goods['shipping_fare'],2);
  1929. $order_goods['price'] = round($order_goods['price'],2);
  1930. $order_goods['total'] = round($order_goods['total'],2);
  1931. if( $order_goods['is_vipcard_buy'] == 1 || $order_goods['is_level_buy'] ==1 )
  1932. {
  1933. $order_goods['price'] = round($order_goods['oldprice'],2);
  1934. }
  1935. $order_goods['real_total'] = round($order_goods['quantity'] * $order_goods['price'],2);
  1936. /**
  1937. $goods_images = file_image_thumb_resize($vv['goods_images'],400);
  1938. if(is_array($goods_images))
  1939. {
  1940. $vv['goods_images'] = $vv['goods_images'];
  1941. }else{
  1942. $vv['goods_images']= tomedia( file_image_thumb_resize($vv['goods_images'],400) );
  1943. }
  1944. **/
  1945. $goods_images = $order_goods['goods_images'];
  1946. if( !is_array($goods_images) )
  1947. {
  1948. $order_goods['image']= tomedia( $goods_images );
  1949. $order_goods['goods_images']= tomedia( $goods_images );
  1950. }else{
  1951. $order_goods['image']= $order_goods['goods_images'];
  1952. }
  1953. $order_goods['hascomment'] = 0;
  1954. $order_goods_comment_info = M('lionfish_comshop_order_comment')->field('comment_id')->where( array('order_id' => $order_id, 'goods_id' => $order_goods['goods_id'] ) )->find();
  1955. if( !empty($order_goods_comment_info) )
  1956. {
  1957. $order_goods['hascomment'] = 1;
  1958. }
  1959. $order_goods['can_ti_refund'] = 1;
  1960. $disable_info = M('lionfish_comshop_order_refund_disable')->where( array('order_id' => $order_id, 'order_goods_id' => $order_goods['order_goods_id'] ) )->find();
  1961. if( !empty($disable_info) )
  1962. {
  1963. $order_goods['can_ti_refund'] = 0;
  1964. }
  1965. if($order_goods['is_refund_state'] == 1)
  1966. {
  1967. //已经再申请退款中了。或者已经退款了。
  1968. $order_refund_info = M('lionfish_comshop_order_refund')->field('state')->where( array('order_id' =>$order_id,'order_goods_id' => $order_goods['order_goods_id'] ) )->find();
  1969. if( $order_refund_info['state'] == 3 )
  1970. {
  1971. $order_goods['is_refund_state'] = 2;
  1972. }
  1973. }
  1974. //ims_
  1975. $goods_info = M('lionfish_comshop_goods')->field('productprice as price')->where( array('id' => $order_goods['goods_id'] ) )->find();
  1976. $goods_cm_info = M('lionfish_comshop_good_common')->field('pick_up_type,pick_up_modify,goods_share_image')->where( array('goods_id' => $order_goods['goods_id'] ) )->find();
  1977. if($pick_up_type == -1 || $goods_cm_info['pick_up_type'] > $pick_up_type)
  1978. {
  1979. $pick_up_type = $goods_cm_info['pick_up_type'];
  1980. if($pick_up_type == 0)
  1981. {
  1982. $pick_up_time = date('m-d', $today_time);
  1983. //$pick_up_weekday = '周'.$arr[date('w',$today_time)];
  1984. }else if( $pick_up_type == 1 ){
  1985. $pick_up_time = date('m-d', $today_time+86400);
  1986. //$pick_up_weekday = '周'.$arr[date('w',$today_time+86400)];
  1987. }else if( $pick_up_type == 2 )
  1988. {
  1989. $pick_up_time = date('m-d', $today_time+86400*2);
  1990. //$pick_up_weekday = '周'.$arr[date('w',$today_time+86400*2)];
  1991. }else if($pick_up_type == 3)
  1992. {
  1993. $pick_up_time = $goods_cm_info['pick_up_modify'];
  1994. }
  1995. }
  1996. if( !empty($goods_cm_info['goods_share_image']) )
  1997. {
  1998. $order_goods['goods_share_image']= tomedia( $goods_cm_info['goods_share_image'] );
  1999. }else{
  2000. $order_goods['goods_share_image'] = $order_goods['image'];
  2001. }
  2002. $order_goods['shop_price'] = $goods_info['price'];
  2003. $store_info = array('s_true_name' =>'','s_logo' => '');
  2004. $store_info['s_true_name'] = D('Home/Front')->get_config_by_name('shoname');
  2005. //$store_info['s_logo'] = load_model_class('front')->get_config_by_name('shoplogo');
  2006. if( !empty($store_info['s_logo']) )
  2007. {
  2008. $store_info['s_logo'] = tomedia($store_info['s_logo']);
  2009. }else{
  2010. $store_info['s_logo'] = '';
  2011. }
  2012. $order_goods['store_info'] = $store_info;
  2013. unset($order_goods['model']);
  2014. unset($order_goods['rela_goodsoption_valueid']);
  2015. unset($order_goods['comment']);
  2016. //ims_ ims_lionfish_comshop_order_goods_refund addtime
  2017. $order_goods_refund_list = M('lionfish_comshop_order_goods_refund')->field('real_refund_quantity,money,addtime')->where( array('order_goods_id' =>$order_goods['order_goods_id'] ) )->order('id asc')->select();
  2018. if( empty($order_goods_refund_list) )
  2019. {
  2020. $order_goods_refund_list = array();
  2021. }else{
  2022. foreach( $order_goods_refund_list as $kre => $rval )
  2023. {
  2024. $rval['addtime'] = date('Y-m-d H:i:s', $rval['addtime']);
  2025. $order_goods_refund_list[$kre] = $rval;
  2026. }
  2027. }
  2028. $order_goods['order_goods_refund_list'] = $order_goods_refund_list;
  2029. $order_goods_list[$key] = $order_goods;
  2030. $shiji_total_money += $order_goods['quantity'] * $order_goods['price'];
  2031. $member_youhui += ($order_goods['real_total'] - $order_goods['total']);
  2032. }
  2033. unset($order_info['store_id']);
  2034. unset($order_info['email']);
  2035. unset($order_info['shipping_city_id']);
  2036. unset($order_info['shipping_country_id']);
  2037. unset($order_info['shipping_province_id']);
  2038. // unset($order_info['comment']);
  2039. unset($order_info['voucher_id']);
  2040. unset($order_info['is_balance']);
  2041. unset($order_info['lottery_win']);
  2042. unset($order_info['ip']);
  2043. unset($order_info['ip_region']);
  2044. unset($order_info['user_agent']);
  2045. //enum('express', 'pickup', 'tuanz_send')
  2046. //var_dump($order_info['total'],$order_info['shipping_fare'],$order['voucher_credit'],$order['fullreduction_money'] );die();
  2047. $order_info['shipping_fare'] = round($order_info['shipping_fare'],2) < 0.01 ? '0.00':round($order_info['shipping_fare'],2) ;
  2048. $order_info['voucher_credit'] = round($order_info['voucher_credit'],2) < 0.01 ? '0.00':round($order_info['voucher_credit'],2) ;
  2049. $order_info['fullreduction_money'] = round($order_info['fullreduction_money'],2) < 0.01 ? '0.00':round($order_info['fullreduction_money'],2) ;
  2050. $need_data = array();
  2051. if($order_info['type'] == 'integral')
  2052. {
  2053. //暂时屏蔽积分商城
  2054. $order_info['score'] = round($order_info['total'],2);
  2055. }
  2056. $order_info['total'] = round($order_info['total']+$order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money'] - $order_info['score_for_money'],2) ;
  2057. if($order_info['total'] < 0)
  2058. {
  2059. $order_info['total'] = '0.00';
  2060. }
  2061. $order_info['real_total'] = round($shiji_total_money,2)+$order_info['shipping_fare'];
  2062. $order_info['price'] = round($order_info['price'],2);
  2063. $order_info['member_youhui'] = round($member_youhui,2) < 0.01 ? '0.00':round($member_youhui,2);
  2064. $order_info['pick_up_time'] = $pick_up_time;
  2065. $order_info['shipping_fare'] = sprintf("%.2f",$order_info['shipping_fare']);
  2066. $order_info['voucher_credit'] = sprintf("%.2f",$order_info['voucher_credit']);
  2067. $order_info['fullreduction_money'] = sprintf("%.2f",$order_info['fullreduction_money']);
  2068. $order_info['total'] = sprintf("%.2f",$order_info['total']);
  2069. $order_info['real_total'] = sprintf("%.2f",$order_info['real_total']);
  2070. $order_info['date_added'] = date('Y-m-d H:i:s', $order_info['date_added']);
  2071. // if($order_info['delivery'] =='pickup')
  2072. // {}else{}
  2073. if( !empty($order_info['pay_time']) && $order_info['pay_time'] >0 )
  2074. {
  2075. $order_info['pay_date'] = date('Y-m-d H:i:s', $order_info['pay_time']);
  2076. }else{
  2077. $order_info['pay_date'] = '';
  2078. }
  2079. $order_info['express_tuanz_date'] = date('Y-m-d H:i:s', $order_info['express_tuanz_time']);
  2080. $order_info['receive_date'] = date('Y-m-d H:i:s', $order_info['receive_time']);
  2081. //"delivery": "pickup", enum('express', 'pickup', 'tuanz_send')
  2082. if($order_info['delivery'] == 'express')
  2083. {
  2084. $order_info['delivery_name'] = '快递';
  2085. }else if($order_info['delivery'] == 'pickup')
  2086. {
  2087. $order_info['delivery_name'] = '用户自提';
  2088. }else if($order_info['delivery'] == 'tuanz_send'){
  2089. $order_info['delivery_name'] = '团长配送';
  2090. }
  2091. $need_data['order_info'] = $order_info;
  2092. $need_data['order_status_info'] = $order_status_info;
  2093. $need_data['shipping_province'] = $shipping_province;
  2094. $need_data['shipping_city'] = $shipping_city;
  2095. $need_data['shipping_country'] = $shipping_country;
  2096. $need_data['order_goods_list'] = $order_goods_list;
  2097. $need_data['goods_count'] = count($order_goods_list);
  2098. //$order_info['order_status_id'] 13 平台介入退款
  2099. $order_refund_historylist = array();
  2100. $pingtai_deal = 0;
  2101. //判断是否已经平台处理完毕
  2102. $order_refund_historylist = M('lionfish_comshop_order_refund_history')->where( array('order_id' => $order_id ) )->order('addtime asc')->select();
  2103. foreach($order_refund_historylist as $key => $val)
  2104. {
  2105. if($val['type'] ==3)
  2106. {
  2107. $pingtai_deal = 1;
  2108. }
  2109. }
  2110. $order_refund = M('lionfish_comshop_order_refund')->where( array('order_id' => $order_id ) )->find();
  2111. if(!empty($order_refund))
  2112. {
  2113. $order_refund['addtime'] = date('Y-m-d H:i:s', $order_refund['addtime']);
  2114. }
  2115. $need_data['pick_up'] = $pick_up_info;
  2116. $need_data['pick_order_info'] = $pick_order_info;
  2117. $order_pay_after_share = D('Home/Front')->get_config_by_name('order_pay_after_share');
  2118. if($order_pay_after_share==1){
  2119. $order_pay_after_share_img = D('Home/Front')->get_config_by_name('order_pay_after_share_img');
  2120. $order_pay_after_share_img = $order_pay_after_share_img ? tomedia($order_pay_after_share_img) : '';
  2121. $need_data['share_img'] = $order_pay_after_share_img;
  2122. }
  2123. //$order_info['order_status_id']
  2124. //0开启,1关闭 取消订单
  2125. $order_can_del_cancle = D('Home/Front')->get_config_by_name('order_can_del_cancle');
  2126. $order_can_del_cancle = empty($order_can_del_cancle) || $order_can_del_cancle == 0 ? 1 : 0;
  2127. $is_hidden_orderlist_phone = D('Home/Front')->get_config_by_name('is_hidden_orderlist_phone');
  2128. $is_show_guess_like = D('Home/Front')->get_config_by_name('is_show_order_guess_like');
  2129. $user_service_switch = D('Home/Front')->get_config_by_name('user_service_switch');
  2130. echo json_encode(
  2131. array(
  2132. 'code' => 0,
  2133. 'data' => $need_data,
  2134. 'pingtai_deal' => $pingtai_deal,
  2135. 'order_refund' => $order_refund,
  2136. 'order_can_del_cancle' => $order_can_del_cancle,
  2137. 'order_pay_after_share' => $order_pay_after_share,
  2138. 'is_hidden_orderlist_phone' => $is_hidden_orderlist_phone,
  2139. 'is_show_guess_like' => $is_show_guess_like,
  2140. 'user_service_switch' => $user_service_switch
  2141. )
  2142. );
  2143. die();
  2144. }
  2145. /**
  2146. * 订单确认付款
  2147. */
  2148. public function order_pay(){
  2149. $gpc = I('request.');
  2150. $token = $gpc['token'];
  2151. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2152. $member_id = $weprogram_token['member_id'];
  2153. $order_id = $gpc['order_id'];
  2154. $is_supply = $gpc['is_supply'];
  2155. if( empty($member_id) )
  2156. {
  2157. $result['code'] = 2;
  2158. $result['msg'] = '登录失效';
  2159. echo json_encode($result);
  2160. die();
  2161. }
  2162. $supply_info = array();
  2163. $order_info = array();
  2164. if($is_supply == 1){
  2165. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  2166. if(empty($supply_info)){
  2167. $result['code'] = 1;
  2168. $result['msg'] = '您不是供应商,无法操作';
  2169. echo json_encode($result);
  2170. die();
  2171. }
  2172. $order_info = M('lionfish_comshop_order')->where( array('store_id' => $supply_info['id'],'order_id' => $order_id) )->find();
  2173. }
  2174. if(empty($order_info)){
  2175. $result['code'] = 1;
  2176. $result['msg'] = '非法操作,供应商不存在该订单';
  2177. echo json_encode($result);
  2178. die();
  2179. }
  2180. //order_status_id == 3
  2181. if($order_info['order_status_id'] != 3)
  2182. {
  2183. $result['code'] = 1;
  2184. $result['msg'] = '订单不是未付款订单,无法确认付款';
  2185. echo json_encode($result);
  2186. die();
  2187. }
  2188. D('Seller/Order')->admin_pay_order($order_id,1);
  2189. $result['code'] = 0;
  2190. echo json_encode($result);
  2191. die();
  2192. }
  2193. /**
  2194. * 订单改价页面
  2195. */
  2196. public function order_change(){
  2197. $gpc = I('request.');
  2198. $token = $gpc['token'];
  2199. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2200. $member_id = $weprogram_token['member_id'];
  2201. $order_id = $gpc['order_id'];
  2202. $is_supply = $gpc['is_supply'];
  2203. if( empty($member_id) )
  2204. {
  2205. $result['code'] = 2;
  2206. $result['msg'] = '登录失效';
  2207. echo json_encode($result);
  2208. die();
  2209. }
  2210. $supply_info = array();
  2211. $order_info = array();
  2212. if($is_supply == 1){
  2213. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  2214. if(empty($supply_info)){
  2215. $result['code'] = 1;
  2216. $result['msg'] = '您不是供应商,无法操作';
  2217. echo json_encode($result);
  2218. die();
  2219. }
  2220. $order_info = M('lionfish_comshop_order')->where( array('store_id' => $supply_info['id'],'order_id' => $order_id) )->find();
  2221. }
  2222. if(empty($order_info)){
  2223. $result['code'] = 1;
  2224. $result['msg'] = '非法操作,供应商不存在该订单';
  2225. echo json_encode($result);
  2226. die();
  2227. }
  2228. //order_status_id == 3
  2229. if($order_info['order_status_id'] != 3)
  2230. {
  2231. $result['code'] = 1;
  2232. $result['msg'] = '订单不是未付款订单,无法改价';
  2233. echo json_encode($result);
  2234. die();
  2235. }
  2236. $order_goods = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id ) )->select();
  2237. $member_youhui = 0;
  2238. foreach($order_goods as $k=>$v){
  2239. $order_goods[$k]['goods_img_url'] = tomedia($v['goods_images']);
  2240. $order_goods[$k]['max_total'] = round($v['total']-$v['fullreduction_money']-$v['voucher_credit']-$v['score_for_money'],2);
  2241. $member_youhui += round(($v['oldprice'] - $v['price'])*$v['quantity'],2);
  2242. $order_goods[$k]['goods_optiontitle'] = D('Seller/Order')->get_order_option_sku($v['order_id'], $v['order_goods_id']);
  2243. $order_goods[$k]['price'] = sprintf("%.2f", $v['price']);
  2244. }
  2245. $youhui_total = round($order_info['voucher_credit']+$order_info['fullreduction_money']+$order_info['score_for_money']+$member_youhui,2);
  2246. $order_info['youhui_total'] = sprintf("%.2f", $youhui_total);
  2247. $order_info['changeprice'] = sprintf("%.2f", $order_info['total'] - $order_info['old_price']);
  2248. $order_info['buyer_total'] = sprintf("%.2f", $order_info['total'] + $order_info['shipping_fare']-$order_info['voucher_credit']-$order_info['fullreduction_money'] - $order_info['score_for_money'] - $member_youhui);
  2249. echo json_encode(
  2250. array(
  2251. 'code' => 0,
  2252. 'order_goods' => $order_goods,
  2253. 'orders' => $order_info
  2254. )
  2255. );
  2256. die();
  2257. }
  2258. /**
  2259. * 订单改价
  2260. */
  2261. public function order_changeprice(){
  2262. $gpc = I('request.');
  2263. $order_id = $gpc['order_id'];
  2264. $order_goods_ids = $gpc['order_goods_id'];
  2265. $change_prices = $gpc['change_price'];
  2266. $is_supply = $gpc['is_supply'];
  2267. $token = $gpc['token'];
  2268. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2269. $member_id = $weprogram_token['member_id'];
  2270. if( empty($member_id) )
  2271. {
  2272. $result['code'] = 2;
  2273. $result['msg'] = '登录失效';
  2274. echo json_encode($result);
  2275. die();
  2276. }
  2277. $supply_info = array();
  2278. $order_info = array();
  2279. if($is_supply == 1){
  2280. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  2281. if(empty($supply_info)){
  2282. $result['code'] = 1;
  2283. $result['msg'] = '您不是供应商,无法操作';
  2284. echo json_encode($result);
  2285. die();
  2286. }
  2287. $order_info = M('lionfish_comshop_order')->where( array('store_id' => $supply_info['id'],'order_id' => $order_id) )->find();
  2288. }
  2289. if(empty($order_info)){
  2290. $result['code'] = 1;
  2291. $result['msg'] = '非法操作,供应商不存在该订单';
  2292. echo json_encode($result);
  2293. die();
  2294. }
  2295. //order_status_id == 3
  2296. if($order_info['order_status_id'] != 3)
  2297. {
  2298. $result['code'] = 1;
  2299. $result['msg'] = '订单不是未付款订单,无法改价';
  2300. echo json_encode($result);
  2301. die();
  2302. }
  2303. if(empty($order_goods_ids) || empty($change_prices)){
  2304. $result['code'] = 1;
  2305. $result['msg'] = '商品订单号和价格参数不能为空';
  2306. echo json_encode($result);
  2307. die();
  2308. }
  2309. $order_goods_ids = explode(',',$order_goods_ids);
  2310. $change_prices = explode(',',$change_prices);
  2311. if(count($order_goods_ids) != count($change_prices)){
  2312. $result['code'] = 1;
  2313. $result['msg'] = '商品订单号和价格参数不匹配';
  2314. echo json_encode($result);
  2315. die();
  2316. }
  2317. //改价后的商品实付价格不能低于0.1元
  2318. foreach($order_goods_ids as $k=>$order_goods_id){
  2319. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$order_id,'order_goods_id' =>$order_goods_id ) )->find();
  2320. $total = $order_goods_info['total'];
  2321. $fullreduction_money = $order_goods_info['fullreduction_money'];
  2322. $voucher_credit = $order_goods_info['voucher_credit'];
  2323. $score_for_money = $order_goods_info['score_for_money'];
  2324. $total = round($total - $fullreduction_money - $voucher_credit - $score_for_money,2);
  2325. if(!empty($change_prices[$k])){
  2326. $change_price = $change_prices[$k];
  2327. $total = floatval($total) + floatval($change_price);
  2328. if(bccomp($total, '0.1', 2) == -1){
  2329. $result['code'] = 1;
  2330. $result['msg'] = '改价后的商品实付价格不能低于0.1元';
  2331. echo json_encode($result);
  2332. die();
  2333. }
  2334. }
  2335. }
  2336. $change_amount = 0;
  2337. foreach($order_goods_ids as $k=>$order_goods_id){
  2338. $order_goods_info = M('lionfish_comshop_order_goods')->where( array('order_id' =>$order_id,'order_goods_id' =>$order_goods_id ) )->find();
  2339. $total = $order_goods_info['total'];
  2340. $update_data = array();
  2341. if(!empty($change_prices[$k])){
  2342. $change_amount = $change_amount + $change_prices[$k];
  2343. $change_price = $change_prices[$k];
  2344. $update_data['total'] = round(floatval($total) + floatval($change_price),2);
  2345. $update_data['is_change_price'] = 1;
  2346. M('lionfish_comshop_order_goods')->where( array('order_id' =>$order_id,'order_goods_id' => $order_goods_id ) )->save( $update_data);
  2347. }
  2348. }
  2349. $order_info = M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->find();
  2350. $order_total = $order_info['total'];
  2351. $order_data = array();
  2352. $order_data['total'] = round(floatval($order_total) + floatval($change_amount),2);
  2353. $order_data['is_change_price'] = 1;
  2354. M('lionfish_comshop_order')->where( array('order_id' =>$order_id) )->save($order_data);
  2355. $oh = array();
  2356. $oh['order_id'] = $order_id;
  2357. $oh['order_status_id']=15;
  2358. $oh['comment']='订单改价';
  2359. $oh['date_added']=time();
  2360. M('lionfish_comshop_order_history')->add($oh);
  2361. $result['code'] = 0;
  2362. echo json_encode($result);
  2363. die();
  2364. }
  2365. /**
  2366. * 供应商确定配送订单
  2367. */
  2368. public function order_delivery(){
  2369. $gpc = I('request.');
  2370. $token = $gpc['token'];
  2371. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2372. $member_id = $weprogram_token['member_id'];
  2373. $order_id = $gpc['order_id'];
  2374. $is_supply = $gpc['is_supply'];
  2375. if( empty($member_id) )
  2376. {
  2377. $result['code'] = 2;
  2378. $result['msg'] = '登录失效';
  2379. echo json_encode($result);
  2380. die();
  2381. }
  2382. $supply_info = array();
  2383. $order_info = array();
  2384. if($is_supply == 1){
  2385. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  2386. if(empty($supply_info)){
  2387. $result['code'] = 1;
  2388. $result['msg'] = '您不是供应商,无法操作';
  2389. echo json_encode($result);
  2390. die();
  2391. }
  2392. $order_info = M('lionfish_comshop_order')->where( array('store_id' => $supply_info['id'],'order_id' => $order_id) )->find();
  2393. }
  2394. if(empty($order_info)){
  2395. $result['code'] = 1;
  2396. $result['msg'] = '非法操作,供应商不存在该订单';
  2397. echo json_encode($result);
  2398. die();
  2399. }
  2400. if($order_info['order_status_id'] != 1)
  2401. {
  2402. $result['code'] = 1;
  2403. $result['msg'] = '订单不是待发货订单,无法确认配送';
  2404. echo json_encode($result);
  2405. die();
  2406. }
  2407. D('Seller/Order')->do_send_localtown($order_id,'供应商操作,开始配送货物');
  2408. $result['code'] = 0;
  2409. echo json_encode($result);
  2410. die();
  2411. }
  2412. /**
  2413. * 选择配送员
  2414. */
  2415. public function choosemember()
  2416. {
  2417. $_GPC = I('request.');
  2418. $kwd = trim($_GPC['keyword']);
  2419. $token = $_GPC['token'];
  2420. $order_id = $_GPC['order_id'];
  2421. $is_supply = $_GPC['is_supply'];
  2422. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2423. $member_id = $weprogram_token['member_id'];
  2424. if( empty($member_id) )
  2425. {
  2426. $result['code'] = 2;
  2427. $result['msg'] = '登录失效';
  2428. echo json_encode($result);
  2429. die();
  2430. }
  2431. $supply_info = array();
  2432. $order_info = array();
  2433. if($is_supply == 1){
  2434. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  2435. if(empty($supply_info)){
  2436. $result['code'] = 1;
  2437. $result['msg'] = '您不是供应商,无法操作';
  2438. echo json_encode($result);
  2439. die();
  2440. }
  2441. $order_info = M('lionfish_comshop_order')->where( array('store_id' => $supply_info['id'],'order_id' => $order_id) )->find();
  2442. }
  2443. if(empty($order_info)){
  2444. $result['code'] = 1;
  2445. $result['msg'] = '非法操作,供应商不存在该订单';
  2446. echo json_encode($result);
  2447. die();
  2448. }
  2449. if($order_info['order_status_id'] != 4)
  2450. {
  2451. $result['code'] = 1;
  2452. $result['msg'] = '订单不是已发货,待收货订单,无法指定配送员';
  2453. echo json_encode($result);
  2454. die();
  2455. }
  2456. $condition = ' 1 ';
  2457. if (!empty($kwd)) {
  2458. $condition .= ' and ( username LIKE "%'.$kwd .'%" or mobile like "%'.$kwd .'%" )';
  2459. }
  2460. $condition .= ' and store_id='.$order_info['store_id'];
  2461. /**
  2462. 分页开始
  2463. **/
  2464. $per_page = 10;
  2465. $page = isset($_GPC['page']) ? $_GPC['page'] : 1;
  2466. $offset = ($page - 1) * $per_page;
  2467. /**
  2468. 分页结束
  2469. **/
  2470. $sql = 'SELECT * FROM ' . C('DB_PREFIX') . 'lionfish_comshop_orderdistribution where '
  2471. . $condition .
  2472. ' order by id asc limit '.$offset.','.$per_page;
  2473. $list = M()->query($sql);
  2474. if( !empty($list) )
  2475. {
  2476. echo json_encode( array('code' => 0, 'data' => $list) );
  2477. die();
  2478. }else{
  2479. echo json_encode( array('code' => 1, 'msg'=>'暂无数据') );
  2480. die();
  2481. }
  2482. }
  2483. public function sub_orderchoose_distribution(){
  2484. $_GPC = I('request.');
  2485. $token = $_GPC['token'];
  2486. $order_id = $_GPC['order_id'];
  2487. $is_supply = $_GPC['is_supply'];
  2488. $distribution_id = $_GPC['distribution_id'];
  2489. $weprogram_token = M('lionfish_comshop_weprogram_token')->field('member_id')->where( array('token' => $token) )->find();
  2490. $member_id = $weprogram_token['member_id'];
  2491. if( empty($member_id) )
  2492. {
  2493. $result['code'] = 2;
  2494. $result['msg'] = '登录失效';
  2495. echo json_encode($result);
  2496. die();
  2497. }
  2498. $supply_info = array();
  2499. $order_info = array();
  2500. if($is_supply == 1){
  2501. $supply_info = M('lionfish_comshop_supply')->where( array('member_id' => $member_id) )->find();
  2502. if(empty($supply_info)){
  2503. echo json_encode(array('code' => 1, 'msg' => '您不是供应商,无法操作'));
  2504. die();
  2505. }
  2506. $order_info = M('lionfish_comshop_order')->where( array('store_id' => $supply_info['id'],'order_id' => $order_id) )->find();
  2507. }
  2508. if(empty($order_info)){
  2509. echo json_encode(array('code' => 1, 'msg' => '非法操作,供应商不存在该订单'));
  2510. die();
  2511. }
  2512. if($order_info['order_status_id'] != 4)
  2513. {
  2514. echo json_encode(array('code' => 1, 'msg' => '订单不是已发货,待收货订单,无法指定配送员'));
  2515. die();
  2516. }
  2517. $distribution_info = M('lionfish_comshop_orderdistribution')->where(array('id'=>$distribution_id,'store_id'=>$supply_info['id']))->find();
  2518. if(empty($distribution_info)){
  2519. echo json_encode(array('code' => 1, 'msg' => '配送员不存在'));
  2520. die();
  2521. }
  2522. $res = D('Home/LocaltownDelivery')->distribution_get_order( $distribution_id , $order_id);
  2523. if($res)
  2524. {
  2525. echo json_encode( array('code' => 0, 'msg' => '分配成功') );
  2526. die();
  2527. }else{
  2528. echo json_encode( array('code' => 1, 'msg' => '已被分配,请刷新页面') );
  2529. die();
  2530. }
  2531. }
  2532. public function share_order(){
  2533. $gpc = I('request.');
  2534. $order_id = $gpc['order_id'];
  2535. $order_info = M('lionfish_comshop_order')->where( array('order_id' => $order_id) )->find();
  2536. $head_id = $order_info['head_id'];
  2537. $member_id = $order_info['member_id'];
  2538. if(empty($order_info)){
  2539. echo json_encode( array('code' => 3, 'msg' => '订单信息不存在') );
  2540. die();
  2541. }
  2542. $cart= D('Home/Car');
  2543. $order_array = array();
  2544. $order_status_id = $order_info['order_status_id'];
  2545. $order_goods_list = M('lionfish_comshop_order_goods')->where( array('order_id' => $order_id) )->order('order_goods_id asc')->select();
  2546. $order_goods_array = array();
  2547. $goods_quantity = 0;
  2548. foreach($order_goods_list as $k=>$val){
  2549. $goods_common_info = "";
  2550. $where='1=1';
  2551. if( $head_id > 0 )
  2552. {
  2553. $where .= " and (g.is_all_sale = 1 or g.id in (SELECT goods_id from ".C('DB_PREFIX')."lionfish_community_head_goods where head_id = {$head_id}) ) ";
  2554. }
  2555. $sql_pingoods = "select g.*,gc.begin_time,gc.end_time,gc.big_img,gc.is_take_fullreduction,gc.labelname,gc.video,gc.pick_up_type,gc.pick_up_modify,gc.oneday_limit_count, gc.total_limit_count, gc.one_limit_count,gc.goods_start_count from " .C('DB_PREFIX')."lionfish_comshop_goods as g,".C('DB_PREFIX')."lionfish_comshop_good_common as gc where {$where} and g.id=gc.goods_id limit 1 ";
  2556. $goods_common_info = M()->query($sql_pingoods);
  2557. $goods_common_info = $goods_common_info[0];
  2558. $tmp_data = array();
  2559. $order_goods_array[$k]['actId'] = $goods_common_info['id'];
  2560. $order_goods_array[$k]['spuName'] = htmlspecialchars_decode($goods_common_info['goodsname']);
  2561. $order_goods_array[$k]['spuCanBuyNum'] = $goods_common_info['total'];
  2562. $order_goods_array[$k]['spuDescribe'] = $goods_common_info['subtitle'];
  2563. $order_goods_array[$k]['end_time'] = $goods_common_info['end_time'];
  2564. $order_goods_array[$k]['soldNum'] = $goods_common_info['seller_count'] + $goods_common_info['sales'];
  2565. $order_goods_array[$k]['oneday_limit_count'] = $goods_common_info['oneday_limit_count'];
  2566. $order_goods_array[$k]['total_limit_count'] = $goods_common_info['total_limit_count'];
  2567. $order_goods_array[$k]['one_limit_count'] = $goods_common_info['one_limit_count'];
  2568. $order_goods_array[$k]['goods_start_count'] = $goods_common_info['goods_start_count'];
  2569. $productprice = $goods_common_info['productprice'];
  2570. $order_goods_array[$k]['marketPrice'] = explode('.', $productprice);
  2571. if( !empty($goods_common_info['big_img']) )
  2572. {
  2573. $order_goods_array[$k]['bigImg'] = tomedia($goods_common_info['big_img']);
  2574. }
  2575. $good_image = D('Home/Pingoods')->get_goods_images($goods_common_info['id']);
  2576. if( !empty($good_image) )
  2577. {
  2578. $order_goods_array[$k]['skuImage'] = tomedia($good_image['image']);
  2579. }
  2580. $price_arr = D('Home/Pingoods')->get_goods_price($goods_common_info['id'], $member_id);
  2581. $price = $price_arr['price'];
  2582. $order_goods_array[$k]['actPrice'] = explode('.', $price);
  2583. //$tmp_data['skuList']= D('Home/Pingoods')->get_goods_options($val['id'], $member_id);
  2584. $order_goods_array[$k]['skuList']= D('Home/Pingoods')->get_goods_options_carquantity($goods_common_info['id'], $member_id, $head_id ,$token);
  2585. if( !empty($tmp_data['skuList']) )
  2586. {
  2587. $order_goods_array[$k]['car_count'] = 0;
  2588. }else{
  2589. $car_count = $cart->get_wecart_goods($val['id'],"",$head_id ,$token);
  2590. if( empty($car_count) )
  2591. {
  2592. $order_goods_array[$k]['car_count'] = 0;
  2593. }else{
  2594. $order_goods_array[$k]['car_count'] = $car_count;
  2595. }
  2596. }
  2597. $goods_quantity = $goods_quantity + $val['quantity'];
  2598. if($order_status_id != 3 && $order_status_id != 5){//不是未付款和取消订单
  2599. $order_goods_array[$k]['price'] = $val['price'];
  2600. $order_goods_array[$k]['oldprice'] = $val['oldprice'];
  2601. }
  2602. }
  2603. if($order_status_id != 3 && $order_status_id != 5) {//不是未付款和取消订单
  2604. $order_array['goods_quantity'] = $goods_quantity;//商品数量
  2605. $order_array['goods_count'] = count($order_goods_list);//商品种类数
  2606. $order_array['order_total'] = $order_info['total'];//订单总金额
  2607. $order_array['old_order_total'] = $order_info['old_price'];//订单原金额
  2608. $order_array['save_money'] = $order_info['old_price'] - $order_info['total'];//省了多少钱
  2609. }
  2610. //用户信息
  2611. $member_id = $order_info['member_id'];
  2612. $member_info = M('lionfish_comshop_member')->where(array('member_id'=>$member_id))->find();
  2613. $member_array = [];
  2614. $member_array['avatar'] = $member_info['avatar'];//用户头像
  2615. $member_array['username'] = $member_info['username'];//用户昵称
  2616. //团长信息
  2617. if($order_info['delivery'] != 'hexiao'){
  2618. $head_id = $order_info['head_id'];
  2619. $head_info = M('lionfish_community_head')->where(array('id'=>$head_id))->field('id,member_id,community_name,head_name,head_mobile,province_id,city_id,country_id,area_id,address')->find();
  2620. $head_member_info = M('lionfish_comshop_member')->where(array('member_id'=>$head_info['member_id']))->find();
  2621. $head_info['province_name'] = D('Seller/area')->get_area_info($head_info['province_id']);
  2622. $head_info['city_name'] = D('Seller/area')->get_area_info($head_info['city_id']);
  2623. $head_info['area_name'] = D('Seller/area')->get_area_info($head_info['area_id']);
  2624. $head_info['country_name'] = D('Seller/area')->get_area_info($head_info['country_id']);
  2625. $head_info['fulladdress'] = $head_info['province_name'].$head_info['city_name'].$head_info['area_name'].$head_info['country_name'].$head_info['address'];
  2626. $head_info['head_images'] = $head_member_info['avatar'];
  2627. $order_array['head_info'] = $head_info;
  2628. }else{
  2629. //门店信息
  2630. $salesroom_list = D('Home/Salesroom')->get_order_salesroom($order_id,0);
  2631. $order_array['salesroom_info'] = array();
  2632. if(!empty($salesroom_list)){
  2633. $order_array['salesroom_info'] = $salesroom_list[0];
  2634. }
  2635. }
  2636. $need_data = array();
  2637. $need_data['orders'] = $order_array;
  2638. $need_data['order_goods_list'] = $order_goods_array;
  2639. $need_data['members'] = $member_array;
  2640. echo json_encode(
  2641. array(
  2642. 'code' => 0,
  2643. 'data' => $need_data
  2644. )
  2645. );
  2646. }
  2647. }