Model_api.php 64 KB

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