Model_api.php 61 KB

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