Api.php 93 KB

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