Apismt.php 27 KB

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