Api.php 104 KB

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