Apixw.php 73 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Apixw 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_shop','shop');
  8. $this->load->_model('Model_fullorder','fullorder');
  9. $this->load->_model('Model_fullorderxw','fullorderxw');
  10. $this->load->_model('Model_fullordertt','fullordertt');
  11. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  12. $this->load->_model('Model_fullordersmt','fullordersmt');
  13. $this->load->_model('Model_country','country');
  14. $this->load->_model('Model_hl','hl');
  15. $this->load->_model('Model_is','is');
  16. $this->load->_model('Model_kdniao','kdniao');
  17. $this->load->_model('Model_typeclass','typeclass');
  18. $this->load->_model('Model_warehouse','warehouse');
  19. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  20. $this->load->_model('Model_dhl','dhl');
  21. $this->load->_model('Model_usps','usps');
  22. $this->load->_model('Model_ups','ups');
  23. $this->load->_model('Model_dhltest','dhltest');
  24. $this->load->_model('Model_customer','customer');
  25. $this->load->_model('Model_customerxw','customerxw');
  26. $this->load->_model('Model_express','express');
  27. $this->load->_model('Model_notice','notice');
  28. $this->load->_model('Model_emaildata','emaildata');
  29. $this->load->_model('Model_whlabel','whlabel');
  30. $this->load->_model('Model_productdescribe','productdescribe');
  31. $this->load->_model('Model_ljg','ljg');
  32. $this->load->_model('Model_commodityread','commodityread');
  33. $this->load->_model('Model_service','service');
  34. $this->load->_model('Model_fedex','fedex');
  35. $this->load->_model('Model_apixw','apixw');
  36. $this->load->_model('Model_cne','cne');
  37. $this->load->_model('Model_specialstock','specialstock');
  38. $this->load->_model('Model_whlabellabel','whlabellabel');
  39. $this->load->_model('Model_allocation','allocation');
  40. $this->load->_model('Model_yswaybill','yswaybill');
  41. $this->load->_model('Model_paypal','paypal');
  42. $this->load->_model('Model_17track','17track');
  43. $this->load->_model('Model_ck','ck');
  44. $this->load->_model('Model_weight','weight');
  45. $this->load->_model('Model_pay','pay');
  46. $this->load->_model('Model_setting','setting');
  47. $this->load->_model('Model_classid','classid');
  48. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  49. $this->load->_model('Model_shopsku','shopsku');
  50. }
  51. //定义方法的调用规则 获取URI第二段值
  52. public function _remap($arg,$arg_array)
  53. {
  54. if($arg == 'isorder')//添加
  55. {
  56. $this->_isorder();
  57. }
  58. else if($arg == 'tb')//同步独立站
  59. {
  60. $this->_tb();
  61. }
  62. else if($arg == 'waybill')//运单上传独立站
  63. {
  64. $this->_waybill($arg_array);
  65. }
  66. else if($arg == 'waybillemail')
  67. {
  68. $this->_waybillemail($arg_array);
  69. }
  70. else if($arg == 'waybillfs')
  71. {
  72. $this->_waybillfs($arg_array);
  73. }
  74. else if($arg == 'headgear')//传输头套信息
  75. {
  76. $this->_headgear($arg_array);
  77. }
  78. else if($arg == 'fsstate')
  79. {
  80. $this->_fsstate();
  81. }
  82. else if($arg == 'zz')
  83. {
  84. $this->_zz();
  85. }
  86. else if($arg == 'zzcs')
  87. {
  88. $this->_zzcs();
  89. }
  90. else if($arg == 'cangku')
  91. {
  92. $this->_cangku();
  93. }
  94. else if($arg == 'kc')
  95. {
  96. $this->_kc();
  97. }
  98. else if($arg == 'wlfs')
  99. {
  100. $this->_wlfs();
  101. }
  102. else if($arg == 'query')
  103. {
  104. $this->_query();
  105. }
  106. else if($arg == 'kcjc')
  107. {
  108. $this->_kcjc();
  109. }
  110. else if($arg == 'klarna')
  111. {
  112. $this->_klarna();
  113. }
  114. else if($arg == 'logistics')
  115. {
  116. $this->_logistics();
  117. }
  118. else if($arg == 'hqpaypal')
  119. {
  120. $this->_hqpaypal();
  121. }
  122. else if($arg == 'hqstripe')
  123. {
  124. $this->_hqstripe();
  125. }
  126. else if($arg == 'htmlstock')
  127. {
  128. $this->_htmlstock();
  129. }
  130. else if($arg == '17track')
  131. {
  132. $this->_17track();
  133. }
  134. }
  135. //通过地址直接获取独立站订单信息
  136. public function _isorder()
  137. {
  138. $sid = '';$sd = array();
  139. if(isset($_SESSION['api']))
  140. {
  141. $user = $this->user->get_api($_SESSION['api']);
  142. $user = explode('|',trim($user['shop'],'|'));
  143. foreach ($user as $value)
  144. {
  145. $sid .= " id = '$value' or";
  146. }
  147. $sid = " and (".rtrim($sid,'or').")";
  148. }
  149. $post = $this->input->post(NULL, TRUE);
  150. $api = $this->input->get('api',true);
  151. $dshop = $this->input->get('dshop',true);
  152. //@$gethl = $this->hl->get_hl();//获取即时汇率
  153. $gethl = array();
  154. /* 订单号加入键值-k */
  155. /**
  156. $dataorder = array();
  157. $fdata = $this->fullorderxw->find_all('dtime > "'.(time()-96*3600).'"','orderinfo');
  158. foreach ($fdata as $v)
  159. {
  160. $dataorder[$v['orderinfo']] = "";//获取到单号
  161. }
  162. **/
  163. /* 订单号加入键值-j */
  164. /* 匹配加入 */
  165. $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 and classid != 36');
  166. // 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)
  167. $dtc = array();
  168. foreach ($dictionaries as $v)
  169. {
  170. if(stripos($v['spare'],'|') !== false)//如果有多个值
  171. {
  172. $v['spare'] = explode('|',$v['spare']);
  173. foreach ($v['spare'] as $k=>$vs)
  174. {
  175. if(stripos($v['zh'],'|') !== false)
  176. {
  177. $vzh = explode('|',$v['zh']);
  178. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  179. }
  180. else
  181. {
  182. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  183. }
  184. }
  185. }
  186. else
  187. {
  188. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  189. }
  190. }
  191. $dictionaries2 = $this->typeclass->find_all();
  192. foreach ($dictionaries2 as $v)
  193. {
  194. $dtctitle[$v['id']] = $v['title'];
  195. }
  196. /* 匹配结束 */
  197. /* 价格加入 */
  198. /**
  199. $money = array();
  200. $productdescribe = $this->productdescribe->find_all('1=1','number,purchase,cost,salesprice,title');
  201. foreach ($productdescribe as $v)
  202. {
  203. $money[$v['number']] = array('purchase'=>$v['purchase'],'cost'=>$v['cost'],'salesprice'=>$v['salesprice'],'title'=>$v['title']);
  204. }
  205. **/
  206. /* 价格加入 */
  207. /* 匹配ID加入 */
  208. $int = array();
  209. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  210. foreach ($intdata as $v)
  211. {
  212. $v['spare'] = explode('|',$v['spare']);
  213. $int[$v['id']] = $v['spare'][0];
  214. }
  215. /* 匹配ID结束 */
  216. /* 国家加入键值-k */
  217. $cuy = array();
  218. $cuydata = $this->country->find_all('1=1','lb,id');
  219. foreach ($cuydata as $v)
  220. {
  221. $cuy[$v['lb']] = $v['id'];//获取到国家ID
  222. }
  223. /* 国家加入键值-j */
  224. /* 币种加入键值-k */
  225. $typeclass = array();
  226. $tdata = $this->typeclass->find_all('classid=30','id,title');
  227. foreach ($tdata as $v)
  228. {
  229. $typeclass[$v['title']] = $v['id'];
  230. }
  231. /* 币种加入键值-j */
  232. /* 支付方式-k */
  233. $pay = array();
  234. $tdata = $this->typeclass->find_all('classid=4','id,spare');
  235. foreach ($tdata as $v)
  236. {
  237. $paytype = $this->pay->get_typeclass($v['id']);
  238. if(isset($paytype['estimaterate']))
  239. {
  240. $estimaterate = $paytype['estimaterate'];
  241. }
  242. else
  243. {
  244. $estimaterate = 0;
  245. }
  246. if(stripos($v['spare'],'|') !== false)//如果有多个值
  247. {
  248. $v['spare'] = explode('|',$v['spare']);
  249. foreach ($v['spare'] as $k=>$vs)
  250. {
  251. $pay[$vs] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
  252. }
  253. }
  254. else
  255. {
  256. $pay[$v['spare']] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
  257. }
  258. }
  259. $pay['stripeios'] = $pay['stripe_payments'];
  260. /* 支付方式-j */
  261. /* 新增SKU-k */
  262. $zjsku = array();
  263. $shopsku = $this->shopsku->find_all();
  264. foreach ($shopsku as $val)
  265. {
  266. $ss = explode(',',trim($val['shop'],','));
  267. foreach ($ss as $v)
  268. {
  269. if(isset($zjsku[$v]))
  270. {
  271. $zjsku[$v] .= ','.trim($val['sku'],',');
  272. }
  273. else
  274. {
  275. $zjsku[$v] = trim($val['sku'],',');
  276. }
  277. }
  278. }
  279. /* 新增SKU-j */
  280. $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
  281. if(isset($post['is']) || (isset($api) && $api = '89757'))
  282. {
  283. $tb = 0;
  284. if($dshop)
  285. {
  286. $shop = $this->shop->find_all("id = '$dshop'");
  287. }
  288. else
  289. {
  290. $shop = $this->shop->find_all("type = 2297 and tb = 1".$sid);//获取独立站信息
  291. }
  292. foreach ($shop as $value)
  293. {
  294. if((time()-$value['tbtime']) < 1)
  295. {
  296. $tb = 1;//正在同步中
  297. break;
  298. }
  299. else
  300. {
  301. $this->shop->save(array('tbtime'=>time()),$value['id']);
  302. }
  303. $setting = $this->setting->get_settings();
  304. $this->db->trans_begin();
  305. $res = $this->apixw->get_hq($value['brandname'],$value['shopadmin'],$value);
  306. $sd[] = $res;
  307. $sjc = $setting['sctime'];//时间差 之前是3600 现在为0
  308. if($res)
  309. {
  310. foreach ($res as $v)
  311. {
  312. if($value['token'] == 'SU')
  313. {
  314. $time = $v['purchased_on']-7*3600-$sjc;//之前是+$sjc
  315. }
  316. else if($value['program'] == 'Shopify')
  317. {
  318. $time = $v['purchased_on'];
  319. }
  320. else
  321. {
  322. if($value['id'] == 1)
  323. {
  324. $time = strtotime($v['purchased_on'])-7*3600-$sjc;//-$sjc;//之前是+$sjc
  325. }
  326. else
  327. {
  328. $time = strtotime($v['purchased_on'])-7*3600-$sjc;//订单时间更为时间戳 //之前是+$sjc
  329. }
  330. }
  331. $num = $this->fullorderxw->find_count('gtime = "'.date('Ymd',$time).'" and shop = "'.$value['id'].'"');
  332. $order_id = $value['id'].$v['order_id'];
  333. $tc = $typeclass[$v['global_currency_code']];
  334. $dataorder = $this->fullorderxw->get_orderinfo($order_id);
  335. $hmdid = '';
  336. if($value['program'] == 'Shopify' && isset($dataorder['id']))
  337. {
  338. if($v['order_comment'] != $dataorder['clientremarks'])
  339. {
  340. $this->fullorderxw->save(array('clientremarks'=>$v['order_comment']),$dataorder['id']);
  341. }
  342. }
  343. if(!isset($dataorder['id']))
  344. //现在为所有订单都获取。!$ord && strcasecmp($v['isstatus'],'processing') == 0如果没有此订单并且订单状态为等待发货则继续
  345. {
  346. if(!isset($cuy[$v['country']]))
  347. {
  348. $cuy[$v['country']] = 1004;
  349. }
  350. $post = $this->apixw->get_data($value,$v,$gethl,$time,$cuy[$v['country']],$is,$num,$v['country'],$tc,$dtc,array(),$int,$dtctitle,$pay,$zjsku);
  351. $kn = explode('-',$post['paypal']);
  352. if($post['pay'] == 23 && $value['klarnaname'] != '' && $value['klarnapass'] != '')
  353. {
  354. $klarna = $this->_klarnadata($post['paypal'],$value['klarnaname'],$value['klarnapass']);
  355. if($klarna != '')
  356. {
  357. $post['klarnadata'] = $klarna;
  358. }
  359. }
  360. if($post['pay'] == 26 && $value['afterpayname'] != '' && $value['afterpaypass'] != '')
  361. {
  362. $afterpay = $this->_afterpay($post['paypal'],$value['afterpayname'],$value['afterpaypass']);
  363. if($afterpay != '')
  364. {
  365. $post['klarnadata'] = $afterpay;
  366. }
  367. }
  368. if($post['pay'] == 27 && $value['clearpayname'] != '' && $value['clearpaypass'] != '')
  369. {
  370. $clearpay = $this->_clearpay($post['paypal'],$value['clearpayname'],$value['clearpaypass']);
  371. if($clearpay != '')
  372. {
  373. $post['klarnadata'] = $clearpay;
  374. }
  375. }
  376. if($post['pay'] == '28' && $post['state'] != '207')
  377. {
  378. continue;
  379. }
  380. if($post['state'] == '217' || $post['state'] == '203')
  381. {
  382. continue;
  383. }
  384. /**
  385. else if($post['pay'] == 22 && $value['paypalname'] != '' && $value['paypalpass'] != '')
  386. {
  387. $paypal = $this->_paypaldata($post['paypal'],$value['paypalname'],$value['paypalpass']);
  388. if($paypal != '')
  389. {
  390. $post['klarnadata'] = $paypal;
  391. }
  392. }
  393. **/
  394. /** 启用自动分配仓库 **/
  395. $post['type'] = 7;//直接进入翔文仓
  396. //条数及申报
  397. $ts = 0;
  398. $dtsbjz = 0;
  399. $zsbjz = 0;
  400. if(!empty($post['fpdata'])){
  401. $w = explode('|',trim($post['whlabel'],'|'));
  402. foreach ($w as $k=>$val)
  403. {
  404. $num = explode('-',trim($val,'-'));
  405. //判断是否是礼物 礼物不计数
  406. $is_gift_str = substr($num[0], 0, 3);
  407. if($is_gift_str != '131'){
  408. $ts += $num[1];
  409. }
  410. }
  411. }
  412. if($ts > 0 && $ts < 6 && $post['country'] == 192)
  413. {
  414. $dtsbjz = ($ts==3)?sprintf("%.1f",100/$ts):100/$ts;
  415. $zsbjz = sprintf("%.2f",$dtsbjz*$ts);
  416. }
  417. $post['ts'] = $ts;
  418. $post['dtsbjz'] = $dtsbjz;
  419. $post['zsbjz'] = $zsbjz;
  420. /** **/
  421. //合并重复项
  422. if(!empty($post['fpdata'])){
  423. $hbcfw = explode('|',trim($post['whlabel'],'|'));
  424. $hbcff = explode(';',trim($post['fpdata'],';'));
  425. $c = 0;
  426. $hbw = array();
  427. $hbf = array();
  428. for($i=0;$i<count($hbcfw);$i++)
  429. {
  430. $w = explode('-',$hbcfw[$i]);
  431. $f = explode('|',$hbcff[$i]);
  432. $w2 = ($w[2]==0)?0:'';
  433. if(!isset($hbw[$w[0].$w2]))
  434. {
  435. $hbw[$w[0].$w2] = $hbcfw[$i];
  436. $hbf[$w[0].$w2] = $hbcff[$i];
  437. }
  438. else
  439. {
  440. $c++;
  441. $cw = explode('-',$hbw[$w[0].$w2]);
  442. $cf = explode('|',$hbf[$w[0].$w2]);
  443. if($cw[2] != 0 && $w[2] != 0)
  444. {
  445. $cf[2] += $f[2];
  446. $cf[9] .= '~'.$f[9];
  447. $hbf[$w[0].$w2] = implode("|",$cf);
  448. $cw[1] += $f[2];
  449. $cw[2] .= '~'.$f[9];
  450. $hbw[$w[0].$w2] = implode("-",$cw);
  451. }
  452. else if($cw[2] == 0 && $w[2] == 0)
  453. {
  454. $cf[2] += $f[2];
  455. $hbf[$w[0].$w2] = implode("|",$cf);
  456. $cw[1] += $f[2];
  457. $hbw[$w[0].$w2] = implode("-",$cw);
  458. }
  459. else
  460. {
  461. $hbw[] = $hbcfw[$i];
  462. $hbf[] = $hbcff[$i];
  463. }
  464. }
  465. }
  466. if($c > 0)
  467. {
  468. $post['fpdata'] = implode(";",$hbf).';';
  469. $post['whlabel'] = '|'.implode("|",$hbw).'|';
  470. }
  471. //合并重复项结束
  472. //非占单设置为禁止占单开始
  473. $hbw = explode('|',trim($post['whlabel'],'|'));
  474. $hbf = explode(';',trim($post['fpdata'],';'));
  475. foreach ($hbw as $k=>$val)
  476. {
  477. $w = explode('-',$val);
  478. $f = explode('|',$hbf[$k]);
  479. if(!isset($w[2]) || $w[2] == 0)
  480. {
  481. $w[2] = "DNOTO";
  482. $f[9] = "DNOTO";
  483. $hbf[$k] = implode("|",$f);
  484. $hbw[$k] = implode("-",$w);
  485. }
  486. }
  487. $post['fpdata'] = implode(";",$hbf).';';
  488. $post['whlabel'] = '|'.implode("|",$hbw).'|';
  489. //非占单设置为禁止占单结束
  490. //查询净重开始
  491. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  492. }
  493. //查询净重结束
  494. $tjid = $this->fullorderxw->insert($post);
  495. if($post['email'] == '')
  496. {
  497. $post['email'] = $post['name'].'@qq.com';
  498. }
  499. $adrs = $this->customerxw->get_email($post['email'],$post['shop']);
  500. preg_match_all('/[0-9]/u',$post['phone'],$result);
  501. $numphone = join('',$result[0]);
  502. $hmdaddress1 = str_replace(array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),strtolower($post['address']));
  503. $hmdaddress2 = str_replace(array(' pkwy',' dr',' st',' rd',' av',' blvd',' aly',' ct',' pl',' ln',' mnr',' ter',' trl',' vw',' cv'),array(' parkway',' drive',' street',' road',' avenue',' boulevard',' alley',' court',' place',' lane',' manor',' terrace',' trail',' view',' cove'),strtolower($post['address']));
  504. $hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($post['address']));
  505. $hmdid = '';
  506. $customerb = $this->customerxw->find_all("type = 2 and (email = '".$post['email']."' or address = '".$post['address']."' or address = '".$hmdaddress1."' or address = '".$hmdaddress2."' or address = '".$hmdaddress3."' or numphone = '".$numphone."')",'*','id desc');
  507. $lkh = (isset($customerb[0]['id']))?2:1;//白名单1黑名单2
  508. if($lkh == 2)
  509. {
  510. $hmdid = $customerb[0]['id'].'-('.$post['email'].'|'.$post['address'].'|'.$numphone.')'.'('.$customerb[0]['email'].'|'.$customerb[0]['address'].$customerb[0]['numphone'].')';
  511. }
  512. if($adrs)
  513. {
  514. $pdlkh = 1;//这个是判断是否老客户
  515. $this->customerxw->save(array('time'=>$post['dtime'],'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']);
  516. $khid = $adrs['id'];
  517. }
  518. else
  519. {
  520. $str = $post['phone'];
  521. preg_match_all('/[0-9]/u',$str,$result);
  522. $numphone = join('',$result[0]);
  523. $ct['shop'] = $post['shop'];
  524. $ct['source'] = 10;
  525. $ct['level'] = 5;
  526. $ct['country'] = $post['country'];
  527. $ct['time'] = $post['dtime'];
  528. $ct['num'] = 1;
  529. $ct['money'] = $post['shouldmoney'];
  530. $ct['zipcode'] = $post['zipcode'];
  531. $ct['name'] = $post['name'];
  532. $ct['phone'] = $post['phone'];
  533. $ct['numphone'] = $numphone;
  534. $ct['email'] = preg_replace('/( | | |\s)+/','',$post['email']);
  535. $ct['province'] = $post['province'];
  536. $ct['city'] = $post['city'];
  537. $ct['address'] = $post['address'];
  538. $ct['zhcx'] = $post['shop'].'-'.$ct['email'];
  539. $khid = $this->customerxw->insert($ct);
  540. $pdlkh = 0;
  541. }
  542. //$this->_znxc($post,$order_id,$lkh,$pdlkh,$hmdid);
  543. }//else{}如果有此订单
  544. }
  545. }
  546. if ($this->db->trans_status() === FALSE)
  547. {
  548. $this->db->trans_commit();
  549. }
  550. else
  551. {
  552. $this->db->trans_commit();
  553. }
  554. usleep(10);//停留2秒
  555. }
  556. if($tb == 1)
  557. {
  558. echo json_encode(array('msg'=>'有店铺正在同步中,请5分钟后再试!','success'=>true));exit;
  559. }
  560. echo json_encode(array('msg'=>'OK!','success'=>true));exit;
  561. }
  562. }
  563. public function _tb()
  564. {
  565. $api = $this->input->get('api',true);
  566. if(isset($api) && $api = '89757')
  567. {
  568. $xg = $this->fullorderxw->find_all('dlz < 1 and source != 1 and waybill != "" and dtime > "'.(time()-48*3600).'"');
  569. /* 店铺加入键值-j */
  570. $fshop = $this->shop->find_all('1=1');
  571. foreach ($fshop as $v)
  572. {
  573. $datashop[$v['id']] = $v;
  574. }
  575. /* 店铺加入键值-k */
  576. /* 快递加入键值-j */
  577. $fex = $this->express->find_all('1=1');
  578. foreach ($fex as $v)
  579. {
  580. $dataex[$v['id']] = $v;
  581. }
  582. /* 快递加入键值-k */
  583. /* 仓库加入键值-k */
  584. $fwh = $this->warehouse->find_all('1=1');
  585. foreach ($fwh as $v)
  586. {
  587. $datack[$v['id']] = $v;
  588. }
  589. /* 仓库加入键值-j */
  590. //$fs = $this->notice->get_ordertatus(216);//216成功状态
  591. foreach ($xg as $v)
  592. {
  593. $shop = $datashop[$v['shop']];
  594. $ex = $dataex[$v['express']];
  595. $warehouse = $datack[$v['type']];
  596. if($ex['iscode'] != 'Other')
  597. {
  598. //独立站地址更新订单状态、物流信息
  599. @$gx = $this->apixw->get_gx(substr($v['orderinfo'],1),$v['waybill'],$xg,$shop,$ex,$xg['shopify']);
  600. $this->fullorderxw->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$v['id']);
  601. /**
  602. if($gx['res'] == 1 && $fs)
  603. {
  604. $ck = $this->_email($fs['content'],$v,$warehouse['company']);
  605. }
  606. **/
  607. }
  608. sleep(3);//停留2秒
  609. }
  610. }
  611. }
  612. //更新独立站运单信息
  613. public function _waybill($arg_array)
  614. {
  615. $where = "dlz < '1' and state = '207' and ";
  616. if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单,已出库——使用模板3 每天早上8点半 触发发送【昨天早上7点-今天早上7点】出库的
  617. {
  618. $where .= "express = '2' and librarytime > '".strtotime(date("Y-m-d 7:00:0",strtotime("-1 day")))."' and librarytime < '".strtotime(date("Y-m-d 7:00:0",time()))."'";
  619. $readid = 3;
  620. }
  621. else if(date("H",time()) == '21' && date("w",time()) != '0')//二、杭州联邦+杭州联邦-不报关,单独用一个模板—新模板2 每天晚上9点半 触发发送 【昨天晚上9:30——今天晚上9:30】出库的
  622. {
  623. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  624. {
  625. $where .= "(express = '24' or express = '31') and librarytime > '".strtotime(date("Y-m-d 21:00:0",strtotime("-2 day")))."' and librarytime < '".strtotime(date("Y-m-d 21:00:0",time()))."'";
  626. }
  627. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  628. {
  629. $where .= "(express = '24' or express = '31') and librarytime > '".strtotime(date("Y-m-d 21:00:0",strtotime("-1 day")))."' and librarytime < '".strtotime(date("Y-m-d 21:00:0",time()))."'";
  630. }
  631. $readid = 2;
  632. }
  633. else if(date("H",time()) == '19' && date("w",time()) != '0')//其他快递-使用模板1 DHL官方、UPS、DPEX 等系统里打印运单自动有运单号的,出库后当天晚上7点执行。
  634. {
  635. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  636. {
  637. $where .= "express != '2' and express != '24' and express != '31' and printtype = '1' and waybill != '' and librarytime > '".strtotime(date("Y-m-d 19:00:0",strtotime("-2 day")))."' and librarytime < '".strtotime(date("Y-m-d 19:00:0",time()))."'";
  638. }
  639. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  640. {
  641. $where .= "express != '2' and express != '24' and express != '31' and printtype = '1' and waybill != '' and librarytime > '".strtotime(date("Y-m-d 19:00:0",strtotime("-1 day")))."' and librarytime < '".strtotime(date("Y-m-d 19:00:0",time()))."'";
  642. }
  643. $readid = 1;
  644. }
  645. else
  646. {
  647. exit;
  648. }
  649. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  650. // 订单加入键值-k
  651. $fdata = $this->fullorderxw->find_all($where);//,'source,id,orderinfo,waybill,shop,express,type,msg,bname,state,client,name,phone,zipcode,address,email,shopify'
  652. //* 订单加入键值-j
  653. //* 店铺加入键值-j
  654. $fshop = $this->shop->find_all('1=1');
  655. foreach ($fshop as $v)
  656. {
  657. $datashop[$v['id']] = $v;
  658. }
  659. //* 店铺加入键值-k
  660. //* 快递加入键值-j
  661. $fex = $this->express->find_all('1=1');
  662. foreach ($fex as $v)
  663. {
  664. $dataex[$v['id']] = $v;
  665. }
  666. //* 快递加入键值-k
  667. //* 仓库加入键值-k
  668. $fwh = $this->warehouse->find_all('1=1');
  669. foreach ($fwh as $v)
  670. {
  671. $datack[$v['id']] = $v;
  672. }
  673. //* 仓库加入键值-j
  674. $i = 0;$j = 0;$ed = array();
  675. foreach ($fdata as $key=>$value)
  676. {
  677. if($value['source'] == 1)
  678. {
  679. $this->fullorderxw->save(array('dlz'=>3,'state'=>216),$value['id']);
  680. }
  681. else
  682. {
  683. $ddh = substr($value['orderinfo'],1);
  684. $ydh = $value['waybill'];
  685. $xg = $value;//此订单数据
  686. $shop = $datashop[$xg['shop']];//此订单店铺
  687. $ex = $dataex[$xg['express']];//此订单快递
  688. $warehouse = $datack[$xg['type']];//此订单仓库
  689. $shopifyid = $value['shopify'];
  690. @$gx = $this->apixw->get_gx($ddh,$ydh,$xg,$shop,$ex,$readid,$shopifyid);
  691. if(!isset($gx['res']))
  692. {
  693. continue;
  694. }
  695. $this->fullorderxw->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$value['id']);
  696. }
  697. sleep(4);
  698. }
  699. $this->_kcjc();
  700. }
  701. public function _kcjc()
  702. {
  703. $gethl = $this->whlabel->find_all("zd != '' and state = '0'");
  704. $b = array();
  705. foreach ($gethl as $k=>$v)
  706. {
  707. $a = $this->fullorderxw->get_number($v['zd']);
  708. if($a['librarytime'] > 0 && $a['library'] == 2)
  709. {
  710. //$b[] = array($v['sku'],$v['zd']);
  711. $this->whlabel->save(array('state'=>1,'orderinfo'=>$a['orderinfo'],'waybill'=>$a['waybill'],'outk'=>$a['librarytime'],'time'=>$a['librarytime']),$v['id']);
  712. }
  713. }
  714. }
  715. public function _waybillemail($arg_array)
  716. {
  717. $this->fullorderxw->save(array('email'=>date("H:i:s",time())),14786);
  718. $urls = array();$sl = 0;$time = time();
  719. if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单
  720. {
  721. $wid = 1;
  722. }
  723. else if(date("H",time()) == '22' && date("w",time()) != '0' && date("i",time()) > '20' && date("i",time()) < '39')//二、杭州联邦+杭州联邦-不报关
  724. {
  725. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  726. {
  727. $wid = 2;
  728. }
  729. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  730. {
  731. $wid = 3;
  732. }
  733. }
  734. else if(date("H",time()) == '20' && date("w",time()) != '0' && date("i",time()) > '20' && date("i",time()) < '39')//其他快递
  735. {
  736. if(date("w",time()) != '1')
  737. {
  738. $wid = 4;
  739. }
  740. else
  741. {
  742. $wid = 5;
  743. }
  744. }
  745. else
  746. {
  747. exit;
  748. }
  749. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '4' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  750. foreach ($notice as $key=>$var)
  751. {
  752. $urls[] = array('url'=>'http://1.wepolicy.cn/api/waybillfs?v='.$var['id'],'data'=>array('var'=>$var,'wid'=>$wid));
  753. }
  754. foreach($urls as $value) {
  755. $ch = curl_init();
  756. $url = $value['url'];
  757. curl_setopt($ch,CURLOPT_URL,$url);
  758. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  759. curl_setopt($ch,CURLOPT_HEADER,0);
  760. curl_setopt($ch,CURLOPT_POST, 1);
  761. curl_setopt($ch,CURLOPT_TIMEOUT,1);
  762. //设置post数据
  763. $post = array();
  764. $post['data'] = $value['data'];
  765. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  766. $res = curl_exec($ch);
  767. curl_close($ch);
  768. $sl++;
  769. }
  770. echo $sl;
  771. echo "<pre>";
  772. print_r($urls);
  773. }
  774. public function _waybillfs()
  775. {
  776. $post = $this->input->post(NULL, TRUE);
  777. $data = $this->input->post('data',true);
  778. if($data)
  779. {
  780. $notice = $data['var'];
  781. $notice['email'] = $this->emaildata->read($notice['email']);
  782. $wid = $data['wid'];
  783. $fsjs = "";
  784. if($wid == 1 && stripos($notice['express'],',2,') !== false)
  785. {
  786. $js = explode(',',trim($notice['js'],','));
  787. if(count($js) > 1)
  788. {
  789. $fsjs = " and (";
  790. foreach ($js as $v)
  791. {
  792. $fsjs .= "js = '$v' or ";
  793. }
  794. $fsjs = trim($fsjs,' or ').")" ;
  795. }
  796. else if(count($js) == 1)
  797. {
  798. $fsjs = " and js = '$js[0]'";
  799. }
  800. $where = "express = '2' and librarytime > '".strtotime(date("Y-m-d 8:30:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 8:30:0",time()))."'".$fsjs;//3
  801. }
  802. else if($wid == 2 && stripos($notice['express'],',1,') !== false)
  803. {
  804. $where = "(express = '24' or express = '31') and librarytime > '".strtotime(date("Y-m-d 22:00:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 22:00:0",time()))."'";//4
  805. }
  806. else if($wid == 3 && stripos($notice['express'],',1,') !== false)
  807. {
  808. $where = "(express = '24' or express = '31') and librarytime > '".strtotime(date("Y-m-d 22:00:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 22:00:0",time()))."'";//3
  809. }
  810. else if($wid == 4 && stripos($notice['express'],',1,') !== false)
  811. {
  812. $where = "express != '2' and express != '24' and express != '31' and printtype = '1' and waybill != '' and librarytime > '".strtotime(date("Y-m-d 20:00:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 20:00:0",time()))."'";//3
  813. }
  814. else if($wid == 5 && stripos($notice['express'],',1,') !== false)
  815. {
  816. $where = "express != '2' and express != '24' and express != '31' and printtype = '1' and waybill != '' and librarytime > '".strtotime(date("Y-m-d 20:00:0",strtotime("-6 day")))."' and librarytime < '".strtotime(date("Y-m-d 20:00:0",time()))."'";//4
  817. }
  818. else
  819. {
  820. exit;
  821. }
  822. $wlfs = array();
  823. $dd = $this->fullorderxw->find_all("source != '1' and dlzemail < '1' and shop = '".$notice['shop']."' and library = 2 and ".$where);
  824. foreach ($dd as $v)
  825. {
  826. $shop = $this->shop->read($v['shop']);
  827. $express = $this->express->read($v['express']);
  828. $fs = $this->notice->get_god($v,$shop,$express,$notice);
  829. if($fs == 1)
  830. {
  831. $this->fullorderxw->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$v['id']);
  832. }
  833. else
  834. {
  835. //$pdtime = date('Y-m-d',time());
  836. //$folderPath = './data/dlzemail/'.$pdtime; // 文件夹路径
  837. //$permissions = 0777; // 权限设置
  838. //if (!file_exists($folderPath)) { mkdir($folderPath, $permissions); }//创建文件夹
  839. //file_exists($folderPath);
  840. if(!is_file("./data/dlzemail/".$v['number'].".txt"))
  841. {
  842. $myfile = fopen("./data/dlzemail/".$v['number'].".txt", "w") or die("Unable to open file!");
  843. fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
  844. fclose($myfile);
  845. }
  846. else
  847. {
  848. $myfile = fopen("./data/dlzemail/".$v['number'].".txt", "a+") or die("Unable to open file!");
  849. fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
  850. fclose($myfile);
  851. }
  852. $this->fullorderxw->save(array('dlzemail'=>2,'dlzemailtime'=>time()),$v['id']);
  853. }
  854. sleep(50);
  855. }
  856. }
  857. }
  858. /**
  859. //更新独立站运单信息
  860. public function _waybill($arg_array)
  861. {
  862. //这里订单索引需要修改 8点是出已打印已出库 11点是已打印未出库
  863. if(!isset($arg_array[0]) || !isset($arg_array[1]))
  864. {
  865. exit;
  866. }
  867. if(date("w",time()) == '0' && $arg_array[0] != '3')//非usps周日不更新
  868. {
  869. echo 7;exit;
  870. }
  871. if($arg_array[0] == 3)
  872. {
  873. $argarray = 2;
  874. $typec = ' and express = 2 and printtime > "'.strtotime("-3 day").'"';//更新usps-usa快递的订单
  875. }
  876. else
  877. {
  878. $argarray = $arg_array[0];
  879. $typec = ' and librarytime > "'.strtotime(date("Y-m-d 16:30:0",strtotime("-5 day"))).'" and librarytime < "'.strtotime(date("Y-m-d 18:0:0",time())).'"';//更新快递的订单
  880. }
  881. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  882. // 订单加入键值-k
  883. $fdata = $this->fullorderxw->find_all('state = "207" and print = "3" and dlz < "1" and libraryconfirm = "2" and library = "'.$argarray.'" and waybill != ""'.$typec,'source,id,orderinfo,waybill,shop,express,type,msg,bname,state,client,name,phone,zipcode,address,email');
  884. //* 订单加入键值-j
  885. //* 店铺加入键值-j
  886. $fshop = $this->shop->find_all('1=1');
  887. foreach ($fshop as $v)
  888. {
  889. $datashop[$v['id']] = $v;
  890. }
  891. //* 店铺加入键值-k
  892. //* 快递加入键值-j
  893. $fex = $this->express->find_all('1=1');
  894. foreach ($fex as $v)
  895. {
  896. $dataex[$v['id']] = $v;
  897. }
  898. //* 快递加入键值-k
  899. //* 仓库加入键值-k
  900. $fwh = $this->warehouse->find_all('1=1');
  901. foreach ($fwh as $v)
  902. {
  903. $datack[$v['id']] = $v;
  904. }
  905. //* 仓库加入键值-j
  906. //$fs = $this->notice->get_ordertatus(216);//216成功状态
  907. $i = 0;$j = 0;$ed = array();
  908. foreach ($fdata as $key=>$value)
  909. {
  910. if($value['source'] == 1)
  911. {
  912. $this->fullorderxw->save(array('dlz'=>3,'state'=>216),$value['id']);
  913. }
  914. else
  915. {
  916. $ddh = substr($value['orderinfo'],1);
  917. $ydh = $value['waybill'];
  918. $xg = $value;//此订单数据
  919. $shop = $datashop[$xg['shop']];//此订单店铺
  920. $ex = $dataex[$xg['express']];//此订单快递
  921. $warehouse = $datack[$xg['type']];//此订单仓库
  922. //独立站地址更新订单状态、物流信息
  923. if($arg_array[0] == 1)//23点更新用留言2
  924. {
  925. $readid = 2;
  926. }
  927. else if($arg_array[0] == 3)//7点更新用留言3
  928. {
  929. $readid = 3;
  930. }
  931. else //20点更新用默认留言(默认留言为1)
  932. {
  933. $readid = $xg['msg'];
  934. }
  935. @$gx = $this->apixw->get_gx($ddh,$ydh,$xg,$shop,$ex,$readid);
  936. if(!isset($gx['res']))
  937. {
  938. exit;
  939. }
  940. $this->fullorderxw->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$xg['id']);
  941. }
  942. //if($gx['res'] == 1 && $fs)
  943. //{
  944. // $ck = $this->_email($fs['content'],$xg,$warehouse['company']);
  945. //}
  946. sleep(2);//停留2秒
  947. }
  948. }
  949. **/
  950. public function _headgear($arg_array)
  951. {
  952. $ip = $this->input->ip_address();
  953. if(!isset($arg_array[0]) || !isset($arg_array[1]))
  954. {
  955. exit;
  956. }
  957. if(!is_numeric($arg_array[0]) || !is_numeric($arg_array[1]))
  958. {
  959. exit;
  960. }
  961. $where = 'printtime > "'.strtotime(date('Y-m-d',$arg_array[0])).'" and print = 3 and library = 1 and (type = 4 or type = 13 or type = 11 or type = 12 or type = 16)';//(type = 4 or type = 7)
  962. if($arg_array[1] == 1)
  963. {
  964. $data = $this->fullordersmt->find_all($where,'express,number,orderinfo,shipremarks,printtime');
  965. }
  966. else
  967. {
  968. $data = $this->fullorderxw->find_all($where,'express,number,orderinfo,shipremarks,printtime');
  969. }
  970. foreach ($data as $k=>$v)
  971. {
  972. $express = $this->express->read($v['express']);
  973. $data[$k]['express'] = $express['servicename'];
  974. if($data[$k]['printtime'] > 0)
  975. {
  976. $data[$k]['printtime'] = date('Y-m-d H:i:s',$v['printtime']);
  977. }
  978. }
  979. //$state = $this->apixw->get_headgear($data);
  980. echo json_encode($data);
  981. }
  982. public function _kc_old()
  983. {
  984. $post = $this->input->post(NULL, TRUE);
  985. if(isset($post['sku']))
  986. {
  987. $sku = $this->input->post('sku',true);
  988. $warehouse = $this->warehouse->find_all();
  989. $data = array();
  990. foreach ($sku as $val)
  991. {
  992. $datasku = array();
  993. foreach ($warehouse as $v)
  994. {
  995. $z = $this->whlabel->find_count('sku = "'.$val.'" and zd = "" and state = 0 and warehouse = "'.$v['id'].'"');
  996. $datasku[] = array('name'=>$v['title'],'number'=>$z);
  997. }
  998. $data[$val] = $datasku;
  999. }
  1000. }
  1001. echo json_encode($data);
  1002. }
  1003. public function _kc()
  1004. {
  1005. $datasku = array();
  1006. $info_list = $this->whlabel->find_pc("warehouse = '5'",'sku,features,warehouse','sku');
  1007. foreach ($info_list as $val)
  1008. {
  1009. $z = $this->whlabel->find_count('sku = "'.$val['sku'].'" and zd = "" and state = 0 and warehouse = "5"');
  1010. $datasku[] = array('sku'=>$val['sku'],'number'=>$z);
  1011. }
  1012. echo json_encode($datasku);
  1013. }
  1014. public function _fsstate()//订单消息页手动发送
  1015. {
  1016. $post = $this->input->post(NULL, TRUE);
  1017. if(isset($post['s']))
  1018. {
  1019. $id_arr = $this->input->post('s');
  1020. $notice = $this->input->post('notice');
  1021. $noticeid = $this->input->post('noticeid');
  1022. $id_arr = explode(',',trim($id_arr,','));
  1023. if(!$id_arr)
  1024. {
  1025. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1026. }
  1027. if($notice == '1' || $notice == '')
  1028. {
  1029. foreach ($id_arr as $v)
  1030. {
  1031. $data = $this->fullorderxw->read($v);
  1032. $adrs = $this->customerxw->get_email($data['email'],$data['shop']);
  1033. //$lkh = ($adrs['type'] == 1)?1:2;//白名单1黑名单2
  1034. $lkh = 1;
  1035. $pdlkh = ($adrs['num'] > 1)?1:0;//判断是否老客户
  1036. $fs = $this->_znxc($data,$data['orderinfo'],$lkh,$pdlkh);
  1037. if($fs == 1)
  1038. {
  1039. $this->fullorderxw->save(array('exstateerror'=>''),$data['id']);
  1040. }
  1041. sleep(40);
  1042. }
  1043. }
  1044. else
  1045. {
  1046. foreach ($id_arr as $v)
  1047. {
  1048. $data = $this->fullorderxw->read($v);
  1049. $fs = $this->_sdfs($data,$noticeid);
  1050. sleep(40);
  1051. }
  1052. }
  1053. echo json_encode(array('msg'=>'发送完成!','id'=>$id_arr,'success'=>true));exit;
  1054. }
  1055. }
  1056. public function _cangku()
  1057. {
  1058. $post = $this->input->post(NULL, TRUE);
  1059. if(isset($post['tk']))
  1060. {
  1061. $tk = $this->input->post('tk');
  1062. $tj = $this->input->post('tj');
  1063. $d = $this->fullorderxw->find_all("dtime > '$tk' and dtime < '$tj'");
  1064. $k = $this->customerxw->find_all("time > '$tk' and time < '$tj'");
  1065. echo json_encode(array('d'=>$d,'k'=>$k));exit;
  1066. }
  1067. }
  1068. public function _znxc($fullorder,$order_id,$lkh,$pdlkh,$hmdid='')
  1069. {
  1070. exit;
  1071. $time = time();
  1072. $sl = explode(';',$fullorder['quantity']);
  1073. $quantity = 0;
  1074. foreach ($sl as $v)
  1075. {
  1076. if($v > 1)
  1077. {
  1078. $quantity = 1;
  1079. }
  1080. }
  1081. $fid = $this->fullorderxw->get_orderinfo($order_id);
  1082. if($lkh == 2 || (count($sl) > 1 && $quantity == 1) || stripos($fullorder['address'],'PO ') !== false || stripos($fullorder['address'],'P.O.') !== false || stripos($fullorder['address'],'P. O.') !== false || stripos($fullorder['address'],'PO.') !== false || stripos($fullorder['address'],'P.O') !== false || stripos($fullorder['address'],' APO ') !== false)//如果是黑名单客户、多产品的、有用户留言的、包含PO BOX、包含APO //留言的正常发$fullorder['clientremarks'] != '' ||
  1083. {
  1084. $asdasd = 0;
  1085. if($lkh == 2)
  1086. {
  1087. $asdasd = 1;
  1088. }
  1089. if(count($sl) > 1 && $quantity == 1)
  1090. {
  1091. $asdasd = 2;
  1092. }
  1093. if(stripos($fullorder['address'],'PO ') !== false || stripos($fullorder['address'],'P.O.') !== false || stripos($fullorder['address'],'P. O.') !== false || stripos($fullorder['address'],'PO.') !== false || stripos($fullorder['address'],'P.O') !== false || stripos($fullorder['address'],' APO ') !== false)
  1094. {
  1095. $asdasd = 3;
  1096. }
  1097. $this->fullorderxw->save(array('content'=>$fid['content'].'黑名单客户、多产品的、包含PO BOX、包含APO的不发送-'.$asdasd.(($hmdid)?'['.$hmdid.']':''),'zdstate'=>$fid['zdstate'].'1-x|'),$fid['id']);//留言的现在正常发
  1098. return 'a';
  1099. }
  1100. else
  1101. {
  1102. /**
  1103. if($fullorder['shouldmoney'] > '400' && $fullorder['guarantee'] == 'Ineligible')//如果金额大于400美元并且无卖家保障
  1104. {
  1105. $tab = 1;
  1106. }
  1107. else if(count($sl) == '1' && $fullorder['quantity'] > 1 && $fullorder['baddress'] != $fullorder['saddress'])//如果item(产品)是1,但quantity大于等于2并且Bill Address不等于Ship Address
  1108. {
  1109. $tab = 4;
  1110. }
  1111. else if($fullorder['baddress'] != $fullorder['saddress'])//如果Bill Address不等于Ship Address
  1112. {
  1113. $tab = 3;
  1114. }
  1115. **/
  1116. if(count($sl) == '1' && $fullorder['quantity'] > 1)//如果item(产品)是1,但quantity大于等于2
  1117. {
  1118. $tab = 2;
  1119. }
  1120. else//常规模板
  1121. {
  1122. $tab = 0;
  1123. }
  1124. $notice = $this->notice->find_all("shop = '".$fullorder['shop']."' and ordertatus = '".$fullorder['state']."' and tab = '$tab' and message = '1' and state = '1' and ktime < '$time' and jtime > '$time'");//有条件不同模板匹配
  1125. if(isset($notice[0]['content']))
  1126. {
  1127. if($pdlkh == '1' && $notice[0]['thq'] != ''&& $notice[0]['thh'] != '')//非常规和老客户模板,如果是老客户并且需要替换的话
  1128. {
  1129. $notice[0]['content'] = str_replace($notice[0]['thq'],$notice[0]['thh'],$notice[0]['content']);
  1130. }
  1131. $shop = $this->shop->read($fullorder['shop']);
  1132. //$express = $this->express->read($fullorder['express']);
  1133. //$service = $this->service->read($express['service']);
  1134. $country = $this->country->read($fullorder['country']);
  1135. $fullorder['country'] = $country['ename'];
  1136. //$express['servicename'] =$service['title'];//增加快递名称
  1137. $express = array();
  1138. $notice[0]['email'] = $this->emaildata->read($notice[0]['email']);
  1139. $go = $this->notice->get_god($fullorder,$shop,$express,$notice[0]);
  1140. if($go == 1)
  1141. {
  1142. $this->fullorderxw->save(array('content'=>$fid['content'].'自动发送-成功;','zdstate'=>$fid['zdstate'].$notice[0]['type'].'-'.$notice[0]['tab'].'|','exstateerror'=>''),$fid['id']);
  1143. return 1;
  1144. }
  1145. else
  1146. {
  1147. $this->fullorderxw->save(array('exstateerror'=>'自动发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice[0]['type'].'-'.$notice[0]['message'].')'),$fid['id']);
  1148. }
  1149. }
  1150. else
  1151. {
  1152. $this->fullorderxw->save(array('exstateerror'=>'当前订单状态无匹配模板'),$fid['id']);
  1153. }
  1154. }
  1155. }
  1156. public function _sdfs($fullorder,$id)//手动发送信息
  1157. {
  1158. $time = time();
  1159. $notice = $this->notice->read($id);//无条件同模板匹配
  1160. $notice['email'] = $this->emaildata->read($notice['email']);
  1161. $shop = $this->shop->read($fullorder['shop']);
  1162. $express = $this->express->read($fullorder['express']);
  1163. if($notice['type'] == '1')
  1164. {
  1165. $fslx = 'tab';
  1166. $content = '自动发送';
  1167. $stripos = '1-';
  1168. }
  1169. else if ($notice['type'] == '2')
  1170. {
  1171. $fslx = 'logisticstatus';
  1172. $content = $notice['title'];
  1173. $stripos = $notice['type'].'-'.$notice[$fslx].'|';
  1174. }
  1175. if(stripos($fullorder['zdstate'],$stripos) === false && $fullorder['wltype'] == '0')//如果没发送过并且允许发送
  1176. {
  1177. $go = $this->notice->get_god($fullorder,$shop,$express,$notice);
  1178. if($go == 1)
  1179. {
  1180. if($notice['type'] == '1')
  1181. {
  1182. $this->fullorderxw->save(array('content'=>$fullorder['content'].$content.'-成功;','zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  1183. }
  1184. else if ($notice['type'] == '2')
  1185. {
  1186. $this->fullorderxw->save(array('wlcontent'=>$fullorder['wlcontent'].$content.'-成功;','wlfstime'=>time(),'zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  1187. }
  1188. return 1;
  1189. }
  1190. else
  1191. {
  1192. if($notice['type'] == '1')
  1193. {
  1194. $this->fullorderxw->save(array('exstateerror'=>$content.'发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  1195. }
  1196. else if ($notice['type'] == '2')
  1197. {
  1198. $this->fullorderxw->save(array('wlerror'=>$content.'发送失败2:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  1199. }
  1200. }
  1201. }
  1202. }
  1203. public function _zz()
  1204. {
  1205. //$f = $this->fullorderxw->find_all("1=1",'wlfstime','wlfstime desc',0,2);
  1206. if(date("w") == '0')
  1207. {
  1208. exit;
  1209. }
  1210. $time = time();
  1211. $tjlike = array();
  1212. $urls = array();$sl = 0;
  1213. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1214. foreach ($notice as $key=>$var)
  1215. {
  1216. $urls[] = array('url'=>'http://a'.rand(10,50).'.wepolicy.cn/api/wlfs?v='.$var['id'],'data'=>array('where'=>array('shop'=>$var['shop'],'expressstate'=>$var['logisticstatus'],'wlcontent'=>$var['title']),'var'=>$var));
  1217. }
  1218. foreach($urls as $value) {
  1219. $tjlike[] = $value['url'];
  1220. $ch = curl_init();
  1221. $url = $value['url'];
  1222. curl_setopt($ch,CURLOPT_URL,$url);
  1223. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1224. curl_setopt($ch,CURLOPT_HEADER,0);
  1225. curl_setopt($ch,CURLOPT_POST, 1);
  1226. curl_setopt($ch,CURLOPT_TIMEOUT,5);
  1227. //设置post数据
  1228. $post = array();
  1229. $post['data'] = $value['data'];
  1230. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1231. $res = curl_exec($ch);
  1232. curl_close($ch);
  1233. $sl++;
  1234. }
  1235. echo "<pre>";
  1236. print_r($tjlike);
  1237. echo $sl;
  1238. /**
  1239. $urls = array();
  1240. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1241. foreach ($notice as $key=>$var)
  1242. {
  1243. $urls[] = array('url'=>'http://1.wepolicy.cn/api/wlfs?v='.$var['id'],'data'=>array('where'=>array('shop'=>$var['shop'],'expressstate'=>$var['logisticstatus'],'wlcontent'=>$var['title']),'var'=>$var));
  1244. }
  1245. $mh = curl_multi_init();
  1246. $urlHandlers = array();
  1247. $urlData = array();
  1248. // 初始化多个请求句柄为一个
  1249. foreach($urls as $value) {
  1250. $ch = curl_init();
  1251. $url = $value['url'];
  1252. $url .= strpos($url, '?') ? '&' : '?';
  1253. curl_setopt($ch, CURLOPT_URL, $url);
  1254. // 设置数据通过字符串返回,而不是直接输出
  1255. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1256. curl_setopt($ch,CURLOPT_HEADER,0);
  1257. curl_setopt($ch,CURLOPT_POST, 1);
  1258. $post = array();
  1259. $post['data'] = $value['data'];
  1260. curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($post));
  1261. $urlHandlers[] = $ch;
  1262. curl_multi_add_handle($mh, $ch);
  1263. }
  1264. $active = null;
  1265. // 检测操作的初始状态是否OK,CURLM_CALL_MULTI_PERFORM为常量值-1
  1266. do {
  1267. // 返回的$active是活跃连接的数量,$mrc是返回值,正常为0,异常为-1
  1268. $mrc = curl_multi_exec($mh, $active);
  1269. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  1270. // 如果还有活动的请求,同时操作状态OK,CURLM_OK为常量值0
  1271. while ($active && $mrc == CURLM_OK) {
  1272. // 持续查询状态并不利于处理任务,每60ms检查一次,此时释放CPU,降低机器负载
  1273. usleep(50000);
  1274. // 如果批处理句柄OK,重复检查操作状态直至OK。select返回值异常时为-1,正常为1(因为只有1个批处理句柄)
  1275. if (curl_multi_select($mh) != -1) {
  1276. do {
  1277. $mrc = curl_multi_exec($mh, $active);
  1278. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  1279. }
  1280. }
  1281. // 获取返回结果
  1282. foreach($urlHandlers as $index => $ch) {
  1283. $urlData[$index] = curl_multi_getcontent($ch);
  1284. // 移除单个curl句柄
  1285. curl_multi_remove_handle($mh, $ch);
  1286. }
  1287. curl_multi_close($mh);
  1288. print_r($urlData);
  1289. **/
  1290. /**
  1291. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1292. foreach ($notice as $key=>$var)
  1293. {
  1294. $where = "shop = '".$var['shop']."' and waybill != '' and library = '2' and expressstate <= '".$var['logisticstatus']."' and librarytime > '".(time()-15*24*3600)."' and wlcontent not like '%".$var['title']."%'";//正式发送的时候开启这个"'
  1295. //$where = "shop = '2' and waybill != '' and library = '2' and librarytime > '".(time()-15*24*3600)."'";
  1296. $ch = curl_init();
  1297. curl_setopt($ch,CURLOPT_URL,'http://'.$_SERVER['HTTP_HOST'].'/api/wlfs?v='.$var['id']);
  1298. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1299. curl_setopt($ch,CURLOPT_HEADER,0);
  1300. curl_setopt($ch,CURLOPT_POST, 1);
  1301. curl_setopt($ch,CURLOPT_TIMEOUT,1);
  1302. //设置post数据
  1303. $post = array();
  1304. $post['data'] = array('where'=>$where,'var'=>$var);
  1305. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1306. $res = curl_exec($ch);
  1307. curl_close($ch);
  1308. //$this->_wlfs($where,$var);
  1309. }
  1310. **/
  1311. /**
  1312. $var = $this->notice->read(63);//已有自动发送,这个是物流发送
  1313. $where = "shop = '".$var['shop']."' and waybill != '' and library = '2' and expressstate <= '".$var['logisticstatus']."' and librarytime > '".(time()-15*24*3600)."' and wlcontent not like '%".$var['title']."%'";//正式发送的时候开启这个"'
  1314. $this->_wlfs($where,$var);
  1315. **/
  1316. }
  1317. public function _wlfs()
  1318. {
  1319. $webhookregister = 0;
  1320. $post = $this->input->post(NULL, TRUE);
  1321. $data = $this->input->post('data',true);
  1322. $where = $data['where'];
  1323. $var = $data['var'];
  1324. $wlfs = array();
  1325. $shopid = $where['shop'];
  1326. @$this->allocation->insert(array('title'=>date('Y-m-d',time()).'-'.$shopid));
  1327. $where = "shop = '".$where['shop']."' and waybill != '' and library = '2' and expressstate <= '".$where['expressstate']."' and librarytime > '".(time()-22*24*3600)."' and wlcontent not like '%".$where['wlcontent']."%'";//正式发送的时候开启这个"'
  1328. //$where = "shop = '".$where['shop']."' and waybill != '' and library = '2' and express = '3' and librarytime > '1636300800' and wlcontent not like '%".$where['wlcontent']."%'";//正式发送的时候开启这个"'
  1329. $data = $this->fullorderxw->find_all($where);
  1330. $csck = array();
  1331. foreach ($data as $k=>$v)
  1332. {
  1333. $vexpress = $v['express'];
  1334. $shop = $this->shop->read($v['shop']);
  1335. $express = $this->express->read($v['express']);
  1336. $service = $this->service->read($express['service']);
  1337. $country = $this->country->read($v['country']);
  1338. $v['country'] = $country['ename'];
  1339. $express['servicename'] =$service['title'];//增加快递名称
  1340. $v['cxcode'] = strtolower($express['cxcode']);//增加快递服务商码
  1341. if($v['expressstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1342. {
  1343. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1344. {
  1345. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1346. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1347. }
  1348. continue;
  1349. }
  1350. if(($express['cxcode'] == '' && $v['exstateerror'] == '') || ($express['cxcode'] == '' && $v['exstateerror'] != ''))
  1351. {
  1352. continue;
  1353. }
  1354. else if($express['cxcode'] == 'fedex' || $express['cxcode'] == 'usps' || $express['cxcode'] == 'dhl')// || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd'
  1355. {
  1356. /**
  1357. if($express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
  1358. {
  1359. $express['cxcode'] = 'cne';
  1360. }
  1361. **/
  1362. $logistics = $express['cxcode'];
  1363. }
  1364. else if(($express['cxcode'] == 'ups' || $express['cxcode'] == '17track') && $v['webhookregister'] == 1)
  1365. {
  1366. continue;
  1367. }
  1368. else if(($express['cxcode'] == 'ups' || $express['cxcode'] == '17track') && $v['webhookregister'] < 1)//使用webhook注册模式 || $express['cxcode'] == '17track'
  1369. {
  1370. $logistics = $express['cxcode'];
  1371. $webhookregister = 1;
  1372. }
  1373. else
  1374. {
  1375. //暂时不启用第三方,这里直接跳出
  1376. $this->fullorderxw->save(array('expressstate'=>'99'),$v['id']);
  1377. continue;
  1378. //$logistics = 'apismt';
  1379. //$v['express'] = strtolower($express['cxcode']);//替换为快递服务商码
  1380. }
  1381. $v['servicename'] =$service['title'];//增加快递名称
  1382. $v['url'] = $express['url'];//增加快递链接
  1383. @$fs = $this->$logistics->get_logistics($v);
  1384. $csck[] = array($v['number'],$fs['f']);
  1385. if(!isset($fs['f']))
  1386. {
  1387. $fs = $this->$logistics->get_logistics($v);
  1388. if(!isset($fs['f']))
  1389. {
  1390. continue;
  1391. }
  1392. if($fs['f'] == '1')
  1393. {
  1394. $v['express'] = $vexpress;
  1395. if($fs['exstate'] > $v['expressstate'] || isset($fs['webhookregister']))
  1396. {
  1397. $this->fullorderxw->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister),$v['id']);
  1398. }
  1399. if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1400. {
  1401. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1402. {
  1403. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1404. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1405. }
  1406. }
  1407. }
  1408. /**
  1409. if($logistics == 'apismt')//第三方未购买,第三方查询直接进入无法查询状态
  1410. {
  1411. $this->fullorderxw->save(array('expressstate'=>'99'),$v['id']);
  1412. }
  1413. **/
  1414. }
  1415. else
  1416. {
  1417. if($fs['f'] == '1')
  1418. {
  1419. $v['express'] = $vexpress;
  1420. if($fs['exstate'] > $v['expressstate'])
  1421. {
  1422. $this->fullorderxw->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister),$v['id']);
  1423. }
  1424. if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1425. {
  1426. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1427. {
  1428. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1429. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1430. }
  1431. }
  1432. }
  1433. }
  1434. }
  1435. @$this->allocation->insert(array('title'=>$shopid.'-'.json_encode($csck)));
  1436. if($wlfs)
  1437. {
  1438. foreach ($wlfs as $k=>$v)
  1439. {
  1440. $t1 = microtime(true);
  1441. $this->_sdfs($v['v'],$v['id']);
  1442. $t2 = microtime(true);
  1443. $t3 = (40-($t2-$t1) < 1)?1:round(40-($t2-$t1));
  1444. sleep($t3);
  1445. }
  1446. }
  1447. }
  1448. public function _zzold()
  1449. {
  1450. $data = $this->fullorderxw->find_all("library = '2' and waybill != '' and exstate != '4' and exstate != '5' and dtime > '1580486400'");
  1451. foreach ($data as $k=>$v)
  1452. {
  1453. $shop = $this->shop->read($v['shop']);
  1454. $express = $this->express->read($v['express']);
  1455. $service = $this->service->read($express['service']);
  1456. $country = $this->country->read($v['country']);
  1457. $v['country'] = $country['ename'];
  1458. $express['servicename'] =$service['title'];//增加快递名称
  1459. if($express['cxcode'] == '' && $v['exstateerror'] == '')
  1460. {
  1461. continue;
  1462. }
  1463. else if($express['cxcode'] == '' && $v['exstateerror'] != '')
  1464. {
  1465. continue;
  1466. }
  1467. else if($express['cxcode'] == 'fedex' || $express['cxcode'] == 'usps' || $express['cxcode'] == 'dhl' || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
  1468. {
  1469. $logistics = $express['cxcode'];
  1470. }
  1471. else
  1472. {
  1473. $logistics = 'apismt';
  1474. }
  1475. $v['express'] = strtolower($express['cxcode']);//替换为快递服务商码
  1476. $v['servicename'] =$service['title'];//增加快递名称
  1477. $v['url'] = $express['url'];//增加快递链接
  1478. $fs = $this->$logistics->get_logistics($v);
  1479. if(!isset($fs['f']))
  1480. {
  1481. $this->fullorderxw->save(array('exstate'=>'99'),$v['id']);
  1482. }
  1483. else
  1484. {
  1485. if($fs['f'] == '0')
  1486. {
  1487. $this->fullorderxw->save(array('excontent'=>$fs['content']),$v['id']);
  1488. }
  1489. if($fs['f'] == '2')
  1490. {
  1491. }
  1492. else
  1493. {
  1494. $this->fullorderxw->save(array('exstate'=>$fs['exstate'],'excontent'=>$fs['data']),$v['id']);
  1495. }
  1496. }
  1497. }
  1498. }
  1499. public function _query()
  1500. {
  1501. header('Access-Control-Allow-Origin: *');
  1502. $post = $this->input->post(NULL, TRUE);
  1503. if(isset($post['orderinfo']))
  1504. {
  1505. $list = array();
  1506. $orderinfo = $this->input->post('orderinfo',true);
  1507. $orderinfo = explode(',',trim($orderinfo,','));
  1508. foreach ($orderinfo as $v)
  1509. {
  1510. $exp="/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
  1511. if(is_numeric($v) && mb_strlen($v) > 8)
  1512. {
  1513. $w = "orderinfo like '%$v%'";
  1514. }
  1515. else if(filter_var($v, FILTER_VALIDATE_EMAIL))
  1516. {
  1517. $w = "email like '%$v%'";
  1518. }
  1519. else
  1520. {
  1521. echo json_encode(array('site'=>0,'success'=>true));exit;
  1522. }
  1523. $data = $this->fullorderxw->find_all($w." and dtime > '1577811600'");
  1524. if(isset($data[0]))
  1525. {
  1526. if($data[0]['library'] != '2')
  1527. {
  1528. $list[] = array('orderinfo'=>$v,'site'=>1);
  1529. }
  1530. else if($data[0]['library'] == '2' && $data[0]['exstate'] == '99')
  1531. {
  1532. $list[] = array('orderinfo'=>$v,'site'=>2);
  1533. }
  1534. else if($data[0]['library'] == '2' && $data[0]['exstate'] != '99')
  1535. {
  1536. if($data[0]['excontent'] != '成功;' && $data[0]['excontent'] != '')
  1537. {
  1538. $list[] = array('orderinfo'=>$v,'site'=>3,'data'=>$data[0]['excontent']);
  1539. }
  1540. else
  1541. {
  1542. $list[] = array('orderinfo'=>$v,'site'=>2);
  1543. }
  1544. }
  1545. }
  1546. else
  1547. {
  1548. $list[] = array('orderinfo'=>$v,'site'=>0);
  1549. }
  1550. }
  1551. echo json_encode(array('t'=>count($orderinfo),'list'=>$list,'success'=>true));exit;
  1552. }
  1553. }
  1554. public function _logistics()
  1555. {
  1556. if(isset($_GET['waybill']))
  1557. {
  1558. $waybill = $this->input->get('waybill',true);
  1559. if($waybill == 1231233123)
  1560. {
  1561. $data = $this->fullorderxw->get_number('ASTE-30922-034');
  1562. echo json_encode(array('track'=>array('f'=>1,'data'=>$data['excontent']),'msg'=>'','success'=>1));exit;
  1563. }
  1564. //$express = $this->input->get('express',true);
  1565. $data = $this->fullorderxw->get_waybill($waybill);
  1566. if($data['excontent'])
  1567. {
  1568. //$a = $this->$express->get_logistics(array('waybill'=>$waybill));
  1569. echo json_encode(array('track'=>array('f'=>1,'data'=>$data['excontent']),'msg'=>'','success'=>1));exit;
  1570. }
  1571. else
  1572. {
  1573. echo json_encode(array('track'=>'','msg'=>'No logistics information','success'=>0));exit;
  1574. }
  1575. }
  1576. }
  1577. public function _klarna()
  1578. {
  1579. $shop = array();$cg = array();$sb = array();
  1580. $ftime = strtotime(date("Y-m-d 0:00:0",strtotime("-10 day")))+8*3600;
  1581. $ttime = strtotime(date("Y-m-d 8:00:0",time()));
  1582. $shopdata = $this->shop->find_all("type = '269' and klarnaname != '' and klarnapass != ''");
  1583. foreach($shopdata as $v)
  1584. {
  1585. $data = $this->fullorderxw->find_all("paypal like '%-%-%-%' and librarytime > '$ftime' and librarytime < '$ttime' and pay = '23' and library = '2' and source != '1' and klarna < '2' and shop = '".$v['id']."'","id,number,orderinfo,paypal,shouldmoney,shop");
  1586. foreach($data as $val)
  1587. {
  1588. $api = $this->_klarnaapi($val['paypal'],$val['shouldmoney'],$v['klarnaname'],$v['klarnapass']);
  1589. $header = $api['header'];
  1590. $api = $api['res'];
  1591. if(isset($api['error_messages'][0]))
  1592. {
  1593. if(stripos($api['error_messages'][0],'amount is 0 for') !== false)
  1594. {
  1595. $this->fullorderxw->save(array('klarna'=>3),$val['id']);
  1596. $sb[] = array($val['number'],$val['orderinfo'],'oooo3');
  1597. }
  1598. else
  1599. {
  1600. $this->fullorderxw->save(array('klarna'=>1,'klarnaerror'=>$api['error_messages'][0]),$val['id']);
  1601. $sb[] = array($val['number'],$val['orderinfo'],'oooo1');
  1602. }
  1603. }
  1604. else if($api == '')
  1605. {
  1606. if(isset($header['http_code']) && $header['http_code'] == 201)
  1607. {
  1608. $this->fullorderxw->save(array('klarna'=>2),$val['id']);
  1609. $cg[] = array($val['number'],$val['orderinfo'],'oooo2');
  1610. }
  1611. else
  1612. {
  1613. $this->fullorderxw->save(array('klarna'=>1,'klarnaerror'=>'未知错误'),$val['id']);
  1614. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1615. }
  1616. }
  1617. else if(isset($api['cs']))
  1618. {
  1619. $this->fullorderxw->save(array('klarna'=>1,'klarnaerror'=>'超时'),$val['id']);
  1620. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1621. }
  1622. else
  1623. {
  1624. $this->fullorderxw->save(array('klarna'=>1,'klarnaerror'=>'未知错误'),$val['id']);
  1625. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1626. }
  1627. }
  1628. }
  1629. echo "<pre>";
  1630. print_r($cg);
  1631. echo "<pre>";
  1632. print_r($sb);
  1633. }
  1634. public function _klarnaapi($paypal,$shouldmoney,$name,$pass)
  1635. {
  1636. $url = 'https://api-na.klarna.com/ordermanagement/v1/orders/'.$paypal.'/captures';
  1637. $data = '{"captured_amount": '.str_replace('.','',$shouldmoney).'}';
  1638. $header[] = "Content-Type:application/json";
  1639. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1640. $ch = curl_init();
  1641. curl_setopt($ch, CURLOPT_URL, $url);
  1642. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1643. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1644. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  1645. curl_setopt($ch, CURLOPT_POST, 1);
  1646. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1647. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  1648. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1649. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1650. $res = curl_exec($ch);
  1651. $header = curl_getinfo($ch);
  1652. if($res === false)
  1653. {
  1654. if(curl_errno($ch))
  1655. {
  1656. return array('res'=>'1','header'=>'','cs'=>1);
  1657. }
  1658. }
  1659. else
  1660. {
  1661. $res = json_decode($res,true);
  1662. return array('res'=>$res,'header'=>$header);
  1663. }
  1664. curl_close($ch);
  1665. }
  1666. public function _klarnadata($paypal,$name,$pass)
  1667. {
  1668. $url = 'https://api-na.klarna.com/ordermanagement/v1/orders/'.$paypal;
  1669. $header[] = "Content-Type:application/json";
  1670. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1671. $ch = curl_init();
  1672. curl_setopt($ch, CURLOPT_URL, $url);
  1673. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1674. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1675. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1676. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1677. $res = curl_exec($ch);
  1678. curl_close($ch);
  1679. $res = json_decode($res,true);
  1680. $data = '';
  1681. if(isset($res['fraud_status']))
  1682. {
  1683. $data = (($res['fraud_status'] == 'ACCEPTED')?1:2).'|<strong>'.$res['purchase_currency'].($res['order_amount']/100).'</strong> , '.(($res['fraud_status'] != 'ACCEPTED')?'<font style="color:#f00">'.$res['fraud_status'].'</font>':$res['fraud_status']).' , description:'.$res['initial_payment_method']['description'].' , number of installments:'.$res['initial_payment_method']['number_of_installments'].'|'.$res['billing_address']['street_address'].(($res['billing_address']['street_address2']!='')?' '.$res['billing_address']['street_address2']:'').','.$res['billing_address']['city'].','.$res['billing_address']['region'].','.$res['billing_address']['postal_code'].','.$res['billing_address']['country'].','.$res['billing_address']['given_name'].' '.$res['billing_address']['family_name'].','.$res['billing_address']['phone'].','.$res['billing_address']['email'].'|'.str_replace('|','&#124;',$res['shipping_address']['street_address']).(($res['shipping_address']['street_address2']!='')?' '.str_replace('|','&#124;',$res['shipping_address']['street_address2']):'').','.$res['shipping_address']['city'].','.$res['shipping_address']['region'].','.$res['shipping_address']['postal_code'].','.$res['shipping_address']['country'].','.$res['shipping_address']['given_name'].' '.$res['shipping_address']['family_name'].','.$res['shipping_address']['phone'].','.$res['shipping_address']['email'];
  1684. }
  1685. return $data;
  1686. }
  1687. public function _hqpaypal()
  1688. {
  1689. $shop = $this->shop->find_all("paypalname != ''");
  1690. foreach ($shop as $val)
  1691. {
  1692. $d = $this->fullorderxw->find_all("shop = '".$val['id']."' and dtime > '".(time()-(5*24*3600))."' and dtime < '".(time()-(3*3600))."' and pay = '22' and klarnadata = ''");
  1693. foreach ($d as $v)
  1694. {
  1695. $paypal = $this->paypal->data($v['paypal'],$val);
  1696. if($paypal != '')
  1697. {
  1698. $this->fullorderxw->save(array('klarnadata'=>$paypal),$v['id']);
  1699. }
  1700. }
  1701. }
  1702. }
  1703. public function _hqstripe()
  1704. {
  1705. $shop = $this->shop->find_all("stripe != ''");
  1706. foreach ($shop as $val)
  1707. {
  1708. $d = $this->fullorderxw->find_all("shop = '".$val['id']."' and dtime > '".(time()-(5*24*3600))."' and dtime < '".time()."' and pay = '1211' and klarnadata = ''");
  1709. foreach ($d as $v)
  1710. {
  1711. $paypal = $this->_stripe($v['paypal'],$val['stripe']);
  1712. if($paypal != '')
  1713. {
  1714. $this->fullorderxw->save(array('klarnadata'=>$paypal),$v['id']);
  1715. }
  1716. }
  1717. }
  1718. }
  1719. public function _stripe($pay,$stripe)
  1720. {
  1721. $url = 'https://api.stripe.com/v1/payment_intents/'.$pay;
  1722. $header[] = "Authorization:Bearer ".$stripe;
  1723. $ch = curl_init();
  1724. curl_setopt($ch, CURLOPT_URL, $url);
  1725. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1726. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1727. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1728. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1729. $res = curl_exec($ch);
  1730. curl_close($ch);
  1731. $res = json_decode($res,true);
  1732. $k = '';
  1733. if(isset($res['shipping']['name']))
  1734. {
  1735. $line = ($res['shipping']['address']['line2'] != '')?$res['shipping']['address']['line1'].' '.$res['shipping']['address']['line2']:$res['shipping']['address']['line1'];
  1736. $k = 'stripe|'.json_encode(array('name'=>$res['shipping']['name'],'email'=>$res['receipt_email'],'address'=>$line.','.$res['shipping']['address']['city'].','.$res['shipping']['address']['state'].','.$res['shipping']['address']['postal_code'].','.$res['shipping']['address']['country'].','.$res['shipping']['phone'],'shouldmoney'=>$res['amount']/100));
  1737. }
  1738. return $k;
  1739. }
  1740. public function _afterpay($paypal,$name,$pass)
  1741. {
  1742. $url = 'https://global-api.afterpay.com/v2/payments?ids='.$paypal;
  1743. $header[] = "Accept:application/json";
  1744. $header[] = "User-Agent: Readme.io API Simulator'";
  1745. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1746. $ch = curl_init();
  1747. curl_setopt($ch, CURLOPT_URL, $url);
  1748. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1749. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1750. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1751. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1752. $res = curl_exec($ch);
  1753. curl_close($ch);
  1754. $res = json_decode($res,true);
  1755. $data = '';
  1756. if(isset($res['results'][0]['orderDetails']['consumer']['email']))
  1757. {
  1758. $data = $res['results'][0]['orderDetails']['consumer']['email'].'|'.str_replace('|','&#124;',$res['results'][0]['orderDetails']['billing']['line1']).','.str_replace('|','&#124;',$res['results'][0]['orderDetails']['billing']['line2']).','.$res['results'][0]['orderDetails']['billing']['area1'].','.$res['results'][0]['orderDetails']['billing']['region'].','.$res['results'][0]['orderDetails']['billing']['postcode'].','.$res['results'][0]['orderDetails']['billing']['countryCode'].','.$res['results'][0]['orderDetails']['billing']['name'].','.$res['results'][0]['orderDetails']['billing']['phoneNumber'].'|'.str_replace('|','&#124;',$res['results'][0]['orderDetails']['shipping']['line1']).','.str_replace('|','&#124;',$res['results'][0]['orderDetails']['shipping']['line2']).','.$res['results'][0]['orderDetails']['shipping']['area1'].','.$res['results'][0]['orderDetails']['shipping']['region'].','.$res['results'][0]['orderDetails']['shipping']['postcode'].','.$res['results'][0]['orderDetails']['shipping']['countryCode'].','.$res['results'][0]['orderDetails']['shipping']['name'].','.$res['results'][0]['orderDetails']['shipping']['phoneNumber'];
  1759. $data = str_replace(',,',',',$data);
  1760. }
  1761. return $data;
  1762. }
  1763. public function _clearpay($paypal,$name,$pass)
  1764. {
  1765. $url = 'https://global-api.afterpay.com/v2/payments?ids='.$paypal;
  1766. $header[] = "Accept:application/json";
  1767. $header[] = "User-Agent: Readme.io API Simulator'";
  1768. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1769. $ch = curl_init();
  1770. curl_setopt($ch, CURLOPT_URL, $url);
  1771. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1772. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1773. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1774. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1775. $res = curl_exec($ch);
  1776. curl_close($ch);
  1777. $res = json_decode($res,true);
  1778. $data = '';
  1779. if(isset($res['results'][0]['orderDetails']['consumer']['email']))
  1780. {
  1781. $data = $res['results'][0]['orderDetails']['consumer']['email'].'|'.str_replace('|','&#124;',$res['results'][0]['orderDetails']['billing']['line1']).','.str_replace('|','&#124;',$res['results'][0]['orderDetails']['billing']['line2']).','.$res['results'][0]['orderDetails']['billing']['area1'].','.$res['results'][0]['orderDetails']['billing']['region'].','.$res['results'][0]['orderDetails']['billing']['postcode'].','.$res['results'][0]['orderDetails']['billing']['countryCode'].','.$res['results'][0]['orderDetails']['billing']['name'].','.$res['results'][0]['orderDetails']['billing']['phoneNumber'].'|'.str_replace('|','&#124;',$res['results'][0]['orderDetails']['shipping']['line1']).','.str_replace('|','&#124;',$res['results'][0]['orderDetails']['shipping']['line2']).','.$res['results'][0]['orderDetails']['shipping']['area1'].','.$res['results'][0]['orderDetails']['shipping']['region'].','.$res['results'][0]['orderDetails']['shipping']['postcode'].','.$res['results'][0]['orderDetails']['shipping']['countryCode'].','.$res['results'][0]['orderDetails']['shipping']['name'].','.$res['results'][0]['orderDetails']['shipping']['phoneNumber'];
  1782. $data = str_replace(',,',',',$data);
  1783. }
  1784. return $data;
  1785. }
  1786. public function _htmlstock()
  1787. {
  1788. if(isset($_GET['hq']))
  1789. {
  1790. $ProductsType = $this->typeclass->find_all("classid = '16' and hq = '1'",'id,title','sequence asc');
  1791. foreach ($ProductsType as $k=>$v)
  1792. {
  1793. if($v['title'] == 'Closure')
  1794. {
  1795. $ProductsType[$k]['title'] = 'Closure/Frontal';
  1796. }
  1797. }
  1798. $HairColor = $this->typeclass->find_all("classid = '8' and hq = '1'",'id,title','sequence asc');
  1799. $HairWavy = $this->typeclass->find_all("classid = '15' and hq = '1'",'id,title','sequence asc');
  1800. $WigType = $this->typeclass->find_all("classid = '18' and hq = '1'",'id,title','sequence asc');
  1801. $Length = $this->typeclass->find_all("classid = '14' and hq = '1'",'id,title','sequence asc');
  1802. echo json_encode(array('ProductsType'=>$ProductsType,'HairColor'=>$HairColor,'HairWavy'=>$HairWavy,'WigType'=>$WigType,'Length'=>$Length));exit;
  1803. //http://1.wepolicy.cn/api/htmlstock?hq=1
  1804. }
  1805. if(isset($_GET['page']))
  1806. {
  1807. $del = array();
  1808. $typeclass13 = $this->typeclass->find_all("classid = '13'");
  1809. $typeclass16 = $this->typeclass->find_all("classid = '16'");
  1810. foreach ($typeclass16 as $key=>$value)
  1811. {
  1812. foreach ($typeclass13 as $v)
  1813. {
  1814. $del[] = $value['title'].' '.$v['title'];
  1815. }
  1816. }
  1817. $page = $this->input->get('page',true);
  1818. $perpage = $this->input->get('perpage',true);
  1819. $category = $this->input->get('ProductsType',true);//类目
  1820. $color = $this->input->get('HairColor',true);//颜色
  1821. $lowe = $this->input->get('HairWavy',true);//花型
  1822. $lacetype = $this->input->get('WigType',true);//头套种类
  1823. $size = $this->input->get('Length',true);//长度
  1824. $title = $this->input->get('title',true);//传输文本
  1825. $warehouse = 5;
  1826. $state = $this->input->get('state',true);
  1827. $where = "warehouse = '5' and state = '0'";
  1828. if($category)
  1829. {
  1830. $where .= " and features like '%-$category-%'";
  1831. }
  1832. if($color)
  1833. {
  1834. $where .= " and features like '%-$color-%'";
  1835. }
  1836. if($lowe)
  1837. {
  1838. $where .= " and features like '%-$lowe-%'";
  1839. }
  1840. if($lacetype)
  1841. {
  1842. $where .= " and features like '%-$lacetype-%'";
  1843. }
  1844. if($size)
  1845. {
  1846. $where .= " and features like '%-$size-%'";
  1847. }
  1848. if($title)
  1849. {
  1850. $where .= " and title like '%$title%'";
  1851. }
  1852. $order_str = "id desc";
  1853. if(empty($page))
  1854. {
  1855. $start = 0;
  1856. $perpage = 1;
  1857. }
  1858. else
  1859. {
  1860. $start = ($page - 1)*$perpage;
  1861. }
  1862. $info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number',$order_str,$start,$perpage);
  1863. $data = array();
  1864. foreach ($info_list as $key=>$value)
  1865. {
  1866. $c = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "5" and features = "'.$value['features'].'" and zd = ""');
  1867. if($c > 1)
  1868. {
  1869. $data[] = array('Item'=>str_replace($del,'',$value['title']),'Stock'=>$c);
  1870. }
  1871. }
  1872. $total = count($this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
  1873. $pagenum = ceil($total/$perpage);
  1874. $over = $total-($start+$perpage);
  1875. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($data));//总数量,剩余数量,总页数,数据
  1876. echo json_encode($rows);exit;
  1877. ///api/htmlstock?page=1&perpage=50&ProductsType=&HairColor=&HairWavy=&WigType=&Length= //页数、每页数量、类目、颜色、花型、头套种类、尺寸
  1878. }
  1879. }
  1880. public function _17track()
  1881. {
  1882. $xq = array();
  1883. $j = file_get_contents('PHP://input');
  1884. $j = json_decode($j, true);
  1885. if(isset($j['data']) && isset($j['sign']))
  1886. {
  1887. $sh = hash("sha256",$j['event'].'/'.json_encode($j['data']).'/0811AC1711EAABB7D764D04B824F8C2D');
  1888. if($j['data']['number'] != '')
  1889. {
  1890. $f = 'fullorder';
  1891. $d = $this->fullorderxw->get_waybill($j['data']['number']);
  1892. if(!$d)
  1893. {
  1894. $f = 'fullordersmt';
  1895. $d = $this->fullordersmt->get_waybill($j['data']['number']);
  1896. }
  1897. if(!$d)
  1898. {
  1899. exit;
  1900. }
  1901. if($j['data']['track']['e'] == 0)//查询不到
  1902. {
  1903. $exstate = 0;//无信息
  1904. }
  1905. else if($j['data']['track']['e'] == 10)//运输途中
  1906. {
  1907. $exstate = 3;//在途中
  1908. }
  1909. else if($j['data']['track']['e'] == 20)//运输过久
  1910. {
  1911. $exstate = 3;//在途中
  1912. }
  1913. else if($j['data']['track']['e'] == 30)//到达待取
  1914. {
  1915. $exstate = 5;//派送中
  1916. }
  1917. else if($j['data']['track']['e'] == 35)//投递失败
  1918. {
  1919. $exstate = 1;//派送异常
  1920. }
  1921. else if($j['data']['track']['e'] == 40)//成功签收
  1922. {
  1923. $exstate = 6;//签收
  1924. }
  1925. else if($j['data']['track']['e'] == 50)//可能异常
  1926. {
  1927. $exstate = 1;//派送异常
  1928. }
  1929. if(isset($j['data']['track']['z1'][0]))
  1930. {
  1931. foreach ($j['data']['track']['z1'] as $v)
  1932. {
  1933. $xq .= $v['a'].' ['.$v['c'].'] '.$v['z'].'<br />';// a日期 c地址 z状态
  1934. }
  1935. }
  1936. $this->$f->save(array('expressstate'=>$exstate,'excontent'=>$xq),$d['id']);
  1937. $time = time();
  1938. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time' and shop = '".$d['shop']."' and logisticstatus = '".$exstate."'");
  1939. if($notice && $d['wlyc'] == '0' && $d['wltype'] != '1' && $d['source'] != '1' && stripos($d['wlcontent'],$notice[0]['title']) === false)
  1940. {
  1941. $this->_sdfs($d,$notice[0]['id']);
  1942. }
  1943. }
  1944. }
  1945. }
  1946. }