Api.php 105 KB

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