Api.php 97 KB

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