Api.php 94 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575
  1. <?php defined('BASEPATH') OR exit('No direct script access allowed');
  2. class Api 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_fullordertt','fullordertt');
  10. $this->load->_model('Model_fullorder_smt','fullorder_smt');
  11. $this->load->_model('Model_fullordersmt','fullordersmt');
  12. $this->load->_model('Model_country','country');
  13. $this->load->_model('Model_hl','hl');
  14. $this->load->_model('Model_is','is');
  15. $this->load->_model('Model_kdniao','kdniao');
  16. $this->load->_model('Model_typeclass','typeclass');
  17. $this->load->_model('Model_warehouse','warehouse');
  18. $this->load->_model('Model_fullorderexcel','fullorderexcel');
  19. $this->load->_model('Model_dhl','dhl');
  20. $this->load->_model('Model_usps','usps');
  21. $this->load->_model('Model_ups','ups');
  22. $this->load->_model('Model_dhltest','dhltest');
  23. $this->load->_model('Model_customer','customer');
  24. $this->load->_model('Model_express','express');
  25. $this->load->_model('Model_notice','notice');
  26. $this->load->_model('Model_emaildata','emaildata');
  27. $this->load->_model('Model_whlabel','whlabel');
  28. $this->load->_model('Model_productdescribe','productdescribe');
  29. $this->load->_model('Model_ljg','ljg');
  30. $this->load->_model('Model_commodityread','commodityread');
  31. $this->load->_model('Model_service','service');
  32. $this->load->_model('Model_fedex','fedex');
  33. $this->load->_model('Model_apismt','apismt');
  34. $this->load->_model('Model_cne','cne');
  35. $this->load->_model('Model_specialstock','specialstock');
  36. $this->load->_model('Model_whlabellabel','whlabellabel');
  37. $this->load->_model('Model_allocation','allocation');
  38. $this->load->_model('Model_yswaybill','yswaybill');
  39. $this->load->_model('Model_paypal','paypal');
  40. $this->load->_model('Model_17track','17track');
  41. $this->load->_model('Model_ck','ck');
  42. $this->load->_model('Model_weight','weight');
  43. $this->load->_model('Model_pay','pay');
  44. $this->load->_model('Model_setting','setting');
  45. $this->load->_model('Model_classid','classid');
  46. $this->load->_model('Model_apiyy','apiyy');
  47. $this->load->_model('Model_whlabel_fc','whlabel_fc');
  48. $this->load->_model('Model_shopsku','shopsku');
  49. $this->load->_model('Model_awlgx','awlgx');
  50. $this->load->_model('Model_apitt','apitt');
  51. $this->load->_model('Model_producttitle','producttitle');
  52. $this->load->_model('Model_afspaypal','afspaypal');
  53. $this->load->_model('Model_message','message');
  54. $this->load->_model("Model_zztmpdata",'zztmpdata');
  55. $this->load->_model("Model_logic_ding","logic_ding");
  56. $this->load->_model("Model_customsdeclaration","customsdeclaration");
  57. $this->load->_model("Model_zzjobs","zzjobs");
  58. }
  59. //定义方法的调用规则 获取URI第二段值
  60. public function _remap($arg,$arg_array)
  61. {
  62. if($arg == 'isorder')//添加
  63. {
  64. $this->_isorder();
  65. }
  66. else if($arg == 'tb')//同步独立站
  67. {
  68. $this->_tb();
  69. }
  70. else if($arg == 'waybill')//运单上传独立站
  71. {
  72. $this->_waybill($arg_array);
  73. }
  74. else if($arg == 'waybillemail')
  75. {
  76. $this->_waybillemail($arg_array);
  77. }
  78. else if($arg == 'waybillfs')
  79. {
  80. $this->_waybillfs($arg_array);
  81. }
  82. else if($arg == 'headgear')//传输头套信息
  83. {
  84. $this->_headgear($arg_array);
  85. }
  86. else if($arg == 'fsstate')
  87. {
  88. $this->_fsstate();
  89. }
  90. else if($arg == 'fswaybillemail')
  91. {
  92. $this->_fswaybillemail();
  93. }
  94. else if($arg == 'zz')
  95. {
  96. $this->_zz();
  97. }
  98. else if($arg == 'zzcs')
  99. {
  100. $this->_zzcs();
  101. }
  102. else if($arg == 'cangku')
  103. {
  104. $this->_cangku();
  105. }
  106. else if($arg == 'kc')
  107. {
  108. $this->_kc();
  109. }
  110. else if($arg == 'wlfs')
  111. {
  112. $this->_wlfs();
  113. }
  114. else if($arg == 'query')
  115. {
  116. $this->_query();
  117. }
  118. else if($arg == 'kcjc')
  119. {
  120. $this->_kcjc();
  121. }
  122. else if($arg == 'klarna')
  123. {
  124. $this->_klarna();
  125. }
  126. else if($arg == 'logistics')
  127. {
  128. $this->_logistics();
  129. }
  130. else if($arg == 'hqpaypal')
  131. {
  132. $this->_hqpaypal();
  133. }
  134. else if($arg == 'hqstripe')
  135. {
  136. $this->_hqstripe();
  137. }
  138. else if($arg == 'htmlstock')
  139. {
  140. $this->_htmlstock();
  141. }
  142. else if($arg == 'dhl')
  143. {
  144. $this->_dhl();
  145. }
  146. else if($arg == '17track')
  147. {
  148. $this->_17track();
  149. }
  150. else if($arg == 'zc17track')
  151. {
  152. $this->_zc17track();
  153. }
  154. }
  155. //通过地址直接获取独立站订单信息
  156. public function _isorder()
  157. {
  158. $sid = '';$sd = array();
  159. if(isset($_SESSION['api']))
  160. {
  161. $user = $this->user->get_api($_SESSION['api']);
  162. $user = explode('|',trim($user['shop'],'|'));
  163. foreach ($user as $value)
  164. {
  165. $sid .= " id = '$value' or";
  166. }
  167. $sid = " and (".rtrim($sid,'or').")";
  168. }
  169. $post = $this->input->post(NULL, TRUE);
  170. $api = $this->input->get('api',true);
  171. $dshop = $this->input->get('dshop',true);
  172. //@$gethl = $this->hl->get_hl();//获取即时汇率
  173. $gethl = array();
  174. /* 订单号加入键值-k */
  175. /**
  176. $dataorder = array();
  177. $fdata = $this->fullorder->find_all('dtime > "'.(time()-96*3600).'"','orderinfo');
  178. foreach ($fdata as $v)
  179. {
  180. $dataorder[$v['orderinfo']] = "";//获取到单号
  181. }
  182. **/
  183. /* 订单号加入键值-j */
  184. /* 匹配加入 */
  185. $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');
  186. // 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)
  187. $dtc = array();
  188. foreach ($dictionaries as $v)
  189. {
  190. if(stripos($v['spare'],'|') !== false)//如果有多个值
  191. {
  192. $v['spare'] = explode('|',$v['spare']);
  193. foreach ($v['spare'] as $k=>$vs)
  194. {
  195. if(stripos($v['zh'],'|') !== false)
  196. {
  197. $vzh = explode('|',$v['zh']);
  198. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  199. }
  200. else
  201. {
  202. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  203. }
  204. }
  205. }
  206. else
  207. {
  208. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  209. }
  210. }
  211. $dictionaries2 = $this->typeclass->find_all();
  212. foreach ($dictionaries2 as $v)
  213. {
  214. $dtctitle[$v['id']] = $v['title'];
  215. }
  216. /* 匹配结束 */
  217. /* 价格加入 */
  218. /**
  219. $money = array();
  220. $productdescribe = $this->productdescribe->find_all('1=1','number,purchase,cost,salesprice,title');
  221. foreach ($productdescribe as $v)
  222. {
  223. $money[$v['number']] = array('purchase'=>$v['purchase'],'cost'=>$v['cost'],'salesprice'=>$v['salesprice'],'title'=>$v['title']);
  224. }
  225. **/
  226. /* 价格加入 */
  227. /* 匹配ID加入 */
  228. $int = array();
  229. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  230. foreach ($intdata as $v)
  231. {
  232. $v['spare'] = explode('|',$v['spare']);
  233. $int[$v['id']] = $v['spare'][0];
  234. }
  235. /* 匹配ID结束 */
  236. /* 国家加入键值-k */
  237. $cuy = array();
  238. $cuydata = $this->country->find_all('1=1','lb,id');
  239. foreach ($cuydata as $v)
  240. {
  241. $cuy[$v['lb']] = $v['id'];//获取到国家ID
  242. }
  243. /* 国家加入键值-j */
  244. /* 币种加入键值-k */
  245. $typeclass = array();
  246. $tdata = $this->typeclass->find_all('classid=30','id,title');
  247. foreach ($tdata as $v)
  248. {
  249. $typeclass[$v['title']] = $v['id'];
  250. }
  251. /* 币种加入键值-j */
  252. /* 支付方式-k */
  253. $pay = array();
  254. $tdata = $this->typeclass->find_all('classid=4','id,spare');
  255. foreach ($tdata as $v)
  256. {
  257. $paytype = $this->pay->get_typeclass($v['id']);
  258. if(isset($paytype['estimaterate']))
  259. {
  260. $estimaterate = $paytype['estimaterate'];
  261. }
  262. else
  263. {
  264. $estimaterate = 0;
  265. }
  266. if(stripos($v['spare'],'|') !== false)//如果有多个值
  267. {
  268. $v['spare'] = explode('|',$v['spare']);
  269. foreach ($v['spare'] as $k=>$vs)
  270. {
  271. $pay[$vs] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
  272. }
  273. }
  274. else
  275. {
  276. $pay[$v['spare']] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
  277. }
  278. }
  279. $pay['stripeios'] = $pay['stripe_payments'];
  280. /* 支付方式-j */
  281. /* 新增SKU-k */
  282. $zjsku = array();
  283. $shopsku = $this->shopsku->find_all();
  284. foreach ($shopsku as $val)
  285. {
  286. $ss = explode(',',trim($val['shop'],','));
  287. foreach ($ss as $v)
  288. {
  289. if(isset($zjsku[$v]))
  290. {
  291. $zjsku[$v] .= ','.trim($val['sku'],',');
  292. }
  293. else
  294. {
  295. $zjsku[$v] = trim($val['sku'],',');
  296. }
  297. }
  298. }
  299. /* 新增SKU-j */
  300. $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
  301. if(isset($post['is']) || (isset($api) && $api = '89757'))
  302. {
  303. $tb = 0;
  304. if($dshop)
  305. {
  306. $shop = $this->shop->find_all("id = '$dshop'");
  307. }
  308. else
  309. {
  310. $shop = $this->shop->find_all("type = 269 and tb = 1".$sid);//获取独立站信息
  311. }
  312. foreach ($shop as $value)
  313. {
  314. if((time()-$value['tbtime']) < 600)
  315. {
  316. $tb = 1;//正在同步中
  317. break;
  318. }
  319. else
  320. {
  321. $this->shop->save(array('tbtime'=>time()),$value['id']);
  322. }
  323. $setting = $this->setting->get_settings();
  324. $this->db->trans_begin();
  325. $res = $this->api->get_hq($value['brandname'],$value['shopadmin'],$value);
  326. $sd[] = $res;
  327. $sjc = $setting['sctime'];//时间差 之前是3600 现在为0
  328. if($res)
  329. {
  330. foreach ($res as $v)
  331. {
  332. if(!isset($v['order_id']))
  333. {
  334. continue;
  335. }
  336. if($value['token'] == 'SU')
  337. {
  338. $time = $v['purchased_on']-7*3600-$sjc;//之前是+$sjc
  339. }
  340. else if($value['program'] == 'Shopify')
  341. {
  342. $time = $v['purchased_on'];
  343. }
  344. else
  345. {
  346. if($value['id'] == 1)
  347. {
  348. $time = strtotime($v['purchased_on'])-7*3600-$sjc;//-$sjc;//之前是+$sjc
  349. }
  350. else
  351. {
  352. $time = strtotime($v['purchased_on'])-7*3600-$sjc;//订单时间更为时间戳 //之前是+$sjc
  353. }
  354. }
  355. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$time).'" and shop = "'.$value['id'].'"');
  356. $order_id = $value['id'].$v['order_id'];
  357. $tc = 0;
  358. if(isset($v['global_currency_code']))
  359. {
  360. $tc = isset($typeclass[$v['global_currency_code']])?$typeclass[$v['global_currency_code']]:0;
  361. }
  362. $dataorder = $this->fullorder->get_orderinfo($order_id);
  363. $hmdid = '';
  364. if($value['program'] == 'Shopify' && isset($dataorder['id']))
  365. {
  366. if($v['order_comment'] != $dataorder['clientremarks'])
  367. {
  368. $this->fullorder->save(array('clientremarks'=>$v['order_comment']),$dataorder['id']);
  369. }
  370. }
  371. if(!isset($dataorder['id']))
  372. //现在为所有订单都获取。!$ord && strcasecmp($v['isstatus'],'processing') == 0如果没有此订单并且订单状态为等待发货则继续
  373. {
  374. if(!isset($cuy[$v['country']]))
  375. {
  376. $cuy[$v['country']] = 1004;
  377. }
  378. $post = $this->api->get_data($value,$v,$gethl,$time,$cuy[$v['country']],$is,$num,$v['country'],$tc,$dtc,array(),$int,$dtctitle,$pay,$zjsku);
  379. $kn = explode('-',$post['paypal']);
  380. if($post['pay'] == 23 && $value['klarnaname'] != '' && $value['klarnapass'] != '')
  381. {
  382. $klarna = $this->_klarnadata($post['paypal'],$value['klarnaname'],$value['klarnapass']);
  383. if($klarna != '')
  384. {
  385. $post['klarnadata'] = $klarna;
  386. }
  387. }
  388. if($post['pay'] == 26 && $value['afterpayname'] != '' && $value['afterpaypass'] != '')
  389. {
  390. $afterpay = $this->_afterpay($post['paypal'],$value['afterpayname'],$value['afterpaypass']);
  391. if($afterpay != '')
  392. {
  393. $post['klarnadata'] = $afterpay;
  394. }
  395. }
  396. if($post['pay'] == 27 && $value['clearpayname'] != '' && $value['clearpaypass'] != '')
  397. {
  398. $clearpay = $this->_clearpay($post['paypal'],$value['clearpayname'],$value['clearpaypass']);
  399. if($clearpay != '')
  400. {
  401. $post['klarnadata'] = $clearpay;
  402. }
  403. }
  404. if($post['pay'] == '28' && $post['state'] != '207')
  405. {
  406. continue;
  407. }
  408. if($post['state'] == '217' || $post['state'] == '203')
  409. {
  410. continue;
  411. }
  412. /**
  413. else if($post['pay'] == 22 && $value['paypalname'] != '' && $value['paypalpass'] != '')
  414. {
  415. $paypal = $this->_paypaldata($post['paypal'],$value['paypalname'],$value['paypalpass']);
  416. if($paypal != '')
  417. {
  418. $post['klarnadata'] = $paypal;
  419. }
  420. }
  421. **/
  422. /** 启用自动分配仓库 **/
  423. $post['express'] = 0;
  424. $warehouse = $this->warehouse->find_all("fpzd = '1'",'*','fpsx desc');
  425. foreach ($warehouse as $v)
  426. {
  427. if($v['bdcountry'] != 0 && $v['bdcountry'] != $post['country'])
  428. {
  429. continue;
  430. }
  431. $yx = 'get_yx_'.$v['bdck'];
  432. $kczd = $this->ck->$yx($post['state'],$v,$post['shop'],$post['number'],$post['whlabel'],$post['fpdata']);
  433. if($kczd['t'] == 0)
  434. {
  435. $country = $this->country->read($post['country']);//获取国家中配置物流
  436. if($country['express'] != 0)
  437. {
  438. $post['express'] = $country['express'];
  439. }
  440. if($v['express'] != 0)//优先使用仓库指定物流,替换掉上面的国家配置物流
  441. {
  442. $post['express'] = $v['express'];
  443. }
  444. $post['type'] = $v['id'];
  445. $post['whlabel'] = $kczd['whlabel'];
  446. $post['fpdata'] = $kczd['fpdata'];
  447. if(stripos($kczd['whlabel'],$v['hz']) !== false)
  448. {
  449. break 1;
  450. }
  451. }
  452. }
  453. $qdw = $this->warehouse->read($post['type']);
  454. $fl = $this->ck->get_fl($qdw['hz'],$post['whlabel'],$post['fpdata']);
  455. $post['sfxh'] = $fl['sfxh'];
  456. $post['ckfl'] = $fl['ckfl'];
  457. $zipcode = substr($post['zipcode'],0,1);
  458. if($post['type'] == 5 && $zipcode > 4)
  459. {
  460. $post['express'] = 63;
  461. }
  462. if($post['express'] > 0)
  463. {
  464. $xze = $this->express->read($post['express']);
  465. $post['printtype'] = $xze['type'];
  466. }
  467. //自动写位置 开始
  468. $zclp = array();$pxsl = array();
  469. $slpx = explode('|',$post['slpx']);//排序
  470. //监听报错原因
  471. //解决礼物类没有slpx的数据
  472. if(!empty($post['slpx'])){
  473. foreach ($slpx as $k=>$v)
  474. {
  475. $v = explode('-',$v);
  476. if(!isset($v[1]))
  477. {
  478. $v[1] == 1;
  479. }
  480. for($i=$v[0];$i<$v[1];$i++)
  481. {
  482. $pxsl[$i] = $k;
  483. }
  484. }
  485. }
  486. $mc = $qdw['bdck'];$zdidjl = '';$zdwzjl = '';
  487. if($qdw['wz'] == 1)
  488. {
  489. $pm = explode(';',trim($post['shipremarks'],';'));
  490. foreach ($pm as $k=>$vv)
  491. {
  492. $vv = trim($vv,' ');
  493. $tmp_vv = str_replace("'","",$vv);
  494. $lp = $this->typeclass->find_all("zh = '$tmp_vv'");
  495. if(isset($lp[0]['classid']))
  496. {
  497. $zclp[] = $vv;
  498. unset($pm[$k]);
  499. }
  500. }
  501. $pm = array_values($pm);
  502. $w = explode('|',trim($post['whlabel'],'|'));
  503. foreach ($w as $k=>$val)
  504. {
  505. $hwm = '';
  506. if(stripos($val,$qdw['hz']) !== false)
  507. {
  508. $num = explode('-',trim($val,'-'));
  509. $xq = explode('~',trim($num[2],'~'));
  510. $pmxq = '(';
  511. foreach ($xq as $v)
  512. {
  513. $zdidjl .= '('.trim($v,$qdw['hz']).')';
  514. $h = $this->$mc->read(trim($v,$qdw['hz']));
  515. if($h['details'] != '')
  516. {
  517. $pmxq .= $qdw['title'].':'.$h['details'].(($h['cpid']>0)?'-'.$h['cpid']:'').',';
  518. }
  519. }
  520. $xrid = ($h['cpid']>0)?'-'.$h['cpid']:'';
  521. if(isset($pxsl[$k]))
  522. {
  523. if(stripos($pm[$pxsl[$k]],$qdw['title'].':'.$h['details'].$xrid) === false)
  524. {
  525. $pm[$pxsl[$k]] .= trim($pmxq,',').')';
  526. }
  527. }
  528. $zdwzjl .= $h['details'].(($h['cpid']>0)?'-'.$h['cpid']:'');
  529. }
  530. }
  531. if($zclp)
  532. {
  533. $zclp = ';'.implode(";",$zclp);
  534. }
  535. else
  536. {
  537. $zclp = '';
  538. }
  539. $post['shipremarks'] = implode(";",$pm).$zclp;
  540. $post['contents'] = $zdidjl.' - '.$zdwzjl;
  541. }
  542. //自动写位置 结束
  543. //条数及申报
  544. $ts = 0;
  545. $dtsbjz = 0;
  546. $zsbjz = 0;
  547. $w = explode('|',trim($post['whlabel'],'|'));
  548. foreach ($w as $k=>$val)
  549. {
  550. $num = explode('-',trim($val,'-'));
  551. //$ts += $num[1];
  552. //判断是否是礼物 礼物不计数
  553. $is_gift_str = substr($num[0], 0, 3);
  554. if($is_gift_str != '131'){
  555. $ts += $num[1];
  556. }
  557. }
  558. if($ts > 0 && $ts < 6 && $post['country'] == 192)
  559. {
  560. $dtsbjz = ($ts==3)?sprintf("%.2f",100/$ts):100/$ts;
  561. $zsbjz = sprintf("%.2f",$dtsbjz*$ts);
  562. }
  563. $post['ts'] = $ts;
  564. $post['dtsbjz'] = $dtsbjz;
  565. $post['zsbjz'] = $zsbjz;
  566. /** **/
  567. //合并重复项
  568. $hbcfw = explode('|',trim($post['whlabel'],'|'));
  569. $hbcff = explode(';',trim($post['fpdata'],';'));
  570. $c = 0;
  571. $hbw = array();
  572. $hbf = array();
  573. for($i=0;$i<count($hbcfw);$i++)
  574. {
  575. $w = explode('-',$hbcfw[$i]);
  576. $f = explode('|',$hbcff[$i]);
  577. $w2 = ($w[2]==0)?0:'';
  578. if(!isset($hbw[$w[0].$w2]))
  579. {
  580. $hbw[$w[0].$w2] = $hbcfw[$i];
  581. $hbf[$w[0].$w2] = $hbcff[$i];
  582. }
  583. else
  584. {
  585. $c++;
  586. $cw = explode('-',$hbw[$w[0].$w2]);
  587. $cf = explode('|',$hbf[$w[0].$w2]);
  588. if($cw[2] != 0 && $w[2] != 0)
  589. {
  590. $cf[2] += $f[2];
  591. $cf[9] .= '~'.$f[9];
  592. $hbf[$w[0].$w2] = implode("|",$cf);
  593. $cw[1] += $f[2];
  594. $cw[2] .= '~'.$f[9];
  595. $hbw[$w[0].$w2] = implode("-",$cw);
  596. }
  597. else if($cw[2] == 0 && $w[2] == 0)
  598. {
  599. $cf[2] += $f[2];
  600. $hbf[$w[0].$w2] = implode("|",$cf);
  601. $cw[1] += $f[2];
  602. $hbw[$w[0].$w2] = implode("-",$cw);
  603. }
  604. else
  605. {
  606. $hbw[] = $hbcfw[$i];
  607. $hbf[] = $hbcff[$i];
  608. }
  609. }
  610. }
  611. if($c > 0)
  612. {
  613. $post['fpdata'] = implode(";",$hbf).';';
  614. $post['whlabel'] = '|'.implode("|",$hbw).'|';
  615. }
  616. //合并重复项结束
  617. //非占单设置为禁止占单开始
  618. $hbw = explode('|',trim($post['whlabel'],'|'));
  619. $hbf = explode(';',trim($post['fpdata'],';'));
  620. foreach ($hbw as $k=>$val)
  621. {
  622. $w = explode('-',$val);
  623. $f = explode('|',$hbf[$k]);
  624. if(!isset($w[2]) || $w[2] == 0)
  625. {
  626. $w[2] = "DNOTO";
  627. $f[9] = "DNOTO";
  628. $hbf[$k] = implode("|",$f);
  629. $hbw[$k] = implode("-",$w);
  630. }
  631. }
  632. $post['fpdata'] = implode(";",$hbf).';';
  633. $post['whlabel'] = '|'.implode("|",$hbw).'|';
  634. //非占单设置为禁止占单结束
  635. //查询净重开始
  636. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  637. $post['zzl'] = ($post['jweight']+100)/1000;
  638. if($post['express'] == 2)
  639. {
  640. $post['zzl'] = intval(($post['jweight']+100)*0.035);
  641. }
  642. //查询净重结束
  643. $tjid = $this->fullorder->insert($post);
  644. if($post['email'] == '')
  645. {
  646. $post['email'] = $post['name'].'@qq.com';
  647. }
  648. $adrs = $this->customer->get_email($post['email'],$post['shop']);
  649. preg_match_all('/[0-9]/u',$post['phone'],$result);
  650. $numphone = join('',$result[0]);
  651. $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']));
  652. $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']));
  653. $hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($post['address']));
  654. $hmdid = '';
  655. $customerb = $this->customer->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');
  656. $lkh = (isset($customerb[0]['id']))?2:1;//白名单1黑名单2
  657. if($lkh == 2)
  658. {
  659. $hmdid = $customerb[0]['id'].'-('.$post['email'].'|'.$post['address'].'|'.$numphone.')'.'('.$customerb[0]['email'].'|'.$customerb[0]['address'].$customerb[0]['numphone'].')';
  660. }
  661. if($adrs)
  662. {
  663. $pdlkh = 1;//这个是判断是否老客户
  664. $this->customer->save(array('time'=>$post['dtime'],'is_tb'=>0,'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']);
  665. $khid = $adrs['id'];
  666. }
  667. else
  668. {
  669. $str = $post['phone'];
  670. preg_match_all('/[0-9]/u',$str,$result);
  671. $numphone = join('',$result[0]);
  672. $ct['shop'] = $post['shop'];
  673. $ct['source'] = 10;
  674. $ct['level'] = 5;
  675. $ct['country'] = $post['country'];
  676. $ct['time'] = $post['dtime'];
  677. $ct['num'] = 1;
  678. $ct['money'] = $post['shouldmoney'];
  679. $ct['zipcode'] = $post['zipcode'];
  680. $ct['name'] = $post['name'];
  681. $ct['phone'] = $post['phone'];
  682. $ct['numphone'] = $numphone;
  683. $ct['email'] = preg_replace('/( | | |\s)+/','',$post['email']);
  684. $ct['province'] = $post['province'];
  685. $ct['city'] = $post['city'];
  686. $ct['address'] = $post['address'];
  687. $ct['zhcx'] = $post['shop'].'-'.$ct['email'];
  688. $ct['is_tb'] = 0;
  689. $khid = $this->customer->insert($ct);
  690. $pdlkh = 0;
  691. }
  692. $this->_znxc($post,$order_id,$lkh,$pdlkh,$hmdid);
  693. /**
  694. if($post['shop'] == '1' || $post['shop'] == '2' || $post['shop'] == '6' || $post['shop'] == '5')
  695. {
  696. $this->_znxc($post,$order_id,$lkh);
  697. }
  698. else
  699. {
  700. $this->_znx($post,$order_id,$lkh);
  701. }
  702. **/
  703. }//else{}如果有此订单
  704. }
  705. }
  706. if ($this->db->trans_status() === FALSE)
  707. {
  708. $this->db->trans_commit();
  709. }
  710. else
  711. {
  712. $this->db->trans_commit();
  713. }
  714. usleep(50);//停留2秒
  715. }
  716. if($tb == 1)
  717. {
  718. echo json_encode(array('msg'=>'有店铺正在同步中,请5分钟后再试!','success'=>true));exit;
  719. }
  720. echo json_encode(array('msg'=>'OK!','success'=>true));exit;
  721. }
  722. }
  723. public function _tb()
  724. {
  725. $api = $this->input->get('api',true);
  726. if(isset($api) && $api = '89757')
  727. {
  728. $data = $this->fullorder->find_all('dlz < 1 and source != 1 and waybill != "" and dtime > "'.(time()-48*3600).'"');
  729. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  730. /* 店铺加入键值-j */
  731. $fshop = $this->shop->find_all('1=1');
  732. foreach ($fshop as $v)
  733. {
  734. $datashop[$v['id']] = $v;
  735. }
  736. /* 店铺加入键值-k */
  737. /* 快递加入键值-j */
  738. $fex = $this->express->find_all('1=1');
  739. foreach ($fex as $v)
  740. {
  741. $dataex[$v['id']] = $v;
  742. }
  743. /* 快递加入键值-k */
  744. /* 仓库加入键值-k */
  745. $fwh = $this->warehouse->find_all('1=1');
  746. foreach ($fwh as $v)
  747. {
  748. $datack[$v['id']] = $v;
  749. }
  750. /* 仓库加入键值-j */
  751. //$fs = $this->notice->get_ordertatus(216);//216成功状态
  752. foreach ($data as $v)
  753. {
  754. $ddh = substr($v['orderinfo'],1);
  755. $ydh = $v['waybill'];
  756. $xg = $v;//此订单数据
  757. $shop = $datashop[$xg['shop']];//此订单店铺
  758. $ex = $dataex[$xg['express']];//此订单快递
  759. $warehouse = $datack[$xg['type']];//此订单仓库
  760. $shopifyid = $v['shopify'];
  761. if($xg['shop'] < 7)
  762. {
  763. $xg['iscode'] = $ex['title'];
  764. $xg['url'] = $shop['shopname'];
  765. @$fs = $this->api->get_paypal($xg);
  766. $this->afspaypal->insert(array('number'=>$xg['number'],'cs'=>$fs));
  767. }
  768. $ms = $this->message->find_all("express like '%,".$xg['express'].",%'");
  769. if(!isset($ms[0]))
  770. {
  771. $ms = $this->message->read(2);
  772. }
  773. else
  774. {
  775. $ms = $ms[0];
  776. }
  777. $shopname = $shop['brandname']; //店铺名
  778. $buyername = $xg['bname']; //Bill Name
  779. $email_call = $shop['shopid']; //发货人邮箱;
  780. $phone = $shop['shopphone']; //发货人电话
  781. $track_type = $ex['title']; //快递名称
  782. $service = $ex['title']; //快递追踪名称
  783. $track_link = $ex['url']; //快递查询网址
  784. $logistics_number = $ydh; //运单号
  785. $t= array('%buyername%','%email_call%','%track_type%','%service%','%track_link%','%logistics_number%','%shop%','%phone%','%jtime%');
  786. $h= array($buyername,$email_call,$track_type,$service,$track_link,$logistics_number,$shopname,$phone,$ex['yjtime']);
  787. $remark = str_replace($t,$h,$ms['content']);
  788. @$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$remark,$shopifyid);
  789. if(!isset($gx['res']))
  790. {
  791. continue;
  792. }
  793. $this->fullorder->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$v['id']);
  794. }
  795. }
  796. }
  797. //更新独立站运单信息
  798. public function _waybill($arg_array)
  799. {
  800. $where = "dlz < '1' and state = '207' and shop != '19' and ";
  801. if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单,已出库——使用模板3 每天早上8点半 触发发送【昨天早上7点-今天早上7点】出库的
  802. {
  803. $where .= "(express = '2' or express = '63' or express = '64') and librarytime > '".strtotime(date("Y-m-d 7:00:0",strtotime("-1 day")))."' and librarytime < '".strtotime(date("Y-m-d 7:00:0",time()))."'";
  804. $readid = 3;
  805. }
  806. else if(date("H",time()) == '21' && date("w",time()) != '0')//二、杭州联邦+杭州联邦-不报关,单独用一个模板—新模板2 每天晚上9点半 触发发送 【昨天晚上9:30——今天晚上9:30】出库的
  807. {
  808. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  809. {
  810. $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()))."'";
  811. }
  812. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  813. {
  814. $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()))."'";
  815. }
  816. $readid = 2;
  817. }
  818. else if(date("H",time()) == '19' && date("w",time()) != '0')//其他快递-使用模板1 DHL官方、UPS、DPEX 等系统里打印运单自动有运单号的,出库后当天晚上7点执行。
  819. {
  820. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  821. {
  822. $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()))."'";
  823. }
  824. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  825. {
  826. $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()))."'";
  827. }
  828. $readid = 1;
  829. }
  830. else
  831. {
  832. exit;
  833. }
  834. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  835. // 订单加入键值-k
  836. $fdata = $this->fullorder->find_all($where);//,'source,id,orderinfo,waybill,shop,express,type,msg,bname,state,client,name,phone,zipcode,address,email,shopify'
  837. //* 订单加入键值-j
  838. //* 店铺加入键值-j
  839. $fshop = $this->shop->find_all('1=1');
  840. foreach ($fshop as $v)
  841. {
  842. $datashop[$v['id']] = $v;
  843. }
  844. //* 店铺加入键值-k
  845. //* 快递加入键值-j
  846. $fex = $this->express->find_all('1=1');
  847. foreach ($fex as $v)
  848. {
  849. $dataex[$v['id']] = $v;
  850. }
  851. //* 快递加入键值-k
  852. //* 仓库加入键值-k
  853. $fwh = $this->warehouse->find_all('1=1');
  854. foreach ($fwh as $v)
  855. {
  856. $datack[$v['id']] = $v;
  857. }
  858. //* 仓库加入键值-j
  859. $i = 0;$j = 0;$ed = array();
  860. foreach ($fdata as $key=>$value)
  861. {
  862. if($value['source'] == 1)
  863. {
  864. $this->fullorder->save(array('dlz'=>3,'state'=>216),$value['id']);
  865. }
  866. else
  867. {
  868. $ddh = substr($value['orderinfo'],1);
  869. $ydh = $value['waybill'];
  870. $xg = $value;//此订单数据
  871. $shop = $datashop[$xg['shop']];//此订单店铺
  872. $ex = $dataex[$xg['express']];//此订单快递
  873. $warehouse = $datack[$xg['type']];//此订单仓库
  874. $shopifyid = $value['shopify'];
  875. if($xg['shop'] < 7)
  876. {
  877. $xg['iscode'] = $ex['title'];
  878. $xg['url'] = $shop['shopname'];
  879. @$fs = $this->api->get_paypal($xg);
  880. $this->afspaypal->insert(array('number'=>$xg['number'],'cs'=>$fs));
  881. }
  882. $ms = $this->message->find_all("express like '%,".$xg['express'].",%'");
  883. if(!isset($ms[0]))
  884. {
  885. $ms = $this->message->read(2);
  886. }
  887. else
  888. {
  889. $ms = $ms[0];
  890. }
  891. $shopname = $shop['brandname']; //店铺名
  892. $buyername = $xg['bname']; //Bill Name
  893. $email_call = $shop['shopid']; //发货人邮箱;
  894. $phone = $shop['shopphone']; //发货人电话
  895. $track_type = $ex['title']; //快递名称
  896. $service = $ex['title']; //快递追踪名称
  897. $track_link = $ex['url']; //快递查询网址
  898. $logistics_number = $ydh; //运单号
  899. $t= array('%buyername%','%email_call%','%track_type%','%service%','%track_link%','%logistics_number%','%shop%','%phone%','%jtime%');
  900. $h= array($buyername,$email_call,$track_type,$service,$track_link,$logistics_number,$shopname,$phone,$ex['yjtime']);
  901. $remark = str_replace($t,$h,$ms['content']);
  902. @$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$remark,$shopifyid);
  903. if(!isset($gx['res']))
  904. {
  905. continue;
  906. }
  907. $this->fullorder->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$value['id']);
  908. }
  909. //sleep(4);
  910. }
  911. //同步更新 淘宝的运单号
  912. $this->_taobao();
  913. $this->_kcjc();
  914. }
  915. public function _taobao()
  916. {
  917. $data = $this->fullorder->find_all("shop = 19 and dlz != '3' and state = '207' and librarytime > 0");
  918. foreach ($data as $k=>$v)
  919. {
  920. $this->fullorder->save(array('dlz'=>3,'state'=>216),$v['id']);
  921. }
  922. }
  923. public function _kcjc()
  924. {
  925. $gethl = $this->whlabel->find_all("zd != '' and state = '0'");
  926. $b = array();
  927. foreach ($gethl as $k=>$v)
  928. {
  929. $a = $this->fullorder->get_number($v['zd']);
  930. if($a['librarytime'] > 0 && $a['library'] == 2)
  931. {
  932. //$b[] = array($v['sku'],$v['zd']);
  933. $this->whlabel->save(array('state'=>1,'orderinfo'=>$a['orderinfo'],'waybill'=>$a['waybill'],'outk'=>$a['librarytime'],'time'=>$a['librarytime']),$v['id']);
  934. }
  935. }
  936. }
  937. public function _waybillemail($arg_array)
  938. {
  939. $urls = array();$sl = 0;$time = time();
  940. /**
  941. if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单
  942. {
  943. $wid = 1;
  944. }
  945. else if(date("H",time()) == '22' && date("w",time()) != '0' && date("i",time()) > '20' && date("i",time()) < '39')//二、杭州联邦+杭州联邦-不报关
  946. {
  947. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  948. {
  949. $wid = 2;
  950. }
  951. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  952. {
  953. $wid = 3;
  954. }
  955. }
  956. else if(date("H",time()) == '20' && date("w",time()) != '0' && date("i",time()) > '20' && date("i",time()) < '39')//其他快递
  957. {
  958. if(date("w",time()) != '1')
  959. {
  960. $wid = 4;
  961. }
  962. else
  963. {
  964. $wid = 5;
  965. }
  966. }
  967. **/
  968. if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单
  969. {
  970. $wid = 1;
  971. }
  972. else if(date("H",time()) == '20' && date("i",time()) > '20' && date("i",time()) < '39')//其他快递
  973. {
  974. $wid = 2;
  975. }
  976. else
  977. {
  978. exit;
  979. }
  980. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '4' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  981. foreach ($notice as $key=>$var)
  982. {
  983. $urls[] = array('url'=>'http://1.wepolicy.cn/api/waybillfs?v='.$var['id'],'data'=>array('var'=>$var,'wid'=>$wid));
  984. }
  985. foreach($urls as $value) {
  986. $ch = curl_init();
  987. $url = $value['url'];
  988. curl_setopt($ch,CURLOPT_URL,$url);
  989. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  990. curl_setopt($ch,CURLOPT_HEADER,0);
  991. curl_setopt($ch,CURLOPT_POST, 1);
  992. curl_setopt($ch,CURLOPT_TIMEOUT,1);
  993. //设置post数据
  994. $post = array();
  995. $post['data'] = $value['data'];
  996. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  997. $res = curl_exec($ch);
  998. curl_close($ch);
  999. $sl++;
  1000. }
  1001. echo $sl;
  1002. echo "<pre>";
  1003. print_r($urls);
  1004. }
  1005. public function _waybillfs()
  1006. {
  1007. $post = $this->input->post(NULL, TRUE);
  1008. $data = $this->input->post('data',true);
  1009. if($data)
  1010. {
  1011. $notice = $data['var'];
  1012. $notice['email'] = $this->emaildata->read($notice['email']);
  1013. $wid = $data['wid'];
  1014. $fsjs = "";
  1015. if($wid == 1 && (stripos($notice['express'],',2,') !== false || stripos($notice['express'],',63,') !== false || stripos($notice['express'],',64,') !== false))
  1016. {
  1017. $js = explode(',',trim($notice['js'],','));
  1018. if(count($js) > 1)
  1019. {
  1020. $fsjs = " and (";
  1021. foreach ($js as $v)
  1022. {
  1023. $fsjs .= "js = '$v' or ";
  1024. }
  1025. $fsjs = trim($fsjs,' or ').")" ;
  1026. }
  1027. else if(count($js) == 1)
  1028. {
  1029. $fsjs = " and js = '$js[0]'";
  1030. }
  1031. $where = "(express = '2' or express = '63' or express = '64') 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
  1032. }
  1033. /**
  1034. else if($wid == 2 && stripos($notice['express'],',1,') !== false)
  1035. {
  1036. $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
  1037. }
  1038. else if($wid == 3 && stripos($notice['express'],',1,') !== false)
  1039. {
  1040. $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
  1041. }
  1042. else if($wid == 4 && stripos($notice['express'],',1,') !== false)
  1043. {
  1044. $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
  1045. }
  1046. else if($wid == 5 && stripos($notice['express'],',1,') !== false)
  1047. {
  1048. $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
  1049. }
  1050. **/
  1051. else if($wid == 2 && stripos($notice['express'],',1,') !== false)
  1052. {
  1053. $where = "express != '2' and express != '63' and express != '64' 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
  1054. }
  1055. else
  1056. {
  1057. exit;
  1058. }
  1059. $wlfs = array();
  1060. $dd = $this->fullorder->find_all("source != '1' and dlzemail < '1' and shop = '".$notice['shop']."' and library = 2 and ".$where);
  1061. $this->logic_ding->sendToDing("获取发送快件的快递条件"."source != '1' and dlzemail < '1' and shop = '".$notice['shop']."' and library = 2 and ".$where);
  1062. foreach ($dd as $v)
  1063. {
  1064. $shop = $this->shop->read($v['shop']);
  1065. $express = $this->express->read($v['express']);
  1066. $fs = $this->notice->get_god($v,$shop,$express,$notice);
  1067. $this->logic_ding->sendToDing($v['orderinfo']."监听邮件发送的异常:订单信息【".json_encode($v,JSON_UNESCAPED_UNICODE)."】获取快递信息【".json_encode($notice,JSON_UNESCAPED_UNICODE)."】返回的信息".json_encode($fs));
  1068. if($fs == 1)
  1069. {
  1070. $this->fullorder->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$v['id']);
  1071. //给crm发送信息 先存储数据 后续定时任务执行
  1072. if($v['shop'] < 10){
  1073. $this->zztmpdata->insert([
  1074. 'type'=>2,
  1075. 'act_name'=>'crm_order',
  1076. 'content'=>json_encode($v),
  1077. 'create_time'=>time()
  1078. ]);
  1079. }
  1080. }
  1081. else
  1082. {
  1083. //$pdtime = date('Y-m-d',time());
  1084. //$folderPath = './data/dlzemail/'.$pdtime; // 文件夹路径
  1085. //$permissions = 0777; // 权限设置
  1086. //if (!file_exists($folderPath)) { mkdir($folderPath, $permissions); }//创建文件夹
  1087. //file_exists($folderPath);
  1088. if(!is_file("./data/dlzemail/".$v['number'].".txt"))
  1089. {
  1090. $myfile = fopen("./data/dlzemail/".$v['number'].".txt", "w") or die("Unable to open file!");
  1091. fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
  1092. fclose($myfile);
  1093. }
  1094. else
  1095. {
  1096. $myfile = fopen("./data/dlzemail/".$v['number'].".txt", "a+") or die("Unable to open file!");
  1097. fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
  1098. fclose($myfile);
  1099. }
  1100. $this->fullorder->save(array('dlzemail'=>2,'dlzemailtime'=>time()),$v['id']);
  1101. }
  1102. sleep(50);
  1103. }
  1104. }
  1105. }
  1106. /**
  1107. //更新独立站运单信息
  1108. public function _waybill($arg_array)
  1109. {
  1110. //这里订单索引需要修改 8点是出已打印已出库 11点是已打印未出库
  1111. if(!isset($arg_array[0]) || !isset($arg_array[1]))
  1112. {
  1113. exit;
  1114. }
  1115. if(date("w",time()) == '0' && $arg_array[0] != '3')//非usps周日不更新
  1116. {
  1117. echo 7;exit;
  1118. }
  1119. if($arg_array[0] == 3)
  1120. {
  1121. $argarray = 2;
  1122. $typec = ' and express = 2 and printtime > "'.strtotime("-3 day").'"';//更新usps-usa快递的订单
  1123. }
  1124. else
  1125. {
  1126. $argarray = $arg_array[0];
  1127. $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())).'"';//更新快递的订单
  1128. }
  1129. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  1130. // 订单加入键值-k
  1131. $fdata = $this->fullorder->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');
  1132. //* 订单加入键值-j
  1133. //* 店铺加入键值-j
  1134. $fshop = $this->shop->find_all('1=1');
  1135. foreach ($fshop as $v)
  1136. {
  1137. $datashop[$v['id']] = $v;
  1138. }
  1139. //* 店铺加入键值-k
  1140. //* 快递加入键值-j
  1141. $fex = $this->express->find_all('1=1');
  1142. foreach ($fex as $v)
  1143. {
  1144. $dataex[$v['id']] = $v;
  1145. }
  1146. //* 快递加入键值-k
  1147. //* 仓库加入键值-k
  1148. $fwh = $this->warehouse->find_all('1=1');
  1149. foreach ($fwh as $v)
  1150. {
  1151. $datack[$v['id']] = $v;
  1152. }
  1153. //* 仓库加入键值-j
  1154. //$fs = $this->notice->get_ordertatus(216);//216成功状态
  1155. $i = 0;$j = 0;$ed = array();
  1156. foreach ($fdata as $key=>$value)
  1157. {
  1158. if($value['source'] == 1)
  1159. {
  1160. $this->fullorder->save(array('dlz'=>3,'state'=>216),$value['id']);
  1161. }
  1162. else
  1163. {
  1164. $ddh = substr($value['orderinfo'],1);
  1165. $ydh = $value['waybill'];
  1166. $xg = $value;//此订单数据
  1167. $shop = $datashop[$xg['shop']];//此订单店铺
  1168. $ex = $dataex[$xg['express']];//此订单快递
  1169. $warehouse = $datack[$xg['type']];//此订单仓库
  1170. //独立站地址更新订单状态、物流信息
  1171. if($arg_array[0] == 1)//23点更新用留言2
  1172. {
  1173. $readid = 2;
  1174. }
  1175. else if($arg_array[0] == 3)//7点更新用留言3
  1176. {
  1177. $readid = 3;
  1178. }
  1179. else //20点更新用默认留言(默认留言为1)
  1180. {
  1181. $readid = $xg['msg'];
  1182. }
  1183. @$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$readid);
  1184. if(!isset($gx['res']))
  1185. {
  1186. exit;
  1187. }
  1188. $this->fullorder->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$xg['id']);
  1189. }
  1190. //if($gx['res'] == 1 && $fs)
  1191. //{
  1192. // $ck = $this->_email($fs['content'],$xg,$warehouse['company']);
  1193. //}
  1194. sleep(2);//停留2秒
  1195. }
  1196. }
  1197. **/
  1198. public function _headgear($arg_array)
  1199. {
  1200. $ip = $this->input->ip_address();
  1201. if(!isset($arg_array[0]) || !isset($arg_array[1]))
  1202. {
  1203. exit;
  1204. }
  1205. if(!is_numeric($arg_array[0]) || !is_numeric($arg_array[1]))
  1206. {
  1207. exit;
  1208. }
  1209. $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)
  1210. if($arg_array[1] == 1)
  1211. {
  1212. $data = $this->fullordersmt->find_all($where,'express,number,orderinfo,shipremarks,printtime');
  1213. }
  1214. else
  1215. {
  1216. $data = $this->fullorder->find_all($where,'express,number,orderinfo,shipremarks,printtime');
  1217. }
  1218. foreach ($data as $k=>$v)
  1219. {
  1220. $express = $this->express->read($v['express']);
  1221. $data[$k]['express'] = $express['servicename'];
  1222. if($data[$k]['printtime'] > 0)
  1223. {
  1224. $data[$k]['printtime'] = date('Y-m-d H:i:s',$v['printtime']);
  1225. }
  1226. }
  1227. //$state = $this->api->get_headgear($data);
  1228. echo json_encode($data);
  1229. }
  1230. public function _kc_old()
  1231. {
  1232. $post = $this->input->post(NULL, TRUE);
  1233. if(isset($post['sku']))
  1234. {
  1235. $sku = $this->input->post('sku',true);
  1236. $warehouse = $this->warehouse->find_all();
  1237. $data = array();
  1238. foreach ($sku as $val)
  1239. {
  1240. $datasku = array();
  1241. foreach ($warehouse as $v)
  1242. {
  1243. $z = $this->whlabel->find_count('sku = "'.$val.'" and zd = "" and state = 0 and warehouse = "'.$v['id'].'"');
  1244. $datasku[] = array('name'=>$v['title'],'number'=>$z);
  1245. }
  1246. $data[$val] = $datasku;
  1247. }
  1248. }
  1249. echo json_encode($data);
  1250. }
  1251. public function _kc()
  1252. {
  1253. $datasku = array();
  1254. $info_list = $this->whlabel->find_pc("warehouse = '5'",'sku,features,warehouse','sku');
  1255. foreach ($info_list as $val)
  1256. {
  1257. $z = $this->whlabel->find_count('sku = "'.$val['sku'].'" and zd = "" and state = 0 and warehouse = "5"');
  1258. $datasku[] = array('sku'=>$val['sku'],'number'=>$z);
  1259. }
  1260. echo json_encode($datasku);
  1261. }
  1262. public function _fsstate()//订单消息页手动发送
  1263. {
  1264. $post = $this->input->post(NULL, TRUE);
  1265. if(isset($post['s']))
  1266. {
  1267. $id_arr = $this->input->post('s');
  1268. $notice = $this->input->post('notice');
  1269. $noticeid = $this->input->post('noticeid');
  1270. $id_arr = explode(',',trim($id_arr,','));
  1271. if(!$id_arr)
  1272. {
  1273. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1274. }
  1275. if($notice == '1' || $notice == '')
  1276. {
  1277. foreach ($id_arr as $v)
  1278. {
  1279. $data = $this->fullorder->read($v);
  1280. $adrs = $this->customer->get_email($data['email'],$data['shop']);
  1281. //$lkh = ($adrs['type'] == 1)?1:2;//白名单1黑名单2
  1282. $lkh = 1;
  1283. $pdlkh = ($adrs['num'] > 1)?1:0;//判断是否老客户
  1284. $fs = $this->_znxc($data,$data['orderinfo'],$lkh,$pdlkh);
  1285. if($fs == 1)
  1286. {
  1287. $this->fullorder->save(array('exstateerror'=>''),$data['id']);
  1288. }
  1289. sleep(40);
  1290. }
  1291. }
  1292. else
  1293. {
  1294. foreach ($id_arr as $v)
  1295. {
  1296. $data = $this->fullorder->read($v);
  1297. $fs = $this->_sdfs($data,$noticeid);
  1298. sleep(40);
  1299. }
  1300. }
  1301. echo json_encode(array('msg'=>'发送完成!','id'=>$id_arr,'success'=>true));exit;
  1302. }
  1303. }
  1304. public function _fswaybillemail()//运单号通知页手动发送
  1305. {
  1306. $post = $this->input->post(NULL, TRUE);
  1307. if(isset($post['s']))
  1308. {
  1309. $time = time();
  1310. $id_arr = $this->input->post('s');
  1311. $id_arr = explode(',',trim($id_arr,','));
  1312. if(!$id_arr)
  1313. {
  1314. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1315. }
  1316. foreach ($id_arr as $v)
  1317. {
  1318. $d = $this->fullorder->read($v);
  1319. $shop = $this->shop->read($d['shop']);
  1320. $ex = $this->express->read($d['express']);
  1321. $fs = $this->notice->find_all("shop = '".$d['shop']."' and message = '1' and state = '1' and type = '4' and ktime < '$time' and jtime > '$time'");
  1322. $fs = $fs[0];
  1323. $fs['email'] = $this->emaildata->read($fs['email']);
  1324. $ck = $this->notice->get_god($d,$shop,$ex,$fs);
  1325. if($ck == 1)
  1326. {
  1327. $this->fullorder->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$v);
  1328. }
  1329. sleep(1);
  1330. }
  1331. echo json_encode(array('msg'=>'发送完成!请检查是否成功','id'=>$id_arr,'success'=>true));exit;
  1332. }
  1333. }
  1334. /**
  1335. public function _fsstate()//订单消息页手动发送 _znxc 针对模板对应类型发送
  1336. {
  1337. $post = $this->input->post(NULL, TRUE);
  1338. if(isset($post['s']))
  1339. {
  1340. $id_arr = $this->input->post('s');
  1341. $id_arr = explode(',',$id_arr);
  1342. if(!$id_arr)
  1343. {
  1344. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1345. }
  1346. foreach ($id_arr as $v)
  1347. {
  1348. $data = $this->fullorder->read($v);
  1349. $adrs = $this->customer->get_email($data['email'],$data['shop']);
  1350. $lkh = ($adrs['type'] == 1)?1:2;//白名单1黑名单2
  1351. $fs = $this->_znxc($data,$data['orderinfo'],$lkh);
  1352. if($fs == 1)
  1353. {
  1354. $this->fullorder->save(array('exstateerror'=>''),$data['id']);
  1355. }
  1356. }
  1357. echo json_encode(array('msg'=>'发送完成!','id'=>$id_arr[0],'success'=>true));exit;
  1358. }
  1359. }
  1360. **/
  1361. public function _cangku()
  1362. {
  1363. $post = $this->input->post(NULL, TRUE);
  1364. if(isset($post['tk']))
  1365. {
  1366. $tk = $this->input->post('tk');
  1367. $tj = $this->input->post('tj');
  1368. $d = $this->fullorder->find_all("dtime > '$tk' and dtime < '$tj'");
  1369. $k = $this->customer->find_all("time > '$tk' and time < '$tj'");
  1370. echo json_encode(array('d'=>$d,'k'=>$k));exit;
  1371. }
  1372. }
  1373. public function _znxc($fullorder,$order_id,$lkh,$pdlkh,$hmdid='')
  1374. {
  1375. $time = time();
  1376. $sl = explode(';',$fullorder['quantity']);
  1377. $quantity = 0;
  1378. foreach ($sl as $v)
  1379. {
  1380. if($v > 1)
  1381. {
  1382. $quantity = 1;
  1383. }
  1384. }
  1385. $fid = $this->fullorder->get_orderinfo($order_id);
  1386. 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'] != '' ||
  1387. {
  1388. $asdasd = 0;
  1389. if($lkh == 2)
  1390. {
  1391. $asdasd = 1;
  1392. }
  1393. if(count($sl) > 1 && $quantity == 1)
  1394. {
  1395. $asdasd = 2;
  1396. }
  1397. 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)
  1398. {
  1399. $asdasd = 3;
  1400. }
  1401. $this->fullorder->save(array('content'=>$fid['content'].'黑名单客户、多产品的、包含PO BOX、包含APO的不发送-'.$asdasd.(($hmdid)?'['.$hmdid.']':''),'zdstate'=>$fid['zdstate'].'1-x|'),$fid['id']);//留言的现在正常发
  1402. return 'a';
  1403. }
  1404. else
  1405. {
  1406. if(count($sl) == '1' && $fullorder['quantity'] > 1)//如果item(产品)是1,但quantity大于等于2
  1407. {
  1408. $tab = 2;
  1409. }
  1410. else if($fullorder['shouldmoney'] > '400' && $fullorder['guarantee'] == 'Ineligible')//如果金额大于400美元并且无卖家保障
  1411. {
  1412. $tab = 1;
  1413. }
  1414. /**
  1415. else if(count($sl) == '1' && $fullorder['quantity'] > 1 && $fullorder['baddress'] != $fullorder['saddress'])//如果item(产品)是1,但quantity大于等于2并且Bill Address不等于Ship Address
  1416. {
  1417. $tab = 4;
  1418. }
  1419. else if($fullorder['baddress'] != $fullorder['saddress'])//如果Bill Address不等于Ship Address
  1420. {
  1421. $tab = 3;
  1422. }
  1423. **/
  1424. else//常规模板
  1425. {
  1426. $tab = 0;
  1427. }
  1428. $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'");//有条件不同模板匹配
  1429. if(isset($notice[0]['content']))
  1430. {
  1431. if($pdlkh == '1' && $notice[0]['thq'] != ''&& $notice[0]['thh'] != '')//非常规和老客户模板,如果是老客户并且需要替换的话
  1432. {
  1433. $notice[0]['content'] = str_replace($notice[0]['thq'],$notice[0]['thh'],$notice[0]['content']);
  1434. }
  1435. $shop = $this->shop->read($fullorder['shop']);
  1436. //$express = $this->express->read($fullorder['express']);
  1437. //$service = $this->service->read($express['service']);
  1438. $country = $this->country->read($fullorder['country']);
  1439. $fullorder['country'] = $country['ename'];
  1440. //$express['servicename'] =$service['title'];//增加快递名称
  1441. $express = array();
  1442. $notice[0]['email'] = $this->emaildata->read($notice[0]['email']);
  1443. $go = $this->notice->get_god($fullorder,$shop,$express,$notice[0]);
  1444. if($go == 1)
  1445. {
  1446. $this->fullorder->save(array('content'=>$fid['content'].'自动发送-成功;','zdstate'=>$fid['zdstate'].$notice[0]['type'].'-'.$notice[0]['tab'].'|','exstateerror'=>''),$fid['id']);
  1447. return 1;
  1448. }
  1449. else
  1450. {
  1451. $this->fullorder->save(array('exstateerror'=>'自动发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice[0]['type'].'-'.$notice[0]['message'].')'),$fid['id']);
  1452. }
  1453. }
  1454. else
  1455. {
  1456. $this->fullorder->save(array('exstateerror'=>'当前订单状态无匹配模板'),$fid['id']);
  1457. }
  1458. }
  1459. }
  1460. public function _sdfs($fullorder,$id)//手动发送信息
  1461. {
  1462. $time = time();
  1463. $notice = $this->notice->read($id);//无条件同模板匹配
  1464. $notice['email'] = $this->emaildata->read($notice['email']);
  1465. $shop = $this->shop->read($fullorder['shop']);
  1466. $express = $this->express->read($fullorder['express']);
  1467. if($notice['type'] == '1')
  1468. {
  1469. $fslx = 'tab';
  1470. $content = '自动发送';
  1471. $stripos = '1-';
  1472. }
  1473. else if ($notice['type'] == '2')
  1474. {
  1475. $fslx = 'logisticstatus';
  1476. $content = $notice['title'];
  1477. $stripos = $notice['type'].'-'.$notice[$fslx].'|';
  1478. }
  1479. if(stripos($fullorder['zdstate'],$stripos) === false && $fullorder['wltype'] == '0')//如果没发送过并且允许发送
  1480. {
  1481. $go = $this->notice->get_god($fullorder,$shop,$express,$notice);
  1482. if($go == 1)
  1483. {
  1484. if($notice['type'] == '1')
  1485. {
  1486. $this->fullorder->save(array('content'=>$fullorder['content'].$content.'-成功;','zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  1487. }
  1488. else if ($notice['type'] == '2')
  1489. {
  1490. $this->fullorder->save(array('wlcontent'=>$fullorder['wlcontent'].$content.'-成功;','wlfstime'=>time(),'zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  1491. }
  1492. return 1;
  1493. }
  1494. else
  1495. {
  1496. if($notice['type'] == '1')
  1497. {
  1498. $this->fullorder->save(array('exstateerror'=>$content.'发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  1499. }
  1500. else if ($notice['type'] == '2')
  1501. {
  1502. $this->fullorder->save(array('wlerror'=>$content.'发送失败2:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  1503. }
  1504. }
  1505. }
  1506. }
  1507. public function _zz()
  1508. {
  1509. //$f = $this->fullorder->find_all("1=1",'wlfstime','wlfstime desc',0,2);
  1510. if(date("w") == '0')
  1511. {
  1512. exit;
  1513. }
  1514. $f17 = array();
  1515. $time = time();
  1516. $tjlike = array();
  1517. $urls = array();$sl = 0;
  1518. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1519. foreach ($notice as $key=>$var)
  1520. {
  1521. $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));
  1522. }
  1523. foreach($urls as $value) {
  1524. $tjlike[] = $value['url'];
  1525. $ch = curl_init();
  1526. $url = $value['url'];
  1527. curl_setopt($ch,CURLOPT_URL,$url);
  1528. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1529. curl_setopt($ch,CURLOPT_HEADER,0);
  1530. curl_setopt($ch,CURLOPT_POST, 1);
  1531. curl_setopt($ch,CURLOPT_TIMEOUT,5);
  1532. //设置post数据
  1533. $post = array();
  1534. $post['data'] = $value['data'];
  1535. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1536. $res = curl_exec($ch);
  1537. curl_close($ch);
  1538. $sl++;
  1539. }
  1540. echo "<pre>";
  1541. print_r($tjlike);
  1542. echo $sl;
  1543. /**
  1544. $urls = array();
  1545. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1546. foreach ($notice as $key=>$var)
  1547. {
  1548. $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));
  1549. }
  1550. $mh = curl_multi_init();
  1551. $urlHandlers = array();
  1552. $urlData = array();
  1553. // 初始化多个请求句柄为一个
  1554. foreach($urls as $value) {
  1555. $ch = curl_init();
  1556. $url = $value['url'];
  1557. $url .= strpos($url, '?') ? '&' : '?';
  1558. curl_setopt($ch, CURLOPT_URL, $url);
  1559. // 设置数据通过字符串返回,而不是直接输出
  1560. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1561. curl_setopt($ch,CURLOPT_HEADER,0);
  1562. curl_setopt($ch,CURLOPT_POST, 1);
  1563. $post = array();
  1564. $post['data'] = $value['data'];
  1565. curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($post));
  1566. $urlHandlers[] = $ch;
  1567. curl_multi_add_handle($mh, $ch);
  1568. }
  1569. $active = null;
  1570. // 检测操作的初始状态是否OK,CURLM_CALL_MULTI_PERFORM为常量值-1
  1571. do {
  1572. // 返回的$active是活跃连接的数量,$mrc是返回值,正常为0,异常为-1
  1573. $mrc = curl_multi_exec($mh, $active);
  1574. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  1575. // 如果还有活动的请求,同时操作状态OK,CURLM_OK为常量值0
  1576. while ($active && $mrc == CURLM_OK) {
  1577. // 持续查询状态并不利于处理任务,每60ms检查一次,此时释放CPU,降低机器负载
  1578. usleep(50000);
  1579. // 如果批处理句柄OK,重复检查操作状态直至OK。select返回值异常时为-1,正常为1(因为只有1个批处理句柄)
  1580. if (curl_multi_select($mh) != -1) {
  1581. do {
  1582. $mrc = curl_multi_exec($mh, $active);
  1583. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  1584. }
  1585. }
  1586. // 获取返回结果
  1587. foreach($urlHandlers as $index => $ch) {
  1588. $urlData[$index] = curl_multi_getcontent($ch);
  1589. // 移除单个curl句柄
  1590. curl_multi_remove_handle($mh, $ch);
  1591. }
  1592. curl_multi_close($mh);
  1593. print_r($urlData);
  1594. **/
  1595. /**
  1596. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1597. foreach ($notice as $key=>$var)
  1598. {
  1599. $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']."%'";//正式发送的时候开启这个"'
  1600. //$where = "shop = '2' and waybill != '' and library = '2' and librarytime > '".(time()-15*24*3600)."'";
  1601. $ch = curl_init();
  1602. curl_setopt($ch,CURLOPT_URL,'http://'.$_SERVER['HTTP_HOST'].'/api/wlfs?v='.$var['id']);
  1603. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1604. curl_setopt($ch,CURLOPT_HEADER,0);
  1605. curl_setopt($ch,CURLOPT_POST, 1);
  1606. curl_setopt($ch,CURLOPT_TIMEOUT,1);
  1607. //设置post数据
  1608. $post = array();
  1609. $post['data'] = array('where'=>$where,'var'=>$var);
  1610. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1611. $res = curl_exec($ch);
  1612. curl_close($ch);
  1613. //$this->_wlfs($where,$var);
  1614. }
  1615. **/
  1616. /**
  1617. $var = $this->notice->read(63);//已有自动发送,这个是物流发送
  1618. $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']."%'";//正式发送的时候开启这个"'
  1619. $this->_wlfs($where,$var);
  1620. **/
  1621. }
  1622. public function _wlfs()
  1623. {
  1624. $webhookregister = 0;
  1625. $post = $this->input->post(NULL, TRUE);
  1626. $data = $this->input->post('data',true);
  1627. $where = $data['where'];
  1628. $var = $data['var'];
  1629. $wlfs = array();
  1630. $shopid = $where['shop'];
  1631. @$this->allocation->insert(array('title'=>date('Y-m-d',time()).'-'.$shopid));
  1632. $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']."%'";//正式发送的时候开启这个"'
  1633. //$where = "shop = '".$where['shop']."' and waybill != '' and library = '2' and express = '3' and librarytime > '1636300800' and wlcontent not like '%".$where['wlcontent']."%'";//正式发送的时候开启这个"'
  1634. $data = $this->fullorder->find_all($where);
  1635. $csck = array();
  1636. foreach ($data as $k=>$v)
  1637. {
  1638. //$this->logic_ding->sendToDing("获取订单的物流信息".$v['number']);
  1639. $vexpress = $v['express'];
  1640. $shop = $this->shop->read($v['shop']);
  1641. $express = $this->express->read($v['express']);
  1642. $service = $this->service->read($express['service']);
  1643. $country = $this->country->read($v['country']);
  1644. $v['country'] = $country['ename'];
  1645. $express['servicename'] =$service['title'];//增加快递名称
  1646. $v['cxcode'] = strtolower($express['cxcode']);//增加快递服务商码
  1647. if($v['expressstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1648. {
  1649. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1650. {
  1651. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1652. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1653. }
  1654. continue;
  1655. }
  1656. if(($express['cxcode'] == '' && $v['exstateerror'] == '') || ($express['cxcode'] == '' && $v['exstateerror'] != ''))
  1657. {
  1658. continue;
  1659. }
  1660. else if($express['cxcode'] == 'usps')//$express['cxcode'] == 'fedex' || $express['cxcode'] == 'dhl' || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd'
  1661. {
  1662. /**
  1663. if($express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
  1664. {
  1665. $express['cxcode'] = 'cne';
  1666. }
  1667. **/
  1668. $logistics = $express['cxcode'];
  1669. }
  1670. else if($express['cxcode'] == 'yscx'){
  1671. $v['servicename'] =$service['title'];//增加快递名称
  1672. $v['url'] = $express['url'];//增加快递链接
  1673. $v['express'] = $vexpress;
  1674. $this->zzjobs->insert([
  1675. 'status'=>0,
  1676. 'quque'=>'ysgjcx',//云尚轨迹查询
  1677. 'payload'=>json_encode([
  1678. 'v'=>$v,
  1679. 'id'=>$var['id']
  1680. ],JSON_UNESCAPED_UNICODE),
  1681. 'do_interval'=>1,
  1682. 'create_time'=>time()
  1683. ]);
  1684. continue;
  1685. }
  1686. else if(($express['cxcode'] == 'ups' && $v['webhookregister'] == 1) || $express['cxcode'] == '17track')
  1687. {
  1688. continue;
  1689. }
  1690. else if($express['cxcode'] == 'ups' && $v['webhookregister'] < 1)//使用webhook注册模式 || $express['cxcode'] == '17track'
  1691. {
  1692. $logistics = $express['cxcode'];
  1693. $webhookregister = 1;
  1694. }
  1695. else
  1696. {
  1697. //暂时不启用第三方,这里直接跳出
  1698. $this->fullorder->save(array('expressstate'=>'99'),$v['id']);
  1699. continue;
  1700. //$logistics = 'apismt';
  1701. //$v['express'] = strtolower($express['cxcode']);//替换为快递服务商码
  1702. }
  1703. $this->logic_ding->sendToDing("检测是否检测--".$v['number']."--执行的轨迹追踪信息--".$logistics);
  1704. $v['servicename'] =$service['title'];//增加快递名称
  1705. $v['url'] = $express['url'];//增加快递链接
  1706. @$fs = $this->$logistics->get_logistics($v);
  1707. $csck[] = array($v['number'],$fs['f'],$fs['content']);
  1708. if(!isset($fs['f']))
  1709. {
  1710. $fs = $this->$logistics->get_logistics($v);
  1711. if(!isset($fs['f']))
  1712. {
  1713. continue;
  1714. }
  1715. if($fs['f'] == '1')
  1716. {
  1717. $v['express'] = $vexpress;
  1718. if($fs['exstate'] > $v['expressstate'] || isset($fs['webhookregister']))
  1719. {
  1720. $this->fullorder->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister,'wlerror'=>''),$v['id']);
  1721. }
  1722. if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1723. {
  1724. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1725. {
  1726. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1727. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1728. }
  1729. }
  1730. }
  1731. /**
  1732. if($logistics == 'apismt')//第三方未购买,第三方查询直接进入无法查询状态
  1733. {
  1734. $this->fullorder->save(array('expressstate'=>'99'),$v['id']);
  1735. }
  1736. **/
  1737. }
  1738. else
  1739. {
  1740. if($fs['f'] == '1')
  1741. {
  1742. $v['express'] = $vexpress;
  1743. if($fs['exstate'] > $v['expressstate'] || isset($fs['webhookregister']))
  1744. {
  1745. $this->fullorder->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister,'wlerror'=>''),$v['id']);
  1746. }
  1747. if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1748. {
  1749. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1750. {
  1751. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1752. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1753. }
  1754. }
  1755. }
  1756. else
  1757. {
  1758. $this->fullorder->save(array('wlerror'=>$fs['content']),$v['id']);
  1759. }
  1760. }
  1761. }
  1762. @$this->allocation->insert(array('title'=>$shopid.'-'.json_encode($csck)));
  1763. if($wlfs)
  1764. {
  1765. foreach ($wlfs as $k=>$v)
  1766. {
  1767. $t1 = microtime(true);
  1768. $this->_sdfs($v['v'],$v['id']);
  1769. $t2 = microtime(true);
  1770. $t3 = (40-($t2-$t1) < 1)?1:round(40-($t2-$t1));
  1771. sleep($t3);
  1772. }
  1773. }
  1774. }
  1775. public function _zzold()
  1776. {
  1777. $data = $this->fullorder->find_all("library = '2' and waybill != '' and exstate != '4' and exstate != '5' and dtime > '1580486400'");
  1778. foreach ($data as $k=>$v)
  1779. {
  1780. $shop = $this->shop->read($v['shop']);
  1781. $express = $this->express->read($v['express']);
  1782. $service = $this->service->read($express['service']);
  1783. $country = $this->country->read($v['country']);
  1784. $v['country'] = $country['ename'];
  1785. $express['servicename'] =$service['title'];//增加快递名称
  1786. if($express['cxcode'] == '' && $v['exstateerror'] == '')
  1787. {
  1788. continue;
  1789. }
  1790. else if($express['cxcode'] == '' && $v['exstateerror'] != '')
  1791. {
  1792. continue;
  1793. }
  1794. else if($express['cxcode'] == 'fedex' || $express['cxcode'] == 'usps' || $express['cxcode'] == 'dhl' || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
  1795. {
  1796. $logistics = $express['cxcode'];
  1797. }
  1798. else
  1799. {
  1800. $logistics = 'apismt';
  1801. }
  1802. $v['express'] = strtolower($express['cxcode']);//替换为快递服务商码
  1803. $v['servicename'] =$service['title'];//增加快递名称
  1804. $v['url'] = $express['url'];//增加快递链接
  1805. $fs = $this->$logistics->get_logistics($v);
  1806. if(!isset($fs['f']))
  1807. {
  1808. $this->fullorder->save(array('exstate'=>'99'),$v['id']);
  1809. }
  1810. else
  1811. {
  1812. if($fs['f'] == '0')
  1813. {
  1814. $this->fullorder->save(array('excontent'=>$fs['content']),$v['id']);
  1815. }
  1816. if($fs['f'] == '2')
  1817. {
  1818. }
  1819. else
  1820. {
  1821. $this->fullorder->save(array('exstate'=>$fs['exstate'],'excontent'=>$fs['data']),$v['id']);
  1822. }
  1823. }
  1824. }
  1825. }
  1826. public function _query()
  1827. {
  1828. header('Access-Control-Allow-Origin: *');
  1829. $post = $this->input->post(NULL, TRUE);
  1830. if(isset($post['orderinfo']))
  1831. {
  1832. $list = array();
  1833. $orderinfo = $this->input->post('orderinfo',true);
  1834. $orderinfo = explode(',',trim($orderinfo,','));
  1835. foreach ($orderinfo as $v)
  1836. {
  1837. $exp="/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
  1838. if(is_numeric($v) && mb_strlen($v) > 8)
  1839. {
  1840. $w = "orderinfo like '%$v%'";
  1841. }
  1842. else if(filter_var($v, FILTER_VALIDATE_EMAIL))
  1843. {
  1844. $w = "email like '%$v%'";
  1845. }
  1846. else
  1847. {
  1848. echo json_encode(array('site'=>0,'success'=>true));exit;
  1849. }
  1850. $data = $this->fullorder->find_all($w." and dtime > '1577811600'");
  1851. if(isset($data[0]))
  1852. {
  1853. if($data[0]['library'] != '2')
  1854. {
  1855. $list[] = array('orderinfo'=>$v,'site'=>1);
  1856. }
  1857. else if($data[0]['library'] == '2' && $data[0]['exstate'] == '99')
  1858. {
  1859. $list[] = array('orderinfo'=>$v,'site'=>2);
  1860. }
  1861. else if($data[0]['library'] == '2' && $data[0]['exstate'] != '99')
  1862. {
  1863. if($data[0]['excontent'] != '成功;' && $data[0]['excontent'] != '')
  1864. {
  1865. $list[] = array('orderinfo'=>$v,'site'=>3,'data'=>$data[0]['excontent']);
  1866. }
  1867. else
  1868. {
  1869. $list[] = array('orderinfo'=>$v,'site'=>2);
  1870. }
  1871. }
  1872. }
  1873. else
  1874. {
  1875. $list[] = array('orderinfo'=>$v,'site'=>0);
  1876. }
  1877. }
  1878. echo json_encode(array('t'=>count($orderinfo),'list'=>$list,'success'=>true));exit;
  1879. }
  1880. }
  1881. public function _logistics()
  1882. {
  1883. if(isset($_GET['waybill']))
  1884. {
  1885. $waybill = $this->input->get('waybill',true);
  1886. $s = $this->input->get('shop',true);
  1887. //$express = $this->input->get('express',true);
  1888. $data = $this->fullorder->get_waybill($waybill);
  1889. if(isset($data['excontent']) && $data['excontent'] != '')
  1890. {
  1891. //$a = $this->$express->get_logistics(array('waybill'=>$waybill));
  1892. echo json_encode(array('track'=>array('f'=>1,'data'=>$data['excontent']),'msg'=>'','success'=>1));exit;
  1893. }
  1894. else
  1895. {
  1896. $shop = $this->shop->get_shopname($s);
  1897. if(!$shop)
  1898. {
  1899. echo json_encode(array('track'=>'','msg'=>'No logistics information','success'=>0));exit;
  1900. }
  1901. $data = $this->fullorder->get_orderinfo($shop.$waybill);
  1902. if(isset($data['excontent']) && $data['excontent'] != '')
  1903. {
  1904. echo json_encode(array('track'=>array('f'=>1,'data'=>$data['excontent']),'msg'=>'','success'=>1));exit;
  1905. }
  1906. echo json_encode(array('track'=>'','msg'=>'No logistics information','success'=>0));exit;
  1907. }
  1908. }
  1909. }
  1910. public function _klarna()
  1911. {
  1912. $shop = array();$cg = array();$sb = array();
  1913. $ftime = strtotime(date("Y-m-d 0:00:0",strtotime("-10 day")))+8*3600;
  1914. $ttime = strtotime(date("Y-m-d 8:00:0",time()));
  1915. $shopdata = $this->shop->find_all("type = '269' and klarnaname != '' and klarnapass != ''");
  1916. foreach($shopdata as $v)
  1917. {
  1918. $data = $this->fullorder->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");
  1919. foreach($data as $val)
  1920. {
  1921. $api = $this->_klarnaapi($val['paypal'],$val['shouldmoney'],$v['klarnaname'],$v['klarnapass']);
  1922. $header = $api['header'];
  1923. $api = $api['res'];
  1924. if(isset($api['error_messages'][0]))
  1925. {
  1926. if(stripos($api['error_messages'][0],'amount is 0 for') !== false)
  1927. {
  1928. $this->fullorder->save(array('klarna'=>3),$val['id']);
  1929. $sb[] = array($val['number'],$val['orderinfo'],'oooo3');
  1930. }
  1931. else
  1932. {
  1933. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>$api['error_messages'][0]),$val['id']);
  1934. $sb[] = array($val['number'],$val['orderinfo'],'oooo1');
  1935. }
  1936. }
  1937. else if($api == '')
  1938. {
  1939. if(isset($header['http_code']) && $header['http_code'] == 201)
  1940. {
  1941. $this->fullorder->save(array('klarna'=>2),$val['id']);
  1942. $cg[] = array($val['number'],$val['orderinfo'],'oooo2');
  1943. }
  1944. else
  1945. {
  1946. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>'未知错误'),$val['id']);
  1947. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1948. }
  1949. }
  1950. else if(isset($api['cs']))
  1951. {
  1952. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>'超时'),$val['id']);
  1953. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1954. }
  1955. else
  1956. {
  1957. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>'未知错误'),$val['id']);
  1958. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1959. }
  1960. }
  1961. }
  1962. echo "<pre>";
  1963. print_r($cg);
  1964. echo "<pre>";
  1965. print_r($sb);
  1966. }
  1967. public function _klarnaapi($paypal,$shouldmoney,$name,$pass)
  1968. {
  1969. $url = 'https://api-na.klarna.com/ordermanagement/v1/orders/'.$paypal.'/captures';
  1970. $data = '{"captured_amount": '.str_replace('.','',$shouldmoney).'}';
  1971. $header[] = "Content-Type:application/json";
  1972. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1973. $ch = curl_init();
  1974. curl_setopt($ch, CURLOPT_URL, $url);
  1975. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1976. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1977. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  1978. curl_setopt($ch, CURLOPT_POST, 1);
  1979. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1980. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  1981. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1982. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1983. $res = curl_exec($ch);
  1984. $header = curl_getinfo($ch);
  1985. if($res === false)
  1986. {
  1987. if(curl_errno($ch))
  1988. {
  1989. return array('res'=>'1','header'=>'','cs'=>1);
  1990. }
  1991. }
  1992. else
  1993. {
  1994. $res = json_decode($res,true);
  1995. return array('res'=>$res,'header'=>$header);
  1996. }
  1997. curl_close($ch);
  1998. }
  1999. public function _klarnadata($paypal,$name,$pass)
  2000. {
  2001. $url = 'https://api-na.klarna.com/ordermanagement/v1/orders/'.$paypal;
  2002. $header[] = "Content-Type:application/json";
  2003. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  2004. $ch = curl_init();
  2005. curl_setopt($ch, CURLOPT_URL, $url);
  2006. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2007. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  2008. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  2009. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  2010. $res = curl_exec($ch);
  2011. curl_close($ch);
  2012. $res = json_decode($res,true);
  2013. $data = '';
  2014. if(isset($res['fraud_status']))
  2015. {
  2016. // $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'];
  2017. if(isset($res['initial_payment_method']['number_of_installments'])){
  2018. $number_of_installments = $res['initial_payment_method']['number_of_installments'];
  2019. }else{
  2020. $number_of_installments = 0;
  2021. }
  2022. $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:'.$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'];
  2023. }
  2024. return $data;
  2025. }
  2026. public function _hqpaypal()
  2027. {
  2028. $shop = $this->shop->find_all("paypalname != ''");
  2029. foreach ($shop as $val)
  2030. {
  2031. $d = $this->fullorder->find_all("shop = '".$val['id']."' and dtime > '".(time()-(5*24*3600))."' and dtime < '".(time()-(3*3600))."' and (pay = '22' || pay = '7') and klarnadata = ''");
  2032. foreach ($d as $v)
  2033. {
  2034. $paypal = $this->paypal->data($v['paypal'],$val);
  2035. if($paypal != '')
  2036. {
  2037. $this->fullorder->save(array('klarnadata'=>$paypal),$v['id']);
  2038. }
  2039. }
  2040. }
  2041. }
  2042. public function _hqstripe()
  2043. {
  2044. $shop = $this->shop->find_all("stripe != ''");
  2045. foreach ($shop as $val)
  2046. {
  2047. $d = $this->fullorder->find_all("shop = '".$val['id']."' and dtime > '".(time()-(5*24*3600))."' and dtime < '".time()."' and pay = '1211' and klarnadata = ''");
  2048. foreach ($d as $v)
  2049. {
  2050. $paypal = $this->_stripe($v['paypal'],$val['stripe']);
  2051. if($paypal != '')
  2052. {
  2053. $this->fullorder->save(array('klarnadata'=>$paypal),$v['id']);
  2054. }
  2055. }
  2056. }
  2057. }
  2058. public function _stripe($pay,$stripe)
  2059. {
  2060. $url = 'https://api.stripe.com/v1/payment_intents/'.$pay;
  2061. $header[] = "Authorization:Bearer ".$stripe;
  2062. $ch = curl_init();
  2063. curl_setopt($ch, CURLOPT_URL, $url);
  2064. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2065. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  2066. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  2067. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  2068. $res = curl_exec($ch);
  2069. curl_close($ch);
  2070. $res = json_decode($res,true);
  2071. $k = '';
  2072. if(isset($res['shipping']['name']))
  2073. {
  2074. $line = ($res['shipping']['address']['line2'] != '')?$res['shipping']['address']['line1'].' '.$res['shipping']['address']['line2']:$res['shipping']['address']['line1'];
  2075. $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));
  2076. }
  2077. return $k;
  2078. }
  2079. public function _afterpay($paypal,$name,$pass)
  2080. {
  2081. $url = 'https://global-api.afterpay.com/v2/payments?ids='.$paypal;
  2082. $header[] = "Accept:application/json";
  2083. $header[] = "User-Agent: Readme.io API Simulator'";
  2084. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  2085. $ch = curl_init();
  2086. curl_setopt($ch, CURLOPT_URL, $url);
  2087. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2088. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  2089. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  2090. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  2091. $res = curl_exec($ch);
  2092. curl_close($ch);
  2093. $res = json_decode($res,true);
  2094. $data = '';
  2095. if(isset($res['results'][0]['orderDetails']['consumer']['email']))
  2096. {
  2097. $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'];
  2098. $data = str_replace(',,',',',$data);
  2099. }
  2100. return $data;
  2101. }
  2102. public function _clearpay($paypal,$name,$pass)
  2103. {
  2104. $url = 'https://global-api.afterpay.com/v2/payments?ids='.$paypal;
  2105. $header[] = "Accept:application/json";
  2106. $header[] = "User-Agent: Readme.io API Simulator'";
  2107. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  2108. $ch = curl_init();
  2109. curl_setopt($ch, CURLOPT_URL, $url);
  2110. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  2111. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  2112. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  2113. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  2114. $res = curl_exec($ch);
  2115. curl_close($ch);
  2116. $res = json_decode($res,true);
  2117. $data = '';
  2118. if(isset($res['results'][0]['orderDetails']['consumer']['email']))
  2119. {
  2120. $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'];
  2121. $data = str_replace(',,',',',$data);
  2122. }
  2123. return $data;
  2124. }
  2125. public function _htmlstock()
  2126. {
  2127. if(isset($_GET['hq']))
  2128. {
  2129. $ProductsType = $this->typeclass->find_all("classid = '16' and hq = '1'",'id,title','sequence asc');
  2130. foreach ($ProductsType as $k=>$v)
  2131. {
  2132. if($v['title'] == 'Closure')
  2133. {
  2134. $ProductsType[$k]['title'] = 'Closure/Frontal';
  2135. }
  2136. }
  2137. $HairColor = $this->typeclass->find_all("classid = '8' and hq = '1'",'id,title','sequence asc');
  2138. $HairWavy = $this->typeclass->find_all("classid = '15' and hq = '1'",'id,title','sequence asc');
  2139. $WigType = $this->typeclass->find_all("classid = '18' and hq = '1'",'id,title','sequence asc');
  2140. $Length = $this->typeclass->find_all("classid = '14' and hq = '1'",'id,title','sequence asc');
  2141. echo json_encode(array('ProductsType'=>$ProductsType,'HairColor'=>$HairColor,'HairWavy'=>$HairWavy,'WigType'=>$WigType,'Length'=>$Length));exit;
  2142. //http://1.wepolicy.cn/api/htmlstock?hq=1
  2143. }
  2144. if(isset($_GET['page']))
  2145. {
  2146. $del = array();
  2147. $typeclass13 = $this->typeclass->find_all("classid = '13'");
  2148. $typeclass16 = $this->typeclass->find_all("classid = '16'");
  2149. foreach ($typeclass16 as $key=>$value)
  2150. {
  2151. foreach ($typeclass13 as $v)
  2152. {
  2153. $del[] = $value['title'].' '.$v['title'];
  2154. }
  2155. }
  2156. $page = $this->input->get('page',true);
  2157. $perpage = $this->input->get('perpage',true);
  2158. $category = $this->input->get('ProductsType',true);//类目
  2159. $color = $this->input->get('HairColor',true);//颜色
  2160. $lowe = $this->input->get('HairWavy',true);//花型
  2161. $lacetype = $this->input->get('WigType',true);//头套种类
  2162. $size = $this->input->get('Length',true);//长度
  2163. $title = $this->input->get('title',true);//传输文本
  2164. $warehouse = 5;
  2165. $state = $this->input->get('state',true);
  2166. $where = "warehouse = '5' and state = '0'";
  2167. if($category)
  2168. {
  2169. $where .= " and features like '%-$category-%'";
  2170. }
  2171. if($color)
  2172. {
  2173. $where .= " and features like '%-$color-%'";
  2174. }
  2175. if($lowe)
  2176. {
  2177. $where .= " and features like '%-$lowe-%'";
  2178. }
  2179. if($lacetype)
  2180. {
  2181. $where .= " and features like '%-$lacetype-%'";
  2182. }
  2183. if($size)
  2184. {
  2185. $where .= " and features like '%-$size-%'";
  2186. }
  2187. if($title)
  2188. {
  2189. $where .= " and title like '%$title%'";
  2190. }
  2191. $order_str = "id desc";
  2192. if(empty($page))
  2193. {
  2194. $start = 0;
  2195. $perpage = 1;
  2196. }
  2197. else
  2198. {
  2199. $start = ($page - 1)*$perpage;
  2200. }
  2201. $info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number',$order_str,$start,$perpage);
  2202. $data = array();
  2203. foreach ($info_list as $key=>$value)
  2204. {
  2205. $c = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "5" and features = "'.$value['features'].'" and zd = ""');
  2206. if($c > 1)
  2207. {
  2208. $data[] = array('Item'=>str_replace($del,'',$value['title']),'Stock'=>$c);
  2209. }
  2210. }
  2211. $total = count($this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
  2212. $pagenum = ceil($total/$perpage);
  2213. $over = $total-($start+$perpage);
  2214. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($data));//总数量,剩余数量,总页数,数据
  2215. echo json_encode($rows);exit;
  2216. ///api/htmlstock?page=1&perpage=50&ProductsType=&HairColor=&HairWavy=&WigType=&Length= //页数、每页数量、类目、颜色、花型、头套种类、尺寸
  2217. }
  2218. }
  2219. public function _zc17track()
  2220. {
  2221. $express = array();
  2222. $ex = $this->express->find_all("cxcode = '17track'");
  2223. foreach ($ex as $v)
  2224. {
  2225. $express[$v['id']] = $v['title'];
  2226. }
  2227. $time_threshold = time() - 12 * 24 * 3600;
  2228. $this->db->select('a.number, a.express,a.waybill');
  2229. $this->db->from('crowd_fullorder as a');
  2230. $this->db->join('express as b', 'a.express = b.id', 'inner');
  2231. $this->db->where('a.waybill !=', '');
  2232. $this->db->where('a.library', '2');
  2233. $this->db->where('a.librarytime >', $time_threshold);
  2234. $this->db->where('a.webhookregister <', 1);
  2235. $this->db->where('b.cxcode', '17track');
  2236. $query = $this->db->get();
  2237. $data = $query->result_array();
  2238. $fsdata = array();
  2239. foreach ($data as $v)
  2240. {
  2241. if(!isset($express[$v['express']]))
  2242. {
  2243. continue;
  2244. }
  2245. if(stripos($express[$v['express']],'DHL') !== false)
  2246. {
  2247. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'100001');
  2248. }
  2249. else if(stripos($express[$v['express']],'UPS') !== false)
  2250. {
  2251. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'100002');
  2252. }
  2253. else if((stripos($express[$v['express']],'FEDEX') !== false)||(stripos($express[$v['express']],'FedEx') !== false) )
  2254. {
  2255. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'100003');
  2256. }
  2257. else if(stripos($express[$v['express']],'TNT') !== false)
  2258. {
  2259. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'100004');
  2260. }
  2261. else if(stripos($express[$v['express']],'ARAMEX') !== false)
  2262. {
  2263. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'100006');
  2264. }
  2265. else if(stripos($express[$v['express']],'YunExpress') !== false){
  2266. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'190008');
  2267. }
  2268. else if(stripos($express[$v['express']],'DEPX') !== false){
  2269. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'100014');
  2270. }
  2271. else if(stripos($express[$v['express']],'EMS') !== false)
  2272. {
  2273. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'3013');
  2274. }
  2275. else if(stripos($express[$v['express']],'GES') !== false)
  2276. {
  2277. $fsdata[] = array('number'=>$v['waybill'],'carrier'=>'190258');
  2278. }
  2279. else
  2280. {
  2281. $fsdata[] = array('number'=>$v['waybill'],'auto_detection'=>'true');
  2282. }
  2283. }
  2284. $fsdata = array_chunk($fsdata, 40);
  2285. $logistics = '17track';
  2286. foreach ($fsdata as $v)
  2287. {
  2288. $fs = $this->$logistics->get_logistics(json_encode($v));
  2289. $this->logic_ding->sendToDing("监听17track注册为什么获取不到的原因,请求参数".json_encode($v));
  2290. $this->logic_ding->sendToDing("监听17track注册为什么获取不到的原因,返回参数".json_encode($fs));
  2291. if(isset($fs['f']))
  2292. {
  2293. $csck[] = array($v,$fs['f'],$fs['content']);
  2294. foreach ($v as $val)
  2295. {
  2296. $d = $this->fullorder->get_waybill($val['number']);
  2297. if($fs['f'] == '1')
  2298. {
  2299. $this->fullorder->save(array('webhookregister'=>1,'wlerror'=>''),$d['id']);
  2300. }
  2301. else
  2302. {
  2303. $this->fullorder->save(array('wlerror'=>$fs['content']),$d['id']);
  2304. }
  2305. }
  2306. }
  2307. else
  2308. {
  2309. $csck[] = array($v,'CW',"CS");
  2310. }
  2311. sleep(3);
  2312. }
  2313. @$this->allocation->insert(array('title'=>json_encode($csck)));
  2314. /**
  2315. $data = $this->fullorder->find_all("waybill != '' and library = '2' and librarytime > '".(time()-12*24*3600)."' and webhookregister < 1");
  2316. $csck = array();
  2317. foreach ($data as $k=>$v)
  2318. {
  2319. $express = $this->express->read($v['express']);
  2320. $service = $this->service->read($express['service']);
  2321. $v['servicename'] =$service['title'];//增加快递名称
  2322. $v['url'] = $express['url'];//增加快递链接
  2323. $logistics = '17track';
  2324. $fs = $this->$logistics->get_logistics($v);
  2325. if(isset($fs['f']))
  2326. {
  2327. $csck[] = array($v['number'],$fs['f'],$fs['content']);
  2328. if($fs['f'] == '1')
  2329. {
  2330. $this->fullorder->save(array('webhookregister'=>1,'wlerror'=>''),$v['id']);
  2331. }
  2332. else
  2333. {
  2334. $this->fullorder->save(array('wlerror'=>$fs['content']),$v['id']);
  2335. }
  2336. }
  2337. else
  2338. {
  2339. $csck[] = array($v['number'],'CW',"CS");
  2340. }
  2341. sleep(1);
  2342. }
  2343. @$this->allocation->insert(array('title'=>$shopid.'-'.json_encode($csck)));
  2344. **/
  2345. }
  2346. public function _17track()
  2347. {
  2348. $xq = array();
  2349. $j = file_get_contents('PHP://input');
  2350. $j = json_decode($j, true);
  2351. $j = $j['data'];
  2352. $express = array();
  2353. $expressdata = $this->express->find_all('1=1');
  2354. foreach ($expressdata as $v)
  2355. {
  2356. $express[$v['id']] = $v['title'];
  2357. }
  2358. //$sh = hash("sha256",$j['event'].'/'.json_encode($j).'/0811AC1711EAABB7D764D04B824F8C2D');
  2359. $f = 'fullorder';
  2360. $d = $this->fullorder->get_waybill($j['number']);
  2361. if(!$d)
  2362. {
  2363. $f = 'fullordersmt';
  2364. $d = $this->fullordersmt->get_waybill($j['number']);
  2365. if(!$d)
  2366. {
  2367. $f = 'fullordertt';
  2368. $d = $this->fullordertt->get_waybill($j['number']);
  2369. }
  2370. }
  2371. if(!$d)
  2372. {
  2373. exit;
  2374. }
  2375. $state = '';
  2376. $zxzt = array_reverse($j['track_info']['milestone']);
  2377. foreach ($zxzt as $v)
  2378. {
  2379. if($v['time_iso'] != NULL)
  2380. {
  2381. $state = $v['key_stage'];
  2382. break;
  2383. }
  2384. }
  2385. $exstate = 0;//无信息
  2386. if($state == 'InfoReceived' || $state == 'PickedUp' || $state == 'Departure' || $state == 'Arrival')//运输途中
  2387. {
  2388. $exstate = 3;//在途中
  2389. }
  2390. else if($state == 'OutForDelivery')//派送中
  2391. {
  2392. $exstate = 4;
  2393. }
  2394. else if($state == 'Returned' || $zxzt == 'Returning')//投递失败
  2395. {
  2396. $exstate = 1;//派送异常
  2397. }
  2398. else if($state == 'Delivered')//成功签收
  2399. {
  2400. $exstate = 6;//签收
  2401. }
  2402. $pd = array();$xq = '';
  2403. if(isset($j['track_info']['tracking']['providers'][0]['events']))
  2404. {
  2405. foreach ($j['track_info']['tracking']['providers'][0]['events'] as $k=>$v)
  2406. {
  2407. if($k == 0)
  2408. {
  2409. $pd = $v['description'];
  2410. }
  2411. $xq .= date('Y-m-d H:i:s',strtotime($v['time_iso'])).' ['.$v['location'].'] '.$v['description'].'<br />';// a日期 c地址 z状态
  2412. }
  2413. if(stripos($express[$d['express']],'Fedex') !== false && stripos($pd,'International shipment release - Import') !== false)
  2414. {
  2415. $exstate = 4;//即将派送
  2416. }
  2417. else if(stripos($express[$d['express']],'DHL') !== false && stripos($pd,'Clearance processing complete') !== false)
  2418. {
  2419. $exstate = 4;//即将派送
  2420. }
  2421. else if(stripos($express[$d['express']],'UPS') !== false && stripos($pd['c'],'Louisville, KY, US') !== false && stripos($pd,'Departed from Facility') !== false)
  2422. {
  2423. $exstate = 4;//即将派送
  2424. }
  2425. else if(stripos($express[$d['express']],'GES') !== false && stripos($pd,'Shipment picked up') !== false)
  2426. {
  2427. $exstate = 4;//即将派送
  2428. }
  2429. else if(stripos($pd,'Delivery exception') !== false || stripos($pd,'Addressee Unknown') !== false || stripos($pd,'Delivered to Agent for Final Delivery') !== false || stripos($pd,'Reminder to pick up your item') !== false || stripos($pd,'Available for Pickup') !== false || stripos($pd,'Processing Exception') !== false || stripos($pd,'Return to Sender Processed') !== false || stripos($pd,'Redelivery Scheduled') !== false || stripos($pd,'Notice Left') !== false || stripos($pd,'Delivery attempted but no response at Consignee address') !== false || stripos($pd,'Delivery attempt could not be completed') !== false || stripos($pd,'Forwarded to a third party agent') !== false || stripos($pd,'Awaiting collection by the consignee') !== false || stripos($pd,'Consignee has moved from the address provided') !== false || stripos($pd,'awaiting customer pickup') !== false)
  2430. {
  2431. $exstate = 1;//异常
  2432. }
  2433. }
  2434. $awlgx = $this->awlgx->get_number($d['number']);
  2435. if($awlgx)
  2436. {
  2437. $this->awlgx->save(array("content"=>$xq,"time"=>time(),'exstate'=>$exstate,'type'=>$f),$awlgx['id']);
  2438. }
  2439. else
  2440. {
  2441. $this->awlgx->insert(array("number"=>$d['number'],"content"=>$xq,"time"=>time(),'exstate'=>$exstate,'type'=>$f));
  2442. }
  2443. if($xq != '')
  2444. {
  2445. $this->$f->save(array('expressstate'=>$exstate,'excontent'=>$xq),$d['id']);
  2446. $time = time();
  2447. if($f == 'fullorder')
  2448. {
  2449. $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."'");
  2450. if($notice && $d['wlyc'] == '0' && $d['wltype'] != '1' && $d['source'] != '1' && stripos($d['wlcontent'],$notice[0]['title']) === false)
  2451. {
  2452. $this->_sdfs($d,$notice[0]['id']);
  2453. //给crm发送信息 先存储数据 后续定时任务执行
  2454. if($d['shop'] < 10){
  2455. //派送中
  2456. if($exstate == 4){
  2457. $this->zztmpdata->insert([
  2458. 'type'=>3,
  2459. 'act_name'=>'crm_order',
  2460. 'content'=>json_encode($d),
  2461. 'create_time'=>time()
  2462. ]);
  2463. }
  2464. //签收完成
  2465. if($exstate == 6){
  2466. $this->zztmpdata->insert([
  2467. 'type'=>4,
  2468. 'act_name'=>'crm_order',
  2469. 'content'=>json_encode($d),
  2470. 'create_time'=>time()
  2471. ]);
  2472. }
  2473. }
  2474. }
  2475. }
  2476. }
  2477. }
  2478. public function _dhl()//DHL
  2479. {
  2480. $data = $this->dhl->find_all("type != 1 and time > '".(time()-24*3600)."'");
  2481. foreach ($data as $v)
  2482. {
  2483. $y = $this->fullorder->get_number($v['number']);
  2484. if(!$y)
  2485. {
  2486. $y = $this->fullordertt->get_number($v['number']);
  2487. if(!$y)
  2488. {
  2489. $y = $this->fullordersmt->get_number($v['number']);
  2490. if(!$y)
  2491. {
  2492. continue;
  2493. }
  2494. }
  2495. }
  2496. //获取dhl规格
  2497. $dhl_gg_info = $this->customsdeclaration->get_ename($y['sbpm']);
  2498. if(empty($dhl_gg_info)){
  2499. continue;
  2500. }else{
  2501. $y['dhl_ggbm'] = $dhl_gg_info['dhlcode'];
  2502. }
  2503. $this->dhl->get_data_c($y,$v['id']);
  2504. }
  2505. }
  2506. }