Model_api.php 70 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880
  1. <?php
  2. class Model_Api extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_weight','weight');
  6. $this->load->_model('Model_classid','classid');
  7. $this->load->_model("Model_logic_ding","logic_ding");
  8. $this->load->_model("Model_logic_match","logic_match");
  9. }
  10. public function get_hq($name,$shopapi,$shop)
  11. {
  12. $jqtime = ($name=='SuperNova')?24*3600:2*3600;
  13. //$jqtime = ($name=='SuperNova')?24*3600*2:(2*3600 + 24*3600);
  14. $fromTime = time()-36*3600-$jqtime;//strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  15. $toTime = time();
  16. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行【".$name."】".json_encode($shop));
  17. if($name == 'SU' || $name== 'SN')
  18. {
  19. $path = $_SERVER["DOCUMENT_ROOT"] . '/data/token/supernovawig.txt';
  20. $token = '';
  21. if(file_exists($path))
  22. {
  23. $fileread = fopen($path, 'r');
  24. $accessstr = fgets($fileread);
  25. fclose($fileread);
  26. $accessarr = explode(':', $accessstr);
  27. if (time() < intval($accessarr[0]))
  28. {
  29. $token = isset($accessarr[1]) ? $accessarr[1] : '';
  30. }
  31. }
  32. if($token == '')
  33. {
  34. $file = fopen($path, 'w');
  35. $tokendata['username'] = 'erpadmin';
  36. $tokendata['password'] = 'erppassword';
  37. $tokenheader[] = 'Accept: application/json';
  38. $tokenheader[] = 'Content-Type: application/json';
  39. $tokenheader[] = 'Content-Length:'.strlen(json_encode($tokendata));
  40. $info = $this->su_curl($tokendata,'http://api.supernovawig.com/v1/account/login',$tokenheader);
  41. $result = json_decode($info,true);
  42. $access_new = (time() + 3600).':'.$result['access-token'];
  43. fwrite($file, $access_new);
  44. fclose($file);
  45. $token = $result['access-token'];
  46. }
  47. $data['X-Pagination-Total-Count'] = 500;//资源的总数量
  48. $data['X-Pagination-Page-Count'] = 1;//资源的总页数
  49. $data['X-Pagination-Current-Page'] = 1;//资源的当前页(目前是第几页)
  50. $data['X-Pagination-Per-Page'] = 500;//每页资源的数量
  51. $header[] = 'access-token:'.$token;
  52. $header[] = 'Accept: application/json';
  53. $header[] = 'Content-Type: application/json';
  54. $header[] = 'Content-Length:'.strlen(json_encode($data));
  55. $info = $this->su_curl($data,'http://api.supernovawig.com/v1/order/list',$header);
  56. //$this->logic_ding->sendToDing("测试获取SU订单".$info);
  57. $result = json_decode($info,true);
  58. $thatDayOrder = array();
  59. if(empty($result['data'])){
  60. return [];
  61. }
  62. foreach ($result['data'] as $v)
  63. {
  64. $productNames = '';
  65. $isparameter = '';
  66. $sku = '';
  67. $quantity = '';
  68. $state = '';
  69. if(!$v['products'] || $v['order_status'] != 'payment_confirmed')
  70. {
  71. continue;
  72. }
  73. foreach($v['products'] as $products)
  74. {
  75. $productNames .= ($productNames != '')?','.$products['name']:$products['name'];
  76. $sku .= ($sku != '')?','.$products['sku']:$products['sku'];
  77. $quantity = floor($products['qty']).';';
  78. foreach($products['custom_option_info'] as $key=>$custom_option_info)
  79. {
  80. $isparameter .= $key.':'.$custom_option_info.',';
  81. }
  82. }
  83. $address = preg_replace('/( | | |\s)+/',' ',$v['customer_address_street1'].(($v['customer_address_street2'] != '')?' '.$v['customer_address_street2']:''));
  84. $thatDayOrder[] = array(
  85. 'order_id' => $v['increment_id'],
  86. 'insurance' => 0,
  87. 'product_name' => $productNames,
  88. 'purchased_on' => $v['updated_at'],
  89. 'name' => $v['customer_firstname'].' '.$v['customer_lastname'],
  90. 'bill_to_name' => $v['customer_firstname'].' '.$v['customer_lastname'],
  91. 'ship_to_name' => $v['customer_firstname'].' '.$v['customer_lastname'],
  92. 'shipping_address' => $address. ',' .$v['customer_address_city']. ',' .$v['customer_address_state']. ',' .$v['customer_address_zip']. ',' .$v['customer_address_country']. ',' .$v['customer_telephone'],
  93. 'billing_address' => $address. ',' .$v['customer_address_city']. ',' .$v['customer_address_state']. ',' .$v['customer_address_zip']. ',' .$v['customer_address_country']. ',' .$v['customer_telephone'],
  94. 'country' => $v['customer_address_country'],
  95. 'region' => $v['customer_address_state'],
  96. 'city' => $v['customer_address_city'],
  97. 'street' => $address,
  98. 'telephone' => preg_replace('/\D/s','',$v['customer_telephone']),
  99. 'postcode' => $v['customer_address_zip'],
  100. 'email' => $v['customer_email'],
  101. 'global_currency_code' => 'USD',
  102. 'base_grand_total' => $v['base_grand_total'],
  103. 'grand_total' => $v['grand_total'],
  104. 'isstatus' => $v['order_status'],
  105. 'isparameter' => $isparameter,
  106. 'sku' => $sku,
  107. 'order_quantity' => $quantity,
  108. 'order_comment' => addslashes($v['order_remark']),
  109. 'paypal_num' => $v['txn_id'],
  110. 'paypal_protection_eligibility' => $v['protection_eligibility'],
  111. 'shippingmethod'=>$v['shipping_method'].' '.$v['shipping_total'],
  112. 'link'=>''
  113. );
  114. }
  115. return $thatDayOrder;
  116. }
  117. if(in_array($name,['alipearlstore','finsahair','baddiebeautyshop','yolissahair','Yolissa']))
  118. {
  119. //limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_max=2025-07-16T00:00:00Z&gateway=klarna
  120. //limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_min=2025-07-16T00:00:00Z&gateway=klarna
  121. // $post['shopify'] = $shopapi.'?limit=10&id=5907832471740';
  122. $post['shopify'] = $shopapi.'?limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&created_at_min='.date('c',time()-3600*24*2);//?status=any所有订单 &limit=200每页多少单 Afterpay (New)
  123. //$post['shopify'] = $shopapi.'?limit=100&fulfillment_status=unshipped&financial_status=paid&status=open&gateway=Afterpay (New)';
  124. $ch = curl_init();
  125. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  126. curl_setopt($ch, CURLOPT_POST, 1);
  127. curl_setopt($ch, CURLOPT_HEADER, 0);
  128. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  129. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  130. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  131. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  132. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  133. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  134. $res = curl_exec($ch);
  135. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行请求参数【".$name."】".json_encode($post));
  136. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".$res);
  137. curl_close($ch);
  138. $res = json_decode($res,true);
  139. $thatDayOrder = array();
  140. if(isset($res['orders']))
  141. {
  142. foreach ($res['orders'] as $v)
  143. {
  144. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行获取信息".json_encode($v));
  145. $productNames = '';
  146. $parameters = array();
  147. $skus = '';
  148. $quantity = '';
  149. $thislink = '';
  150. $price = [];
  151. $row_total = [];
  152. $tax_amount = [];
  153. $discount_amount = [];
  154. $product_ids = [];
  155. foreach($v['line_items'] as $key=>$val)
  156. {
  157. $productNames .= ($key > 0)?','.$val['title']:$val['title'];
  158. $skus .= ($key > 0)?','.$val['sku']:$val['sku'];
  159. $quantity .= floor($val['quantity']).';';
  160. $parameters[] = $val['variant_title'];
  161. // $price[] = $val['price_set']['shop_money']['amount'];
  162. // $row_total[] = $val['price'];
  163. // $tax_amount[] = 0;
  164. // $discount_amount[] =$val['total_discount'];
  165. $product_ids[] = $val['product_id'];
  166. }
  167. if(strpos($v['name'],"#M-") !== false){
  168. continue;
  169. }
  170. if(isset($v['gateway'])){
  171. if(stripos($v['gateway'],'shopify_') !== false)
  172. {
  173. $pay = 'shopifypay';
  174. }
  175. else if(stripos($v['gateway'],'paypal') !== false)
  176. {
  177. $pay = 'paypal_express';
  178. }
  179. else if(stripos($v['gateway'],'gift_card') !== false)
  180. {
  181. $pay = 'gift_card';
  182. }
  183. else if(stripos($v['gateway'],'shop_cash') !== false)
  184. {
  185. $pay = 'shop_cash';
  186. }
  187. else if(stripos($v['gateway'],'Klarna') !== false || stripos($v['gateway'],'klarna') !== false){
  188. if( (stripos($v['gateway'],'Payoneer') !== false) || (stripos($v['gateway'],'payoneer') !== false) ){
  189. $pay ="PayoneerKlarna";
  190. }else{
  191. $pay ="klarna_payments";
  192. }
  193. }
  194. else if(stripos($v['gateway'],'Afterpay') !== false || stripos($v['gateway'],'afterpay') !== false){
  195. $pay ="afterpaypayovertime";
  196. }
  197. else if(stripos($v['gateway'],'Airwallex') !== false || stripos($v['gateway'],'Airwallex') !== false){
  198. $pay ="custompaymentmethod";
  199. }
  200. else
  201. {
  202. $pay = $v['gateway'];
  203. }
  204. }else{
  205. if(count($v['payment_gateway_names'])>1){
  206. $v['payment_gateway_names'] = array_reverse($v['payment_gateway_names']);
  207. }
  208. if(isset($v['payment_gateway_names'])&&isset($v['payment_gateway_names'][0])){
  209. if(stripos($v['payment_gateway_names'][0],'shopify_') !== false)
  210. {
  211. $pay = 'shopifypay';
  212. }
  213. else if(stripos($v['payment_gateway_names'][0],'paypal') !== false)
  214. {
  215. $pay = 'paypal_express';
  216. }
  217. else if(stripos($v['payment_gateway_names'][0],'gift_card') !== false)
  218. {
  219. if(isset($v['payment_gateway_names'][1])){
  220. $pay = $this->checkPay($v['payment_gateway_names'][1]);
  221. }else{
  222. $pay = 'gift_card';
  223. }
  224. }
  225. else if(stripos($v['payment_gateway_names'][0],'shop_cash') !== false)
  226. {
  227. $pay = 'shop_cash';
  228. }
  229. else if(stripos($v['payment_gateway_names'][0],'Klarna') !== false || stripos($v['payment_gateway_names'][0],'klarna') !== false){
  230. //$pay ="klarna_payments";
  231. if( (stripos($v['payment_gateway_names'][0],'Payoneer') !== false) || (stripos($v['payment_gateway_names'][0],'payoneer') !== false) ){
  232. $pay ="PayoneerKlarna";
  233. }else{
  234. $pay ="klarna_payments";
  235. }
  236. }
  237. else if(stripos($v['payment_gateway_names'][0],'Afterpay') !== false ){
  238. $pay ="afterpaypayovertime";
  239. }
  240. else if(stripos($v['payment_gateway_names'][0],'Airwallex') !== false ){
  241. $pay ="custompaymentmethod";
  242. }
  243. else
  244. {
  245. $pay = isset($v['payment_gateway_names'][0])?$v['payment_gateway_names'][0]:"";
  246. }
  247. }else{
  248. $this->logic_ding->sendToDing("订单".$v['name']."没有支付方式【".json_encode($v)."】");
  249. $pay = "";
  250. }
  251. }
  252. $khbz = '';
  253. if(!isset($v['shipping_address']['country_code']))
  254. {
  255. $v['shipping_address'] = $v['billing_address'];
  256. $khbz = '客户自提订单; ';
  257. }
  258. $shipping_address = $v['shipping_address']['address1'] .' '.$v['shipping_address']['address2']. ',' . $v['shipping_address']['city'] . ',' . $v['shipping_address']['province'] . ',' . $v['shipping_address']['zip'] . ',' . $v['shipping_address']['country_code'] . ',' . $v['shipping_address']['phone'];
  259. @$billing_address = $v['billing_address']['address1'].' ' . $v['billing_address']['address2'].',' . $v['billing_address']['city'] . ',' . $v['billing_address']['province'] . ',' . $v['billing_address']['zip'] . ',' . $v['billing_address']['country_code'] . ',' . $v['billing_address']['phone'];
  260. $created_at = explode('T',$v['created_at']);
  261. $created_at_hi = explode('-',$created_at[1]);
  262. $created_at = $created_at[0].' '.$created_at_hi[0];
  263. $paypal = '';
  264. $paypal_protection_eligibility = "";
  265. $d = $this->authorization($shop,$v['id']);
  266. if($d['g'] == 1)
  267. {
  268. $paypal = $d['d'];
  269. $paypal_protection_eligibility = $d['protection_eligibility'];
  270. }
  271. // if($name == 'baddiebeautyshop')
  272. // {
  273. // $wcsku = '';
  274. // $wcquantity = '';
  275. // $ztsku = explode(',',rtrim($skus,','));
  276. // $ztquantity = explode(';',rtrim($quantity,';'));
  277. // foreach ($ztsku as $txk=>$txval)
  278. // {
  279. // $skupx = array(13=>'',22=>'',8=>'',15=>'',18=>'','100'=>'',33=>'',34=>'',35=>'',7=>'','dc'=>'','c'=>'',14=>'',12=>'',25=>'',26=>'',27=>'',10=>'',6=>'',9=>'',999=>'',9999=>'');
  280. // $w = $this->whlabel->get_sku($txval);
  281. // if(isset($w['features']))
  282. // {
  283. // $features = explode('-',trim($w['features'],'-'));
  284. // foreach ($features as $val)
  285. // {
  286. // $t = $this->typeclass->read($val);
  287. // if(isset($t['spare']))
  288. // {
  289. // if(stripos($t['spare'],'|') !== false)
  290. // {
  291. // $t['spare'] = explode('|',trim($t['spare'],'|'));
  292. // $t['spare'] = $t['spare'][0];
  293. // }
  294. // $skupx[$t['classid']] = $t['spare'];
  295. // }
  296. // }
  297. // $skupx = implode("-",$skupx);
  298. // $skupx = str_replace('- ','-',trim($skupx,'-'));
  299. // $skupx = str_replace(array('--------','-------','------','-----','----','---','--'),'-',$skupx);
  300. // $wcsku .= $skupx.',';
  301. // $wcquantity .= $ztquantity[$txk].',';
  302. // }
  303. // else
  304. // {
  305. // continue;
  306. // }
  307. // }
  308. // if($wcsku == '')
  309. // {
  310. // continue;
  311. // }
  312. // else
  313. // {
  314. // $skus = rtrim($wcsku,',');
  315. // $quantity = rtrim($wcquantity,',');
  316. // }
  317. // }
  318. $authorid = '';
  319. $wjauthorid = '';
  320. $sourcecontentid = '';
  321. $link = '';
  322. if($shop['tweak'] !='' && stripos($v['referring_site'],'author_id') !== false)
  323. {
  324. $geturl = explode('&',$v['referring_site']);
  325. foreach ($geturl as $hqid)
  326. {
  327. if(stripos($hqid,'author_id') !== false)
  328. {
  329. $wjauthorid = str_replace('author_id=','',$hqid);
  330. }
  331. if(stripos($hqid,'source_content_id') !== false)
  332. {
  333. $sourcecontentid = str_replace('source_content_id=','',$hqid);
  334. }
  335. }
  336. $link = str_replace($shop['thurl'],$shop['url'],$v['referring_site']);
  337. }
  338. else if($shop['tweak'] !='' && stripos($v['landing_site'],'author_id') !== false)
  339. {
  340. $geturl = explode('&',$v['landing_site']);
  341. foreach ($geturl as $hqid)
  342. {
  343. if(stripos($hqid,'author_id') !== false)
  344. {
  345. $wjauthorid = str_replace('author_id=','',$hqid);
  346. }
  347. if(stripos($hqid,'source_content_id') !== false)
  348. {
  349. $sourcecontentid = str_replace('source_content_id=','',$hqid);
  350. }
  351. }
  352. $link = $shop['url'].$v['landing_site'];
  353. }
  354. if($link != '')
  355. {
  356. $authorid = $this->authorid($link,$shop['tweak']);
  357. }
  358. $shippingmethod = '';
  359. if(isset($v['shipping_lines'][0]['code'])){
  360. $shippingmethod = $v['shipping_lines'][0]['code'].' '.$v['shipping_lines'][0]['discounted_price'];
  361. }
  362. $this->logic_ding->sendToTmp(json_encode($v));
  363. $thatDayOrder[] = array(
  364. 'order_id' => $v['name'],//订单号
  365. 'product_name' => $productNames,//产品标题
  366. 'purchased_on' => strtotime($created_at),//订单时间
  367. 'name' => $v['shipping_address']['name'],//收货人
  368. 'bill_to_name' => $v['billing_address']['name'],//账单人名称
  369. 'ship_to_name' => $v['shipping_address']['name'],//收货人名称
  370. 'shipping_address' => $shipping_address,
  371. 'billing_address' => $billing_address,
  372. 'country' => $v['shipping_address']['country_code'],//收货国家二字码
  373. 'region' => $v['shipping_address']['province_code'],//收货省/州
  374. 'city' => $v['shipping_address']['city'],//收货城市
  375. 'street' => $v['shipping_address']['address1'].' '.$v['shipping_address']['address2'],//收货地址
  376. 'telephone' => $v['shipping_address']['phone'],//收货人手机
  377. 'postcode' => $v['shipping_address']['zip'],//收货人邮政编码
  378. 'email' => $v['customer']['email'],//收货人邮箱
  379. 'global_currency_code' => $v['currency'],//币种
  380. 'base_grand_total' => $v['total_price'],//应收金额
  381. 'grand_total' => $v['total_price_set']['shop_money']['amount'],//币种支付金额
  382. 'isstatus' => 'processing',//$v['order_status'],//默认processing待发货状态
  383. 'isparameter' => implode(';',$parameters),
  384. // 'price'=>implode(",",$price),
  385. // 'row_total'=>implode(",",$row_total),
  386. // 'tax_amount'=>implode(",",$tax_amount),
  387. // 'discount_amount'=>implode(",",$discount_amount),
  388. 'product_ids' => implode(",",$product_ids),
  389. 'sku' => $skus,
  390. 'order_quantity' => $quantity,
  391. 'order_comment' => $khbz.addslashes($v['note']),//客户备注
  392. 'pay' => $pay,
  393. 'paypal_num' => $paypal,
  394. 'insurance' => 0,
  395. 'paypal_protection_eligibility' => $paypal_protection_eligibility,
  396. 'shippingmethod'=>$shippingmethod,
  397. 'link'=>$link,//产品链接
  398. 'shopify'=>$v['id'],
  399. 'authorid'=>$authorid,
  400. 'wjauthorid'=>$wjauthorid,
  401. 'sourcecontentid'=>$sourcecontentid
  402. );
  403. }
  404. return array_reverse($thatDayOrder);
  405. }
  406. }
  407. else if($name == '123')
  408. {
  409. if($shop['apitoken_time'] > time())
  410. {
  411. $token = $shop['apitoken'];
  412. }
  413. else
  414. {
  415. $res = $this->shop->hq_token($shop);
  416. $token = $res;
  417. }
  418. $data = '?';
  419. //$data .= '&searchCriteria[filterGroups][0][filters][0][conditionType]=ConditionType';//字段类型
  420. $data .= 'searchCriteria[sortOrders][0][field]=created_at';
  421. $data .= '&searchCriteria[sortOrders][0][direction]=DESC';
  422. $data .= '&searchCriteria[pageSize]=50';
  423. $data .= '&searchCriteria[currentPage]=1';
  424. $data .= '&searchCriteria[filterGroups][0][filters][0][field]=status';//字段名称
  425. $data .= '&searchCriteria[filterGroups][0][filters][0][value]=processing';//字段内容
  426. $url = 'http://pc.hnwmzp.cn/rest/V1/orders'.$data;//订单
  427. $res = $this->su_curl('',$url,$header=array("Authorization: Bearer ".$token,"Content-Type: application/json"),$date_type='json',$timeout=300,$httptype="GET",$userpwd='');
  428. $res = json_decode($res,true);
  429. foreach ($res['items'] as $read)
  430. {
  431. $productNames = '';//产品名称
  432. $sku = '';
  433. $parameters = '';
  434. $quantity = '';
  435. $orderid = '';
  436. $link = '';
  437. foreach ($read['items'] as $list)
  438. {
  439. $productNames .= $list['name'].',';
  440. $sku .= $list['sku'].',';
  441. $link .= $list['extension_attributes']['product_url'].',';
  442. if(isset($list['extension_attributes']['select_options']))
  443. {
  444. foreach ($list['extension_attributes']['select_options'] as $s)
  445. {
  446. $p = json_decode($s,true);
  447. $parameters .= $p['label'].':'.$p['value'].'---';
  448. }
  449. }
  450. $parameters = trim($parameters,'---').';';
  451. $quantity .= $list['qty_ordered'].';';
  452. $orderid = $list['order_id'];
  453. }
  454. $sku = str_replace(array('<','>'),array('&lt;','&gt;'),$sku);
  455. $bill_street = '';//街道地址
  456. foreach ($read['billing_address']['street'] as $s)
  457. {
  458. $bill_street .= $s.' ';
  459. }
  460. $ship_street = '';//街道地址
  461. foreach ($read['billing_address']['street'] as $s)
  462. {
  463. $ship_street .= $s.' ';
  464. }
  465. $ly = isset($read['extension_attributes']['osc_order_comment'])?addslashes($read['extension_attributes']['osc_order_comment']):'';//留言
  466. $thatDayOrder[] = array
  467. (
  468. 'orderid' => $orderid,
  469. 'order_id' => $read['increment_id'],
  470. 'insurance' => $read['extension_attributes']['amextrafee_base_fee_amount'],//运费险
  471. 'product_name' => trim($productNames,','),
  472. 'purchased_on' => $read['created_at'],
  473. 'name' => (isset($read['customer_firstname'])?$read['customer_firstname']:'').' '.(isset($read['customer_lastname'])?$read['customer_lastname']:''),
  474. 'bill_to_name' => $read['billing_address']['firstname'].' '.$read['billing_address']['lastname'],
  475. 'ship_to_name' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['firstname'].' '.$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['lastname'],
  476. 'billing_address' => trim($bill_street,' '). ',' .$read['billing_address']['city']. ',' .(isset($read['billing_address']['region'])?$read['billing_address']['region']. ',':'') .$read['billing_address']['postcode']. ',' .$read['billing_address']['country_id']. ',' .$read['billing_address']['telephone'],
  477. 'shipping_address' => trim($ship_street,' '). ',' . $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['city']. ',' .(isset($read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region'])?$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region'].',':'').$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['postcode']. ',' .$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['country_id']. ',' .$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['telephone'],
  478. 'country' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['country_id'],
  479. 'region' => isset($read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region'])?$read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['region']:'',
  480. 'city' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['city'],
  481. 'street' => $ship_street,
  482. 'telephone' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['telephone'],
  483. 'postcode' => $read['extension_attributes']['shipping_assignments']['0']['shipping']['address']['postcode'],
  484. 'email' =>$read['billing_address']['email'],
  485. 'global_currency_code' => $read['global_currency_code'],
  486. 'base_grand_total' => $read['base_grand_total'],
  487. 'grand_total' => $read['order_currency_code'].$read['grand_total'],
  488. 'isstatus' => $read['status'],
  489. 'isparameter' => trim($parameters,';'),
  490. 'sku' => trim($sku,','),
  491. 'order_quantity' => trim($quantity,';'),
  492. 'order_comment' => $ly,
  493. 'paypal_num' => isset($read['payment']['last_trans_id'])?$read['payment']['last_trans_id']:'',
  494. 'pay' => $read['payment']['method'],
  495. 'paypal_protection_eligibility' => isset($read['payment']['additional_information']['9'])?$read['payment']['additional_information']['9']:'',
  496. 'shippingmethod'=> ($read['base_shipping_amount'] > 0 || $read['tax_amount'] > 0)?$read['shipping_description'].' '.$read['base_shipping_amount'].' Tax:'.$read['tax_amount'].';':$read['shipping_description'].' '.$read['base_shipping_amount'].' Tax:'.$read['tax_amount'],
  497. 'link'=>trim($link,','),
  498. 'author_id' => '',
  499. 'source_content_id' => '',
  500. );
  501. }
  502. return $thatDayOrder;
  503. }
  504. else
  505. {
  506. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行mengnnto【".$name."】");
  507. $post = array();
  508. $post['synchronization'] = 1;
  509. $post['name'] = $name;
  510. $post['from'] = $fromTime;
  511. $post['to'] = $toTime;
  512. $ch = curl_init();
  513. curl_setopt($ch,CURLOPT_URL,$shopapi);
  514. curl_setopt($ch, CURLOPT_POST, 1);
  515. curl_setopt($ch, CURLOPT_HEADER, 0);
  516. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  517. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  518. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  519. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  520. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  521. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  522. $res = curl_exec($ch);
  523. //$this->logic_ding->sendToDing("测试获取magento订单".$res);
  524. curl_close($ch);
  525. if($res)
  526. {
  527. $res = json_decode($res,true);
  528. $x = array();
  529. if($res)
  530. {
  531. foreach ($res as $v)
  532. {
  533. //$this->logic_ding->sendToDing("获取magento订单".json_encode($v,JSON_UNESCAPED_UNICODE));
  534. if(!isset($v['order_id']))
  535. {
  536. continue;
  537. }
  538. $source = '';
  539. $sc = substr($v['order_id'],0,3);
  540. if($sc == '600')
  541. {
  542. $source = $shop['thurl']; //手机订单
  543. }
  544. else
  545. {
  546. $source = $shop['url'];//PC订单
  547. }
  548. if($v['wjauthorid'] != '' && $v['sourcecontentid'] != '' && $source != '' && $shop['tweak'] != '')
  549. {
  550. $authorid = $this->authorid($source.'?author_id='.$v['wjauthorid'].'&source_content_id='.$v['sourcecontentid'],$shop['tweak']);
  551. if($authorid)
  552. {
  553. $v['authorid'] = $authorid;
  554. }
  555. }
  556. $x[] = $v;
  557. }
  558. }
  559. return $x;
  560. }
  561. }
  562. }
  563. public function checkPay($gateway){
  564. if(stripos($gateway,'shopify_') !== false)
  565. {
  566. $pay = 'shopifypay';
  567. }
  568. else if(stripos($gateway,'paypal') !== false)
  569. {
  570. $pay = 'paypal_express';
  571. }
  572. else if(stripos($gateway,'shop_cash') !== false)
  573. {
  574. $pay = 'shop_cash';
  575. }
  576. else if(stripos($gateway,'Klarna') !== false || stripos($gateway,'klarna') !== false){
  577. $pay ="klarna_payments";
  578. }
  579. else if(stripos($gateway,'Afterpay') !== false || stripos($gateway,'afterpay') !== false){
  580. $pay ="afterpaypayovertime";
  581. }
  582. else if(stripos($gateway,'Airwallex') !== false || stripos($gateway,'Airwallex') !== false){
  583. $pay ="custompaymentmethod";
  584. }
  585. else
  586. {
  587. $pay = $gateway;
  588. }
  589. return $pay;
  590. }
  591. public function authorid($link,$tweak)
  592. {
  593. $ch = curl_init();
  594. $post = array();
  595. $ai['link'] = $link;
  596. $ai['tweak'] = $tweak;
  597. $ch = curl_init();
  598. curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:3001/dec');
  599. curl_setopt($ch, CURLOPT_POST, 1);
  600. curl_setopt($ch, CURLOPT_HEADER, 0);
  601. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  602. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  603. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  604. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($ai));
  605. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  606. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
  607. $author_id = curl_exec($ch);
  608. curl_close($ch);
  609. $author_id = json_decode($author_id,true);
  610. if(isset($author_id['plainText']))
  611. {
  612. return $author_id['plainText'];
  613. }
  614. }
  615. public function authorization($shop,$shopifyid)//shopify获取交易号
  616. {
  617. if($shop['brandname'] == 'yolissahair'){
  618. $shopname = 'xxu7p0-3q';
  619. }elseif ($shop['brandname'] == 'Yolissa') {
  620. $shopname = 'xxu7p0-3q';
  621. }else{
  622. $shopname = $shop['brandname'];
  623. }
  624. $post = [];
  625. $post['shopify_pay'] = [
  626. "url"=> 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json',
  627. "token"=>"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",
  628. ];
  629. $ch = curl_init();
  630. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  631. curl_setopt($ch, CURLOPT_POST, 1);
  632. curl_setopt($ch, CURLOPT_HEADER, 0);
  633. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  634. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  635. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  636. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  637. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  638. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  639. $res = curl_exec($ch);
  640. curl_close($ch);
  641. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行shopfiy支付信息【".$shopifyid."】".$res."}{".json_encode($post));
  642. // $shopifyid = $shopifyid;
  643. // $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
  644. // $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  645. // $ch = curl_init();
  646. // curl_setopt($ch, CURLOPT_URL, $url);
  647. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  648. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  649. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  650. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  651. // $res = curl_exec($ch);
  652. // $headerA = curl_getinfo($ch)
  653. $a = json_decode($res,true);
  654. if(!isset($a['transactions']))
  655. {
  656. return array('g'=>0);exit;
  657. }
  658. $tmp_pay_list = [];
  659. foreach ($a['transactions'] as $v){
  660. if(stripos($v['gateway'],'gift_card') === false){
  661. $tmp_pay_list[] = $v;
  662. }
  663. }
  664. $a['transactions'] = $tmp_pay_list;
  665. if(count($a['transactions']) < 2){
  666. //
  667. if($a['transactions'][0]['gateway'] == 'Klarna' ){
  668. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  669. }elseif(stripos($a['transactions'][0]['gateway'],'Payoneer Checkout Klarna') !== false){
  670. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  671. }elseif(stripos($a['transactions'][0]['gateway'],'Afterpay') !== false){
  672. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  673. }elseif(stripos($a['transactions'][0]['gateway'],'Airwallex') !== false){
  674. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  675. }else{
  676. $a['transactions'] = array_reverse($a['transactions']);
  677. if(isset($a['transactions'][0]['authorization']))
  678. {
  679. $protection_eligibility = "";
  680. if(isset($a['transactions'][0]['receipt'])){
  681. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  682. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  683. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  684. if(!empty($a['transactions'][0]['receipt']['purchase_units'])){
  685. if(!empty($a['transactions'][0]['receipt']['purchase_units'][0]['payments'])){
  686. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection'])){
  687. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'])){
  688. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'];
  689. }
  690. }
  691. }
  692. }
  693. }
  694. }
  695. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  696. }
  697. else
  698. {
  699. return array('g'=>0);
  700. }
  701. }
  702. }else{
  703. $end_info = end($a['transactions']);
  704. if($end_info['gateway'] == 'Klarna' ){
  705. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  706. }elseif(stripos($end_info['gateway'],'Payoneer Checkout Klarna') !== false){
  707. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  708. }elseif(stripos($end_info['gateway'],'Afterpay') !== false){
  709. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  710. }elseif(stripos($end_info['gateway'],'Airwallex') !== false){
  711. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  712. }
  713. else{
  714. $a['transactions'] = array_reverse($a['transactions']);
  715. if(isset($a['transactions'][0]['authorization']))
  716. {
  717. $protection_eligibility = "";
  718. if(isset($a['transactions'][0]['receipt'])){
  719. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  720. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  721. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  722. if(!empty($a['transactions'][0]['receipt']['purchase_units'])){
  723. if(!empty($a['transactions'][0]['receipt']['purchase_units'][0]['payments'])){
  724. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection'])){
  725. if(isset($a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'])){
  726. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units'][0]['payments']['captures'][0]['seller_protection']['status'];
  727. }
  728. }
  729. }
  730. }
  731. }
  732. }
  733. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  734. }
  735. else
  736. {
  737. return array('g'=>0);
  738. }
  739. }
  740. }
  741. }
  742. public function su_curl($data,$url,$header=array(),$date_type='json',$timeout=300,$httptype="POST",$userpwd='')
  743. {
  744. if ($date_type == 'http_build_query')
  745. {
  746. $data = http_build_query($data);
  747. }
  748. else if ($date_type == 'json')
  749. {
  750. $data = json_encode($data);
  751. }
  752. $ch = curl_init();
  753. curl_setopt($ch, CURLOPT_URL, $url);
  754. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  755. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  756. curl_setopt($ch, CURLOPT_HEADER, false);
  757. switch ($httptype)
  758. {
  759. case "GET":
  760. curl_setopt($ch, CURLOPT_HTTPGET, true);
  761. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  762. break;
  763. case "POST":
  764. curl_setopt($ch, CURLOPT_POST, true);
  765. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  766. break;
  767. case "PUT":
  768. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  769. break;
  770. case "DELETE":
  771. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  772. break;
  773. }
  774. $isSecure = strpos($url, "https://");
  775. if ($isSecure === 0)
  776. {
  777. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  778. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  779. }
  780. if(!empty($header))
  781. {
  782. curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
  783. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  784. }
  785. if(!empty($userpwd))
  786. {
  787. curl_setopt($ch,CURLOPT_USERPWD,$userpwd);
  788. }
  789. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  790. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  791. $result = curl_exec($ch);
  792. curl_close($ch);
  793. return $result;
  794. }
  795. public function get_hq2($name,$from,$to)
  796. {
  797. $jqtime = ($name=='SuperNova')?9*3600:3600;
  798. $fromTime = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  799. $toTime = time();
  800. $ch = curl_init();
  801. $url = 'http://edm.alipearl.net/soapapi.php';
  802. curl_setopt($ch,CURLOPT_URL,$url);
  803. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  804. curl_setopt($ch,CURLOPT_HEADER,0);
  805. curl_setopt($ch,CURLOPT_POST, 1);
  806. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  807. //设置post数据
  808. $post = array();
  809. $post['synchronization'] = 1;
  810. $post['name'] = $name;
  811. $post['from'] = $from;
  812. $post['to'] = $to;
  813. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  814. $res = curl_exec($ch);
  815. curl_close($ch);
  816. $res = json_decode($res,true);
  817. if(isset($res))
  818. {
  819. return $res;
  820. }
  821. }
  822. public function get_gx($ddh,$ydh,$xg,$shop,$ex,$msg,$shopifyid)
  823. {
  824. $res = '';
  825. if(in_array($shop['shopname'],['alipearlstore','finsahair','baddiebeautyshop','yolissahair']))
  826. {
  827. if($shop['shopname'] == 'yolissahair'){
  828. $shopname = 'xxu7p0-3q';
  829. }else{
  830. $shopname = $shop['shopname'];
  831. }
  832. $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/fulfillment_orders.json';
  833. $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  834. // $ch = curl_init();
  835. // curl_setopt($ch, CURLOPT_URL, $url);
  836. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  837. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  838. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  839. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  840. // $res = curl_exec($ch);
  841. // $headerA = curl_getinfo($ch);
  842. $post = [];
  843. $post['shopify_yd_one'] = 1;
  844. $post['url'] = $url;
  845. $post['token'] = $shop['token'];
  846. $ch = curl_init();
  847. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  848. curl_setopt($ch, CURLOPT_POST, 1);
  849. curl_setopt($ch, CURLOPT_HEADER, 0);
  850. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  851. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  852. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  853. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  854. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  855. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  856. $res = curl_exec($ch);
  857. curl_close($ch);
  858. $this->logic_ding->sendToDing("shopfiy的运单同步第一步".json_encode($post)."|".$res);
  859. //如果为空 啥都不用执行 直接返回 期待下次执行
  860. if(empty($res)){
  861. return ;
  862. }
  863. $a = json_decode($res,true);
  864. $od = array();
  865. foreach ($a['fulfillment_orders'] as $v)
  866. {
  867. $od[] = array('fulfillment_order_id'=>$v['id']);
  868. }
  869. $data = array('fulfillment'=>array('notify_customer'=>false,'tracking_info'=>array('number'=>$ydh,'company'=>$ex['title']),
  870. 'line_items_by_fulfillment_order'=>$od));
  871. // $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json';
  872. // $header[] = "Content-Type: application/json";
  873. // $header[] = "X-Shopify-Access-Token: ".$shop['token'];
  874. // $ch = curl_init();
  875. // curl_setopt($ch, CURLOPT_URL, $url);
  876. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  877. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  878. // curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  879. // curl_setopt($ch, CURLOPT_POST, 1);
  880. // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  881. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  882. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  883. // $res = curl_exec($ch);
  884. // $header = curl_getinfo($ch);
  885. $post = [
  886. 'shopify_yd_two'=>1,
  887. 'token'=>$shop['token'],
  888. 'url'=>'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json',
  889. 'data'=>$data,
  890. ];
  891. $ch = curl_init();
  892. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  893. curl_setopt($ch, CURLOPT_POST, 1);
  894. curl_setopt($ch, CURLOPT_HEADER, 0);
  895. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  896. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  897. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  898. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  899. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  900. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  901. $res = curl_exec($ch);
  902. curl_close($ch);
  903. $this->logic_ding->sendToDing("shopfiy的运单同步第二步".json_encode($post)."|".$res);
  904. $b = json_decode($res,true);
  905. $this->logic_ding->sendToDing("erp同步独立站的信息_".$ydh."_".json_encode($b,JSON_UNESCAPED_UNICODE));
  906. if(isset($b['fulfillment']['id']))
  907. {
  908. return array('res'=>1,'state'=>216,'cw'=>'');
  909. }
  910. else
  911. {
  912. return array('res'=>2,'state'=>$xg['state'],'cw'=>$res);
  913. }
  914. }
  915. else
  916. {
  917. $post = array();
  918. $post['update'] = 1;
  919. $post['ddh'] = $ddh;
  920. $post['ydh'] = $ydh;
  921. $post['xg'] = $xg;
  922. $post['shop'] = $shop;
  923. $post['ex'] = $ex;
  924. $post['msg'] = isset($msg)?$msg:2;
  925. $this->logic_ding->sendToDing("erp同步独立站的信息tijiao1".json_encode($post,JSON_UNESCAPED_UNICODE));
  926. $ch = curl_init();
  927. $url = 'http://edm.alipearl.net/soapapi.php';
  928. curl_setopt($ch,CURLOPT_URL,$url);
  929. curl_setopt($ch, CURLOPT_POST, 1);
  930. curl_setopt($ch, CURLOPT_HEADER, 0);
  931. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  932. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  933. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  934. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  935. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  936. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
  937. $res = curl_exec($ch);
  938. curl_close($ch);
  939. $res = json_decode($res,true);
  940. $this->logic_ding->sendToDing("erp同步独立站的信息1_".$ydh."_".json_encode($res,JSON_UNESCAPED_UNICODE));
  941. if($res)
  942. {
  943. if($res == 1)
  944. {
  945. return array('res'=>1,'state'=>216,'cs'=>$res);
  946. }
  947. else
  948. {
  949. return array('res'=>2,'state'=>$xg['state'],'cs'=>$res);
  950. }
  951. }
  952. else
  953. {
  954. return array('res'=>2,'state'=>$xg['state'],'cs'=>'a');
  955. }
  956. }
  957. }
  958. public function get_data($shop,$v,$gethl,$time,$country,$is,$num,$lb,$tc,$dtc,$money,$int,$dtctitle,$pay,$zjsku)
  959. {
  960. $hl = 0;
  961. foreach ($v as $kk=>$vv)
  962. {
  963. if(!$vv)
  964. {
  965. $v[$kk] = "";
  966. }
  967. else
  968. {
  969. $v[$kk] = str_replace("'","’",$vv);
  970. }
  971. }
  972. if(strcasecmp($v['isstatus'],'pending_Payment') == 0 || strcasecmp($v['isstatus'],'pending') == 0 || strcasecmp($v['isstatus'],'Pending_PayPal') == 0 || strcasecmp($v['isstatus'],'payment_pending') == 0)
  973. {
  974. $post['state'] = 203;//订单状态,等待买家付款
  975. }
  976. else if(strcasecmp($v['isstatus'],'Payment_Review') == 0 || strcasecmp($v['isstatus'],'payment_processing') == 0)
  977. {
  978. $post['state'] = 204;//订单状态,资金未到帐
  979. }
  980. else if(strcasecmp($v['isstatus'],'suspected_Fraud') == 0 || strcasecmp($v['isstatus'],' payment_suspected_fraud') == 0)
  981. {
  982. $post['state'] = 205;//订单状态,风控保持
  983. }
  984. else if(strcasecmp($v['isstatus'],'PayPal_Canceled_Reversal') == 0 || strcasecmp($v['isstatus'],'payment_canceled') == 0 || strcasecmp($v['isstatus'],'refunded') == 0)
  985. {
  986. $post['state'] = 206;//订单状态,买家申请取消
  987. }
  988. else if(strcasecmp($v['isstatus'],'processing') == 0 || strcasecmp($v['isstatus'],'payment_confirmed') == 0)
  989. {
  990. $post['state'] = 207;//订单状态,等待发货
  991. }
  992. else if(strcasecmp($v['isstatus'],'on_Hold') == 0 || strcasecmp($v['isstatus'],'holded') == 0)
  993. {
  994. $post['state'] = 212;//订单状态,冻结中的订单
  995. }
  996. else if(strcasecmp($v['isstatus'],'complete') == 0 || strcasecmp($v['isstatus'],'completed') == 0)
  997. {
  998. $post['state'] = 216;//订单状态,已完成
  999. }
  1000. else if(strcasecmp($v['isstatus'],'closed') == 0 || strcasecmp($v['isstatus'],'canceled') == 0)
  1001. {
  1002. $post['state'] = 217;//订单状态,已关闭
  1003. }
  1004. else if(strcasecmp($v['isstatus'],'paypal_reversed') == 0)
  1005. {
  1006. $post['state'] = 215;//争议
  1007. }
  1008. else
  1009. {
  1010. $post['state'] = 283;//未获取到状态
  1011. }
  1012. if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
  1013. {
  1014. $v['sku'] = rtrim($v['sku'],',').','.$zjsku[$shop['id']];
  1015. }
  1016. $post['shop'] = $shop['id'];//店铺ID
  1017. $post['user'] = $shop['shopuser'];//店铺负责人
  1018. $post['orderid'] = isset($v['orderid'])?$v['orderid']:0;//M2ID
  1019. $post['product'] = $v['product_name'];//产品名称
  1020. $post['link'] = $v['link'];//产品链接
  1021. $post['issku'] = $v['sku'];
  1022. $post['quantity'] = rtrim($v['order_quantity'],';');
  1023. $post['clientremarks'] = $v['order_comment'];//客户备注
  1024. $post['paypal'] = $v['paypal_num'];//交易号
  1025. $post['guarantee'] = $v['paypal_protection_eligibility'];//卖家保障
  1026. $post['parameter'] = $v['isparameter'];//属性
  1027. $post['shippingmethod'] = $v['shippingmethod'];//用户选择快递方式及运费金额
  1028. $sc = substr($v['order_id'],0,3);
  1029. if($sc == '600')
  1030. {
  1031. $source = 3; //手机订单
  1032. }
  1033. else
  1034. {
  1035. $source = 2;//PC订单
  1036. }
  1037. $post['source'] = $source;//订单类型
  1038. $post['type'] = 1;//发货仓库
  1039. $post['capital'] = 3;//资金支付状况,全部付款
  1040. $post['number'] = $shop['shortname'].'-'.date('ymd',$time).'-'.(substr(strval($num+1+1000),1,3));//编号
  1041. if($shop['program'] == 'Shopify'){
  1042. $post['orderinfo'] = $v['order_id'];//订单号
  1043. }else{
  1044. $post['orderinfo'] = $shop['id'].$v['order_id'];//订单号
  1045. }
  1046. $post['insurance'] = isset($v['insurance'])?$v['insurance']:0;//运输保险费用
  1047. $post['baddress'] = $v['billing_address'];
  1048. $post['saddress'] = $v['shipping_address'];
  1049. $post['country'] = $country;//此国家的ID
  1050. $post['al'] = $lb;//联邦名称
  1051. $post['bname'] = preg_replace('/( | | |\s)/',' ',$v['bill_to_name']);//名称
  1052. $post['sname'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//名称
  1053. $post['client'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//公司名称
  1054. $post['name'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//收件人名称
  1055. $post['phone'] = preg_replace('/\D/s','',$v['telephone']);//收件人电话
  1056. $post['email'] = preg_replace('/( | | |\s)+/','',$v['email']);//客户邮箱
  1057. $post['zipcode'] = $v['postcode'];//收件人邮编
  1058. $post['province'] = $v['region'];//收件人省份
  1059. $post['city'] = $v['city'];//收件人城市
  1060. $post['address'] = $v['street'];//收件人地址
  1061. $post['shouldmoney'] = $v['base_grand_total'];//应收金额
  1062. $post['skje'] = $post['shouldmoney'];//收款金额
  1063. $post['ismoney'] = $v['grand_total'];//支付币种金额
  1064. $post['authorid'] = isset($v['authorid'])?$v['authorid']:'';
  1065. $post['wjauthorid'] = isset($v['wjauthorid'])?$v['wjauthorid']:'';
  1066. $post['sourcecontentid'] = isset($v['sourcecontentid'])?$v['sourcecontentid']:'';
  1067. $yga = $post['shouldmoney'];//金额
  1068. $post['budget'] = 0;
  1069. if(isset($v['pay']) && isset($pay[$v['pay']]) && $yga > 0)
  1070. {
  1071. $post['pay'] = $pay[$v['pay']]['id'];
  1072. $ygc = $pay[$v['pay']]['estimaterate'];//预估到账公式
  1073. $post['estimaterate'] = $pay[$v['pay']]['estimaterate'];
  1074. $ifbudget = eval("return $yga*1.$ygc;");
  1075. if($ifbudget > 0)
  1076. {
  1077. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  1078. }
  1079. }
  1080. else if($yga > 0)
  1081. {
  1082. $post['pay'] = 0;
  1083. $ygb = $shop['estimaterate'];//店铺默认到账公式
  1084. $post['estimaterate'] = $shop['estimaterate'];
  1085. $ifbudget = eval("return $yga*1.$ygb;");
  1086. if($ifbudget > 0)
  1087. {
  1088. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  1089. }
  1090. }
  1091. $post['buytime'] = $time;//格式化付款时间
  1092. $post['dtime'] = $time;//订单时间
  1093. $post['gtime'] = date('Ymd',$time);//格式化订单时间
  1094. $post['currencytitle'] = $v['global_currency_code'];//结算币种名称
  1095. $post['currency'] = $tc;//钱币ID
  1096. $post['time'] = time();//同步时间
  1097. $post['shopify'] = (isset($v['shopify']))?$v['shopify']:0;//同步时间
  1098. /**
  1099. foreach ($gethl as $v)
  1100. {
  1101. $code = str_replace(" ","",$v['code']);
  1102. if($code == $post['currencytitle'])//查找对应汇率值
  1103. {
  1104. $hl = $v['refePrice']/100;
  1105. }
  1106. }
  1107. **/
  1108. $post['hl'] = '6.4';//汇率
  1109. /**
  1110. $pxsku = array();$pxquantity = array();//sku重新排序 头套波波提前
  1111. $newssku = explode(',',trim($post['issku'],','));
  1112. $newquantity = explode(';',trim($post['quantity'],';'));
  1113. foreach ($newssku as $k=>$v)
  1114. {
  1115. if(stripos($v,'wig') !== false || stripos($v,'Bob') !== false)
  1116. {
  1117. $pxsku[$k] = $v;
  1118. $pxquantity[$k] = $newquantity[$k];
  1119. }
  1120. else
  1121. {
  1122. $pxsku[999+$k] = $v;
  1123. $pxquantity[999+$k] = $newquantity[$k];
  1124. }
  1125. }
  1126. ksort($pxsku);
  1127. ksort($pxquantity);
  1128. $post['issku'] = implode(",",$pxsku);
  1129. $post['quantity'] = implode(";",$pxquantity);
  1130. **/
  1131. // if(stripos($post['issku'],'+') !== false){
  1132. // $this->logic_ding->sendToDing("测试获取3+1订单未转化数据".json_encode($v));
  1133. // $this->logic_ding->sendToDing("测试获取3+1订单已转化数据".json_encode($post));
  1134. // }
  1135. //$this->logic_ding->sendToDing("获取独立站的订单".json_encode($v));
  1136. $matching = $this->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle,$shop,[
  1137. 'row_total'=>isset($v['row_total'])?$v['row_total']:"0",
  1138. 'price'=>isset($v['price'])?$v['price']:"0",
  1139. ]);
  1140. $price_tmp = isset($v['price'])?$v['price']:"0";
  1141. $row_total_tmp = isset($v['row_total'])?$v['row_total']:"0";
  1142. $tax_amount_tmp = isset($v['tax_amount'])?$v['tax_amount']:"0";
  1143. $discount_amount_tmp = isset($v['discount_amount'])?$v['discount_amount']:"0";
  1144. $product_ids_tmp = isset($v['product_ids'])?$v['product_ids']:"";
  1145. $extra_price = $this->tranExtraPrice($post['issku'],$post['quantity'],$price_tmp,$row_total_tmp,$tax_amount_tmp,$discount_amount_tmp,$product_ids_tmp);
  1146. $post['extra_price'] = json_encode($extra_price,JSON_UNESCAPED_UNICODE);
  1147. $post['shipremarks'] = $matching['title'];
  1148. $post['cost'] = $matching['cost'];
  1149. $post['purchase'] = $matching['purchase'];
  1150. $post['fpdata'] = $matching['product'];
  1151. $post['whlabel'] = $matching['whlabel'];
  1152. $post['slpx'] = $matching['wcslpx'];
  1153. return $post;
  1154. }
  1155. public function tranExtraPrice($issku,$org_qty,$org_price,$org_row_total,$org_tax_amount,$org_discount_amount,$product_ids_tmp){
  1156. $sku = explode(',',$issku);
  1157. $tmp_qty = explode(';',$org_qty);
  1158. $tmp_price = explode(",",$org_price);
  1159. $tmp_row_total = explode(",",$org_row_total);
  1160. $tmp_tax_amount = explode(",",$org_tax_amount);
  1161. $tmp_discount_amount = explode(",",$org_discount_amount);
  1162. $product_ids = explode(",",$product_ids_tmp);
  1163. $extra_price = [];
  1164. foreach ($sku as $k=>$value)
  1165. {
  1166. $qty = isset($tmp_qty[$k])?$tmp_qty[$k]:0;
  1167. $price = isset($tmp_price[$k])?$tmp_price[$k]:0;
  1168. $row_total = isset($tmp_row_total[$k])?$tmp_row_total[$k]:0;
  1169. $tax_amount = isset($tmp_tax_amount[$k])?$tmp_tax_amount[$k]:0;
  1170. $discount_amount = isset($tmp_discount_amount[$k])?$tmp_discount_amount[$k]:0;
  1171. $product_id = empty($product_ids[$k])?"":$product_ids[$k];
  1172. $extra_price[$k] = [
  1173. 'qty'=>$qty,
  1174. 'price'=>sprintf("%.2f",$price),
  1175. 'row_total'=> sprintf("%.2f",($row_total*1 - $discount_amount*1 + $tax_amount*1)) ,
  1176. 'sub_total'=>$price*$qty,
  1177. 'tax_amount'=>$tax_amount,
  1178. 'discount_amount'=>$discount_amount,
  1179. 'product_id'=>$product_id,
  1180. ];
  1181. }
  1182. return $extra_price;
  1183. }
  1184. /**
  1185. *
  1186. *
  1187. *
  1188. 匹配仓库品名、产品、成本
  1189. *
  1190. *
  1191. *
  1192. **/
  1193. public function matching($quantity,$issku,$dtc,$money,$int,$dtctitle,$shop=[],$extra = [])
  1194. {
  1195. $sl = explode(';',$quantity);
  1196. $x=0;$product = '';//product 每单多产品链接组合
  1197. $purchase = 0;$cost = 0;//每单所有产品总成本价格;
  1198. $whlabel = '|';//库存产品码
  1199. $cscs = array();$cscs = $issku;
  1200. $nr = '';$cs = array();
  1201. $t = array('/\-\-/','/\+/','/\#Color/','/\#Long/','/-[1-4]-/','/(\w+)~(\w+)-/');
  1202. $h = array('-','-','','','-','');
  1203. $issku = str_replace(array('(',')'),array('(',')'),$issku);
  1204. $issku = str_replace(array(' <','> '),array('<','>'),$issku);
  1205. $issku = strtolower($issku);
  1206. $varsku = preg_replace($t,$h,$issku);////转大写、匹配更改和删除
  1207. $varsku = strtolower($varsku);//转小写
  1208. $sku = explode(',',$varsku);//多产品分割为多数组
  1209. //根据要求添加了 row_total和商品单价
  1210. $row_total = [];
  1211. $price = [];
  1212. if(isset($extra['row_total'])){
  1213. $row_total_tmp = explode(',',$extra['row_total']);
  1214. foreach($sku as $k=>$v){
  1215. $row_total[$k] = isset($row_total_tmp[$k])?$row_total_tmp[$k]:0;
  1216. }
  1217. }else{
  1218. foreach($sku as $k=>$v){
  1219. $row_total[$k] = 0;
  1220. }
  1221. }
  1222. if(isset($extra['price'])){
  1223. $price_tmp = explode(',',$extra['price']);
  1224. foreach($sku as $k=>$v){
  1225. $price[$k] = isset($price_tmp[$k])?$price_tmp[$k]:0;
  1226. }
  1227. }else{
  1228. foreach($sku as $k=>$v){
  1229. $price[$k] = 0;
  1230. }
  1231. }
  1232. $pd = explode(',',$issku);
  1233. $slpx = array();
  1234. $tqjcskua = array();//先检测是否只匹配品名
  1235. $tqjcskub = array();
  1236. //添加price 和 row_total
  1237. $tqjcpricea = [];
  1238. $tqjcpriceb = [];
  1239. $tqjcrow_totala = [];
  1240. $tqjcrow_totalb = [];
  1241. $tqjcpircegit = [];
  1242. $tqjcqda = array();
  1243. $tqjcqdb = array();
  1244. $tqjcgit = array();//礼物类放SKU顺序中间
  1245. $tqjcgitpd = array();//礼物类放SKU顺序中间
  1246. foreach ($sku as $k=>$value)
  1247. {
  1248. //查找是否有头套和HD开始
  1249. $cid = array();
  1250. $cf = explode('-',trim($value,'-'));
  1251. $cf = array_filter($cf);
  1252. foreach ($cf as $v)
  1253. {
  1254. if(isset($dtc[$v]['id']) && isset($dtc[$v]['jm']))
  1255. {
  1256. $cid[$dtc[$v]['classid']] = array('id'=>$dtc[$v]['id'],'spare'=>$v,'jm'=>$dtc[$v]['jm']);
  1257. }
  1258. }
  1259. if(isset($cid['44']) && isset($cid['18']))
  1260. {
  1261. if(isset($dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['id']))
  1262. {
  1263. $value = '-'.$value.'-';
  1264. $sku[$k] = '-'.$sku[$k].'-';
  1265. $pd[$k] = '-'.$pd[$k].'-';
  1266. $value = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$value);
  1267. $value = str_replace('-'.$cid['44']['spare'],'-',$value);
  1268. $sku[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$sku[$k]);
  1269. $sku[$k] = str_replace('-'.$cid['44']['spare'],'-',$sku[$k]);
  1270. $pd[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$pd[$k]);
  1271. $pd[$k] = str_replace('-'.$cid['44']['spare'],'-',$pd[$k]);
  1272. $value = strtolower(trim($value,'-'));
  1273. $pd[$k] = strtolower(trim($pd[$k],'-'));
  1274. $sku[$k] = strtolower(trim($sku[$k],'-'));
  1275. }
  1276. else if(stripos($value,'-transparent') !== false || stripos($value,'-tr') === false)
  1277. {
  1278. $value = str_replace(array('-transparent','-tr'),'',$value);
  1279. $sku[$k] = str_replace(array('-transparent','-tr'),'',$sku[$k]);
  1280. $pd[$k] = str_replace(array('-transparent','-tr'),'',$pd[$k]);
  1281. }
  1282. }
  1283. //查找是否有头套和HD结束
  1284. if(isset($dtc[$value]['classid']))
  1285. {
  1286. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  1287. {
  1288. $tqjcskua[$k] = $value;
  1289. $tqjcqda[$k] = $pd[$k];
  1290. $tqjcpricea[$k] = isset($price[$k])?$price[$k]:0;
  1291. $tqjcrow_totala[$k] = isset($row_total[$k])?$row_total[$k]:0;
  1292. continue;
  1293. }
  1294. }
  1295. if(stripos($value,'gift') !== false)
  1296. {
  1297. $tqjcgit[$k] = $value;
  1298. $tqjcpircegit[$k] = 0;
  1299. $tqjcgitpd[$k] = $pd[$k];
  1300. continue;
  1301. }
  1302. $tqjcskub[$k] = $value;
  1303. $tqjcqdb[$k] = $pd[$k];
  1304. $tqjcpriceb[$k] = isset($price[$k])?$price[$k]:0;
  1305. $tqjcrow_totalb[$k] = isset($row_total[$k])?$row_total[$k]:0;
  1306. }
  1307. $sku = $tqjcskub+$tqjcgit+$tqjcskua;
  1308. $price = $tqjcpriceb+$tqjcpircegit+$tqjcpricea;
  1309. $row_total = $tqjcrow_totalb+$tqjcpircegit+$tqjcrow_totala;
  1310. $newsl = array();
  1311. foreach ($sku as $k=>$value)
  1312. {
  1313. if(!isset($sl[$k]))
  1314. {
  1315. $sl[$k] = 1;
  1316. }
  1317. $newsl[] = $sl[$k];
  1318. }
  1319. $sl = array_values($newsl);
  1320. $pd = $tqjcqdb+$tqjcgitpd+$tqjcqda;
  1321. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  1322. $price = array_values($price);
  1323. $row_total = array_values($row_total);
  1324. // $this->logic_ding->sendToDing("测试获取订单数据SKU转化".json_encode($sku));
  1325. // $this->logic_ding->sendToDing("测试获取订单数据price转化".json_encode($price));
  1326. // $this->logic_ding->sendToDing("测试获取订单数据row_total转化".json_encode($row_total));
  1327. $pd = array_values($pd);
  1328. /**
  1329. $tqjcskua = array();//先检测是否只匹配品名
  1330. $tqjcskub = array();
  1331. foreach ($sku as $k=>$value)
  1332. {
  1333. if(isset($dtc[$value]['classid']))
  1334. {
  1335. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  1336. {
  1337. $tqjcskua[$k] = $value;
  1338. continue;
  1339. }
  1340. }
  1341. $tqjcskub[$k] = $value;
  1342. }
  1343. $sku = $tqjcskub+$tqjcskua;
  1344. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  1345. **/
  1346. foreach ($sku as $index=>$value)
  1347. {
  1348. $bmsku = '';
  1349. if(stripos($value,'-<') !== false && stripos($value,'>-') === false)
  1350. {
  1351. $isskufg = explode('-<',$value);
  1352. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1353. }
  1354. if(stripos($value,'-<') !== false && stripos($value,'>-') !== false)
  1355. {
  1356. $isskufg = explode('-<',$value);
  1357. $isskufgh = explode('>-',$isskufg[1]);
  1358. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1359. }
  1360. if(stripos($value,'-<') === false && stripos($value,'>-') !== false)
  1361. {
  1362. $isskufg = explode('>-',$value);
  1363. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1364. }
  1365. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') === false)
  1366. {
  1367. $isskufg = explode('-&lt;',$value);
  1368. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1369. }
  1370. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') !== false)
  1371. {
  1372. $isskufg = explode('-&lt;',$value);
  1373. $isskufgh = explode('&gt;-',$isskufg[1]);
  1374. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1375. }
  1376. if(stripos($value,'-&lt;') === false && stripos($value,'&gt;-') !== false)
  1377. {
  1378. $isskufg = explode('&gt;-',$value);
  1379. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1380. }
  1381. $value = trim($value,' ');$cpson = array();$cplf = array();
  1382. $thisid='';$tha=array();$thb=array();
  1383. $purchasemy=0;$costmy=0;$salespricemy=0;
  1384. $djay = array();//每单单个产品公司销售价格
  1385. $ptitlea='';$ptitleb='';//每单产品名称
  1386. $cpa='';$cpb='';$fc = 0;
  1387. $number = array('dc'=>'','c'=>'');
  1388. $classid = $this->classid->sku();
  1389. $pm = $classid;//品名顺序
  1390. //等级-真人发类型-化纤发编号-颜色-花型-蕾丝头套种类-化纤头套类型-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-化纤其它属性-头套其它属性-头套属性 100为头套额外附加
  1391. $cp = array(16=>126,22=>'',13=>80,14=>'',43=>'',8=>57,15=>'');//产品默认ID内容
  1392. //16->类目、22->真人发类型、13->等级、14->长度、8->颜色、15->曲度(花型)
  1393. $cptt = array(16=>128,13=>80,43=>'',8=>'57',15=>'',18=>'',6=>30,10=>72,9=>'',44=>'',39=>'',50=>'',51=>'');//头套
  1394. $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'',7=>'');//卡子发,7=>33重量
  1395. $cpgi = array(16=>131,34=>'');//礼物
  1396. //$cpac = array(16=>133,35=>'',7=>'');//配件
  1397. //类目 等级 13 配件类型 35 配件其它 45 (头发)颜色 8 曲度 15 单包片数 38 重量 7 重新修订 不过需要根据cp来判断
  1398. $cpac = array(16=>133,35=>'',45=>'',38=>'',7=>'');//配件
  1399. $cphxtt = array(16=>1297,13=>80,14=>'',40=>'',8=>57,15=>'',41=>'',42=>'');
  1400. $cphxhair = array(16=>1702,13=>80,14=>'',47=>'',46=>'',8=>57,15=>'',38=>'',48=>'');
  1401. if((preg_match('/\d\*\df/',$pd[$x]) || preg_match('/\df/',$pd[$x]) || stripos($pd[$x],'+F') !== false || stripos($pd[$x],'Frontal') !== false) && stripos($pd[$x],'wig') === false && stripos($pd[$x],'Bob') === false)
  1402. {
  1403. $u27 = (stripos($pd[$x],'SilkBaseFrontal') !== false)?199:197;
  1404. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,26=>191,9=>'',44=>'');//蕾丝发块
  1405. $fc = 1;
  1406. }
  1407. else if((preg_match('/\d\*\dc/',$pd[$x]) || preg_match('/\dc/',$pd[$x]) || stripos($pd[$x],'+C') !== false || stripos($pd[$x],'Closure') !== false) && stripos($pd[$x],'wig') === false && stripos($pd[$x],'Bob') === false && !preg_match('/\dcolor/',$pd[$x]) && !preg_match('/\dColor/',$pd[$x]))
  1408. {
  1409. $u27 = (stripos($pd[$x],'SilkBaseClosure') !== false)?196:195;
  1410. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,25=>182,9=>'',44=>'');//蕾丝发块
  1411. if(stripos($pd[$x],'2*6') !== false)
  1412. {
  1413. $cplf[12] = 76;
  1414. }
  1415. $fc = 1;
  1416. }
  1417. $cpcppd = 0;
  1418. $cpcptype = $this->typeclass->find_all("classid = 33");
  1419. foreach ($cpcptype as $v)
  1420. {
  1421. $val = explode('|',trim($v['spare'],'|'));
  1422. foreach ($val as $vv)
  1423. {
  1424. if(stripos('-'.$pd[$x].'-','-'.$vv.'-') !== false)
  1425. {
  1426. $cpcppd++;
  1427. }
  1428. }
  1429. }
  1430. if($fc==1)
  1431. {
  1432. $cpson = $cplf;
  1433. }
  1434. else if ((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false || stripos($pd[$x],'BH-') !== false ) && stripos($pd[$x],'Syn') === false && stripos($pd[$x],'Gift') === false)//
  1435. {
  1436. $cpson = $cptt;
  1437. }
  1438. else if ((stripos($pd[$x],'SyHair') !== false || (stripos($pd[$x],'SyHair') !== false && stripos($pd[$x],'Syn') !== false)) && $cpcppd == 0)
  1439. {
  1440. $cpson = $cphxhair;
  1441. $cp = $cpson;
  1442. }
  1443. else if (stripos($pd[$x],'Syn') !== false && $cpcppd == 0)
  1444. {
  1445. $cpson = $cphxtt;
  1446. $cp = $cpson;
  1447. }
  1448. else if ($cpcppd > 0)
  1449. {
  1450. $cpson = $cpcp;
  1451. $cp = $cpcp;
  1452. }
  1453. else if (stripos($pd[$x],'Gift') !== false)
  1454. {
  1455. $cpson = $cpgi;
  1456. }
  1457. else if (stripos($pd[$x],'Accs') !== false)
  1458. {
  1459. $cpson = $cpac;
  1460. }
  1461. else
  1462. {
  1463. $cpson = $cp;
  1464. }
  1465. //$cpson = $fc==1?$cplf:((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false)?$cptt:(stripos($pd[$x],'Clip') !== false?$cpcp:array()));//是否是类似发块或头套产品
  1466. $cs[$x] = $cpson;
  1467. $son = explode('-',$value);//字符串转数组
  1468. $snum = 0;$cpsl = 0;
  1469. foreach ($son as $val)
  1470. {
  1471. if(stripos($val,'^') !== false)
  1472. {
  1473. $snum += str_replace('^','',$val);
  1474. }
  1475. if(isset($dtc[$val]))//如果能匹配到
  1476. {
  1477. if(is_numeric($val) || $dtc[$val]['classid'] == '14')//如果是组合产品
  1478. {
  1479. $cpsl++;
  1480. if(!is_numeric($val))
  1481. {
  1482. $pm['c'] = $dtc[$val]['zh'];
  1483. }
  1484. else
  1485. {
  1486. $pm['c'] = $val.'寸';//尺寸不匹配,并且准备写入到+号后面
  1487. }
  1488. $number['c'] = $val;
  1489. }
  1490. else
  1491. {
  1492. if(isset($cp[$dtc[$val]['classid']]))//判断匹配ID属于头部还是尾部
  1493. {
  1494. $cp[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1495. }
  1496. if(isset($cpson[$dtc[$val]['classid']]))
  1497. {
  1498. if($dtc[$val]['id'] != 66)//按要求暂时不匹配中棕颜色
  1499. {
  1500. $cpson[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1501. }
  1502. }
  1503. /**
  1504. if($pm[15] == '卡子发卡子发' || $dtc[$val]['zh'] == '卡子发卡子发')
  1505. {
  1506. $slpx[] = 1;
  1507. $pm[$dtc[$val]['classid']] = $pm[$dtc[$val]['classid']].' '.$dtc[$val]['zh'];
  1508. }
  1509. else
  1510. **/
  1511. if($dtc[$val]['classid'] == '999')
  1512. {
  1513. $pm[$dtc[$val]['classid']] .= $dtc[$val]['zh'];//其它正常匹配
  1514. }
  1515. else
  1516. {
  1517. $pm[$dtc[$val]['classid']] = $dtc[$val]['zh'];//其它正常匹配
  1518. }
  1519. }
  1520. }
  1521. else if(preg_match('/((\d+)\s+(\d+))/',$val) && stripos($val,'NO') === false)//如果不能匹配是多尺寸字符串
  1522. {
  1523. $j = (stripos($pd[$x],'+') !== false)?' +':'';//判断sku是否是+号类型
  1524. if(isset($cpson[16]))
  1525. {
  1526. if($cpson[16] != 128)
  1527. {
  1528. $cpslnum = explode(' ',trim($val,' '));
  1529. $cpsl += count($cpslnum);
  1530. $pm['dc'] = $val.$j;//写入多尺寸字符串
  1531. }
  1532. }
  1533. else
  1534. {
  1535. $cpslnum = explode(' ',trim($val,' '));
  1536. $cpsl += count($cpslnum);
  1537. $pm['dc'] = $val.$j;
  1538. }
  1539. $number['dc'] = $val;
  1540. }
  1541. }
  1542. if($sl[$x] > 1 || $snum > 1)
  1543. {
  1544. $slx = $sl[$x];
  1545. if($snum>1)
  1546. {
  1547. $slx = ($slx>1)?$slx:1;
  1548. $slx *= $snum;
  1549. }
  1550. $slpx[] = $cpsl;
  1551. $nr .= '['.$bmsku.implode(" ",$pm).']*'.$slx.'包'.';';//数组转字符串
  1552. }
  1553. else
  1554. {
  1555. if($cpsl > 0)
  1556. {
  1557. $slpx[] = $cpsl;
  1558. }
  1559. $slx = 1;
  1560. $pdpm = $bmsku.implode("",$pm);
  1561. if($pdpm != '')
  1562. {
  1563. $nr .= $bmsku.implode(" ",$pm).';';//数组转字符串
  1564. }
  1565. }
  1566. //以下是特殊类型的匹配
  1567. if(stripos($nr,'带绒布内衬半蕾丝头套') !== false && stripos($nr,'#') !== false)
  1568. {
  1569. $nr = preg_replace('/\#(\d+)/','内衬颜色$1号色',$nr);
  1570. }
  1571. $weightsku = array();
  1572. $weightdata = $this->weight->find_all();
  1573. foreach ($weightdata as $w)
  1574. {
  1575. $weightsku[$w['features']] = $w['weight'];
  1576. }
  1577. if($number['dc'] != '')
  1578. {
  1579. if(stripos($pd[$x],'+') !== false)
  1580. {
  1581. foreach ($cp as $v)
  1582. {
  1583. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1584. }
  1585. }
  1586. else
  1587. {
  1588. foreach ($cpson as $v)
  1589. {
  1590. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1591. }
  1592. }
  1593. $dc = explode(' ',trim($number['dc'],' '));
  1594. for($i=0;$i<count($dc);$i++)
  1595. {
  1596. if(isset($dtc[$dc[$i]]['id']))
  1597. {
  1598. $thisid = $dtc[$dc[$i]]['id'];
  1599. /**
  1600. $tha[$dc[$i]] = isset($tha[$dc[$i]])?array('zh'=>$tha[$dc[$i]]['zh'],'id'=>$tha[$dc[$i]]['id'],'count'=>$tha[$dc[$i]]['count']+1):array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  1601. **/
  1602. //一样的不再合并
  1603. $tha[] = array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  1604. }
  1605. }
  1606. foreach ($tha as $v)
  1607. {
  1608. $item = array_merge($cp);$weight = 0;
  1609. if($cp['16'] == '126')
  1610. {
  1611. $weight = $weightsku['126'];
  1612. }
  1613. else if($cp['16'] == '127')
  1614. {
  1615. if(isset($item[9]))
  1616. {
  1617. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  1618. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  1619. if(isset($weightsku[$sku127a]))
  1620. {
  1621. $weight = $weightsku[$sku127a];
  1622. }
  1623. else if(isset($weightsku[$sku127b]))
  1624. {
  1625. $weight = $weightsku[$sku127b];
  1626. }
  1627. }
  1628. }
  1629. else if($cp['16'] == '128')
  1630. {
  1631. if(isset($item[8]))
  1632. {
  1633. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  1634. if(isset($weightsku[$sku128]))
  1635. {
  1636. $weight = $weightsku[$sku128];
  1637. }
  1638. }
  1639. }
  1640. $cpa = $cp;$cpa[14] = $v['id'];$cpa[22] = '';//增加长度ID、去除真人发类型
  1641. $whlabel .= implode("",$cpa).'-'.$slx*$v['count'].'-0|';
  1642. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  1643. $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1644. // if(isset($price[$index])){
  1645. // $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|'.$price[$index].'|'.$row_total[$index].'|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1646. // }else{
  1647. // $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1648. // }
  1649. }
  1650. }
  1651. if($number['c'] != '')
  1652. {
  1653. $fk = $cp;
  1654. foreach ($cpson as $k=>$v)
  1655. {
  1656. $fk[$k] = $v;//+号左右ID合并右完整ID
  1657. }
  1658. if(isset($fk[16]) && ($fk[16] ==133)){
  1659. $tmp = $this->logic_match->doAction($fk);
  1660. if(!empty($tmp)){
  1661. $fk = $tmp;
  1662. }
  1663. }
  1664. foreach ($fk as $v)
  1665. {
  1666. $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1667. }
  1668. $c = explode(' ',trim($number['c'],' '));
  1669. for($i=0;$i<count($c);$i++)
  1670. {
  1671. $thisid = $dtc[$c[$i]]['id'];
  1672. /**
  1673. $thb[$c[$i]] = isset($thb[$c[$i]])?array('zh'=>$thb[$c[$i]]['zh'],'id'=>$thb[$c[$i]]['id'],'count'=>$thb[$c[$i]]['count']+1):array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  1674. **/
  1675. //一样的不再合并
  1676. $thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  1677. }
  1678. foreach ($thb as $v)
  1679. {
  1680. $item = array_merge($fk);$weight = 0;
  1681. if($fk['16'] == '126')
  1682. {
  1683. $weight = $weightsku[$item[0]];
  1684. }
  1685. else if($fk['16'] == '127')
  1686. {
  1687. if(isset($item[9]))
  1688. {
  1689. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  1690. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  1691. if(isset($weightsku[$sku127a]))
  1692. {
  1693. $weight = $weightsku[$sku127a];
  1694. }
  1695. else if(isset($weightsku[$sku127b]))
  1696. {
  1697. $weight = $weightsku[$sku127b];
  1698. }
  1699. }
  1700. }
  1701. else if($fk['16'] == '128')
  1702. {
  1703. if(isset($item[8]))
  1704. {
  1705. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  1706. if(isset($weightsku[$sku128]))
  1707. {
  1708. $weight = $weightsku[$sku128];
  1709. }
  1710. }
  1711. }
  1712. //var_dump($fk);
  1713. $cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型
  1714. $whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|';
  1715. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  1716. // if(isset($price[$index])){
  1717. // $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|'.$price[$index].'|'.$row_total[$index].'|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1718. // }else{
  1719. // $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1720. // }
  1721. $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1722. }
  1723. }
  1724. if (stripos($pd[$x],'Gift-') !== false)
  1725. {
  1726. $ptitleg = '';
  1727. foreach ($cpson as $v)
  1728. {
  1729. $ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1730. }
  1731. $whlabel .= implode("",$cpson).'-'.$slx.'-0|';
  1732. // if(isset($price[$index])){
  1733. // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|'.$price[$index].'|'.$row_total[$index].'||0|0|0|0;';
  1734. // }else{
  1735. // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  1736. // }
  1737. $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  1738. }
  1739. $x++;
  1740. $purchase += $purchasemy;
  1741. $cost += $costmy;
  1742. }
  1743. $product = str_replace('--','-',$product);
  1744. $qbslpx = 0;$wcslpx = '';
  1745. foreach ($slpx as $v)
  1746. {
  1747. $wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|';
  1748. $qbslpx += $v;
  1749. }
  1750. $nr = str_replace(array('(',')'),array('(',')'),$nr);
  1751. if(stripos($whlabel,'|--|') !== false)
  1752. {
  1753. $whlabel = '';
  1754. $product = '';
  1755. }
  1756. return array('title'=>preg_replace(array('/(\s+)/','/分\s/u'),array(' ','分'),trim($nr,';')),'purchase'=>$purchase,'cost'=>$cost,'product'=>str_replace(array('---','--'),array('-','-'),$product),'whlabel'=>$whlabel,'wcslpx'=>trim($wcslpx,'|'),'cs'=>$cscs);
  1757. }
  1758. public function get_headgear($data)
  1759. {
  1760. $ch = curl_init();
  1761. $url = 'http://54.190.55.35/application/main.php';
  1762. curl_setopt($ch,CURLOPT_URL,$url);
  1763. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1764. curl_setopt($ch,CURLOPT_HEADER,0);
  1765. curl_setopt($ch,CURLOPT_POST, 1);
  1766. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
  1767. //设置post数据
  1768. $post = array();
  1769. $post['timestamp'] = time();
  1770. $post['key'] = substr(md5($post['timestamp'].'.wigs'),1,20);
  1771. $post['data'] = $data;
  1772. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1773. $res = curl_exec($ch);
  1774. curl_close($ch);
  1775. $res = json_decode($res,true);
  1776. if(isset($res))
  1777. {
  1778. return $res;
  1779. }
  1780. }
  1781. public function get_paypal($v)
  1782. {
  1783. if($v['express'] == 7 || $v['express'] == 51)
  1784. {
  1785. return 'GES不需要发送';exit;
  1786. }
  1787. if($v['shop'] == 5){
  1788. return "Shopify不需要发送";
  1789. }
  1790. $post = array();
  1791. $orderinfo = preg_replace('/^' . preg_quote($v['shop'], '/') . '/', '', $v['orderinfo']);
  1792. $post['incrementId'] = $orderinfo;
  1793. $post['trackingNumber'] = $v['waybill'];
  1794. $post['carrier'] = $v['iscode'];
  1795. $url = 'https://www.'.$v['url'].'.com/applepay/payment/addTrack';
  1796. $ch = curl_init();
  1797. curl_setopt($ch,CURLOPT_URL,$url);
  1798. curl_setopt($ch, CURLOPT_POST, 1);
  1799. curl_setopt($ch, CURLOPT_HEADER, 0);
  1800. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1801. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1802. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1803. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1804. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1805. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  1806. $res = curl_exec($ch);
  1807. curl_close($ch);
  1808. return $res;
  1809. }
  1810. } //end class