Api.php 105 KB

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