Api.php 99 KB

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