Api.php 97 KB

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