Apismt.php 27 KB

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