Api.php 104 KB

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