Api.php 99 KB

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