Apixw.php 73 KB

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