Model_api.php 65 KB

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