Apismt_old.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  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. }
  31. //定义方法的调用规则 获取URI第二段值
  32. public function _remap($arg,$arg_array)
  33. {
  34. if($arg == 'aeorder')//添加
  35. {
  36. $this->_aeorder_zg($arg_array);
  37. }
  38. else if($arg == 'smtaeorder')//更改物流状态并发送站内信
  39. {
  40. $this->_aeorder($arg_array);
  41. }
  42. else if($arg == 'logistics')//更改物流状态并发送站内信
  43. {
  44. $this->_logistics($arg_array);
  45. }
  46. }
  47. public function _aeorder_zg($arg_array)
  48. {
  49. echo 1;
  50. }
  51. public function _aeorder($arg_array)
  52. {
  53. $gethl = $this->hl->get_hl();//获取即时汇率
  54. $dictionaries = $this->typeclass->find_all('ae!= "" 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)'); //产品人发类型颜色
  55. $dtc = array();
  56. foreach ($dictionaries as $v)
  57. {
  58. if(stripos($v['spare'],'|') !== false)//如果有多个值
  59. {
  60. $v['spare'] = explode('|',$v['spare']);
  61. foreach ($v['spare'] as $vs)
  62. {
  63. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id']);
  64. }
  65. }
  66. else
  67. {
  68. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id']);
  69. }
  70. }
  71. $dictionaries2 = $this->typeclass->find_all();
  72. foreach ($dictionaries2 as $v)
  73. {
  74. $dtctitle[$v['id']] = $v['title'];
  75. }
  76. $dtc['Clip'] = array('classid'=>18,'zh'=>'卡子发卡子发','id'=>0);
  77. $dtc['Clip--D'] = array('classid'=>18,'zh'=>'卡子发卡子发','id'=>0);
  78. $dtc['Clip--L'] = array('classid'=>18,'zh'=>'卡子发卡子发','id'=>0);
  79. $dtc['with bangs'] = array('classid'=>999,'zh'=>'(带齐刘海)','id'=>0);
  80. $dtc['no bangs'] = array('classid'=>999,'zh'=>'(无刘海)','id'=>0);
  81. $dtc['nwb'] = array('classid'=>15,'zh'=>'扁头 自然曲','id'=>111);//中文词不一样,ID一样
  82. $dtctitle[126] = 'Hair Weaving';
  83. $dtctitle[127] = 'Closure';
  84. $dtctitle[128] = 'Wigs';
  85. $dtctitle[130] = 'Clip-in Full Head';
  86. /* 匹配结束 */
  87. /* 价格加入 */
  88. $money = array();
  89. $productdescribe = $this->productdescribe->find_all('1=1','number,purchase,cost,salesprice,title');
  90. foreach ($productdescribe as $v)
  91. {
  92. $money[$v['number']] = array('purchase'=>$v['purchase'],'cost'=>$v['cost'],'salesprice'=>$v['salesprice'],'title'=>$v['title']);
  93. }
  94. /* 价格加入 */
  95. /* 匹配ID加入 */
  96. $int = array();
  97. $intdata = $this->typeclass->find_all('classid=14','id,ae');
  98. foreach ($intdata as $v)
  99. {
  100. $v['spare'] = explode('|',$v['spare']);
  101. $int[$v['id']] = $v['spare'][0];
  102. }
  103. /* 匹配ID结束 */
  104. /* 匹配状态加入 */
  105. $zt = array();$ste = array();
  106. $ztdata = $this->typeclass->find_all('classid=29','id,classtitle');
  107. foreach ($ztdata as $v)
  108. {
  109. $zt[$v['classtitle']] = $v['id'];
  110. $ste[$v['id']] = $v['classtitle'];
  111. }
  112. /* 匹配状态结束 */
  113. /* 国家加入键值-k */
  114. $cuy = array();
  115. $cuydata = $this->country->find_all('1=1','al,lb,id');
  116. foreach ($cuydata as $v)
  117. {
  118. $cuy[$v['al']] = array('id'=>$v['id'],'lb'=>$v['lb']);//获取到国家ID
  119. }
  120. /* 国家加入键值-j */
  121. /* 币种加入键值-k */
  122. $typeclass = array();
  123. $tdata = $this->typeclass->find_all('classid=30','id,title');
  124. foreach ($tdata as $v)
  125. {
  126. $typeclass[$v['title']] = $v['id'];
  127. }
  128. /* 币种加入键值-j */
  129. $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
  130. $sid = '';
  131. if(isset($_SESSION['api']))
  132. {
  133. $user = $this->user->get_api($_SESSION['api']);
  134. $user = explode('|',trim($user['shop'],'|'));
  135. foreach ($user as $value)
  136. {
  137. $sid .= " id = '$value' or";
  138. }
  139. $sid = " and (".rtrim($sid,'or').")";
  140. }
  141. $post = $this->input->post(NULL, TRUE);
  142. if(isset($post['is']) || isset($arg_array[0]))
  143. {
  144. $shop = $this->shop->find_all("code != '' and type = 270 and tb = 1".$sid);//获取店铺信息
  145. foreach ($shop as $value)
  146. {
  147. //订单状态: 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"]
  148. $data = array();
  149. for($i=1;$i<5;$i++)
  150. {
  151. $res = $this->apismt->get_hq($i,50,time()-360000,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']);
  152. if(!$res)
  153. {
  154. continue;
  155. }
  156. foreach ($res as $va)
  157. {
  158. $data[] = $va;
  159. }
  160. }
  161. $this->_state($data,$ste,$zt,$value);
  162. }
  163. $this->_orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is);
  164. //$this->zd();//查找消息模板并发送
  165. }
  166. }
  167. public function _state($res,$ste,$zt,$value)
  168. {
  169. foreach ($res as $v)
  170. {
  171. $dataorder = $this->fullordersmt->get_orderinfo($v['orderinfo']);
  172. if(isset($dataorder['state']))
  173. {
  174. if($ste[$dataorder['state']] == $v['state'])
  175. {
  176. continue;
  177. }
  178. else
  179. {
  180. $shop = $this->shop->read($dataorder['shop']);
  181. $data = $this->apismt->get_order($v['orderinfo'],$shop['code']);
  182. if($data['express'])
  183. {
  184. $express = $this->express->get_aecode($data['express']);
  185. $express = $express['id'];
  186. $waybill = $data['waybill'];
  187. }
  188. else
  189. {
  190. $express = $dataorder['express'];
  191. $waybill = $dataorder['waybill'];
  192. }
  193. $dlz = isset($v['dlz'])?$v['dlz']:$dataorder['dlz'];
  194. $expressstate = isset($data['expressstate'])?$data['expressstate']:$dataorder['expressstate'];
  195. $this->fullordersmt->save(array('state'=>$zt[$v['state']],'express'=>$express,'waybill'=>$waybill,'dlz'=>$dlz,'expressstate'=>$expressstate),$dataorder['id']);
  196. }
  197. }
  198. else
  199. {
  200. $smtorder = $this->fullordersmtorder->get_orderinfo($v['orderinfo']);
  201. if(!$smtorder)
  202. {
  203. $this->fullordersmtorder->insert(array('orderinfo'=>$v['orderinfo'],'shop'=>$value['id']));
  204. }
  205. }
  206. }
  207. }
  208. //获取订单信息
  209. public function _orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is)
  210. {
  211. $time = time();
  212. $smtorder = $this->fullordersmtorder->find_all("type = '0'",'*','id desc');
  213. foreach ($smtorder as $var)
  214. {
  215. $dataorder = $this->fullordersmt->get_orderinfo($var['orderinfo']);
  216. if(isset($dataorder['orderinfo']))
  217. {
  218. $this->fullordersmtorder->save(array('type'=>1),$var['id']);
  219. continue;
  220. }
  221. $shop = $this->shop->read($var['shop']);
  222. $post = $this->apismt->get_order($var['orderinfo'],$shop['code']);
  223. if(!isset($post['state']))
  224. {
  225. continue;
  226. }
  227. if($post['buytime'] == '0' && $post['state'] != 'FINISH')
  228. {
  229. /**
  230. $notice = $this->notice->find_all("type = '1' and state = '1' and ktime < '$time' and jtime > '$time' and ordertatus = '203' and shop = '".$var['shop']."'");//未发送并且未付款并且未关闭
  231. if($notice && $var['type'] == '0' && $var['msg'] == '0')
  232. {
  233. $var['userid'] = $post['userid'];
  234. $var['name'] = ($post['fullname'])?$post['fullname']:$post['name'];
  235. $go = $this->notice->get_smtone($var,$shop,$notice[0]['content']);//速卖通
  236. if($go == 1)
  237. {
  238. $this->fullordersmtorder->save(array('msg'=>1),$var['id']);
  239. }
  240. }
  241. **/
  242. $notice = $this->notice->get_go($var,$shop,'ordertatus','203');
  243. if($notice == 1)
  244. {
  245. $this->fullordersmtorder->save(array('msg'=>1),$var['id']);
  246. }
  247. continue;
  248. }
  249. else if($post['buytime'] == '0' && $post['state'] == 'FINISH')
  250. {
  251. $this->fullordersmtorder->remove($var['id']);
  252. continue;
  253. }
  254. $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"');
  255. $post['shop'] = $var['shop'];//不可删
  256. $state = $post['state'];
  257. $post['state'] = $zt[$state];//更改状态为ID
  258. $post['user'] = $shop['shopuser'];
  259. $post['al'] = $cuy[$post['country']]['lb'];//国家二字码
  260. $post['country'] = $cuy[$post['country']]['id'];//国家ID
  261. $post['currency'] = $typeclass['USD'];//币种-美元ID
  262. $post['currencytitle'] = 'USD';//币种-美元ID
  263. $post['type'] = 1;//发货仓库
  264. $post['capital'] = 3;//资金支付状况,全部付款
  265. $nmb = substr(strval($num+1+1000),1,3);
  266. $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.$nmb;//编号
  267. $post['numberpx'] = substr(date('ymd',$post['buytime']),1).$nmb;//按编号排序
  268. $yga = $post['shouldmoney'];$ygb = $shop['estimaterate'];
  269. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  270. $post['gtime'] = date('Ymd',$post['buytime']);//格式化付款时间
  271. if(isset($post['express']))
  272. {
  273. if($post['express'])
  274. {
  275. $express = $this->express->get_aecode($post['express']);
  276. $post['express'] = ($express)?$express['id']:0;
  277. }
  278. }
  279. else
  280. {
  281. $post['express'] = 0;
  282. }
  283. $post['name'] = str_replace("'","’",$post['name']);
  284. $post['userid'] = str_replace("'","’",$post['userid']);
  285. $post['fullname'] = str_replace("'","’",$post['fullname']);
  286. $post['address'] = str_replace("'","’",$post['address']);
  287. $sku = '';$fpdata = '';$title = '';$whlabel = '';
  288. foreach ($post['sku'] as $val)
  289. {
  290. //$val['skucode'] = is_array($val['skucode'])?'':$val['skucode'];//之前获取sku_code会出现数组,现在不会出现数组,暂保留
  291. $val['skucode'] = str_replace(";","%' and skuid like '%",$val['skucode']);
  292. $ku = "and skuid like '%".$val['skucode']."%'";
  293. $u = $this->commodityread->get_tbproduct($val['id'],$ku);
  294. if($u)
  295. {
  296. $read = $this->api->matching($val['num'],$u['sku'],$dtc,$money,$int,$dtctitle);
  297. $fpdata .= $read['product'];
  298. $whlabel .= $read['whlabel'];
  299. $title .= $read['title'];
  300. $sku .= ($u['sku']!='')?$val['id'].':'.$u['sku'].';':$val['id'].';';
  301. }
  302. }
  303. $post['sku'] = rtrim($sku,';');
  304. $post['fpdata'] = $fpdata;
  305. $post['shipremarks'] = $title;
  306. $post['whlabel'] = ($whlabel!='|')?str_replace('||','|',$whlabel):'';
  307. foreach ($gethl as $v)
  308. {
  309. $code = str_replace(" ","",$v['code']);
  310. if($code == 'USD')//查找对应汇率值
  311. {
  312. $hl = $v['refePrice']/100;
  313. }
  314. }
  315. $post['hl'] = $hl;
  316. $post['mergeid'] = 0;
  317. if($this->fullordersmt->insert($post))
  318. {
  319. $this->fullordersmtorder->save(array('type'=>1),$var['id']);
  320. $adrs = $this->customersmt->get_us($post['userid'],$var['shop']);
  321. if($adrs)
  322. {
  323. $this->customersmt->save(array('time'=>$post['buytime'],'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']);
  324. }
  325. else
  326. {
  327. $ct['shop'] = $var['shop'];
  328. $ct['source'] = 1;
  329. $ct['level'] = 5;
  330. $ct['country'] = $post['country'];
  331. $ct['time'] = $post['buytime'];
  332. $ct['num'] = 1;
  333. $ct['money'] = $post['shouldmoney'];
  334. $ct['zipcode'] = $post['zipcode'];
  335. $ct['name'] = $post['name'];
  336. $ct['client'] = $post['name'];
  337. $ct['phone'] = $post['phone'];
  338. $ct['userid'] = $post['userid'];
  339. $ct['fullname'] = $post['fullname'];
  340. $ct['province'] = $post['province'];
  341. $ct['city'] = $post['city'];
  342. $ct['address'] = $post['address'];
  343. $this->customersmt->insert($ct);
  344. }
  345. }
  346. }
  347. echo 'orderinfo-ok-';
  348. }
  349. public function _logistics($arg_array)
  350. {
  351. $post = $this->input->post(NULL, TRUE);
  352. if(isset($arg_array[0]))
  353. {
  354. $wl = $this->wl();//物流
  355. //$zd = $this->zd();//自动 已放入获取订单中执行
  356. //$yx = $this->yx();//营销
  357. if($wl > 0)
  358. {
  359. echo json_encode(array('msg'=>'发送站内信成功','success'=>true));exit;
  360. }
  361. else
  362. {
  363. echo json_encode(array('msg'=>'无需要发送信息','success'=>false));exit;
  364. }
  365. }
  366. }
  367. public function zd()
  368. {
  369. $time = time();
  370. $notice = $this->notice->find_all("type = '1' and state = '1' and ktime < '$time' and jtime > '$time'");
  371. foreach ($notice as $key=>$var)
  372. {
  373. $where = "state = '".$var['ordertatus']."' and shop = '".$var['shop']."' and source != '1'";
  374. if($var['ordertatus'] == 207)//等待发货
  375. {
  376. $where .= " and review > '4' and print != '1'";
  377. }
  378. else if($var['ordertatus'] == 209)//等待买家收货
  379. {
  380. $where .= " and library = '2' and print = '3' and waybill != ''";//已打印已出库
  381. }
  382. else if($var['ordertatus'] == 216)//已完成
  383. {
  384. $where .= " and library = '2' and print = '3'";
  385. }
  386. $data = $this->fullordersmt->find_all($where);
  387. foreach ($data as $k=>$v)
  388. {
  389. $shop = $this->shop->read($v['shop']);
  390. $express = $this->express->read($v['express']);
  391. $service = $this->service->read($express['service']);
  392. $express['servicename'] =$service['title'];//增加快递名称
  393. if($var['ordertatus'] == 209 && $v['dlz'] == '0' && $v['waybill'] != '')//发货声明
  394. {
  395. $dlz = $this->apismt->get_out($v['waybill'],'all',$v['orderinfo'],$express['aecode'],$shop['code']);
  396. if(isset($dlz['result_success']))
  397. {
  398. $this->fullordersmt->save(array('dlz'=>1,'exstate'=>1),$v['id']);
  399. }
  400. else
  401. {
  402. $this->fullordersmt->save(array('dlz'=>2,'exstate'=>1),$v['id']);
  403. }
  404. }
  405. if(stripos($v['zdstate'],$v['state']) === false || $v['zdstate'] == "")
  406. {
  407. $go = $this->notice->get_god($v,$shop,$express,$var['content'],$var['message']);
  408. if($go == 1)
  409. {
  410. $this->fullordersmt->save(array('content'=>$v['content'].$var['title'].'成功;','zdstate'=>$v['zdstate'].$v['state'].'|'),$v['id']);
  411. $i++;
  412. }
  413. else
  414. {
  415. $this->fullordersmt->save(array('exstateerror'=>$go),$v['id']);
  416. }
  417. }
  418. }
  419. }
  420. echo 'zd-ok';
  421. }
  422. public function wl()
  423. {
  424. $i = 0;
  425. $data = $this->fullordersmt->find_all("state = '209' and library = '2' and source != 1");
  426. if($data)
  427. {
  428. foreach ($data as $var)
  429. {
  430. $ex = $this->express->read($var['express']);//查找快递
  431. if($ex['cxcode'] == '' && $var['exstateerror'] == '')
  432. {
  433. $this->fullordersmt->save(array('exstateerror'=>'此快递不支持轨迹查询'),$var['id']);
  434. continue;
  435. }
  436. else if($ex['cxcode'] == '' && $var['exstateerror'] != '')
  437. {
  438. continue;
  439. }
  440. else if($ex['cxcode'] == 'fedex')
  441. {
  442. $logistics = 'fedex';
  443. }
  444. else if($ex['cxcode'] == 'usps')
  445. {
  446. $logistics = 'usps';
  447. }
  448. else if($ex['cxcode'] == 'dhl')
  449. {
  450. $logistics = 'dhl';
  451. }
  452. else
  453. {
  454. $logistics = 'apismt';
  455. }
  456. $service = $this->service->read($ex['service']);
  457. $var['express'] = strtolower($ex['cxcode']);//替换为快递服务商码
  458. $var['servicename'] =$service['title'];//增加快递名称
  459. $var['url'] = $ex['url'];//增加快递链接
  460. $v = $this->$logistics->get_logistics($var);
  461. if($v)
  462. {
  463. if($v['f'] == 1 && $v['exstate'] != $var['exstate'])//正常物流状态发送站内信
  464. {
  465. if($v['exstate'] == 4)
  466. {
  467. $this->fullordersmt->save(array('state'=>216,'exstate'=>$v['exstate']),$var['id']);
  468. }
  469. else
  470. {
  471. $this->fullordersmt->save(array('exstate'=>$v['exstate']),$var['id']);
  472. }
  473. $shop = $this->shop->read($var['shop']);
  474. $go = $this->notice->get_go($var,$shop,'logisticstatus',$v['exstate']);
  475. if($v['exstate'] == 1)
  476. {
  477. $msg = '揽收';
  478. }
  479. else if($v['exstate'] == 2)
  480. {
  481. $msg = '在途中';
  482. }
  483. else if($v['exstate'] == 3)
  484. {
  485. $msg = '派送中';
  486. }
  487. else if($v['exstate'] == 4)
  488. {
  489. $msg = '已签收';
  490. }
  491. $gg = ($go==1)?$msg.':站内信成功;':$msg.':站内信失败;';
  492. $go = ($go==1)?'':$go;
  493. $this->fullordersmt->save(array('content'=>$var['content'].$gg,'exstateerror'=>$go),$var['id']);
  494. $i++;
  495. }
  496. else if ($v['f'] == '0')
  497. {
  498. $this->fullordersmt->save(array('exstateerror'=>$v['content']),$var['id']);
  499. }
  500. }
  501. }
  502. }
  503. return $i;exit;
  504. }
  505. public function StrCombinations($arr,$len=0,&$res,$str="")//字符串组合
  506. {
  507. $arr_len = count($arr);
  508. if($len == 0)
  509. {
  510. $res[] = $str;
  511. }
  512. else
  513. {
  514. for($i=0; $i<$arr_len; $i++)
  515. {
  516. $tmp = array_shift($arr);
  517. if (empty($str))
  518. {
  519. $this->StrCombinations($arr, $len-1, $res,$tmp);
  520. }
  521. else
  522. {
  523. $this->StrCombinations($arr, $len-1, $res,$str.";".$tmp);
  524. }
  525. array_push($arr, $tmp);
  526. }
  527. }
  528. }
  529. /**
  530. //获取新订单及更改状态
  531. public function _state($res,$ste,$zt,$value)
  532. {
  533. foreach ($res as $v)
  534. {
  535. if($v['state'] == 'PLACE_ORDER_SUCCESS')
  536. {
  537. continue;
  538. }
  539. $dataorder = $this->fullordersmt->get_orderinfo($v['orderinfo']);
  540. if(isset($dataorder['orderinfo']))
  541. {
  542. if($dataorder['mergeid'] != '5' && $ste[$dataorder['state']] != $v['state'])
  543. {
  544. $shop = $this->shop->read($dataorder['shop']);
  545. $data = $this->apismt->get_order($v['orderinfo'],$shop['code']);
  546. if($data['express'])
  547. {
  548. $express = $this->express->get_aecode($data['express']);
  549. $express = $express['id'];
  550. $waybill = $data['waybill'];
  551. }
  552. else
  553. {
  554. $express = $dataorder['express'];
  555. $waybill = $dataorder['waybill'];
  556. }
  557. $dlz = isset($v['dlz'])?$v['dlz']:$dataorder['dlz'];
  558. $expressstate = isset($data['expressstate'])?$data['expressstate']:$dataorder['expressstate'];
  559. $this->fullordersmt->save(array('state'=>$zt[$v['state']],'express'=>$express,'waybill'=>$waybill,'dlz'=>$dlz,'expressstate'=>$expressstate),$dataorder['id']);
  560. }
  561. }
  562. else
  563. {
  564. $this->fullordersmt->insert(array('orderinfo'=>$v['orderinfo'],'mergeid'=>5,'shop'=>$value['id'],'user'=>$value['shopuser']));
  565. }
  566. }
  567. //触发站内信模板,出发站内信模板查找
  568. }
  569. //获取订单信息
  570. public function _orderinfo($gethl,$dtc,$dtctitle,$money,$int,$zt,$cuy,$typeclass,$is)
  571. {
  572. $dataroder = $this->fullordersmt->find_all("mergeid = 5");
  573. foreach ($dataroder as $var)
  574. {
  575. $shop = $this->shop->read($var['shop']);
  576. $post = $this->apismt->get_order($var['orderinfo'],$shop['code']);
  577. if(!$post['state'])
  578. {
  579. continue;
  580. }
  581. $num = $this->fullordersmt->find_count('gtime = "'.date('Ymd',$post['buytime']).'" and shop = "'.$shop['id'].'"');
  582. $post['shop'] = $var['shop'];//不可删
  583. $state = $post['state'];
  584. $post['state'] = $zt[$state];//更改状态为ID
  585. $post['al'] = $cuy[$post['country']]['lb'];//国家二字码
  586. $post['country'] = $cuy[$post['country']]['id'];//国家ID
  587. $post['currency'] = $typeclass['USD'];//币种-美元ID
  588. $post['currencytitle'] = 'USD';//币种-美元ID
  589. $post['type'] = 1;//发货仓库
  590. $post['capital'] = 3;//资金支付状况,全部付款
  591. $nmb = substr(strval($num+1+1000),1,3);
  592. $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$post['buytime']),1).'-'.$nmb;//编号
  593. $post['numberpx'] = substr(date('ymd',$post['buytime']),1).$nmb;//按编号排序
  594. $yga = $post['shouldmoney'];$ygb = $shop['estimaterate'];
  595. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  596. $post['gtime'] = date('Ymd',$post['dtime']);//格式化订单时间
  597. if(isset($post['express']))
  598. {
  599. if($post['express'])
  600. {
  601. $express = $this->express->get_aecode($post['express']);
  602. $post['express'] = $express['id'];
  603. }
  604. }
  605. $post['name'] = str_replace("'","’",$post['name']);
  606. $post['userid'] = str_replace("'","’",$post['userid']);
  607. $post['fullname'] = str_replace("'","’",$post['fullname']);
  608. $post['address'] = str_replace("'","’",$post['address']);
  609. $sku = '';$fpdata = '';$title = '';$whlabel = '';
  610. foreach ($post['sku'] as $val)
  611. {
  612. //$val['skucode'] = is_array($val['skucode'])?'':$val['skucode'];//之前获取sku_code会出现数组,现在不会出现数组,暂保留
  613. $u = $this->commodityread->get_productid($val['id'],$val['skucode']);
  614. $sku .= ($u['sku']!='')?$val['id'].':'.$u['sku'].';':$val['id'].';';
  615. $read = $this->api->matching($val['num'],$u['sku'],$dtc,$money,$int,$dtctitle);
  616. $fpdata .= $read['product'];
  617. $title .= $read['title'];
  618. $whlabel .= $read['whlabel'];
  619. }
  620. $post['sku'] = rtrim($sku,';');
  621. $post['fpdata'] = $fpdata;
  622. $post['shipremarks'] = $title;
  623. $post['whlabel'] = ($whlabel!='|')?str_replace('||','|',$whlabel):'';
  624. foreach ($gethl as $v)
  625. {
  626. $code = str_replace(" ","",$v['code']);
  627. if($code == 'USD')//查找对应汇率值
  628. {
  629. $hl = $v['refePrice']/100;
  630. }
  631. }
  632. $post['hl'] = $hl;
  633. $post['mergeid'] = 0;
  634. $this->fullordersmt->save($post,$var['id']);
  635. if($post['buytime'] != '0')
  636. {
  637. $adrs = $this->customersmt->get_us($post['userid'],$var['shop']);
  638. if($adrs)
  639. {
  640. $this->customersmt->save(array('time'=>$post['buytime'],'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']);
  641. }
  642. else
  643. {
  644. $ct['shop'] = $var['shop'];
  645. $ct['source'] = 1;
  646. $ct['level'] = 5;
  647. $ct['country'] = $post['country'];
  648. $ct['time'] = $post['buytime'];
  649. $ct['num'] = 1;
  650. $ct['money'] = $post['shouldmoney'];
  651. $ct['zipcode'] = $post['zipcode'];
  652. $ct['name'] = $post['name'];
  653. $ct['client'] = $post['name'];
  654. $ct['phone'] = $post['phone'];
  655. $ct['userid'] = $post['userid'];
  656. $ct['fullname'] = $post['fullname'];
  657. $ct['province'] = $post['province'];
  658. $ct['city'] = $post['city'];
  659. $ct['address'] = $post['address'];
  660. $this->customersmt->insert($ct);
  661. }
  662. }
  663. }
  664. }
  665. **/
  666. }