Api.php 79 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127
  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. }
  52. //定义方法的调用规则 获取URI第二段值
  53. public function _remap($arg,$arg_array)
  54. {
  55. if($arg == 'isorder')//添加
  56. {
  57. $this->_isorder();
  58. }
  59. else if($arg == 'tb')//同步独立站
  60. {
  61. $this->_tb();
  62. }
  63. else if($arg == 'waybill')//运单上传独立站
  64. {
  65. $this->_waybill($arg_array);
  66. }
  67. else if($arg == 'waybillemail')
  68. {
  69. $this->_waybillemail($arg_array);
  70. }
  71. else if($arg == 'waybillfs')
  72. {
  73. $this->_waybillfs($arg_array);
  74. }
  75. else if($arg == 'headgear')//传输头套信息
  76. {
  77. $this->_headgear($arg_array);
  78. }
  79. else if($arg == 'fsstate')
  80. {
  81. $this->_fsstate();
  82. }
  83. else if($arg == 'zz')
  84. {
  85. $this->_zz();
  86. }
  87. else if($arg == 'zzcs')
  88. {
  89. $this->_zzcs();
  90. }
  91. else if($arg == 'cangku')
  92. {
  93. $this->_cangku();
  94. }
  95. else if($arg == 'kc')
  96. {
  97. $this->_kc();
  98. }
  99. else if($arg == 'wlfs')
  100. {
  101. $this->_wlfs();
  102. }
  103. else if($arg == 'query')
  104. {
  105. $this->_query();
  106. }
  107. else if($arg == 'kcjc')
  108. {
  109. $this->_kcjc();
  110. }
  111. else if($arg == 'klarna')
  112. {
  113. $this->_klarna();
  114. }
  115. else if($arg == 'logistics')
  116. {
  117. $this->_logistics();
  118. }
  119. else if($arg == 'hqpaypal')
  120. {
  121. $this->_hqpaypal();
  122. }
  123. else if($arg == 'hqstripe')
  124. {
  125. $this->_hqstripe();
  126. }
  127. else if($arg == 'htmlstock')
  128. {
  129. $this->_htmlstock();
  130. }
  131. else if($arg == '17track')
  132. {
  133. $this->_17track();
  134. }
  135. }
  136. //通过地址直接获取独立站订单信息
  137. public function _isorder()
  138. {
  139. $sid = '';$sd = array();
  140. if(isset($_SESSION['api']))
  141. {
  142. $user = $this->user->get_api($_SESSION['api']);
  143. $user = explode('|',trim($user['shop'],'|'));
  144. foreach ($user as $value)
  145. {
  146. $sid .= " id = '$value' or";
  147. }
  148. $sid = " and (".rtrim($sid,'or').")";
  149. }
  150. $post = $this->input->post(NULL, TRUE);
  151. $api = $this->input->get('api',true);
  152. $dshop = $this->input->get('dshop',true);
  153. //@$gethl = $this->hl->get_hl();//获取即时汇率
  154. $gethl = array();
  155. /* 订单号加入键值-k */
  156. /**
  157. $dataorder = array();
  158. $fdata = $this->fullorder->find_all('dtime > "'.(time()-96*3600).'"','orderinfo');
  159. foreach ($fdata as $v)
  160. {
  161. $dataorder[$v['orderinfo']] = "";//获取到单号
  162. }
  163. **/
  164. /* 订单号加入键值-j */
  165. /* 匹配加入 */
  166. $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');
  167. // 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)
  168. $dtc = array();
  169. foreach ($dictionaries as $v)
  170. {
  171. if(stripos($v['spare'],'|') !== false)//如果有多个值
  172. {
  173. $v['spare'] = explode('|',$v['spare']);
  174. foreach ($v['spare'] as $k=>$vs)
  175. {
  176. if(stripos($v['zh'],'|') !== false)
  177. {
  178. $vzh = explode('|',$v['zh']);
  179. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$vzh[$k],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  180. }
  181. else
  182. {
  183. $dtc[strtolower($vs)] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$vs);
  184. }
  185. }
  186. }
  187. else
  188. {
  189. $dtc[strtolower($v['spare'])] = array('classid'=>$v['classid'],'zh'=>$v['zh'],'id'=>$v['id'],'jm'=>$v['jm'],'spare'=>$v['spare']);
  190. }
  191. }
  192. $dictionaries2 = $this->typeclass->find_all();
  193. foreach ($dictionaries2 as $v)
  194. {
  195. $dtctitle[$v['id']] = $v['title'];
  196. }
  197. /* 匹配结束 */
  198. /* 价格加入 */
  199. /**
  200. $money = array();
  201. $productdescribe = $this->productdescribe->find_all('1=1','number,purchase,cost,salesprice,title');
  202. foreach ($productdescribe as $v)
  203. {
  204. $money[$v['number']] = array('purchase'=>$v['purchase'],'cost'=>$v['cost'],'salesprice'=>$v['salesprice'],'title'=>$v['title']);
  205. }
  206. **/
  207. /* 价格加入 */
  208. /* 匹配ID加入 */
  209. $int = array();
  210. $intdata = $this->typeclass->find_all('classid=14','id,spare');
  211. foreach ($intdata as $v)
  212. {
  213. $v['spare'] = explode('|',$v['spare']);
  214. $int[$v['id']] = $v['spare'][0];
  215. }
  216. /* 匹配ID结束 */
  217. /* 国家加入键值-k */
  218. $cuy = array();
  219. $cuydata = $this->country->find_all('1=1','lb,id');
  220. foreach ($cuydata as $v)
  221. {
  222. $cuy[$v['lb']] = $v['id'];//获取到国家ID
  223. }
  224. /* 国家加入键值-j */
  225. /* 币种加入键值-k */
  226. $typeclass = array();
  227. $tdata = $this->typeclass->find_all('classid=30','id,title');
  228. foreach ($tdata as $v)
  229. {
  230. $typeclass[$v['title']] = $v['id'];
  231. }
  232. /* 币种加入键值-j */
  233. /* 支付方式-k */
  234. $pay = array();
  235. $tdata = $this->typeclass->find_all('classid=4','id,spare');
  236. foreach ($tdata as $v)
  237. {
  238. $paytype = $this->pay->get_typeclass($v['id']);
  239. if(isset($paytype['estimaterate']))
  240. {
  241. $estimaterate = $paytype['estimaterate'];
  242. }
  243. else
  244. {
  245. $estimaterate = 0;
  246. }
  247. if(stripos($v['spare'],'|') !== false)//如果有多个值
  248. {
  249. $v['spare'] = explode('|',$v['spare']);
  250. foreach ($v['spare'] as $k=>$vs)
  251. {
  252. $pay[$vs] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
  253. }
  254. }
  255. else
  256. {
  257. $pay[$v['spare']] = array('id'=>$v['id'],'estimaterate'=>$estimaterate);
  258. }
  259. }
  260. $pay['stripeios'] = $pay['stripe_payments'];
  261. /* 支付方式-j */
  262. /* 新增SKU-k */
  263. $zjsku = array();
  264. $shopsku = $this->shopsku->find_all();
  265. foreach ($shopsku as $val)
  266. {
  267. $ss = explode(',',trim($val['shop'],','));
  268. foreach ($ss as $v)
  269. {
  270. if(isset($zjsku[$v]))
  271. {
  272. $zjsku[$v] .= ','.trim($val['sku'],',');
  273. }
  274. else
  275. {
  276. $zjsku[$v] = trim($val['sku'],',');
  277. }
  278. }
  279. }
  280. /* 新增SKU-j */
  281. $is = $this->is->find_all('1=1','*','number asc');//获取仓库平匹配表
  282. if(isset($post['is']) || (isset($api) && $api = '89757'))
  283. {
  284. $tb = 0;
  285. if($dshop)
  286. {
  287. $shop = $this->shop->find_all("id = '$dshop'");
  288. }
  289. else
  290. {
  291. $shop = $this->shop->find_all("type = 269 and tb = 1".$sid);//获取独立站信息
  292. }
  293. foreach ($shop as $value)
  294. {
  295. if((time()-$value['tbtime']) < 600)
  296. {
  297. $tb = 1;//正在同步中
  298. break;
  299. }
  300. else
  301. {
  302. $this->shop->save(array('tbtime'=>time()),$value['id']);
  303. }
  304. $setting = $this->setting->get_settings();
  305. $this->db->trans_begin();
  306. $res = $this->api->get_hq($value['brandname'],$value['shopadmin'],$value);
  307. $sd[] = $res;
  308. $sjc = $setting['sctime'];//时间差 之前是3600 现在为0
  309. if($res)
  310. {
  311. foreach ($res as $v)
  312. {
  313. if($value['token'] == 'SU')
  314. {
  315. $time = $v['purchased_on']-7*3600-$sjc;//之前是+$sjc
  316. }
  317. else if($value['program'] == 'Shopify')
  318. {
  319. $time = $v['purchased_on'];
  320. }
  321. else
  322. {
  323. if($value['id'] == 1)
  324. {
  325. $time = strtotime($v['purchased_on'])-7*3600-$sjc;//-$sjc;//之前是+$sjc
  326. }
  327. else
  328. {
  329. $time = strtotime($v['purchased_on'])-7*3600-$sjc;//订单时间更为时间戳 //之前是+$sjc
  330. }
  331. }
  332. $num = $this->fullorder->find_count('gtime = "'.date('Ymd',$time).'" and shop = "'.$value['id'].'"');
  333. $order_id = $value['id'].$v['order_id'];
  334. $tc = $typeclass[$v['global_currency_code']];
  335. $dataorder = $this->fullorder->get_orderinfo($order_id);
  336. $hmdid = '';
  337. if($value['program'] == 'Shopify' && isset($dataorder['id']))
  338. {
  339. if($v['order_comment'] != $dataorder['clientremarks'])
  340. {
  341. $this->fullorder->save(array('clientremarks'=>$v['order_comment']),$dataorder['id']);
  342. }
  343. }
  344. if(!isset($dataorder['id']))
  345. //现在为所有订单都获取。!$ord && strcasecmp($v['isstatus'],'processing') == 0如果没有此订单并且订单状态为等待发货则继续
  346. {
  347. if(!isset($cuy[$v['country']]))
  348. {
  349. $cuy[$v['country']] = 1004;
  350. }
  351. $post = $this->api->get_data($value,$v,$gethl,$time,$cuy[$v['country']],$is,$num,$v['country'],$tc,$dtc,array(),$int,$dtctitle,$pay,$zjsku);
  352. $kn = explode('-',$post['paypal']);
  353. if($post['pay'] == 23 && $value['klarnaname'] != '' && $value['klarnapass'] != '')
  354. {
  355. $klarna = $this->_klarnadata($post['paypal'],$value['klarnaname'],$value['klarnapass']);
  356. if($klarna != '')
  357. {
  358. $post['klarnadata'] = $klarna;
  359. }
  360. }
  361. if($post['pay'] == 26 && $value['afterpayname'] != '' && $value['afterpaypass'] != '')
  362. {
  363. $afterpay = $this->_afterpay($post['paypal'],$value['afterpayname'],$value['afterpaypass']);
  364. if($afterpay != '')
  365. {
  366. $post['klarnadata'] = $afterpay;
  367. }
  368. }
  369. if($post['pay'] == 27 && $value['clearpayname'] != '' && $value['clearpaypass'] != '')
  370. {
  371. $clearpay = $this->_clearpay($post['paypal'],$value['clearpayname'],$value['clearpaypass']);
  372. if($clearpay != '')
  373. {
  374. $post['klarnadata'] = $clearpay;
  375. }
  376. }
  377. if($post['pay'] == '28' && $post['state'] != '207')
  378. {
  379. continue;
  380. }
  381. if($post['state'] == '217' || $post['state'] == '203')
  382. {
  383. continue;
  384. }
  385. /**
  386. else if($post['pay'] == 22 && $value['paypalname'] != '' && $value['paypalpass'] != '')
  387. {
  388. $paypal = $this->_paypaldata($post['paypal'],$value['paypalname'],$value['paypalpass']);
  389. if($paypal != '')
  390. {
  391. $post['klarnadata'] = $paypal;
  392. }
  393. }
  394. **/
  395. /** 启用自动分配仓库 **/
  396. $warehouse = $this->warehouse->find_all("fpzd = '1'",'*','fpsx desc');
  397. foreach ($warehouse as $v)
  398. {
  399. if($v['bdcountry'] != 0 && $v['bdcountry'] != $post['country'])
  400. {
  401. continue;
  402. }
  403. $yx = 'get_yx_'.$v['bdck'];
  404. $kczd = $this->ck->$yx($post['state'],$v,$post['shop'],$post['number'],$post['whlabel'],$post['fpdata']);
  405. if($kczd['t'] == 0)
  406. {
  407. $country = $this->country->read($post['country']);//获取国家中配置物流
  408. if($country['express'] != 0)
  409. {
  410. $post['express'] = $country['express'];
  411. }
  412. if($v['express'] != 0)//优先使用仓库指定物流,替换掉上面的国家配置物流
  413. {
  414. $post['express'] = $v['express'];
  415. }
  416. $post['type'] = $v['id'];
  417. $post['whlabel'] = $kczd['whlabel'];
  418. $post['fpdata'] = $kczd['fpdata'];
  419. if(stripos($kczd['whlabel'],$v['hz']) !== false)
  420. {
  421. break 1;
  422. }
  423. }
  424. }
  425. $qdw = $this->warehouse->read($post['type']);
  426. $fl = $this->ck->get_fl($qdw['hz'],$post['whlabel'],$post['fpdata']);
  427. $post['sfxh'] = $fl['sfxh'];
  428. $post['ckfl'] = $fl['ckfl'];
  429. //自动写位置 开始
  430. $zclp = array();$pxsl = array();
  431. $slpx = explode('|',$post['slpx']);//排序
  432. foreach ($slpx as $k=>$v)
  433. {
  434. $v = explode('-',$v);
  435. if(!isset($v[1]))
  436. {
  437. $v[1] == 1;
  438. }
  439. for($i=$v[0];$i<$v[1];$i++)
  440. {
  441. $pxsl[$i] = $k;
  442. }
  443. }
  444. $mc = $qdw['bdck'];$zdidjl = '';$zdwzjl = '';
  445. if($qdw['wz'] == 1)
  446. {
  447. $pm = explode(';',trim($post['shipremarks'],';'));
  448. foreach ($pm as $k=>$vv)
  449. {
  450. $vv = trim($vv,' ');
  451. $lp = $this->typeclass->find_all("zh = '$vv'");
  452. if(isset($lp[0]['classid']))
  453. {
  454. $zclp[] = $vv;
  455. unset($pm[$k]);
  456. }
  457. }
  458. $pm = array_values($pm);
  459. $w = explode('|',trim($post['whlabel'],'|'));
  460. foreach ($w as $k=>$val)
  461. {
  462. $hwm = '';
  463. if(stripos($val,$qdw['hz']) !== false)
  464. {
  465. $num = explode('-',trim($val,'-'));
  466. $xq = explode('~',trim($num[2],'~'));
  467. $pmxq = '(';
  468. foreach ($xq as $v)
  469. {
  470. $zdidjl .= '('.trim($v,$qdw['hz']).')';
  471. $h = $this->$mc->read(trim($v,$qdw['hz']));
  472. if($h['details'] != '')
  473. {
  474. $pmxq .= $qdw['title'].':'.$h['details'].(($h['cpid']>0)?'-'.$h['cpid']:'').',';
  475. }
  476. }
  477. $xrid = ($h['cpid']>0)?'-'.$h['cpid']:'';
  478. if(isset($pxsl[$k]))
  479. {
  480. if(stripos($pm[$pxsl[$k]],$qdw['title'].':'.$h['details'].$xrid) === false)
  481. {
  482. $pm[$pxsl[$k]] .= trim($pmxq,',').')';
  483. }
  484. }
  485. $zdwzjl .= $h['details'].(($h['cpid']>0)?'-'.$h['cpid']:'');
  486. }
  487. }
  488. if($zclp)
  489. {
  490. $zclp = ';'.implode(";",$zclp);
  491. }
  492. else
  493. {
  494. $zclp = '';
  495. }
  496. $post['shipremarks'] = implode(";",$pm).$zclp;
  497. $post['contents'] = $zdidjl.' - '.$zdwzjl;
  498. }
  499. //自动写位置 结束
  500. /** **/
  501. //合并重复项
  502. $hbcfw = explode('|',trim($post['whlabel'],'|'));
  503. $hbcff = explode(';',trim($post['fpdata'],';'));
  504. $c = 0;
  505. $hbw = array();
  506. $hbf = array();
  507. for($i=0;$i<count($hbcfw);$i++)
  508. {
  509. $w = explode('-',$hbcfw[$i]);
  510. $f = explode('|',$hbcff[$i]);
  511. $w2 = ($w[2]==0)?0:'';
  512. if(!isset($hbw[$w[0].$w2]))
  513. {
  514. $hbw[$w[0].$w2] = $hbcfw[$i];
  515. $hbf[$w[0].$w2] = $hbcff[$i];
  516. }
  517. else
  518. {
  519. $c++;
  520. $cw = explode('-',$hbw[$w[0].$w2]);
  521. $cf = explode('|',$hbf[$w[0].$w2]);
  522. if($cw[2] != 0 && $w[2] != 0)
  523. {
  524. $cf[2] += $f[2];
  525. $cf[9] .= '~'.$f[9];
  526. $hbf[$w[0].$w2] = implode("|",$cf);
  527. $cw[1] += $f[2];
  528. $cw[2] .= '~'.$f[9];
  529. $hbw[$w[0].$w2] = implode("-",$cw);
  530. }
  531. else if($cw[2] == 0 && $w[2] == 0)
  532. {
  533. $cf[2] += $f[2];
  534. $hbf[$w[0].$w2] = implode("|",$cf);
  535. $cw[1] += $f[2];
  536. $hbw[$w[0].$w2] = implode("-",$cw);
  537. }
  538. else
  539. {
  540. $hbw[] = $hbcfw[$i];
  541. $hbf[] = $hbcff[$i];
  542. }
  543. }
  544. }
  545. if($c > 0)
  546. {
  547. $post['fpdata'] = implode(";",$hbf).';';
  548. $post['whlabel'] = '|'.implode("|",$hbw).'|';
  549. }
  550. //合并重复项结束
  551. //非占单设置为禁止占单开始
  552. $hbw = explode('|',trim($post['whlabel'],'|'));
  553. $hbf = explode(';',trim($post['fpdata'],';'));
  554. foreach ($hbw as $k=>$val)
  555. {
  556. $w = explode('-',$val);
  557. $f = explode('|',$hbf[$k]);
  558. if(!isset($w[2]) || $w[2] == 0)
  559. {
  560. $w[2] = "DNOTO";
  561. $f[9] = "DNOTO";
  562. $hbf[$k] = implode("|",$f);
  563. $hbw[$k] = implode("-",$w);
  564. }
  565. }
  566. $post['fpdata'] = implode(";",$hbf).';';
  567. $post['whlabel'] = '|'.implode("|",$hbw).'|';
  568. //非占单设置为禁止占单结束
  569. //查询净重开始
  570. $post['jweight'] = $this->weight->get_weightcx($post['fpdata']);
  571. //查询净重结束
  572. $tjid = $this->fullorder->insert($post);
  573. if($post['email'] == '')
  574. {
  575. $post['email'] = $post['name'].'@qq.com';
  576. }
  577. $adrs = $this->customer->get_email($post['email'],$post['shop']);
  578. preg_match_all('/[0-9]/u',$post['phone'],$result);
  579. $numphone = join('',$result[0]);
  580. $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']));
  581. $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']));
  582. $hmdaddress3 = str_replace(array(' avenue',' ave',' av'),array(' ave',' avenue',' ave'),strtolower($post['address']));
  583. $hmdid = '';
  584. $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');
  585. $lkh = (isset($customerb[0]['id']))?2:1;//白名单1黑名单2
  586. if($lkh == 2)
  587. {
  588. $hmdid = $customerb[0]['id'].'-('.$post['email'].'|'.$post['address'].'|'.$numphone.')'.'('.$customerb[0]['email'].'|'.$customerb[0]['address'].$customerb[0]['numphone'].')';
  589. }
  590. if($adrs)
  591. {
  592. $pdlkh = 1;//这个是判断是否老客户
  593. $this->customer->save(array('time'=>$post['dtime'],'num'=>$adrs['num']+1,'money'=>$adrs['money']+$post['shouldmoney']),$adrs['id']);
  594. $khid = $adrs['id'];
  595. }
  596. else
  597. {
  598. $str = $post['phone'];
  599. preg_match_all('/[0-9]/u',$str,$result);
  600. $numphone = join('',$result[0]);
  601. $ct['shop'] = $post['shop'];
  602. $ct['source'] = 10;
  603. $ct['level'] = 5;
  604. $ct['country'] = $post['country'];
  605. $ct['time'] = $post['dtime'];
  606. $ct['num'] = 1;
  607. $ct['money'] = $post['shouldmoney'];
  608. $ct['zipcode'] = $post['zipcode'];
  609. $ct['name'] = $post['name'];
  610. $ct['phone'] = $post['phone'];
  611. $ct['numphone'] = $numphone;
  612. $ct['email'] = preg_replace('/( | | |\s)+/','',$post['email']);
  613. $ct['province'] = $post['province'];
  614. $ct['city'] = $post['city'];
  615. $ct['address'] = $post['address'];
  616. $ct['zhcx'] = $post['shop'].'-'.$ct['email'];
  617. $khid = $this->customer->insert($ct);
  618. $pdlkh = 0;
  619. }
  620. $this->_znxc($post,$order_id,$lkh,$pdlkh,$hmdid);
  621. /**
  622. if($post['shop'] == '1' || $post['shop'] == '2' || $post['shop'] == '6' || $post['shop'] == '5')
  623. {
  624. $this->_znxc($post,$order_id,$lkh);
  625. }
  626. else
  627. {
  628. $this->_znx($post,$order_id,$lkh);
  629. }
  630. **/
  631. }//else{}如果有此订单
  632. }
  633. }
  634. if ($this->db->trans_status() === FALSE)
  635. {
  636. $this->db->trans_commit();
  637. }
  638. else
  639. {
  640. $this->db->trans_commit();
  641. }
  642. sleep(5);//停留2秒
  643. }
  644. if($tb == 1)
  645. {
  646. echo json_encode(array('msg'=>'有店铺正在同步中,请5分钟后再试!','success'=>true));exit;
  647. }
  648. echo json_encode(array('msg'=>'OK!','success'=>true));exit;
  649. }
  650. }
  651. public function _tb()
  652. {
  653. $api = $this->input->get('api',true);
  654. if(isset($api) && $api = '89757')
  655. {
  656. $xg = $this->fullorder->find_all('dlz < 1 and source != 1 and waybill != "" and dtime > "'.(time()-48*3600).'"');
  657. /* 店铺加入键值-j */
  658. $fshop = $this->shop->find_all('1=1');
  659. foreach ($fshop as $v)
  660. {
  661. $datashop[$v['id']] = $v;
  662. }
  663. /* 店铺加入键值-k */
  664. /* 快递加入键值-j */
  665. $fex = $this->express->find_all('1=1');
  666. foreach ($fex as $v)
  667. {
  668. $dataex[$v['id']] = $v;
  669. }
  670. /* 快递加入键值-k */
  671. /* 仓库加入键值-k */
  672. $fwh = $this->warehouse->find_all('1=1');
  673. foreach ($fwh as $v)
  674. {
  675. $datack[$v['id']] = $v;
  676. }
  677. /* 仓库加入键值-j */
  678. //$fs = $this->notice->get_ordertatus(216);//216成功状态
  679. foreach ($xg as $v)
  680. {
  681. $shop = $datashop[$v['shop']];
  682. $ex = $dataex[$v['express']];
  683. $warehouse = $datack[$v['type']];
  684. if($ex['iscode'] != 'Other')
  685. {
  686. //独立站地址更新订单状态、物流信息
  687. @$gx = $this->api->get_gx(substr($v['orderinfo'],1),$v['waybill'],$xg,$shop,$ex,$xg['shopify']);
  688. $this->fullorder->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$v['id']);
  689. /**
  690. if($gx['res'] == 1 && $fs)
  691. {
  692. $ck = $this->_email($fs['content'],$v,$warehouse['company']);
  693. }
  694. **/
  695. }
  696. sleep(3);//停留2秒
  697. }
  698. }
  699. }
  700. //更新独立站运单信息
  701. public function _waybill($arg_array)
  702. {
  703. $where = "dlz < '1' and state = '207' and ";
  704. if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单,已出库——使用模板3 每天早上8点半 触发发送【昨天早上7点-今天早上7点】出库的
  705. {
  706. $where .= "express = '2' and librarytime > '".strtotime(date("Y-m-d 7:00:0",strtotime("-1 day")))."' and librarytime < '".strtotime(date("Y-m-d 7:00:0",time()))."'";
  707. $readid = 3;
  708. }
  709. else if(date("H",time()) == '21' && date("w",time()) != '0')//二、杭州联邦+杭州联邦-不报关,单独用一个模板—新模板2 每天晚上9点半 触发发送 【昨天晚上9:30——今天晚上9:30】出库的
  710. {
  711. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  712. {
  713. $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()))."'";
  714. }
  715. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  716. {
  717. $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()))."'";
  718. }
  719. $readid = 2;
  720. }
  721. else if(date("H",time()) == '19' && date("w",time()) != '0')//其他快递-使用模板1 DHL官方、UPS、DPEX 等系统里打印运单自动有运单号的,出库后当天晚上7点执行。
  722. {
  723. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  724. {
  725. $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()))."'";
  726. }
  727. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  728. {
  729. $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()))."'";
  730. }
  731. $readid = 1;
  732. }
  733. else
  734. {
  735. exit;
  736. }
  737. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  738. // 订单加入键值-k
  739. $fdata = $this->fullorder->find_all($where);//,'source,id,orderinfo,waybill,shop,express,type,msg,bname,state,client,name,phone,zipcode,address,email,shopify'
  740. //* 订单加入键值-j
  741. //* 店铺加入键值-j
  742. $fshop = $this->shop->find_all('1=1');
  743. foreach ($fshop as $v)
  744. {
  745. $datashop[$v['id']] = $v;
  746. }
  747. //* 店铺加入键值-k
  748. //* 快递加入键值-j
  749. $fex = $this->express->find_all('1=1');
  750. foreach ($fex as $v)
  751. {
  752. $dataex[$v['id']] = $v;
  753. }
  754. //* 快递加入键值-k
  755. //* 仓库加入键值-k
  756. $fwh = $this->warehouse->find_all('1=1');
  757. foreach ($fwh as $v)
  758. {
  759. $datack[$v['id']] = $v;
  760. }
  761. //* 仓库加入键值-j
  762. $i = 0;$j = 0;$ed = array();
  763. foreach ($fdata as $key=>$value)
  764. {
  765. if($value['source'] == 1)
  766. {
  767. $this->fullorder->save(array('dlz'=>3,'state'=>216),$value['id']);
  768. }
  769. else
  770. {
  771. $ddh = substr($value['orderinfo'],1);
  772. $ydh = $value['waybill'];
  773. $xg = $value;//此订单数据
  774. $shop = $datashop[$xg['shop']];//此订单店铺
  775. $ex = $dataex[$xg['express']];//此订单快递
  776. $warehouse = $datack[$xg['type']];//此订单仓库
  777. $shopifyid = $value['shopify'];
  778. @$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$readid,$shopifyid);
  779. if(!isset($gx['res']))
  780. {
  781. continue;
  782. }
  783. $this->fullorder->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$value['id']);
  784. }
  785. sleep(4);
  786. }
  787. $this->_kcjc();
  788. }
  789. public function _kcjc()
  790. {
  791. $gethl = $this->whlabel->find_all("zd != '' and state = '0'");
  792. $b = array();
  793. foreach ($gethl as $k=>$v)
  794. {
  795. $a = $this->fullorder->get_number($v['zd']);
  796. if($a['librarytime'] > 0 && $a['library'] == 2)
  797. {
  798. //$b[] = array($v['sku'],$v['zd']);
  799. $this->whlabel->save(array('state'=>1,'orderinfo'=>$a['orderinfo'],'waybill'=>$a['waybill'],'outk'=>$a['librarytime'],'time'=>$a['librarytime']),$v['id']);
  800. }
  801. }
  802. }
  803. public function _waybillemail($arg_array)
  804. {
  805. $this->fullorder->save(array('email'=>date("H:i:s",time())),14786);
  806. $urls = array();$sl = 0;$time = time();
  807. if(date("H",time()) == '8' && date("i",time()) > '20' && date("i",time()) < '39')//USPS-USA单
  808. {
  809. $wid = 1;
  810. }
  811. else if(date("H",time()) == '22' && date("w",time()) != '0' && date("i",time()) > '20' && date("i",time()) < '39')//二、杭州联邦+杭州联邦-不报关
  812. {
  813. if(date("w",time()) == '1')//周一执行:周六晚上9点半——周一晚上9点半 之间出库的
  814. {
  815. $wid = 2;
  816. }
  817. else //周二到周六: 前一天晚上9点半——当天晚上9点半之间出库的
  818. {
  819. $wid = 3;
  820. }
  821. }
  822. else if(date("H",time()) == '20' && date("w",time()) != '0' && date("i",time()) > '20' && date("i",time()) < '39')//其他快递
  823. {
  824. if(date("w",time()) != '1')
  825. {
  826. $wid = 4;
  827. }
  828. else
  829. {
  830. $wid = 5;
  831. }
  832. }
  833. else
  834. {
  835. exit;
  836. }
  837. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '4' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  838. foreach ($notice as $key=>$var)
  839. {
  840. $urls[] = array('url'=>'http://1.wepolicy.cn/api/waybillfs?v='.$var['id'],'data'=>array('var'=>$var,'wid'=>$wid));
  841. }
  842. foreach($urls as $value) {
  843. $ch = curl_init();
  844. $url = $value['url'];
  845. curl_setopt($ch,CURLOPT_URL,$url);
  846. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  847. curl_setopt($ch,CURLOPT_HEADER,0);
  848. curl_setopt($ch,CURLOPT_POST, 1);
  849. curl_setopt($ch,CURLOPT_TIMEOUT,1);
  850. //设置post数据
  851. $post = array();
  852. $post['data'] = $value['data'];
  853. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  854. $res = curl_exec($ch);
  855. curl_close($ch);
  856. $sl++;
  857. }
  858. echo $sl;
  859. echo "<pre>";
  860. print_r($urls);
  861. }
  862. public function _waybillfs()
  863. {
  864. $post = $this->input->post(NULL, TRUE);
  865. $data = $this->input->post('data',true);
  866. if($data)
  867. {
  868. $notice = $data['var'];
  869. $notice['email'] = $this->emaildata->read($notice['email']);
  870. $wid = $data['wid'];
  871. $fsjs = "";
  872. if($wid == 1 && stripos($notice['express'],',2,') !== false)
  873. {
  874. $js = explode(',',trim($notice['js'],','));
  875. if(count($js) > 1)
  876. {
  877. $fsjs = " and (";
  878. foreach ($js as $v)
  879. {
  880. $fsjs .= "js = '$v' or ";
  881. }
  882. $fsjs = trim($fsjs,' or ').")" ;
  883. }
  884. else if(count($js) == 1)
  885. {
  886. $fsjs = " and js = '$js[0]'";
  887. }
  888. $where = "express = '2' 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
  889. }
  890. else if($wid == 2 && stripos($notice['express'],',1,') !== false)
  891. {
  892. $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
  893. }
  894. else if($wid == 3 && stripos($notice['express'],',1,') !== false)
  895. {
  896. $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
  897. }
  898. else if($wid == 4 && stripos($notice['express'],',1,') !== false)
  899. {
  900. $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
  901. }
  902. else if($wid == 5 && stripos($notice['express'],',1,') !== false)
  903. {
  904. $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
  905. }
  906. else
  907. {
  908. exit;
  909. }
  910. $wlfs = array();
  911. $dd = $this->fullorder->find_all("source != '1' and dlzemail < '1' and shop = '".$notice['shop']."' and library = 2 and ".$where);
  912. foreach ($dd as $v)
  913. {
  914. $shop = $this->shop->read($v['shop']);
  915. $express = $this->express->read($v['express']);
  916. $fs = $this->notice->get_god($v,$shop,$express,$notice);
  917. if($fs == 1)
  918. {
  919. $this->fullorder->save(array('dlzemail'=>1,'dlzemailtime'=>time()),$v['id']);
  920. }
  921. else
  922. {
  923. //$pdtime = date('Y-m-d',time());
  924. //$folderPath = './data/dlzemail/'.$pdtime; // 文件夹路径
  925. //$permissions = 0777; // 权限设置
  926. //if (!file_exists($folderPath)) { mkdir($folderPath, $permissions); }//创建文件夹
  927. //file_exists($folderPath);
  928. if(!is_file("./data/dlzemail/".$v['number'].".txt"))
  929. {
  930. $myfile = fopen("./data/dlzemail/".$v['number'].".txt", "w") or die("Unable to open file!");
  931. fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
  932. fclose($myfile);
  933. }
  934. else
  935. {
  936. $myfile = fopen("./data/dlzemail/".$v['number'].".txt", "a+") or die("Unable to open file!");
  937. fwrite($myfile, json_encode($fs.';'.$v.';'.$shop.';'.$express.';'.$notice));
  938. fclose($myfile);
  939. }
  940. $this->fullorder->save(array('dlzemail'=>2,'dlzemailtime'=>time()),$v['id']);
  941. }
  942. sleep(50);
  943. }
  944. }
  945. }
  946. /**
  947. //更新独立站运单信息
  948. public function _waybill($arg_array)
  949. {
  950. //这里订单索引需要修改 8点是出已打印已出库 11点是已打印未出库
  951. if(!isset($arg_array[0]) || !isset($arg_array[1]))
  952. {
  953. exit;
  954. }
  955. if(date("w",time()) == '0' && $arg_array[0] != '3')//非usps周日不更新
  956. {
  957. echo 7;exit;
  958. }
  959. if($arg_array[0] == 3)
  960. {
  961. $argarray = 2;
  962. $typec = ' and express = 2 and printtime > "'.strtotime("-3 day").'"';//更新usps-usa快递的订单
  963. }
  964. else
  965. {
  966. $argarray = $arg_array[0];
  967. $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())).'"';//更新快递的订单
  968. }
  969. $dataorder = array();$datashop = array();$dataex = array();$datack = array();
  970. // 订单加入键值-k
  971. $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');
  972. //* 订单加入键值-j
  973. //* 店铺加入键值-j
  974. $fshop = $this->shop->find_all('1=1');
  975. foreach ($fshop as $v)
  976. {
  977. $datashop[$v['id']] = $v;
  978. }
  979. //* 店铺加入键值-k
  980. //* 快递加入键值-j
  981. $fex = $this->express->find_all('1=1');
  982. foreach ($fex as $v)
  983. {
  984. $dataex[$v['id']] = $v;
  985. }
  986. //* 快递加入键值-k
  987. //* 仓库加入键值-k
  988. $fwh = $this->warehouse->find_all('1=1');
  989. foreach ($fwh as $v)
  990. {
  991. $datack[$v['id']] = $v;
  992. }
  993. //* 仓库加入键值-j
  994. //$fs = $this->notice->get_ordertatus(216);//216成功状态
  995. $i = 0;$j = 0;$ed = array();
  996. foreach ($fdata as $key=>$value)
  997. {
  998. if($value['source'] == 1)
  999. {
  1000. $this->fullorder->save(array('dlz'=>3,'state'=>216),$value['id']);
  1001. }
  1002. else
  1003. {
  1004. $ddh = substr($value['orderinfo'],1);
  1005. $ydh = $value['waybill'];
  1006. $xg = $value;//此订单数据
  1007. $shop = $datashop[$xg['shop']];//此订单店铺
  1008. $ex = $dataex[$xg['express']];//此订单快递
  1009. $warehouse = $datack[$xg['type']];//此订单仓库
  1010. //独立站地址更新订单状态、物流信息
  1011. if($arg_array[0] == 1)//23点更新用留言2
  1012. {
  1013. $readid = 2;
  1014. }
  1015. else if($arg_array[0] == 3)//7点更新用留言3
  1016. {
  1017. $readid = 3;
  1018. }
  1019. else //20点更新用默认留言(默认留言为1)
  1020. {
  1021. $readid = $xg['msg'];
  1022. }
  1023. @$gx = $this->api->get_gx($ddh,$ydh,$xg,$shop,$ex,$readid);
  1024. if(!isset($gx['res']))
  1025. {
  1026. exit;
  1027. }
  1028. $this->fullorder->save(array('dlz'=>$gx['res'],'state'=>$gx['state']),$xg['id']);
  1029. }
  1030. //if($gx['res'] == 1 && $fs)
  1031. //{
  1032. // $ck = $this->_email($fs['content'],$xg,$warehouse['company']);
  1033. //}
  1034. sleep(2);//停留2秒
  1035. }
  1036. }
  1037. **/
  1038. public function _headgear($arg_array)
  1039. {
  1040. $ip = $this->input->ip_address();
  1041. if(!isset($arg_array[0]) || !isset($arg_array[1]))
  1042. {
  1043. exit;
  1044. }
  1045. if(!is_numeric($arg_array[0]) || !is_numeric($arg_array[1]))
  1046. {
  1047. exit;
  1048. }
  1049. $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)
  1050. if($arg_array[1] == 1)
  1051. {
  1052. $data = $this->fullordersmt->find_all($where,'express,number,orderinfo,shipremarks,printtime');
  1053. }
  1054. else
  1055. {
  1056. $data = $this->fullorder->find_all($where,'express,number,orderinfo,shipremarks,printtime');
  1057. }
  1058. foreach ($data as $k=>$v)
  1059. {
  1060. $express = $this->express->read($v['express']);
  1061. $data[$k]['express'] = $express['servicename'];
  1062. if($data[$k]['printtime'] > 0)
  1063. {
  1064. $data[$k]['printtime'] = date('Y-m-d H:i:s',$v['printtime']);
  1065. }
  1066. }
  1067. //$state = $this->api->get_headgear($data);
  1068. echo json_encode($data);
  1069. }
  1070. public function _kc_old()
  1071. {
  1072. $post = $this->input->post(NULL, TRUE);
  1073. if(isset($post['sku']))
  1074. {
  1075. $sku = $this->input->post('sku',true);
  1076. $warehouse = $this->warehouse->find_all();
  1077. $data = array();
  1078. foreach ($sku as $val)
  1079. {
  1080. $datasku = array();
  1081. foreach ($warehouse as $v)
  1082. {
  1083. $z = $this->whlabel->find_count('sku = "'.$val.'" and zd = "" and state = 0 and warehouse = "'.$v['id'].'"');
  1084. $datasku[] = array('name'=>$v['title'],'number'=>$z);
  1085. }
  1086. $data[$val] = $datasku;
  1087. }
  1088. }
  1089. echo json_encode($data);
  1090. }
  1091. public function _kc()
  1092. {
  1093. $datasku = array();
  1094. $info_list = $this->whlabel->find_pc("warehouse = '5'",'sku,features,warehouse','sku');
  1095. foreach ($info_list as $val)
  1096. {
  1097. $z = $this->whlabel->find_count('sku = "'.$val['sku'].'" and zd = "" and state = 0 and warehouse = "5"');
  1098. $datasku[] = array('sku'=>$val['sku'],'number'=>$z);
  1099. }
  1100. echo json_encode($datasku);
  1101. }
  1102. public function _fsstate()//订单消息页手动发送
  1103. {
  1104. $post = $this->input->post(NULL, TRUE);
  1105. if(isset($post['s']))
  1106. {
  1107. $id_arr = $this->input->post('s');
  1108. $notice = $this->input->post('notice');
  1109. $noticeid = $this->input->post('noticeid');
  1110. $id_arr = explode(',',trim($id_arr,','));
  1111. if(!$id_arr)
  1112. {
  1113. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1114. }
  1115. if($notice == '1' || $notice == '')
  1116. {
  1117. foreach ($id_arr as $v)
  1118. {
  1119. $data = $this->fullorder->read($v);
  1120. $adrs = $this->customer->get_email($data['email'],$data['shop']);
  1121. //$lkh = ($adrs['type'] == 1)?1:2;//白名单1黑名单2
  1122. $lkh = 1;
  1123. $pdlkh = ($adrs['num'] > 1)?1:0;//判断是否老客户
  1124. $fs = $this->_znxc($data,$data['orderinfo'],$lkh,$pdlkh);
  1125. if($fs == 1)
  1126. {
  1127. $this->fullorder->save(array('exstateerror'=>''),$data['id']);
  1128. }
  1129. sleep(40);
  1130. }
  1131. }
  1132. else
  1133. {
  1134. foreach ($id_arr as $v)
  1135. {
  1136. $data = $this->fullorder->read($v);
  1137. $fs = $this->_sdfs($data,$noticeid);
  1138. sleep(40);
  1139. }
  1140. }
  1141. echo json_encode(array('msg'=>'发送完成!','id'=>$id_arr,'success'=>true));exit;
  1142. }
  1143. }
  1144. /**
  1145. public function _fsstate()//订单消息页手动发送 _znxc 针对模板对应类型发送
  1146. {
  1147. $post = $this->input->post(NULL, TRUE);
  1148. if(isset($post['s']))
  1149. {
  1150. $id_arr = $this->input->post('s');
  1151. $id_arr = explode(',',$id_arr);
  1152. if(!$id_arr)
  1153. {
  1154. echo json_encode(array('msg'=>'参数错误!','success'=>false));exit;
  1155. }
  1156. foreach ($id_arr as $v)
  1157. {
  1158. $data = $this->fullorder->read($v);
  1159. $adrs = $this->customer->get_email($data['email'],$data['shop']);
  1160. $lkh = ($adrs['type'] == 1)?1:2;//白名单1黑名单2
  1161. $fs = $this->_znxc($data,$data['orderinfo'],$lkh);
  1162. if($fs == 1)
  1163. {
  1164. $this->fullorder->save(array('exstateerror'=>''),$data['id']);
  1165. }
  1166. }
  1167. echo json_encode(array('msg'=>'发送完成!','id'=>$id_arr[0],'success'=>true));exit;
  1168. }
  1169. }
  1170. **/
  1171. public function _cangku()
  1172. {
  1173. $post = $this->input->post(NULL, TRUE);
  1174. if(isset($post['tk']))
  1175. {
  1176. $tk = $this->input->post('tk');
  1177. $tj = $this->input->post('tj');
  1178. $d = $this->fullorder->find_all("dtime > '$tk' and dtime < '$tj'");
  1179. $k = $this->customer->find_all("time > '$tk' and time < '$tj'");
  1180. echo json_encode(array('d'=>$d,'k'=>$k));exit;
  1181. }
  1182. }
  1183. public function _znxc($fullorder,$order_id,$lkh,$pdlkh,$hmdid='')
  1184. {
  1185. $time = time();
  1186. $sl = explode(';',$fullorder['quantity']);
  1187. $quantity = 0;
  1188. foreach ($sl as $v)
  1189. {
  1190. if($v > 1)
  1191. {
  1192. $quantity = 1;
  1193. }
  1194. }
  1195. $fid = $this->fullorder->get_orderinfo($order_id);
  1196. 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'] != '' ||
  1197. {
  1198. $asdasd = 0;
  1199. if($lkh == 2)
  1200. {
  1201. $asdasd = 1;
  1202. }
  1203. if(count($sl) > 1 && $quantity == 1)
  1204. {
  1205. $asdasd = 2;
  1206. }
  1207. 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)
  1208. {
  1209. $asdasd = 3;
  1210. }
  1211. $this->fullorder->save(array('content'=>$fid['content'].'黑名单客户、多产品的、包含PO BOX、包含APO的不发送-'.$asdasd.(($hmdid)?'['.$hmdid.']':''),'zdstate'=>$fid['zdstate'].'1-x|'),$fid['id']);//留言的现在正常发
  1212. return 'a';
  1213. }
  1214. else
  1215. {
  1216. if($fullorder['shouldmoney'] > '400' && $fullorder['guarantee'] == 'Ineligible')//如果金额大于400美元并且无卖家保障
  1217. {
  1218. $tab = 1;
  1219. }
  1220. /**
  1221. else if(count($sl) == '1' && $fullorder['quantity'] > 1 && $fullorder['baddress'] != $fullorder['saddress'])//如果item(产品)是1,但quantity大于等于2并且Bill Address不等于Ship Address
  1222. {
  1223. $tab = 4;
  1224. }
  1225. else if($fullorder['baddress'] != $fullorder['saddress'])//如果Bill Address不等于Ship Address
  1226. {
  1227. $tab = 3;
  1228. }
  1229. **/
  1230. else if(count($sl) == '1' && $fullorder['quantity'] > 1)//如果item(产品)是1,但quantity大于等于2
  1231. {
  1232. $tab = 2;
  1233. }
  1234. else//常规模板
  1235. {
  1236. $tab = 0;
  1237. }
  1238. $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'");//有条件不同模板匹配
  1239. if(isset($notice[0]['content']))
  1240. {
  1241. if($pdlkh == '1' && $notice[0]['thq'] != ''&& $notice[0]['thh'] != '')//非常规和老客户模板,如果是老客户并且需要替换的话
  1242. {
  1243. $notice[0]['content'] = str_replace($notice[0]['thq'],$notice[0]['thh'],$notice[0]['content']);
  1244. }
  1245. $shop = $this->shop->read($fullorder['shop']);
  1246. //$express = $this->express->read($fullorder['express']);
  1247. //$service = $this->service->read($express['service']);
  1248. $country = $this->country->read($fullorder['country']);
  1249. $fullorder['country'] = $country['ename'];
  1250. //$express['servicename'] =$service['title'];//增加快递名称
  1251. $express = array();
  1252. $notice[0]['email'] = $this->emaildata->read($notice[0]['email']);
  1253. $go = $this->notice->get_god($fullorder,$shop,$express,$notice[0]);
  1254. if($go == 1)
  1255. {
  1256. $this->fullorder->save(array('content'=>$fid['content'].'自动发送-成功;','zdstate'=>$fid['zdstate'].$notice[0]['type'].'-'.$notice[0]['tab'].'|','exstateerror'=>''),$fid['id']);
  1257. return 1;
  1258. }
  1259. else
  1260. {
  1261. $this->fullorder->save(array('exstateerror'=>'自动发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice[0]['type'].'-'.$notice[0]['message'].')'),$fid['id']);
  1262. }
  1263. }
  1264. else
  1265. {
  1266. $this->fullorder->save(array('exstateerror'=>'当前订单状态无匹配模板'),$fid['id']);
  1267. }
  1268. }
  1269. }
  1270. public function _sdfs($fullorder,$id)//手动发送信息
  1271. {
  1272. $time = time();
  1273. $notice = $this->notice->read($id);//无条件同模板匹配
  1274. $notice['email'] = $this->emaildata->read($notice['email']);
  1275. $shop = $this->shop->read($fullorder['shop']);
  1276. $express = $this->express->read($fullorder['express']);
  1277. if($notice['type'] == '1')
  1278. {
  1279. $fslx = 'tab';
  1280. $content = '自动发送';
  1281. $stripos = '1-';
  1282. }
  1283. else if ($notice['type'] == '2')
  1284. {
  1285. $fslx = 'logisticstatus';
  1286. $content = $notice['title'];
  1287. $stripos = $notice['type'].'-'.$notice[$fslx].'|';
  1288. }
  1289. if(stripos($fullorder['zdstate'],$stripos) === false && $fullorder['wltype'] == '0')//如果没发送过并且允许发送
  1290. {
  1291. $go = $this->notice->get_god($fullorder,$shop,$express,$notice);
  1292. if($go == 1)
  1293. {
  1294. if($notice['type'] == '1')
  1295. {
  1296. $this->fullorder->save(array('content'=>$fullorder['content'].$content.'-成功;','zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  1297. }
  1298. else if ($notice['type'] == '2')
  1299. {
  1300. $this->fullorder->save(array('wlcontent'=>$fullorder['wlcontent'].$content.'-成功;','wlfstime'=>time(),'zdstate'=>$fullorder['zdstate'].$notice['type'].'-'.$notice[$fslx].'|','exstateerror'=>'','wlerror'=>''),$fullorder['id']);
  1301. }
  1302. return 1;
  1303. }
  1304. else
  1305. {
  1306. if($notice['type'] == '1')
  1307. {
  1308. $this->fullorder->save(array('exstateerror'=>$content.'发送失败1:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  1309. }
  1310. else if ($notice['type'] == '2')
  1311. {
  1312. $this->fullorder->save(array('wlerror'=>$content.'发送失败2:'.date('Y-m-d H',time()).'-'.$go.'('.$notice['type'].'-'.$notice[$fslx].')'),$fullorder['id']);
  1313. }
  1314. }
  1315. }
  1316. }
  1317. public function _zz()
  1318. {
  1319. //$f = $this->fullorder->find_all("1=1",'wlfstime','wlfstime desc',0,2);
  1320. if(date("w") == '0')
  1321. {
  1322. exit;
  1323. }
  1324. $time = time();
  1325. $tjlike = array();
  1326. $urls = array();$sl = 0;
  1327. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1328. foreach ($notice as $key=>$var)
  1329. {
  1330. $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));
  1331. }
  1332. foreach($urls as $value) {
  1333. $tjlike[] = $value['url'];
  1334. $ch = curl_init();
  1335. $url = $value['url'];
  1336. curl_setopt($ch,CURLOPT_URL,$url);
  1337. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1338. curl_setopt($ch,CURLOPT_HEADER,0);
  1339. curl_setopt($ch,CURLOPT_POST, 1);
  1340. curl_setopt($ch,CURLOPT_TIMEOUT,5);
  1341. //设置post数据
  1342. $post = array();
  1343. $post['data'] = $value['data'];
  1344. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1345. $res = curl_exec($ch);
  1346. curl_close($ch);
  1347. $sl++;
  1348. }
  1349. echo "<pre>";
  1350. print_r($tjlike);
  1351. echo $sl;
  1352. /**
  1353. $urls = array();
  1354. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1355. foreach ($notice as $key=>$var)
  1356. {
  1357. $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));
  1358. }
  1359. $mh = curl_multi_init();
  1360. $urlHandlers = array();
  1361. $urlData = array();
  1362. // 初始化多个请求句柄为一个
  1363. foreach($urls as $value) {
  1364. $ch = curl_init();
  1365. $url = $value['url'];
  1366. $url .= strpos($url, '?') ? '&' : '?';
  1367. curl_setopt($ch, CURLOPT_URL, $url);
  1368. // 设置数据通过字符串返回,而不是直接输出
  1369. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1370. curl_setopt($ch,CURLOPT_HEADER,0);
  1371. curl_setopt($ch,CURLOPT_POST, 1);
  1372. $post = array();
  1373. $post['data'] = $value['data'];
  1374. curl_setopt($ch,CURLOPT_POSTFIELDS,http_build_query($post));
  1375. $urlHandlers[] = $ch;
  1376. curl_multi_add_handle($mh, $ch);
  1377. }
  1378. $active = null;
  1379. // 检测操作的初始状态是否OK,CURLM_CALL_MULTI_PERFORM为常量值-1
  1380. do {
  1381. // 返回的$active是活跃连接的数量,$mrc是返回值,正常为0,异常为-1
  1382. $mrc = curl_multi_exec($mh, $active);
  1383. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  1384. // 如果还有活动的请求,同时操作状态OK,CURLM_OK为常量值0
  1385. while ($active && $mrc == CURLM_OK) {
  1386. // 持续查询状态并不利于处理任务,每60ms检查一次,此时释放CPU,降低机器负载
  1387. usleep(50000);
  1388. // 如果批处理句柄OK,重复检查操作状态直至OK。select返回值异常时为-1,正常为1(因为只有1个批处理句柄)
  1389. if (curl_multi_select($mh) != -1) {
  1390. do {
  1391. $mrc = curl_multi_exec($mh, $active);
  1392. } while ($mrc == CURLM_CALL_MULTI_PERFORM);
  1393. }
  1394. }
  1395. // 获取返回结果
  1396. foreach($urlHandlers as $index => $ch) {
  1397. $urlData[$index] = curl_multi_getcontent($ch);
  1398. // 移除单个curl句柄
  1399. curl_multi_remove_handle($mh, $ch);
  1400. }
  1401. curl_multi_close($mh);
  1402. print_r($urlData);
  1403. **/
  1404. /**
  1405. $notice = $this->notice->find_all("message = '1' and state = '1' and type = '2' and ktime < '$time' and jtime > '$time'");//已有自动发送,这个是物流发送
  1406. foreach ($notice as $key=>$var)
  1407. {
  1408. $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']."%'";//正式发送的时候开启这个"'
  1409. //$where = "shop = '2' and waybill != '' and library = '2' and librarytime > '".(time()-15*24*3600)."'";
  1410. $ch = curl_init();
  1411. curl_setopt($ch,CURLOPT_URL,'http://'.$_SERVER['HTTP_HOST'].'/api/wlfs?v='.$var['id']);
  1412. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1413. curl_setopt($ch,CURLOPT_HEADER,0);
  1414. curl_setopt($ch,CURLOPT_POST, 1);
  1415. curl_setopt($ch,CURLOPT_TIMEOUT,1);
  1416. //设置post数据
  1417. $post = array();
  1418. $post['data'] = array('where'=>$where,'var'=>$var);
  1419. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1420. $res = curl_exec($ch);
  1421. curl_close($ch);
  1422. //$this->_wlfs($where,$var);
  1423. }
  1424. **/
  1425. /**
  1426. $var = $this->notice->read(63);//已有自动发送,这个是物流发送
  1427. $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']."%'";//正式发送的时候开启这个"'
  1428. $this->_wlfs($where,$var);
  1429. **/
  1430. }
  1431. public function _wlfs()
  1432. {
  1433. $webhookregister = 0;
  1434. $post = $this->input->post(NULL, TRUE);
  1435. $data = $this->input->post('data',true);
  1436. $where = $data['where'];
  1437. $var = $data['var'];
  1438. $wlfs = array();
  1439. $shopid = $where['shop'];
  1440. @$this->allocation->insert(array('title'=>date('Y-m-d',time()).'-'.$shopid));
  1441. $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']."%'";//正式发送的时候开启这个"'
  1442. //$where = "shop = '".$where['shop']."' and waybill != '' and library = '2' and express = '3' and librarytime > '1636300800' and wlcontent not like '%".$where['wlcontent']."%'";//正式发送的时候开启这个"'
  1443. $data = $this->fullorder->find_all($where);
  1444. $csck = array();
  1445. foreach ($data as $k=>$v)
  1446. {
  1447. $vexpress = $v['express'];
  1448. $shop = $this->shop->read($v['shop']);
  1449. $express = $this->express->read($v['express']);
  1450. $service = $this->service->read($express['service']);
  1451. $country = $this->country->read($v['country']);
  1452. $v['country'] = $country['ename'];
  1453. $express['servicename'] =$service['title'];//增加快递名称
  1454. $v['cxcode'] = strtolower($express['cxcode']);//增加快递服务商码
  1455. if($v['expressstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1456. {
  1457. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1458. {
  1459. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1460. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1461. }
  1462. continue;
  1463. }
  1464. if(($express['cxcode'] == '' && $v['exstateerror'] == '') || ($express['cxcode'] == '' && $v['exstateerror'] != ''))
  1465. {
  1466. continue;
  1467. }
  1468. else if($express['cxcode'] == 'usps')//$express['cxcode'] == 'fedex' || $express['cxcode'] == 'dhl' || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd'
  1469. {
  1470. /**
  1471. if($express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
  1472. {
  1473. $express['cxcode'] = 'cne';
  1474. }
  1475. **/
  1476. $logistics = $express['cxcode'];
  1477. }
  1478. else if(($express['cxcode'] == 'ups' || $express['cxcode'] == '17track') && $v['webhookregister'] == 1)
  1479. {
  1480. continue;
  1481. }
  1482. else if(($express['cxcode'] == 'ups' || $express['cxcode'] == '17track') && $v['webhookregister'] < 1)//使用webhook注册模式 || $express['cxcode'] == '17track'
  1483. {
  1484. $logistics = $express['cxcode'];
  1485. $webhookregister = 1;
  1486. }
  1487. else
  1488. {
  1489. //暂时不启用第三方,这里直接跳出
  1490. $this->fullorder->save(array('expressstate'=>'99'),$v['id']);
  1491. continue;
  1492. //$logistics = 'apismt';
  1493. //$v['express'] = strtolower($express['cxcode']);//替换为快递服务商码
  1494. }
  1495. $v['servicename'] =$service['title'];//增加快递名称
  1496. $v['url'] = $express['url'];//增加快递链接
  1497. @$fs = $this->$logistics->get_logistics($v);
  1498. $csck[] = array($v['number'],$fs['f']);
  1499. if(!isset($fs['f']))
  1500. {
  1501. $fs = $this->$logistics->get_logistics($v);
  1502. if(!isset($fs['f']))
  1503. {
  1504. continue;
  1505. }
  1506. if($fs['f'] == '1')
  1507. {
  1508. $v['express'] = $vexpress;
  1509. if($fs['exstate'] > $v['expressstate'] || isset($fs['webhookregister']))
  1510. {
  1511. $this->fullorder->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister),$v['id']);
  1512. }
  1513. if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1514. {
  1515. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1516. {
  1517. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1518. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1519. }
  1520. }
  1521. }
  1522. /**
  1523. if($logistics == 'apismt')//第三方未购买,第三方查询直接进入无法查询状态
  1524. {
  1525. $this->fullorder->save(array('expressstate'=>'99'),$v['id']);
  1526. }
  1527. **/
  1528. }
  1529. else
  1530. {
  1531. if($fs['f'] == '1')
  1532. {
  1533. $v['express'] = $vexpress;
  1534. if($fs['exstate'] > $v['expressstate'])
  1535. {
  1536. $this->fullorder->save(array('expressstate'=>$fs['exstate'],'excontent'=>$fs['data'],'webhookregister'=>$webhookregister),$v['id']);
  1537. }
  1538. if($fs['exstate'] == $var['logisticstatus'] && $v['wlyc'] == '0' && $v['wltype'] != '1' && $v['source'] != '1')//获取快递状态等于模板状态、订单状态等于模板状态、出库时间大于-、未加入物流异常、允许发送邮件状态、非线下单
  1539. {
  1540. if($v['shop'] < '7')// && $v['shouldmoney'] > 100)
  1541. {
  1542. $wlfs[] = array('v'=>$v,'id'=>$var['id']);
  1543. //$go = $this->_sdfs($v,$var['id']);//更新顺带发送
  1544. }
  1545. }
  1546. }
  1547. }
  1548. }
  1549. @$this->allocation->insert(array('title'=>$shopid.'-'.json_encode($csck)));
  1550. if($wlfs)
  1551. {
  1552. foreach ($wlfs as $k=>$v)
  1553. {
  1554. $t1 = microtime(true);
  1555. $this->_sdfs($v['v'],$v['id']);
  1556. $t2 = microtime(true);
  1557. $t3 = (40-($t2-$t1) < 1)?1:round(40-($t2-$t1));
  1558. sleep($t3);
  1559. }
  1560. }
  1561. }
  1562. public function _zzold()
  1563. {
  1564. $data = $this->fullorder->find_all("library = '2' and waybill != '' and exstate != '4' and exstate != '5' and dtime > '1580486400'");
  1565. foreach ($data as $k=>$v)
  1566. {
  1567. $shop = $this->shop->read($v['shop']);
  1568. $express = $this->express->read($v['express']);
  1569. $service = $this->service->read($express['service']);
  1570. $country = $this->country->read($v['country']);
  1571. $v['country'] = $country['ename'];
  1572. $express['servicename'] =$service['title'];//增加快递名称
  1573. if($express['cxcode'] == '' && $v['exstateerror'] == '')
  1574. {
  1575. continue;
  1576. }
  1577. else if($express['cxcode'] == '' && $v['exstateerror'] != '')
  1578. {
  1579. continue;
  1580. }
  1581. else if($express['cxcode'] == 'fedex' || $express['cxcode'] == 'usps' || $express['cxcode'] == 'dhl' || $express['cxcode'] == 'cne' || $express['cxcode'] == 'dpex' || $express['cxcode'] == 'dpd')
  1582. {
  1583. $logistics = $express['cxcode'];
  1584. }
  1585. else
  1586. {
  1587. $logistics = 'apismt';
  1588. }
  1589. $v['express'] = strtolower($express['cxcode']);//替换为快递服务商码
  1590. $v['servicename'] =$service['title'];//增加快递名称
  1591. $v['url'] = $express['url'];//增加快递链接
  1592. $fs = $this->$logistics->get_logistics($v);
  1593. if(!isset($fs['f']))
  1594. {
  1595. $this->fullorder->save(array('exstate'=>'99'),$v['id']);
  1596. }
  1597. else
  1598. {
  1599. if($fs['f'] == '0')
  1600. {
  1601. $this->fullorder->save(array('excontent'=>$fs['content']),$v['id']);
  1602. }
  1603. if($fs['f'] == '2')
  1604. {
  1605. }
  1606. else
  1607. {
  1608. $this->fullorder->save(array('exstate'=>$fs['exstate'],'excontent'=>$fs['data']),$v['id']);
  1609. }
  1610. }
  1611. }
  1612. }
  1613. public function _query()
  1614. {
  1615. header('Access-Control-Allow-Origin: *');
  1616. $post = $this->input->post(NULL, TRUE);
  1617. if(isset($post['orderinfo']))
  1618. {
  1619. $list = array();
  1620. $orderinfo = $this->input->post('orderinfo',true);
  1621. $orderinfo = explode(',',trim($orderinfo,','));
  1622. foreach ($orderinfo as $v)
  1623. {
  1624. $exp="/^([0-9A-Za-z\\-_\\.]+)@([0-9a-z]+\\.[a-z]{2,3}(\\.[a-z]{2})?)$/i";
  1625. if(is_numeric($v) && mb_strlen($v) > 8)
  1626. {
  1627. $w = "orderinfo like '%$v%'";
  1628. }
  1629. else if(filter_var($v, FILTER_VALIDATE_EMAIL))
  1630. {
  1631. $w = "email like '%$v%'";
  1632. }
  1633. else
  1634. {
  1635. echo json_encode(array('site'=>0,'success'=>true));exit;
  1636. }
  1637. $data = $this->fullorder->find_all($w." and dtime > '1577811600'");
  1638. if(isset($data[0]))
  1639. {
  1640. if($data[0]['library'] != '2')
  1641. {
  1642. $list[] = array('orderinfo'=>$v,'site'=>1);
  1643. }
  1644. else if($data[0]['library'] == '2' && $data[0]['exstate'] == '99')
  1645. {
  1646. $list[] = array('orderinfo'=>$v,'site'=>2);
  1647. }
  1648. else if($data[0]['library'] == '2' && $data[0]['exstate'] != '99')
  1649. {
  1650. if($data[0]['excontent'] != '成功;' && $data[0]['excontent'] != '')
  1651. {
  1652. $list[] = array('orderinfo'=>$v,'site'=>3,'data'=>$data[0]['excontent']);
  1653. }
  1654. else
  1655. {
  1656. $list[] = array('orderinfo'=>$v,'site'=>2);
  1657. }
  1658. }
  1659. }
  1660. else
  1661. {
  1662. $list[] = array('orderinfo'=>$v,'site'=>0);
  1663. }
  1664. }
  1665. echo json_encode(array('t'=>count($orderinfo),'list'=>$list,'success'=>true));exit;
  1666. }
  1667. }
  1668. public function _logistics()
  1669. {
  1670. if(isset($_GET['waybill']))
  1671. {
  1672. $waybill = $this->input->get('waybill',true);
  1673. if($waybill == 1231233123)
  1674. {
  1675. $data = $this->fullorder->get_number('ASTE-30922-034');
  1676. echo json_encode(array('track'=>array('f'=>1,'data'=>$data['excontent']),'msg'=>'','success'=>1));exit;
  1677. }
  1678. //$express = $this->input->get('express',true);
  1679. $data = $this->fullorder->get_waybill($waybill);
  1680. if($data['excontent'])
  1681. {
  1682. //$a = $this->$express->get_logistics(array('waybill'=>$waybill));
  1683. echo json_encode(array('track'=>array('f'=>1,'data'=>$data['excontent']),'msg'=>'','success'=>1));exit;
  1684. }
  1685. else
  1686. {
  1687. echo json_encode(array('track'=>'','msg'=>'No logistics information','success'=>0));exit;
  1688. }
  1689. }
  1690. }
  1691. public function _klarna()
  1692. {
  1693. $shop = array();$cg = array();$sb = array();
  1694. $ftime = strtotime(date("Y-m-d 0:00:0",strtotime("-10 day")))+8*3600;
  1695. $ttime = strtotime(date("Y-m-d 8:00:0",time()));
  1696. $shopdata = $this->shop->find_all("type = '269' and klarnaname != '' and klarnapass != ''");
  1697. foreach($shopdata as $v)
  1698. {
  1699. $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");
  1700. foreach($data as $val)
  1701. {
  1702. $api = $this->_klarnaapi($val['paypal'],$val['shouldmoney'],$v['klarnaname'],$v['klarnapass']);
  1703. $header = $api['header'];
  1704. $api = $api['res'];
  1705. if(isset($api['error_messages'][0]))
  1706. {
  1707. if(stripos($api['error_messages'][0],'amount is 0 for') !== false)
  1708. {
  1709. $this->fullorder->save(array('klarna'=>3),$val['id']);
  1710. $sb[] = array($val['number'],$val['orderinfo'],'oooo3');
  1711. }
  1712. else
  1713. {
  1714. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>$api['error_messages'][0]),$val['id']);
  1715. $sb[] = array($val['number'],$val['orderinfo'],'oooo1');
  1716. }
  1717. }
  1718. else if($api == '')
  1719. {
  1720. if(isset($header['http_code']) && $header['http_code'] == 201)
  1721. {
  1722. $this->fullorder->save(array('klarna'=>2),$val['id']);
  1723. $cg[] = array($val['number'],$val['orderinfo'],'oooo2');
  1724. }
  1725. else
  1726. {
  1727. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>'未知错误'),$val['id']);
  1728. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1729. }
  1730. }
  1731. else if(isset($api['cs']))
  1732. {
  1733. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>'超时'),$val['id']);
  1734. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1735. }
  1736. else
  1737. {
  1738. $this->fullorder->save(array('klarna'=>1,'klarnaerror'=>'未知错误'),$val['id']);
  1739. $sb[] = array($val['number'],$val['orderinfo'],'oooo0');
  1740. }
  1741. }
  1742. }
  1743. echo "<pre>";
  1744. print_r($cg);
  1745. echo "<pre>";
  1746. print_r($sb);
  1747. }
  1748. public function _klarnaapi($paypal,$shouldmoney,$name,$pass)
  1749. {
  1750. $url = 'https://api-na.klarna.com/ordermanagement/v1/orders/'.$paypal.'/captures';
  1751. $data = '{"captured_amount": '.str_replace('.','',$shouldmoney).'}';
  1752. $header[] = "Content-Type:application/json";
  1753. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1754. $ch = curl_init();
  1755. curl_setopt($ch, CURLOPT_URL, $url);
  1756. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1757. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1758. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  1759. curl_setopt($ch, CURLOPT_POST, 1);
  1760. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1761. curl_setopt($ch, CURLOPT_TIMEOUT, 20);
  1762. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1763. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1764. $res = curl_exec($ch);
  1765. $header = curl_getinfo($ch);
  1766. if($res === false)
  1767. {
  1768. if(curl_errno($ch))
  1769. {
  1770. return array('res'=>'1','header'=>'','cs'=>1);
  1771. }
  1772. }
  1773. else
  1774. {
  1775. $res = json_decode($res,true);
  1776. return array('res'=>$res,'header'=>$header);
  1777. }
  1778. curl_close($ch);
  1779. }
  1780. public function _klarnadata($paypal,$name,$pass)
  1781. {
  1782. $url = 'https://api-na.klarna.com/ordermanagement/v1/orders/'.$paypal;
  1783. $header[] = "Content-Type:application/json";
  1784. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1785. $ch = curl_init();
  1786. curl_setopt($ch, CURLOPT_URL, $url);
  1787. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1788. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1789. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1790. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1791. $res = curl_exec($ch);
  1792. curl_close($ch);
  1793. $res = json_decode($res,true);
  1794. $data = '';
  1795. if(isset($res['fraud_status']))
  1796. {
  1797. $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'];
  1798. }
  1799. return $data;
  1800. }
  1801. public function _hqpaypal()
  1802. {
  1803. $shop = $this->shop->find_all("paypalname != ''");
  1804. foreach ($shop as $val)
  1805. {
  1806. $d = $this->fullorder->find_all("shop = '".$val['id']."' and dtime > '".(time()-(5*24*3600))."' and dtime < '".(time()-(3*3600))."' and pay = '22' and klarnadata = ''");
  1807. foreach ($d as $v)
  1808. {
  1809. $paypal = $this->paypal->data($v['paypal'],$val);
  1810. if($paypal != '')
  1811. {
  1812. $this->fullorder->save(array('klarnadata'=>$paypal),$v['id']);
  1813. }
  1814. }
  1815. }
  1816. }
  1817. public function _hqstripe()
  1818. {
  1819. $shop = $this->shop->find_all("stripe != ''");
  1820. foreach ($shop as $val)
  1821. {
  1822. $d = $this->fullorder->find_all("shop = '".$val['id']."' and dtime > '".(time()-(5*24*3600))."' and dtime < '".time()."' and pay = '1211' and klarnadata = ''");
  1823. foreach ($d as $v)
  1824. {
  1825. $paypal = $this->_stripe($v['paypal'],$val['stripe']);
  1826. if($paypal != '')
  1827. {
  1828. $this->fullorder->save(array('klarnadata'=>$paypal),$v['id']);
  1829. }
  1830. }
  1831. }
  1832. }
  1833. public function _stripe($pay,$stripe)
  1834. {
  1835. $url = 'https://api.stripe.com/v1/payment_intents/'.$pay;
  1836. $header[] = "Authorization:Bearer ".$stripe;
  1837. $ch = curl_init();
  1838. curl_setopt($ch, CURLOPT_URL, $url);
  1839. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1840. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1841. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1842. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1843. $res = curl_exec($ch);
  1844. curl_close($ch);
  1845. $res = json_decode($res,true);
  1846. $k = '';
  1847. if(isset($res['shipping']['name']))
  1848. {
  1849. $line = ($res['shipping']['address']['line2'] != '')?$res['shipping']['address']['line1'].' '.$res['shipping']['address']['line2']:$res['shipping']['address']['line1'];
  1850. $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));
  1851. }
  1852. return $k;
  1853. }
  1854. public function _afterpay($paypal,$name,$pass)
  1855. {
  1856. $url = 'https://global-api.afterpay.com/v2/payments?ids='.$paypal;
  1857. $header[] = "Accept:application/json";
  1858. $header[] = "User-Agent: Readme.io API Simulator'";
  1859. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1860. $ch = curl_init();
  1861. curl_setopt($ch, CURLOPT_URL, $url);
  1862. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1863. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1864. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1865. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1866. $res = curl_exec($ch);
  1867. curl_close($ch);
  1868. $res = json_decode($res,true);
  1869. $data = '';
  1870. if(isset($res['results'][0]['orderDetails']['consumer']['email']))
  1871. {
  1872. $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'];
  1873. $data = str_replace(',,',',',$data);
  1874. }
  1875. return $data;
  1876. }
  1877. public function _clearpay($paypal,$name,$pass)
  1878. {
  1879. $url = 'https://global-api.afterpay.com/v2/payments?ids='.$paypal;
  1880. $header[] = "Accept:application/json";
  1881. $header[] = "User-Agent: Readme.io API Simulator'";
  1882. $header[] = "Authorization: Basic ".base64_encode($name.":".$pass);
  1883. $ch = curl_init();
  1884. curl_setopt($ch, CURLOPT_URL, $url);
  1885. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  1886. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  1887. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1888. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1889. $res = curl_exec($ch);
  1890. curl_close($ch);
  1891. $res = json_decode($res,true);
  1892. $data = '';
  1893. if(isset($res['results'][0]['orderDetails']['consumer']['email']))
  1894. {
  1895. $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'];
  1896. $data = str_replace(',,',',',$data);
  1897. }
  1898. return $data;
  1899. }
  1900. public function _htmlstock()
  1901. {
  1902. if(isset($_GET['hq']))
  1903. {
  1904. $ProductsType = $this->typeclass->find_all("classid = '16' and hq = '1'",'id,title','sequence asc');
  1905. foreach ($ProductsType as $k=>$v)
  1906. {
  1907. if($v['title'] == 'Closure')
  1908. {
  1909. $ProductsType[$k]['title'] = 'Closure/Frontal';
  1910. }
  1911. }
  1912. $HairColor = $this->typeclass->find_all("classid = '8' and hq = '1'",'id,title','sequence asc');
  1913. $HairWavy = $this->typeclass->find_all("classid = '15' and hq = '1'",'id,title','sequence asc');
  1914. $WigType = $this->typeclass->find_all("classid = '18' and hq = '1'",'id,title','sequence asc');
  1915. $Length = $this->typeclass->find_all("classid = '14' and hq = '1'",'id,title','sequence asc');
  1916. echo json_encode(array('ProductsType'=>$ProductsType,'HairColor'=>$HairColor,'HairWavy'=>$HairWavy,'WigType'=>$WigType,'Length'=>$Length));exit;
  1917. //http://1.wepolicy.cn/api/htmlstock?hq=1
  1918. }
  1919. if(isset($_GET['page']))
  1920. {
  1921. $del = array();
  1922. $typeclass13 = $this->typeclass->find_all("classid = '13'");
  1923. $typeclass16 = $this->typeclass->find_all("classid = '16'");
  1924. foreach ($typeclass16 as $key=>$value)
  1925. {
  1926. foreach ($typeclass13 as $v)
  1927. {
  1928. $del[] = $value['title'].' '.$v['title'];
  1929. }
  1930. }
  1931. $page = $this->input->get('page',true);
  1932. $perpage = $this->input->get('perpage',true);
  1933. $category = $this->input->get('ProductsType',true);//类目
  1934. $color = $this->input->get('HairColor',true);//颜色
  1935. $lowe = $this->input->get('HairWavy',true);//花型
  1936. $lacetype = $this->input->get('WigType',true);//头套种类
  1937. $size = $this->input->get('Length',true);//长度
  1938. $title = $this->input->get('title',true);//传输文本
  1939. $warehouse = 5;
  1940. $state = $this->input->get('state',true);
  1941. $where = "warehouse = '5' and state = '0'";
  1942. if($category)
  1943. {
  1944. $where .= " and features like '%-$category-%'";
  1945. }
  1946. if($color)
  1947. {
  1948. $where .= " and features like '%-$color-%'";
  1949. }
  1950. if($lowe)
  1951. {
  1952. $where .= " and features like '%-$lowe-%'";
  1953. }
  1954. if($lacetype)
  1955. {
  1956. $where .= " and features like '%-$lacetype-%'";
  1957. }
  1958. if($size)
  1959. {
  1960. $where .= " and features like '%-$size-%'";
  1961. }
  1962. if($title)
  1963. {
  1964. $where .= " and title like '%$title%'";
  1965. }
  1966. $order_str = "id desc";
  1967. if(empty($page))
  1968. {
  1969. $start = 0;
  1970. $perpage = 1;
  1971. }
  1972. else
  1973. {
  1974. $start = ($page - 1)*$perpage;
  1975. }
  1976. $info_list = $this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number',$order_str,$start,$perpage);
  1977. $data = array();
  1978. foreach ($info_list as $key=>$value)
  1979. {
  1980. $c = $this->whlabel->find_count($where.' and sku = "'.$value['sku'].'" and state = 0 and warehouse = "5" and features = "'.$value['features'].'" and zd = ""');
  1981. if($c > 1)
  1982. {
  1983. $data[] = array('Item'=>str_replace($del,'',$value['title']),'Stock'=>$c);
  1984. }
  1985. }
  1986. $total = count($this->whlabel->find_pc($where,'sku,features,warehouse','id,warehouse,sku,title,features,number'));
  1987. $pagenum = ceil($total/$perpage);
  1988. $over = $total-($start+$perpage);
  1989. $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($data));//总数量,剩余数量,总页数,数据
  1990. echo json_encode($rows);exit;
  1991. ///api/htmlstock?page=1&perpage=50&ProductsType=&HairColor=&HairWavy=&WigType=&Length= //页数、每页数量、类目、颜色、花型、头套种类、尺寸
  1992. }
  1993. }
  1994. public function _17track()
  1995. {
  1996. $express = array();
  1997. $expressdata = $this->express->find_all('1=1');
  1998. foreach ($expressdata as $v)
  1999. {
  2000. $express[$v['id']] = $v['title'];
  2001. }
  2002. $xq = array();
  2003. $j = file_get_contents('PHP://input');
  2004. $j = json_decode($j, true);
  2005. if(isset($j['data']) && isset($j['sign']))
  2006. {
  2007. $sh = hash("sha256",$j['event'].'/'.json_encode($j['data']).'/0811AC1711EAABB7D764D04B824F8C2D');
  2008. if($j['data']['number'] != '')
  2009. {
  2010. $f = 'fullorder';
  2011. $d = $this->fullorder->get_waybill($j['data']['number']);
  2012. if(!$d)
  2013. {
  2014. $f = 'fullordersmt';
  2015. $d = $this->fullordersmt->get_waybill($j['data']['number']);
  2016. }
  2017. if(!$d)
  2018. {
  2019. exit;
  2020. }
  2021. if($j['data']['track']['e'] == 0)//查询不到
  2022. {
  2023. $exstate = 0;//无信息
  2024. }
  2025. else if($j['data']['track']['e'] == 10)//运输途中
  2026. {
  2027. $exstate = 3;//在途中
  2028. }
  2029. else if($j['data']['track']['e'] == 20)//运输过久
  2030. {
  2031. $exstate = 3;//在途中
  2032. }
  2033. /**
  2034. else if($j['data']['track']['e'] == 30)//到达待取
  2035. {
  2036. $exstate = 5;//派送中
  2037. }
  2038. **/
  2039. else if($j['data']['track']['e'] == 35)//投递失败
  2040. {
  2041. $exstate = 1;//派送异常
  2042. }
  2043. else if($j['data']['track']['e'] == 40)//成功签收
  2044. {
  2045. $exstate = 6;//签收
  2046. }
  2047. else if($j['data']['track']['e'] == 50)//可能异常
  2048. {
  2049. $exstate = 1;//派送异常
  2050. }
  2051. $pd = array();
  2052. if(isset($j['data']['track']['z1'][0]))
  2053. {
  2054. foreach ($j['data']['track']['z1'] as $v)
  2055. {
  2056. $xq .= $v['a'].' ['.$v['c'].'] '.$v['z'].'<br />';// a日期 c地址 z状态
  2057. }
  2058. $pd = $j['data']['track']['z1'][0];
  2059. if(stripos($express[$d['express']],'Fedex') !== false && stripos($pd['z'],'International shipment release - Import') !== false)
  2060. {
  2061. $exstate = 4;//即将派送
  2062. }
  2063. else if(stripos($express[$d['express']],'DHL') !== false && stripos($pd['z'],'Clearance processing complete') !== false)
  2064. {
  2065. $exstate = 4;//即将派送
  2066. }
  2067. else if(stripos($express[$d['express']],'UPS') !== false && stripos($pd['c'],'Louisville, KY, US') !== false && stripos($pd['z'],'Departed from Facility') !== false)
  2068. {
  2069. $exstate = 4;//即将派送
  2070. }
  2071. else if(stripos($express[$d['express']],'GES') !== false && stripos($pd['z'],'Shipment picked up') !== false)
  2072. {
  2073. $exstate = 4;//即将派送
  2074. }
  2075. }
  2076. $this->awlgx->insert(array("number"=>$d['number'],"content"=>$xq,"time"=>time(),'exstate'=>$exstate));
  2077. $this->$f->save(array('expressstate'=>$exstate,'excontent'=>$xq),$d['id']);
  2078. $time = time();
  2079. $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."'");
  2080. if($notice && $d['wlyc'] == '0' && $d['wltype'] != '1' && $d['source'] != '1' && stripos($d['wlcontent'],$notice[0]['title']) === false)
  2081. {
  2082. $this->_sdfs($d,$notice[0]['id']);
  2083. }
  2084. }
  2085. }
  2086. }
  2087. }