Api.php 105 KB

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