Apismt.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Apismt extends Start_Controller {
  3. public function __construct(){
  4. parent::__construct();
  5. $this->load->library('session');
  6. $this->load->_model('Model_api','api');
  7. $this->load->_model('Model_apismt','apismt');
  8. $this->load->_model('Model_shop','shop');
  9. $this->load->_model('Model_fullordersmt','fullordersmt');
  10. $this->load->_model('Model_fullordersmtorder','fullordersmtorder');
  11. $this->load->_model('Model_country','country');
  12. $this->load->_model('Model_hl','hl');
  13. $this->load->_model('Model_is','is');
  14. $this->load->_model('Model_kdniao','kdniao');
  15. $this->load->_model('Model_typeclass','typeclass');
  16. $this->load->_model('Model_warehouse','warehouse');
  17. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  18. $this->load->_model('Model_dhltest','dhltest');
  19. $this->load->_model('Model_customersmt','customersmt');
  20. $this->load->_model('Model_express','express');
  21. $this->load->_model('Model_service','service');
  22. $this->load->_model('Model_notice','notice');
  23. $this->load->_model('Model_whlabel','whlabel');
  24. $this->load->_model('Model_productdescribe','productdescribe');
  25. $this->load->_model('Model_ljg','ljg');
  26. $this->load->_model('Model_commodityread','commodityread');
  27. $this->load->_model('Model_fedex','fedex');
  28. $this->load->_model('Model_dhl','dhl');
  29. $this->load->_model('Model_usps','usps');
  30. $this->load->_model('Model_specialstock','specialstock');
  31. $this->load->_model('Model_ck','ck');
  32. $this->load->_model('Model_weight','weight');
  33. $this->load->_model('Model_classid','classid');
  34. $this->load->_model('Model_apiyy','apiyy');
  35. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  36. $this->load->_model('Model_shopsku','shopsku');
  37. }
  38. //定义方法的调用规则 获取URI第二段值
  39. public function _remap($arg,$arg_array)
  40. {
  41. if($arg == 'smtaeorder')//添加
  42. {
  43. $this->_aeorder_zg($arg_array);
  44. }
  45. else if($arg == 'aeorder')//更改物流状态并发送站内信
  46. {
  47. $this->_aeorder($arg_array);
  48. }
  49. else if($arg == 'aeorder_zg')//手动
  50. {
  51. $this->_aeorder_zg($arg_array);
  52. }
  53. else if($arg == 'znx')//更改物流状态并发送站内信
  54. {
  55. $this->_znx($arg_array);
  56. }
  57. }
  58. public function _aeorder_zg($arg_array)
  59. {
  60. echo 1;
  61. }
  62. public function _aeorder($arg_array)
  63. {
  64. @$gethl = $this->hl->get_hl();//获取即时汇率
  65. $dictionaries = $this->typeclass->find_all('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32');
  66. // and (classid=13 or classid=22 or classid=8 or classid=15 or classid=27 or classid=25 or classid=26 or classid=18 or classid=14 or classid=9 or classid=12 or classid=10 or classid=6 or classid=100 or classid=999)
  67. $dtc = array();
  68. foreach ($dictionaries as $v)
  69. {
  70. if(stripos($v['spare'],'|') !== false)//如果有多个值
  71. {
  72. $v['spare'] = explode('|',$v['spare']);
  73. foreach ($v['spare'] as $k=>$vs)
  74. {
  75. if(stripos($v['zh'],'|') !== false)
  76. {
  77. $vzh = explode('|',$v['zh']);
  78. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  79. }
  80. else
  81. {
  82. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  83. }
  84. }
  85. }
  86. else
  87. {
  88. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  89. }
  90. }
  91. $dictionaries2 = $this->typeclass->find_all();
  92. foreach ($dictionaries2 as $v)
  93. {
  94. $dtctitle[$v['id']] = $v['title'];
  95. }
  96. /* 匹配结束 */
  97. /* 价格加入 */
  98. /**
  99. $money = array();
  100. $productdescribe = $this->productdescribe->find_all('1=1','number,purchase,cost,salesprice,title');
  101. foreach ($productdescribe as $v)
  102. {
  103. $money[$v['number']] = array('purchase'=>$v['purchase'],'cost'=>$v['cost'],'salesprice'=>$v['salesprice'],'title'=>$v['title']);
  104. }
  105. **/
  106. /* 价格加入 */
  107. /* 匹配ID加入 */
  108. $int = array();
  109. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  110. foreach ($intdata as $v)
  111. {
  112. $v['spare'] = explode('|',$v['spare']);
  113. $int[$v['id']] = $v['spare'][0];
  114. }
  115. /* 匹配ID结束 */
  116. /* 匹配状态加入 */
  117. $zt = array();$ste = array();
  118. $ztdata = $this->typeclass->find_all('classid=29','id,classtitle');
  119. foreach ($ztdata as $v)
  120. {
  121. $zt[$v['classtitle']] = $v['id'];
  122. $ste[$v['id']] = $v['classtitle'];
  123. }
  124. /* 匹配状态结束 */
  125. /* 国家加入键值-k */
  126. $cuy = array();
  127. $cuydata = $this->country->find_all('1=1','al,lb,id,ename');
  128. foreach ($cuydata as $v)
  129. {
  130. $cuy[$v['al']] = array('id'=>$v['id'],'lb'=>$v['lb'],'ename'=>$v['ename']);//获取到国家ID
  131. }
  132. /* 国家加入键值-j */
  133. /* 币种加入键值-k */
  134. $typeclass = array();
  135. $tdata = $this->typeclass->find_all('classid=30','id,title');
  136. foreach ($tdata as $v)
  137. {
  138. $typeclass[$v['title']] = $v['id'];
  139. }
  140. /* 币种加入键值-j */
  141. /* 新增SKU-k */
  142. $zjsku = array();
  143. $shopsku = $this->shopsku->find_all();
  144. foreach ($shopsku as $val)
  145. {
  146. $ss = explode(',',trim($val['shop'],','));
  147. foreach ($ss as $v)
  148. {
  149. if(isset($zjsku[$v]))
  150. {
  151. $zjsku[$v] .= ','.trim($val['sku'],',');
  152. }
  153. else
  154. {
  155. $zjsku[$v] = trim($val['sku'],',');
  156. }
  157. }
  158. }
  159. /* 新增SKU-j */
  160. $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
  161. $sid = '';
  162. if(isset($_SESSION['api']))
  163. {
  164. $user = $this->user->get_api($_SESSION['api']);
  165. $user = explode('|',trim($user['shop'],'|'));
  166. foreach ($user as $value)
  167. {
  168. $sid .= " id = '$value' or";
  169. }
  170. $sid = " and (".rtrim($sid,'or').")";
  171. }
  172. $post = $this->input->post(NULL, TRUE);
  173. if(isset($post['is']) || isset($arg_array[0]))
  174. {
  175. $shop = $this->shop->find_all("code != '' and type = 270 and tb = 1".$sid);//获取店铺信息
  176. foreach ($shop as $value)
  177. {
  178. //订单状态: PLACE_ORDER_SUCCESS:等待买家付款; IN_CANCEL:买家申请取消; WAIT_SELLER_SEND_GOODS:等待您发货; SELLER_PART_SEND_GOODS:部分发货; WAIT_BUYER_ACCEPT_GOODS:等待买家收货; FUND_PROCESSING:买家确认收货后,等待退放款处理的状态; FINISH:已结束的订单; IN_ISSUE:含纠纷的订单; IN_FROZEN:冻结中的订单; WAIT_SELLER_EXAMINE_MONEY:等待您确认金额; RISK_CONTROL:订单处于风控24小时中,从买家在线支付完成后开始,持续24小时。例:["FINISH_PAY_CLOSED","FINISH_CANCEL"]
  179. $data = array();
  180. $n = $value['id'] == 7?75:60;
  181. for($i=1;$i<$n;$i++)
  182. {
  183. $res = $this->apismt->get_hqfull($i,50,time()-90*24*3600,time(),'["IN_CANCEL","WAIT_SELLER_SEND_GOODS","SELLER_PART_SEND_GOODS","WAIT_BUYER_ACCEPT_GOODS","FUND_PROCESSING","IN_ISSUE","IN_FROZEN","WAIT_SELLER_EXAMINE_MONEY","RISK_CONTROL"]',$value['code']);
  184. if(!$res)
  185. {
  186. continue;
  187. }
  188. foreach ($res as $va)
  189. {
  190. $data[] = $va;
  191. }
  192. }
  193. $this->_state($data,$ste,$zt,$value);
  194. }
  195. $this->_orderinfo($gethl,$dtc,$dtctitle,array(),$int,$zt,$cuy,$typeclass,$is,$zjsku);
  196. $this->_fhsm();//发货声明
  197. $this->_wfk($cuy);//未付款单独发送
  198. $this->_znx();//查找消息模板并发送
  199. }
  200. }
  201. public function _state($res,$ste,$zt,$shop)
  202. {
  203. foreach ($res as $v)
  204. {
  205. $v['shop'] = $shop['id'];
  206. if($v['fundstate'] != 'NOT_PAY' && $v['fundstate'] != '')
  207. {
  208. $dataorder = $this->fullordersmt->get_orderinfo($v['orderinfo']);
  209. if(!isset($dataorder['state']))
  210. {
  211. $smtorder = $this->fullordersmtorder->get_orderinfo($v['orderinfo']);
  212. if(!$smtorder && $v['orderinfo'] != '0')
  213. {
  214. $this->fullordersmtorder->insert(array('orderinfo'=>$v['orderinfo'],'msg'=>0,'shop'=>$shop['id'],'fundstate'=>0));
  215. }
  216. else if($smtorder['fundstate'] == '1')//已付款$v[order]搜索有,证明已付款
  217. {
  218. $this->fullordersmtorder->save(array('fundstate'=>0),$smtorder['id']);
  219. }
  220. continue;
  221. }
  222. else if(!isset($zt[$v['state']]) || $ste[$dataorder['state']] == $v['state'])
  223. {
  224. continue;
  225. }
  226. else if($ste[$dataorder['state']] != $v['state'] && $dataorder['tb'] == '0')
  227. {
  228. $orderexpress = $this->express->read($dataorder['express']);
  229. $data = $this->apismt->get_order($v['orderinfo'],$shop['code']);
  230. $overtime = $zt[$v['state']] == 207?$data['overtime']:$dataorder['overtime'];
  231. if($data['express'])
  232. {
  233. $express = $this->express->get_aecode($data['express']);
  234. if($data['express'] == $orderexpress['aecode'])
  235. {
  236. $express = $dataorder['express'];
  237. }
  238. else
  239. {
  240. $express = isset($express['id'])?$express['id']:$dataorder['express'];
  241. }
  242. $waybill = $data['waybill'];
  243. }
  244. else
  245. {
  246. $express = $dataorder['express'];
  247. $waybill = $dataorder['waybill'];
  248. }
  249. $dlz = $data['express']?1:$dataorder['dlz'];
  250. $expressstate = isset($data['expressstate'])?$data['expressstate']:$dataorder['expressstate'];
  251. /**
  252. //库存开始
  253. $warehouse = $this->warehouse->read($dataorder['type']);
  254. $warehousenew = $this->warehouse->read($dataorder['type']);
  255. $thisfpdata = explode(';',rtrim($dataorder['fpdata'],';'));
  256. $fpcount = '';
  257. foreach ($thisfpdata as $v)
  258. {
  259. $thisv = explode('|',$v);
  260. $thisv = explode(',',$thisv[0]);
  261. $fpcount .= $thisv[1].'|';
  262. }
  263. $ft = array();
  264. $ftdata = explode('|',rtrim($fpcount,'|'));
  265. foreach ($ftdata as $va)
  266. {
  267. $ftitle = '';
  268. $va = explode('-',trim($va,'-'));
  269. foreach ($va as $v)
  270. {
  271. $v = $this->typeclass->read($v);
  272. $ftitle .= $v['title'].' ';
  273. }
  274. $ft[] = rtrim($ftitle,' ');
  275. }
  276. @$this->specialstock->get_kc($dataorder['state'],$zt[$v['state']],$dataorder['whlabel'],$dataorder['whlabel'],$dataorder['number']);
  277. @$this->whlabel->get_kc($dataorder['state'],$zt[$v['state']],$warehousenew['zd'],$warehousenew['ys'],$dataorder['type'],$dataorder['whlabel'],$fpcount,$ft,$dataorder['number'],$dataorder['shop'],$dataorder['type'],$dataorder['whlabel']);
  278. //库存结束
  279. $warehouse = $this->warehouse->read($dataorder['type']);
  280. if($dataorder['library'] == 1 || ($dataorder['library'] != 2 && ($zt[$v['state']] != '207' || $zt[$v['state']] == '209')))
  281. {
  282. $kcyz = $this->ck->get_kc($zt[$v['state']],$warehouse,$dataorder['shop'],$dataorder['number'],$dataorder['whlabel'],$dataorder['fpdata']);
  283. }
  284. $fl = $this->ck->get_fl($warehouse['hz'],$dataorder['whlabel'],$dataorder['fpdata']);
  285. **/
  286. $this->fullordersmt->save(array('state'=>$zt[$v['state']],'express'=>$express,'waybill'=>$waybill,'dlz'=>$dlz,'expressstate'=>$expressstate,'overtime'=>$overtime),$dataorder['id']);
  287. }
  288. }
  289. else
  290. {
  291. $smtorder = $this->fullordersmtorder->get_orderinfo($v['orderinfo']);
  292. if(!$smtorder)
  293. {
  294. $this->fullordersmtorder->insert(array('orderinfo'=>$v['orderinfo'],'msg'=>0,'shop'=>$shop['id'],'fundstate'=>1));
  295. }
  296. }
  297. }
  298. }
  299. //获取订单信息
  300. public function _wfk($cuy)
  301. {
  302. $data = $this->fullordersmtorder->find_all("type = '0' and msg = '0'");
  303. foreach ($data as $v)
  304. {
  305. $shop = $this->shop->read($v['shop']);
  306. $data = $this->apismt->get_order($v['orderinfo'],$shop['code']);
  307. if(isset($data['country']) && isset($data['state']))
  308. {
  309. $data['country'] = $cuy[$data['country']]['ename'];
  310. $data['shop'] = $shop['id'];$count = '';
  311. if($data['state'] == 'PLACE_ORDER_SUCCESS')
  312. {
  313. $notice = $this->notice->get_go($data,$shop,'ordertatus','283');
  314. if($notice == 1)
  315. {
  316. $msg = 1;
  317. }
  318. else
  319. {
  320. $msg = 4;$count = $notice;
  321. }
  322. }
  323. else
  324. {
  325. $msg = 2;
  326. }
  327. $this->fullordersmtorder->save(array('msg'=>$msg,'count'=>$count),$v['id']);
  328. }
  329. else
  330. {
  331. $this->fullordersmtorder->save(array('msg'=>3),$v['id']);
  332. }
  333. }
  334. }
  335. //获取订单信息
  336. public function _orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is)
  337. {
  338. $time = time();
  339. $smtorder = $this->fullordersmtorder->find_all("type = '0' and fundstate = '0'",'*','id desc');
  340. foreach ($smtorder as $var)
  341. {
  342. $dataorder = $this->fullordersmt->get_orderinfo($var['orderinfo']);
  343. if(isset($dataorder['orderinfo']) || $var['orderinfo'] == '0')
  344. {
  345. $this->fullordersmtorder->save(array('type'=>1),$var['id']);
  346. continue;
  347. }
  348. $shop = $this->shop->read($var['shop']);
  349. $post = $this->apismt->get_order($var['orderinfo'],$shop['code']);
  350. if(!isset($post['state']))
  351. {
  352. continue;
  353. }
  354. $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');
  355. $num2 = $this->fullordersmt->find_all('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"','id');
  356. $num2 = count($num2);
  357. if(date('Ymd',$post['buytime']) == '20190902' && $var['shop'] == 13)
  358. {
  359. $num = $num+1;$num2 = $num2+1;
  360. }
  361. if($num != $num2)
  362. {
  363. continue;//计算两遍数量对比防止错误编号
  364. }
  365. if(!$post['country'] || $post['country'] == NULL || $post['country'] == 'null')
  366. {
  367. continue;
  368. }
  369. $post['shop'] = $var['shop'];//不可删
  370. $state = $post['state'];
  371. $post['state'] = $zt[$state];//更改状态为ID
  372. $post['user'] = $shop['shopuser'];
  373. if($post['country'] == 'GB')
  374. {
  375. $post['country'] = 'UK';
  376. }
  377. $post['al'] = $cuy[$post['country']]['lb'];//国家二字码
  378. $post['country'] = $cuy[$post['country']]['id'];//国家ID
  379. $post['currency'] = $typeclass['USD'];//币种-美元ID
  380. $post['currencytitle'] = 'USD';//币种-美元ID
  381. $post['type'] = 1;//发货仓库
  382. $post['capital'] = 3;//资金支付状况,全部付款
  383. if($num > 998)
  384. {
  385. $nmb = $num+1;
  386. }
  387. else
  388. {
  389. $nmb = substr(strval($num+1+1000),1,3);
  390. }
  391. $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.$nmb;//编号
  392. $post['numberpx'] = date('ymd',$post['buytime'])*10000+$nmb;//按编号排序
  393. $post['skje'] = $post['shouldmoney'];//收款金额
  394. $yga = $post['shouldmoney'];$ygb = $shop['estimaterate'];
  395. $post['estimaterate'] = $shop['estimaterate'];
  396. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  397. $post['gtime'] = date('Ymd',$post['buytime']);//格式化付款时间
  398. if(isset($post['express']))
  399. {
  400. if($post['express'])
  401. {
  402. $express = $this->express->get_aecode($post['express']);
  403. $post['express'] = ($express)?$express['id']:0;
  404. }
  405. }
  406. else
  407. {
  408. $post['express'] = 0;
  409. }
  410. $post['name'] = str_replace("'","’",$post['name']);
  411. $post['userid'] = str_replace("'","’",$post['userid']);
  412. $post['fullname'] = str_replace("'","’",$post['fullname']);
  413. $post['address'] = str_replace("'","’",$post['address']);
  414. $sku = '';$fpdata = '';$title = '';$whlabel = '';$link = '';
  415. foreach ($post['sku'] as $val)
  416. {
  417. //$val['skucode'] = is_array($val['skucode'])?'':$val['skucode'];//之前获取sku_code会出现数组,现在不会出现数组,暂保留
  418. $val['skucode'] = str_replace(";","%' and skuid like '%",$val['skucode']);
  419. $ku = "and skuid like '%".$val['skucode']."%'";
  420. $u = $this->commodityread->get_tbproduct($val['id'],$ku);
  421. if($u)
  422. {
  423. $read = $this->api->matching($val['num'],$u['sku'],$dtc,$money,$int,$dtctitle);
  424. $fpdata .= $read['product'];
  425. $whlabel .= $read['whlabel'];
  426. $title .= $read['title'];
  427. $sku .= ($u['sku']!='')?$val['id'].':'.$u['sku'].';':$val['id'].';';
  428. $link .= ($link!='')?',https://www.aliexpress.com/item/'.$val['id'].'.html':'https://www.aliexpress.com/item/'.$val['id'].'.html';
  429. }
  430. }
  431. $post['sku'] = rtrim($sku,';');
  432. $post['link'] = $link;
  433. $post['fpdata'] = $fpdata;
  434. $post['shipremarks'] = $title;
  435. $post['whlabel'] = ($whlabel!='|')?str_replace('||','|',$whlabel):'';
  436. /**
  437. foreach ($gethl as $v)
  438. {
  439. $code = str_replace(" ","",$v['code']);
  440. if($code == 'USD')//查找对应汇率值
  441. {
  442. $hl = $v['refePrice']/100;
  443. }
  444. }
  445. **/
  446. $post['hl'] = '6.4';
  447. $post['mergeid'] = 0;
  448. $post['oldaddress'] = json_encode(array('country'=>$post['country'],'province'=>$post['province'],'city'=>$post['city'],'zipcode'=>$post['zipcode'],'phone'=>$post['phone'],'address'=>$post['address'],'name'=>$post['name'],'money'=>$post['shouldmoney']));
  449. if($post['shop'] != '9' && $post['shop'] != '26')
  450. {
  451. $warehouse = $this->warehouse->find_all("fpzd = '1'",'*','fpsx desc');
  452. foreach ($warehouse as $v)
  453. {
  454. if($v['bdcountry'] != 0 && $v['bdcountry'] != $post['country'])
  455. {
  456. continue;
  457. }
  458. $yx = 'get_yx_'.$v['bdck'];
  459. $kczd = $this->ck->$yx($post['state'],$v,$post['shop'],$post['number'],$post['whlabel'],$post['fpdata']);
  460. if($kczd['t'] == 0)
  461. {
  462. $country = $this->country->read($post['country']);//获取国家中配置物流
  463. if($country['express'] != 0)
  464. {
  465. $post['express'] = $country['express'];
  466. }
  467. if($v['express'] != 0)//优先使用仓库指定物流,替换掉上面的国家配置物流
  468. {
  469. $post['express'] = $v['express'];
  470. }
  471. if(stripos($kczd['whlabel'],$v['hz']) !== false)
  472. {
  473. $post['type'] = $v['id'];
  474. $post['whlabel'] = $kczd['whlabel'];
  475. $post['fpdata'] = $kczd['fpdata'];
  476. break 1;
  477. }
  478. }
  479. }
  480. $qdw = $this->warehouse->read($post['type']);
  481. $fl = $this->ck->get_fl($qdw['hz'],$post['whlabel'],$post['fpdata']);
  482. $post['sfxh'] = $fl['sfxh'];
  483. $post['ckfl'] = $fl['ckfl'];
  484. //特殊仓自动写位置 开始
  485. $zclp = array();
  486. $mc = $qdw['bdck'];
  487. if($mc == 'specialstock')
  488. {
  489. $pm = explode(';',trim($post['shipremarks'],';'));
  490. foreach ($pm as $k=>$vv)
  491. {
  492. $vv = trim($vv,' ');
  493. $lp = $this->typeclass->find_all("zh = '$vv'");
  494. if(isset($lp[0]['classid']))
  495. {
  496. $zclp[] = $vv;
  497. unset($pm[$k]);
  498. }
  499. }
  500. $pm = array_values($pm);
  501. $w = explode('|',trim($post['whlabel'],'|'));
  502. foreach ($w as $k=>$val)
  503. {
  504. $hwm = '';
  505. if(stripos($val,$qdw['hz']) !== false)
  506. {
  507. $num = explode('-',trim($val,'-'));
  508. $xq = explode('~',trim($num[2],'~'));
  509. foreach ($xq as $v)
  510. {
  511. $h = $this->$mc->read(trim($v,$qdw['hz']));
  512. $pm[$k] .= '(该货物在特殊库存仓 , 位置:'.$h['details'].(($h['cpid']>0)?' - 编码:'.$h['cpid']:'').')';
  513. }
  514. }
  515. }
  516. if($zclp)
  517. {
  518. $zclp = ';'.implode(";",$zclp);
  519. }
  520. else
  521. {
  522. $zclp = '';
  523. }
  524. $post['shipremarks'] = implode(";",$pm).$zclp;
  525. }
  526. //特殊仓自动写位置 结束
  527. //合并重复项
  528. $hbcfw = explode('|',trim($post['whlabel'],'|'));
  529. $hbcff = explode(';',trim($post['fpdata'],';'));
  530. $c = 0;
  531. $hbw = array();
  532. $hbf = array();
  533. for($i=0;$i<count($hbcfw);$i++)
  534. {
  535. $w = explode('-',$hbcfw[$i]);
  536. $f = explode('|',$hbcff[$i]);
  537. $w2 = ($w[2]==0)?0:'';
  538. if(!isset($hbw[$w[0].$w2]))
  539. {
  540. $hbw[$w[0].$w2] = $hbcfw[$i];
  541. $hbf[$w[0].$w2] = $hbcff[$i];
  542. }
  543. else
  544. {
  545. $c++;
  546. $cw = explode('-',$hbw[$w[0].$w2]);
  547. $cf = explode('|',$hbf[$w[0].$w2]);
  548. if($cw[2] != 0 && $w[2] != 0)
  549. {
  550. $cf[2] += $f[2];
  551. $cf[9] .= '~'.$f[9];
  552. $hbf[$w[0].$w2] = implode("|",$cf);
  553. $cw[1] += $f[2];
  554. $cw[2] .= '~'.$f[9];
  555. $hbw[$w[0].$w2] = implode("-",$cw);
  556. }
  557. else if($cw[2] == 0 && $w[2] == 0)
  558. {
  559. $cf[2] += $f[2];
  560. $hbf[$w[0].$w2] = implode("|",$cf);
  561. $cw[1] += $f[2];
  562. $hbw[$w[0].$w2] = implode("-",$cw);
  563. }
  564. else
  565. {
  566. $hbw[] = $hbcfw[$i];
  567. $hbf[] = $hbcff[$i];
  568. }
  569. }
  570. }
  571. if($c > 0)
  572. {
  573. $post['fpdata'] = implode(";",$hbf).';';
  574. $post['whlabel'] = '|'.implode("|",$hbw).'|';
  575. }
  576. //合并重复项结束
  577. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  578. }
  579. $tjid = $this->fullordersmt->insert($post);
  580. if($tjid)
  581. {
  582. $this->fullordersmtorder->save(array('type'=>1),$var['id']);
  583. $adrs = $this->customersmt->get_us($post['userid'],$var['shop']);
  584. if($adrs)
  585. {
  586. $this->customersmt->save(array('time'=>$post['buytime'],'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']);
  587. $khid = $adrs['id'];
  588. }
  589. else
  590. {
  591. $ct['shop'] = $var['shop'];
  592. $ct['source'] = 1;
  593. $ct['level'] = 5;
  594. $ct['country'] = $post['country'];
  595. $ct['time'] = $post['buytime'];
  596. $ct['num'] = 1;
  597. $ct['money'] = $post['shouldmoney'];
  598. $ct['zipcode'] = $post['zipcode'];
  599. $ct['name'] = $post['name'];
  600. $ct['client'] = $post['name'];
  601. $ct['phone'] = $post['phone'];
  602. $ct['userid'] = $post['userid'];
  603. $ct['fullname'] = $post['fullname'];
  604. $ct['province'] = $post['province'];
  605. $ct['city'] = $post['city'];
  606. $ct['address'] = $post['address'];
  607. $ct['zhcx'] = $var['shop'].'-'.$post['userid'];
  608. $khid = $this->customersmt->insert($ct);
  609. }
  610. }
  611. }
  612. echo 'orderinfo-ok-';
  613. }
  614. public function _znx()
  615. {
  616. $time = time();
  617. $notice = $this->notice->find_all("message = '2' and state = '1' and ktime < '$time' and jtime > '$time'");
  618. foreach ($notice as $key=>$var)
  619. {
  620. $ordertatus = $var['ordertatus'];
  621. $where = "shop = '".$var['shop']."' and source != '1' and buytime > 1569513600";
  622. if($var['ordertatus'] == 209 || $var['ordertatus'] == 216)//等待买家收货//已完成
  623. {
  624. $where .= " and review > '4' and library = '2' and print = '3' and waybill != ''";//已打印已出库
  625. }
  626. $where .= " and state = '".$ordertatus."'";
  627. $data = $this->fullordersmt->find_all($where);
  628. foreach ($data as $k=>$v)
  629. {
  630. $shop = $this->shop->read($v['shop']);
  631. $express = $this->express->read($v['express']);
  632. $service = $this->service->read($express['service']);
  633. $country = $this->country->read($v['country']);
  634. $v['country'] = $country['ename'];
  635. $express['servicename'] =$service['title'];//增加快递名称
  636. if($var['type'] == 1 && stripos($v['zdstate'],$v['state']) === false)
  637. {
  638. $go = $this->notice->get_god($v,$shop,$express,$var);
  639. if($go == 1)
  640. {
  641. $this->fullordersmt->save(array('content'=>$v['content'].$var['title'].'成功;','zdstate'=>$v['zdstate'].$v['state'].'|','exstateerror'=>''),$v['id']);
  642. }
  643. else
  644. {
  645. $this->fullordersmt->save(array('exstateerror'=>date('Y-m-d H:i',time()).'-'.$go),$v['id']);
  646. }
  647. }
  648. else if($var['type'] == 2)
  649. {
  650. if($express['cxcode'] == '' && $v['exstateerror'] == '')
  651. {
  652. $this->fullordersmt->save(array('exstateerror'=>'此快递不支持轨迹查询'),$var['id']);
  653. continue;
  654. }
  655. else if($express['cxcode'] == '' && $v['exstateerror'] != '')
  656. {
  657. continue;
  658. }
  659. else if($express['cxcode'] == 'fedex' || $express['cxcode'] == 'usps' || $express['cxcode'] == 'dhl' || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
  660. {
  661. $logistics = $express['cxcode'];
  662. }
  663. else
  664. {
  665. $logistics = 'apismt';
  666. }
  667. $v['cxcode'] = strtolower($express['cxcode']);//增加快递服务商码
  668. $v['servicename'] =$service['title'];//增加快递名称
  669. $v['url'] = $express['url'];//增加快递链接
  670. $fs = $this->$logistics->get_logistics($v);
  671. if($fs)
  672. {
  673. if($fs['f'] == 1 && $fs['exstate'] == 4)
  674. {
  675. $this->fullordersmt->save(array('state'=>216,'zdstate'=>$fs['exstate'].'|'),$v['id']);
  676. }
  677. if($fs['f'] == 1 && stripos('|'.$v['zdstate'],'|'.$fs['exstate'].'|') === false && $fs['exstate'] == $var['logisticstatus'])//正常物流状态发送站内信
  678. {
  679. $go = $this->notice->get_god($v,$shop,$express,$var);
  680. if($go == 1)
  681. {
  682. $this->fullordersmt->save(array('content'=>$v['content'].$var['title'].'成功;','zdstate'=>$v['zdstate'].$fs['exstate'].'|'),$v['id']);
  683. }
  684. else
  685. {
  686. $this->fullordersmt->save(array('exstateerror'=>date('Y-m-d H',time()).'-'.$go),$v['id']);
  687. }
  688. }
  689. }
  690. }
  691. }
  692. }
  693. echo 'znx-ok';
  694. }
  695. public function _fhsm()
  696. {
  697. $data = $this->fullordersmt->find_all("dlz = '0' and library = '2' and waybill != '' and (state = '207' or state = '209')");
  698. foreach ($data as $k=>$v)
  699. {
  700. $shop = $this->shop->read($v['shop']);
  701. $express = $this->express->read($v['express']);
  702. if($v['merge'] == $v['id'])
  703. {
  704. $t = $this->fullordersmt->find_all("merge = '".$v['merge']."' and dlz != '1'");
  705. $l=0;
  706. foreach ($t as $vv)
  707. {
  708. $d = $this->apismt->get_out($v['waybill'],'all',$vv['orderinfo'],$express['aecode'],$shop['code']);
  709. if(isset($d['result_success']) && $d['result_success'] == "true")
  710. {
  711. $this->fullordersmt->save(array('dlz'=>1,'exstate'=>1,'state'=>209),$vv['id']);
  712. }
  713. else
  714. {
  715. $this->fullordersmt->save(array('dlz'=>2,'exstate'=>1),$vv['id']);
  716. }
  717. $l++;
  718. if($l > 10)
  719. {
  720. break;
  721. }
  722. }
  723. }
  724. $dlz = $this->apismt->get_out($v['waybill'],'all',$v['orderinfo'],$express['aecode'],$shop['code']);
  725. if(isset($dlz['result_success']) && $dlz['result_success'] == "true")
  726. {
  727. $this->fullordersmt->save(array('dlz'=>1,'exstate'=>1,'state'=>209),$v['id']);
  728. }
  729. else
  730. {
  731. $this->fullordersmt->save(array('dlz'=>2,'exstate'=>1),$v['id']);
  732. }
  733. }
  734. }
  735. }