Model_apixw.php 37 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  1. <?php
  2. class Model_Apixw extends Lin_Model {
  3. function __construct(){
  4. parent::__construct();
  5. $this->load->_model('Model_weight','weight');
  6. $this->load->_model('Model_classid','classid');
  7. }
  8. public function get_hq($name,$shopapi,$shop)
  9. {
  10. $post['shopify'] = $shopapi;//?status=any所有订单 &limit=200每页多少单
  11. $toTime = time();
  12. $ch = curl_init();
  13. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  14. curl_setopt($ch, CURLOPT_POST, 1);
  15. curl_setopt($ch, CURLOPT_HEADER, 0);
  16. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  17. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  18. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  19. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  20. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  21. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  22. $res = curl_exec($ch);
  23. curl_close($ch);
  24. $res = json_decode($res,true);
  25. $thatDayOrder = array();
  26. if(isset($res['orders']))
  27. {
  28. foreach ($res['orders'] as $v)
  29. {
  30. $productNames = '';
  31. $parameters = array();
  32. $skus = '';
  33. $quantity = '';
  34. $thislink = '';
  35. foreach($v['line_items'] as $key=>$val)
  36. {
  37. $productNames .= ($key > 0)?','.$val['name']:$val['name'];
  38. $skus .= ($key > 0)?','.$val['sku']:$val['sku'];
  39. $quantity .= floor($val['quantity']).';';
  40. }
  41. if(stripos($v['payment_gateway_names'][0],'shopify_') !== false)
  42. {
  43. $pay = 'shopifypay';
  44. }
  45. else if(stripos($v['payment_gateway_names'][0],'paypal') !== false)
  46. {
  47. $pay = 'paypal_express';
  48. }
  49. else if(stripos($v['payment_gateway_names'][0],'gift_card') !== false)
  50. {
  51. $pay = 'gift_card';
  52. }
  53. else if(stripos($v['payment_gateway_names'][0],'shop_cash') !== false)
  54. {
  55. $pay = 'shop_cash';
  56. }
  57. else
  58. {
  59. $pay = $v['payment_gateway_names'][0];
  60. }
  61. $khbz = '';
  62. if(!isset($v['shipping_address']['country_code']))
  63. {
  64. $v['shipping_address'] = $v['billing_address'];
  65. $khbz = '客户自提订单; ';
  66. }
  67. $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'];
  68. @$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'];
  69. $created_at = explode('T',$v['created_at']);
  70. $created_at_hi = explode('-',$created_at[1]);
  71. $created_at = $created_at[0].' '.$created_at_hi[0];
  72. $paypal = '';
  73. $d = $this->authorization($shop,$v['id']);
  74. if($d['g'] == 1)
  75. {
  76. $paypal = $d['d'];
  77. }
  78. $authorid = '';
  79. $wjauthorid = '';
  80. $sourcecontentid = '';
  81. $link = '';
  82. $thatDayOrder[] = array(
  83. 'order_id' => $v['order_number'],//订单号
  84. 'product_name' => $productNames,//产品标题
  85. 'purchased_on' => strtotime($created_at),//订单时间
  86. 'name' => $v['shipping_address']['name'],//收货人
  87. 'bill_to_name' => $v['billing_address']['name'],//账单人名称
  88. 'ship_to_name' => $v['shipping_address']['name'],//收货人名称
  89. 'shipping_address' => $shipping_address,
  90. 'billing_address' => $billing_address,
  91. 'country' => $v['shipping_address']['country_code'],//收货国家二字码
  92. 'region' => $v['shipping_address']['province_code'],//收货省/州
  93. 'city' => $v['shipping_address']['city'],//收货城市
  94. 'street' => $v['shipping_address']['address2'].' '.$v['shipping_address']['address1'],//收货地址
  95. 'telephone' => $v['shipping_address']['phone'],//收货人手机
  96. 'postcode' => $v['shipping_address']['zip'],//收货人邮政编码
  97. 'email' => $v['customer']['email'],//收货人邮箱
  98. 'global_currency_code' => $v['currency'],//币种
  99. 'base_grand_total' => $v['total_price'],//应收金额
  100. 'grand_total' => $v['total_price_set']['shop_money']['amount'],//币种支付金额
  101. 'isstatus' => 'processing',//$v['order_status'],//默认processing待发货状态
  102. 'isparameter' => implode(';',$parameters),
  103. 'sku' => $skus,
  104. 'order_quantity' => $quantity,
  105. 'order_comment' => $khbz.addslashes($v['note']),//客户备注
  106. 'pay' => $pay,
  107. 'paypal_num' => $paypal,
  108. 'insurance' => 0,
  109. 'paypal_protection_eligibility' => '',
  110. 'shippingmethod'=>'',
  111. 'link'=>$link,//产品链接
  112. 'shopify'=>$v['id'],
  113. 'authorid'=>$authorid,
  114. 'wjauthorid'=>$wjauthorid,
  115. 'sourcecontentid'=>$sourcecontentid
  116. );
  117. }
  118. return array_reverse($thatDayOrder);
  119. }
  120. }
  121. public function authorid($link,$tweak)
  122. {
  123. $ch = curl_init();
  124. $post = array();
  125. $ai['link'] = $link;
  126. $ai['tweak'] = $tweak;
  127. $ch = curl_init();
  128. curl_setopt($ch, CURLOPT_URL, 'http://127.0.0.1:3001/dec');
  129. curl_setopt($ch, CURLOPT_POST, 1);
  130. curl_setopt($ch, CURLOPT_HEADER, 0);
  131. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  132. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  133. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  134. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($ai));
  135. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  136. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
  137. $author_id = curl_exec($ch);
  138. curl_close($ch);
  139. $author_id = json_decode($author_id,true);
  140. if(isset($author_id['plainText']))
  141. {
  142. return $author_id['plainText'];
  143. }
  144. }
  145. public function authorization($shop,$shopifyid)//shopify获取交易号
  146. {
  147. $shopifyid = $shopifyid;
  148. $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
  149. $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  150. $ch = curl_init();
  151. curl_setopt($ch, CURLOPT_URL, $url);
  152. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  153. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  154. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  155. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  156. $res = curl_exec($ch);
  157. $headerA = curl_getinfo($ch);
  158. $a = json_decode($res,true);
  159. if(!isset($a['transactions']))
  160. {
  161. return array('g'=>0);exit;
  162. }
  163. $a['transactions'] = array_reverse($a['transactions']);
  164. if(isset($a['transactions'][0]['authorization']))
  165. {
  166. return array('g'=>1,'d'=>$a['transactions'][0]['authorization']);
  167. }
  168. else
  169. {
  170. return array('g'=>0);
  171. }
  172. }
  173. public function su_curl($data,$url,$header=array(),$date_type='json',$timeout=300,$httptype="POST",$userpwd='')
  174. {
  175. if ($date_type == 'http_build_query')
  176. {
  177. $data = http_build_query($data);
  178. }
  179. else if ($date_type == 'json')
  180. {
  181. $data = json_encode($data);
  182. }
  183. $ch = curl_init();
  184. curl_setopt($ch, CURLOPT_URL, $url);
  185. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  186. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  187. curl_setopt($ch, CURLOPT_HEADER, false);
  188. switch ($httptype)
  189. {
  190. case "GET":
  191. curl_setopt($ch, CURLOPT_HTTPGET, true);
  192. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  193. break;
  194. case "POST":
  195. curl_setopt($ch, CURLOPT_POST, true);
  196. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  197. break;
  198. case "PUT":
  199. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  200. break;
  201. case "DELETE":
  202. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  203. break;
  204. }
  205. $isSecure = strpos($url, "https://");
  206. if ($isSecure === 0)
  207. {
  208. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  209. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  210. }
  211. if(!empty($header))
  212. {
  213. curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
  214. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  215. }
  216. if(!empty($userpwd))
  217. {
  218. curl_setopt($ch,CURLOPT_USERPWD,$userpwd);
  219. }
  220. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  221. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  222. $result = curl_exec($ch);
  223. curl_close($ch);
  224. return $result;
  225. }
  226. public function get_hq2($name,$from,$to)
  227. {
  228. $jqtime = ($name=='SuperNova')?9*3600:3600;
  229. $fromTime = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  230. $toTime = time();
  231. $ch = curl_init();
  232. $url = 'http://edm.alipearl.net/soapapi.php';
  233. curl_setopt($ch,CURLOPT_URL,$url);
  234. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  235. curl_setopt($ch,CURLOPT_HEADER,0);
  236. curl_setopt($ch,CURLOPT_POST, 1);
  237. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  238. //设置post数据
  239. $post = array();
  240. $post['synchronization'] = 1;
  241. $post['name'] = $name;
  242. $post['from'] = $from;
  243. $post['to'] = $to;
  244. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  245. $res = curl_exec($ch);
  246. curl_close($ch);
  247. $res = json_decode($res,true);
  248. if(isset($res))
  249. {
  250. return $res;
  251. }
  252. }
  253. public function get_gx($ddh,$ydh,$xg,$shop,$ex,$msg,$shopifyid)
  254. {
  255. $res = '';
  256. if($shop['shopname'] == 'alipearlstore' || $shop['shopname'] == 'finsahair' || $shop['shopname'] == 'baddiebeautyshop')
  257. {
  258. $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/fulfillment_orders.json';
  259. $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  260. $ch = curl_init();
  261. curl_setopt($ch, CURLOPT_URL, $url);
  262. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  263. curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  264. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  265. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  266. $res = curl_exec($ch);
  267. $headerA = curl_getinfo($ch);
  268. $a = json_decode($res,true);
  269. $od = array();
  270. foreach ($a['fulfillment_orders'] as $v)
  271. {
  272. $od[] = array('fulfillment_order_id'=>$v['id']);
  273. }
  274. $data = array('fulfillment'=>array('notify_customer'=>false,'tracking_info'=>array('number'=>$ydh,'company'=>$ex['title']),
  275. 'line_items_by_fulfillment_order'=>$od));
  276. $data = json_encode($data);
  277. $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/fulfillments.json';
  278. $header[] = "Content-Type: application/json";
  279. $header[] = "X-Shopify-Access-Token: ".$shop['token'];
  280. $ch = curl_init();
  281. curl_setopt($ch, CURLOPT_URL, $url);
  282. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  283. curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  284. curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  285. curl_setopt($ch, CURLOPT_POST, 1);
  286. curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  287. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  288. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  289. $res = curl_exec($ch);
  290. $header = curl_getinfo($ch);
  291. $b = json_decode($res,true);
  292. if(isset($b['fulfillment']['id']))
  293. {
  294. return array('res'=>1,'state'=>216);
  295. }
  296. else
  297. {
  298. return array('res'=>2,'state'=>$xg['state']);
  299. }
  300. }
  301. else
  302. {
  303. $post = array();
  304. $post['update'] = 1;
  305. $post['ddh'] = $ddh;
  306. $post['ydh'] = $ydh;
  307. $post['xg'] = $xg;
  308. $post['shop'] = $shop;
  309. $post['ex'] = $ex;
  310. $post['msg'] = isset($msg)?$msg:2;
  311. $ch = curl_init();
  312. $url = 'http://edm.alipearl.net/soapapi.php';
  313. curl_setopt($ch,CURLOPT_URL,$url);
  314. curl_setopt($ch, CURLOPT_POST, 1);
  315. curl_setopt($ch, CURLOPT_HEADER, 0);
  316. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  317. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  318. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  319. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  320. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  321. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
  322. $res = curl_exec($ch);
  323. curl_close($ch);
  324. $res = json_decode($res,true);
  325. if($res)
  326. {
  327. if($res == 1)
  328. {
  329. return array('res'=>1,'state'=>216,'cs'=>$res);
  330. }
  331. else
  332. {
  333. return array('res'=>2,'state'=>$xg['state'],'cs'=>$res);
  334. }
  335. }
  336. else
  337. {
  338. return array('res'=>2,'state'=>$xg['state'],'cs'=>'a');
  339. }
  340. }
  341. }
  342. public function get_data($shop,$v,$gethl,$time,$country,$is,$num,$lb,$tc,$dtc,$money,$int,$dtctitle,$pay,$zjsku)
  343. {
  344. $hl = 0;
  345. foreach ($v as $kk=>$vv)
  346. {
  347. if(!$vv)
  348. {
  349. $v[$kk] = "";
  350. }
  351. else
  352. {
  353. $v[$kk] = str_replace("'","’",$vv);
  354. }
  355. }
  356. if(strcasecmp($v['isstatus'],'pending_Payment') == 0 || strcasecmp($v['isstatus'],'pending') == 0 || strcasecmp($v['isstatus'],'Pending_PayPal') == 0 || strcasecmp($v['isstatus'],'payment_pending') == 0)
  357. {
  358. $post['state'] = 203;//订单状态,等待买家付款
  359. }
  360. else if(strcasecmp($v['isstatus'],'Payment_Review') == 0 || strcasecmp($v['isstatus'],'payment_processing') == 0)
  361. {
  362. $post['state'] = 204;//订单状态,资金未到帐
  363. }
  364. else if(strcasecmp($v['isstatus'],'suspected_Fraud') == 0 || strcasecmp($v['isstatus'],' payment_suspected_fraud') == 0)
  365. {
  366. $post['state'] = 205;//订单状态,风控保持
  367. }
  368. else if(strcasecmp($v['isstatus'],'PayPal_Canceled_Reversal') == 0 || strcasecmp($v['isstatus'],'payment_canceled') == 0 || strcasecmp($v['isstatus'],'refunded') == 0)
  369. {
  370. $post['state'] = 206;//订单状态,买家申请取消
  371. }
  372. else if(strcasecmp($v['isstatus'],'processing') == 0 || strcasecmp($v['isstatus'],'payment_confirmed') == 0)
  373. {
  374. $post['state'] = 207;//订单状态,等待发货
  375. }
  376. else if(strcasecmp($v['isstatus'],'on_Hold') == 0 || strcasecmp($v['isstatus'],'holded') == 0)
  377. {
  378. $post['state'] = 212;//订单状态,冻结中的订单
  379. }
  380. else if(strcasecmp($v['isstatus'],'complete') == 0 || strcasecmp($v['isstatus'],'completed') == 0)
  381. {
  382. $post['state'] = 216;//订单状态,已完成
  383. }
  384. else if(strcasecmp($v['isstatus'],'closed') == 0 || strcasecmp($v['isstatus'],'canceled') == 0)
  385. {
  386. $post['state'] = 217;//订单状态,已关闭
  387. }
  388. else if(strcasecmp($v['isstatus'],'paypal_reversed') == 0)
  389. {
  390. $post['state'] = 215;//争议
  391. }
  392. else
  393. {
  394. $post['state'] = 283;//未获取到状态
  395. }
  396. if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
  397. {
  398. $v['sku'] = rtrim($v['sku'],',').','.$zjsku[$shop['id']];
  399. }
  400. $post['shop'] = $shop['id'];//店铺ID
  401. $post['user'] = $shop['shopuser'];//店铺负责人
  402. $post['product'] = $v['product_name'];//产品名称
  403. $post['link'] = $v['link'];//产品链接
  404. $post['issku'] = $v['sku'];
  405. $post['quantity'] = rtrim($v['order_quantity'],';');
  406. $post['clientremarks'] = $v['order_comment'];//客户备注
  407. $post['paypal'] = $v['paypal_num'];//交易号
  408. $post['guarantee'] = $v['paypal_protection_eligibility'];//卖家保障
  409. $post['parameter'] = $v['isparameter'];//属性
  410. $post['shippingmethod'] = $v['shippingmethod'];//用户选择快递方式及运费金额
  411. $sc = substr($v['order_id'],0,3);
  412. if($sc == '600')
  413. {
  414. $source = 3; //手机订单
  415. }
  416. else
  417. {
  418. $source = 2;//PC订单
  419. }
  420. $post['source'] = $source;//订单类型
  421. $post['type'] = 1;//发货仓库
  422. $post['capital'] = 3;//资金支付状况,全部付款
  423. $post['number'] = $shop['shortname'].'-'.substr(date('ymd',$time),1).'-'.(substr(strval($num+1+1000),1,3));//编号
  424. $post['orderinfo'] = $shop['id'].$v['order_id'];//订单号
  425. $post['insurance'] = $v['insurance'];//运输保险费用
  426. $post['baddress'] = $v['billing_address'];
  427. $post['saddress'] = $v['shipping_address'];
  428. $post['country'] = $country;//此国家的ID
  429. $post['al'] = $lb;//联邦名称
  430. $post['bname'] = preg_replace('/( | | |\s)/',' ',$v['bill_to_name']);//名称
  431. $post['sname'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//名称
  432. $post['client'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//公司名称
  433. $post['name'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//收件人名称
  434. $post['phone'] = preg_replace('/\D/s','',$v['telephone']);//收件人电话
  435. $post['email'] = preg_replace('/( | | |\s)+/','',$v['email']);//客户邮箱
  436. $post['zipcode'] = $v['postcode'];//收件人邮编
  437. $post['province'] = $v['region'];//收件人省份
  438. $post['city'] = $v['city'];//收件人城市
  439. $post['address'] = $v['street'];//收件人地址
  440. $post['shouldmoney'] = $v['base_grand_total'];//应收金额
  441. $post['skje'] = $post['shouldmoney'];//收款金额
  442. $post['ismoney'] = $v['grand_total'];//支付币种金额
  443. $post['authorid'] = isset($v['authorid'])?$v['authorid']:'';
  444. $post['wjauthorid'] = isset($v['wjauthorid'])?$v['wjauthorid']:'';
  445. $post['sourcecontentid'] = isset($v['sourcecontentid'])?$v['sourcecontentid']:'';
  446. $yga = $post['shouldmoney'];//金额
  447. $post['budget'] = 0;
  448. $post['pay'] = '25';//默认其它
  449. if(isset($pay[$v['pay']]['id']))
  450. {
  451. $post['pay'] = $pay[$v['pay']]['id'];
  452. }
  453. /**
  454. if(isset($v['pay']) && $yga > 0)
  455. {
  456. $post['pay'] = $pay[$v['pay']]['id'];
  457. $ygc = $pay[$v['pay']]['estimaterate'];//预估到账公式
  458. $post['estimaterate'] = $pay[$v['pay']]['estimaterate'];
  459. $ifbudget = eval("return $yga*1.$ygc;");
  460. if($ifbudget > 0)
  461. {
  462. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  463. }
  464. }
  465. else if($yga > 0)
  466. {
  467. $post['pay'] = 0;
  468. $ygb = $shop['estimaterate'];//店铺默认到账公式
  469. $post['estimaterate'] = $shop['estimaterate'];
  470. $ifbudget = eval("return $yga*1.$ygb;");
  471. if($ifbudget > 0)
  472. {
  473. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  474. }
  475. }
  476. **/
  477. $post['buytime'] = $time;//格式化付款时间
  478. $post['dtime'] = $time;//订单时间
  479. $post['gtime'] = date('Ymd',$time);//格式化订单时间
  480. $post['currencytitle'] = $v['global_currency_code'];//结算币种名称
  481. $post['currency'] = $tc;//钱币ID
  482. $post['time'] = time();//同步时间
  483. $post['shopify'] = (isset($v['shopify']))?$v['shopify']:0;//同步时间
  484. /**
  485. foreach ($gethl as $v)
  486. {
  487. $code = str_replace(" ","",$v['code']);
  488. if($code == $post['currencytitle'])//查找对应汇率值
  489. {
  490. $hl = $v['refePrice']/100;
  491. }
  492. }
  493. **/
  494. $post['hl'] = '6.4';//汇率
  495. /**
  496. $pxsku = array();$pxquantity = array();//sku重新排序 头套波波提前
  497. $newssku = explode(',',trim($post['issku'],','));
  498. $newquantity = explode(';',trim($post['quantity'],';'));
  499. foreach ($newssku as $k=>$v)
  500. {
  501. if(stripos($v,'wig') !== false || stripos($v,'Bob') !== false)
  502. {
  503. $pxsku[$k] = $v;
  504. $pxquantity[$k] = $newquantity[$k];
  505. }
  506. else
  507. {
  508. $pxsku[999+$k] = $v;
  509. $pxquantity[999+$k] = $newquantity[$k];
  510. }
  511. }
  512. ksort($pxsku);
  513. ksort($pxquantity);
  514. $post['issku'] = implode(",",$pxsku);
  515. $post['quantity'] = implode(";",$pxquantity);
  516. **/
  517. $matching = $this->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle,$shop);
  518. $post['shipremarks'] = $matching['title'];
  519. $post['cost'] = $matching['cost'];
  520. $post['purchase'] = $matching['purchase'];
  521. $post['fpdata'] = $matching['product'];
  522. $post['whlabel'] = $matching['whlabel'];
  523. $post['slpx'] = $matching['wcslpx'];
  524. return $post;
  525. }
  526. /**
  527. *
  528. *
  529. *
  530. 匹配仓库品名、产品、成本
  531. *
  532. *
  533. *
  534. **/
  535. public function matching($quantity,$issku,$dtc,$money,$int,$dtctitle)
  536. {
  537. $sl = explode(';',$quantity);
  538. $x=0;$product = '';//product 每单多产品链接组合
  539. $purchase = 0;$cost = 0;//每单所有产品总成本价格;
  540. $whlabel = '|';//库存产品码
  541. $nr = '';$cs = array();
  542. $t = array('/\-\-/','/\+/','/\#Color/','/\#Long/','/-[1-4]-/','/(\w+)~(\w+)-/');
  543. $h = array('-','-','','','-','');
  544. $issku = str_replace(array('(',')'),array('(',')'),$issku);
  545. $issku = str_replace(array(' <','> '),array('<','>'),$issku);
  546. $issku = strtolower($issku);
  547. $varsku = preg_replace($t,$h,$issku);////转大写、匹配更改和删除
  548. $varsku = strtolower($varsku);//转小写
  549. $sku = explode(',',$varsku);//多产品分割为多数组
  550. $pd = explode(',',$issku);
  551. $cid = array();
  552. $slpx = array();
  553. $tqjcskua = array();//先检测是否只匹配品名
  554. $tqjcskub = array();
  555. $tqjcqda = array();
  556. $tqjcqdb = array();
  557. $tqjcgit = array();//礼物类放SKU顺序中间
  558. $tqjcgitpd = array();//礼物类放SKU顺序中间
  559. foreach ($sku as $k=>$value)
  560. {
  561. //查找是否有头套和HD开始
  562. $cf = explode('-',trim($value,'-'));
  563. $cf = array_filter($cf);
  564. foreach ($cf as $v)
  565. {
  566. if(isset($dtc[$v]['id']) && isset($dtc[$v]['jm']))
  567. {
  568. $cid[$dtc[$v]['classid']] = array('id'=>$dtc[$v]['id'],'spare'=>$v,'jm'=>$dtc[$v]['jm']);
  569. }
  570. }
  571. if(isset($cid['44']) && isset($cid['18']) && isset($dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['id']))
  572. {
  573. $value = '-'.$value.'-';
  574. $sku[$k] = '-'.$sku[$k].'-';
  575. $pd[$k] = '-'.$pd[$k].'-';
  576. $value = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$value);
  577. $value = str_replace('-'.$cid['44']['spare'],'-',$value);
  578. $sku[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$sku[$k]);
  579. $sku[$k] = str_replace('-'.$cid['44']['spare'],'-',$sku[$k]);
  580. $pd[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$pd[$k]);
  581. $pd[$k] = str_replace('-'.$cid['44']['spare'],'-',$pd[$k]);
  582. $value = strtolower(trim($value,'-'));
  583. $pd[$k] = strtolower(trim($pd[$k],'-'));
  584. $sku[$k] = strtolower(trim($sku[$k],'-'));
  585. }
  586. //查找是否有头套和HD结束
  587. if(isset($dtc[$value]['classid']))
  588. {
  589. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  590. {
  591. $tqjcskua[$k] = $value;
  592. $tqjcqda[$k] = $pd[$k];
  593. continue;
  594. }
  595. }
  596. if(stripos($value,'gift') !== false)
  597. {
  598. $tqjcgit[$k] = $value;
  599. $tqjcgitpd[$k] = $pd[$k];
  600. continue;
  601. }
  602. $tqjcskub[$k] = $value;
  603. $tqjcqdb[$k] = $pd[$k];
  604. }
  605. $sku = $tqjcskub+$tqjcgit+$tqjcskua;
  606. $newsl = array();
  607. foreach ($sku as $k=>$value)
  608. {
  609. if(!isset($sl[$k]))
  610. {
  611. $sl[$k] = 1;
  612. }
  613. $newsl[] = $sl[$k];
  614. }
  615. $sl = array_values($newsl);
  616. $pd = $tqjcqdb+$tqjcgitpd+$tqjcqda;
  617. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  618. $pd = array_values($pd);
  619. /**
  620. $tqjcskua = array();//先检测是否只匹配品名
  621. $tqjcskub = array();
  622. foreach ($sku as $k=>$value)
  623. {
  624. if(isset($dtc[$value]['classid']))
  625. {
  626. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  627. {
  628. $tqjcskua[$k] = $value;
  629. continue;
  630. }
  631. }
  632. $tqjcskub[$k] = $value;
  633. }
  634. $sku = $tqjcskub+$tqjcskua;
  635. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  636. **/
  637. foreach ($sku as $value)
  638. {
  639. $bmsku = '';
  640. if(stripos($value,'-<') !== false && stripos($value,'>-') === false)
  641. {
  642. $isskufg = explode('-<',$value);
  643. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  644. }
  645. if(stripos($value,'-<') !== false && stripos($value,'>-') !== false)
  646. {
  647. $isskufg = explode('-<',$value);
  648. $isskufgh = explode('>-',$isskufg[1]);
  649. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  650. }
  651. if(stripos($value,'-<') === false && stripos($value,'>-') !== false)
  652. {
  653. $isskufg = explode('>-',$value);
  654. $bmsku = strtoupper($isskufg[0]).'&gt;';
  655. }
  656. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') === false)
  657. {
  658. $isskufg = explode('-&lt;',$value);
  659. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  660. }
  661. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') !== false)
  662. {
  663. $isskufg = explode('-&lt;',$value);
  664. $isskufgh = explode('&gt;-',$isskufg[1]);
  665. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  666. }
  667. if(stripos($value,'-&lt;') === false && stripos($value,'&gt;-') !== false)
  668. {
  669. $isskufg = explode('&gt;-',$value);
  670. $bmsku = strtoupper($isskufg[0]).'&gt;';
  671. }
  672. $value = trim($value,' ');$cpson = array();$cplf = array();
  673. $thisid='';$tha=array();$thb=array();
  674. $purchasemy=0;$costmy=0;$salespricemy=0;
  675. $djay = array();//每单单个产品公司销售价格
  676. $ptitlea='';$ptitleb='';//每单产品名称
  677. $cpa='';$cpb='';$fc = 0;
  678. $number = array('dc'=>'','c'=>'');
  679. $classid = $this->classid->sku();
  680. $pm = $classid;//品名顺序
  681. //等级-真人发类型-化纤发编号-颜色-花型-蕾丝头套种类-化纤头套类型-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-化纤其它属性-头套其它属性-头套属性 100为头套额外附加
  682. $cp = array(16=>126,22=>'',13=>80,14=>'',43=>'',8=>57,15=>'');//产品默认ID内容
  683. //16->类目、22->真人发类型、13->等级、14->长度、8->颜色、15->曲度(花型)
  684. $cptt = array(16=>128,13=>80,43=>'',8=>'57',15=>'',18=>'',6=>30,10=>72,9=>'',39=>'');//头套
  685. $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'');//卡子发,7=>33重量
  686. $cpgi = array(16=>131,34=>'');//礼物
  687. $cpac = array(16=>133,35=>'');//配件
  688. $cphxtt = array(16=>1297,13=>80,14=>'',40=>'',8=>57,15=>'',41=>'',42=>'');
  689. $cphxhair = array(16=>1702,13=>80,14=>'',47=>'',46=>'',8=>57,15=>'',38=>'',48=>'');
  690. 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)
  691. {
  692. $u27 = (stripos($pd[$x],'SilkBaseFrontal') !== false)?199:197;
  693. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,26=>191,9=>'',44=>'');//蕾丝发块
  694. $fc = 1;
  695. }
  696. 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)
  697. {
  698. $u27 = (stripos($pd[$x],'SilkBaseClosure') !== false)?196:195;
  699. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,25=>182,9=>'',44=>'');//蕾丝发块
  700. if(stripos($pd[$x],'2*6') !== false)
  701. {
  702. $cplf[12] = 76;
  703. }
  704. $fc = 1;
  705. }
  706. $cpcppd = 0;
  707. $cpcptype = $this->typeclass->find_all("classid = 33");
  708. foreach ($cpcptype as $v)
  709. {
  710. $val = explode('|',trim($v['spare'],'|'));
  711. foreach ($val as $vv)
  712. {
  713. if(stripos($pd[$x],$vv) !== false)
  714. {
  715. $cpcppd++;
  716. }
  717. }
  718. }
  719. if($fc==1)
  720. {
  721. $cpson = $cplf;
  722. }
  723. else if ((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false) && stripos($pd[$x],'Syn') === false && stripos($pd[$x],'Gift') === false)//
  724. {
  725. $cpson = $cptt;
  726. }
  727. else if ((stripos($pd[$x],'SyHair') !== false || (stripos($pd[$x],'SyHair') !== false && stripos($pd[$x],'Syn') !== false)) && $cpcppd == 0)
  728. {
  729. $cpson = $cphxhair;
  730. $cp = $cpson;
  731. }
  732. else if (stripos($pd[$x],'Syn') !== false && $cpcppd == 0)
  733. {
  734. $cpson = $cphxtt;
  735. $cp = $cpson;
  736. }
  737. else if ($cpcppd > 0)
  738. {
  739. $cpson = $cpcp;
  740. $cp = $cpcp;
  741. }
  742. else if (stripos($pd[$x],'Gift') !== false)
  743. {
  744. $cpson = $cpgi;
  745. }
  746. else if (stripos($pd[$x],'Accs') !== false)
  747. {
  748. $cpson = $cpac;
  749. }
  750. else
  751. {
  752. $cpson = $cp;
  753. }
  754. //$cpson = $fc==1?$cplf:((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false)?$cptt:(stripos($pd[$x],'Clip') !== false?$cpcp:array()));//是否是类似发块或头套产品
  755. $cs[$x] = $cpson;
  756. $son = explode('-',$value);//字符串转数组
  757. $snum = 0;$cpsl = 0;
  758. foreach ($son as $val)
  759. {
  760. if(stripos($val,'^') !== false)
  761. {
  762. $snum += str_replace('^','',$val);
  763. }
  764. if(isset($dtc[$val]))//如果能匹配到
  765. {
  766. if(is_numeric($val) || $dtc[$val]['classid'] == '14')//如果是组合产品
  767. {
  768. $cpsl++;
  769. if(!is_numeric($val))
  770. {
  771. $pm['c'] = $dtc[$val]['zh'];
  772. }
  773. else
  774. {
  775. $pm['c'] = $val.'寸';//尺寸不匹配,并且准备写入到+号后面
  776. }
  777. $number['c'] = $val;
  778. }
  779. else
  780. {
  781. if(isset($cp[$dtc[$val]['classid']]))//判断匹配ID属于头部还是尾部
  782. {
  783. $cp[$dtc[$val]['classid']] = $dtc[$val]['id'];
  784. }
  785. if(isset($cpson[$dtc[$val]['classid']]))
  786. {
  787. if($dtc[$val]['id'] != 66)//按要求暂时不匹配中棕颜色
  788. {
  789. $cpson[$dtc[$val]['classid']] = $dtc[$val]['id'];
  790. }
  791. }
  792. /**
  793. if($pm[15] == '卡子发卡子发' || $dtc[$val]['zh'] == '卡子发卡子发')
  794. {
  795. $slpx[] = 1;
  796. $pm[$dtc[$val]['classid']] = $pm[$dtc[$val]['classid']].' '.$dtc[$val]['zh'];
  797. }
  798. else
  799. **/
  800. if($dtc[$val]['classid'] == '999')
  801. {
  802. $pm[$dtc[$val]['classid']] .= $dtc[$val]['zh'];//其它正常匹配
  803. }
  804. else
  805. {
  806. $pm[$dtc[$val]['classid']] = $dtc[$val]['zh'];//其它正常匹配
  807. }
  808. }
  809. }
  810. else if(preg_match('/((\d+)\s+(\d+))/',$val) && stripos($val,'NO') === false)//如果不能匹配是多尺寸字符串
  811. {
  812. $j = (stripos($pd[$x],'+') !== false)?' +':'';//判断sku是否是+号类型
  813. if(isset($cpson[16]))
  814. {
  815. if($cpson[16] != 128)
  816. {
  817. $cpslnum = explode(' ',trim($val,' '));
  818. $cpsl += count($cpslnum);
  819. $pm['dc'] = $val.$j;//写入多尺寸字符串
  820. }
  821. }
  822. else
  823. {
  824. $cpslnum = explode(' ',trim($val,' '));
  825. $cpsl += count($cpslnum);
  826. $pm['dc'] = $val.$j;
  827. }
  828. $number['dc'] = $val;
  829. }
  830. }
  831. if($sl[$x] > 1 || $snum > 1)
  832. {
  833. $slx = $sl[$x];
  834. if($snum>1)
  835. {
  836. $slx = ($slx>1)?$slx:1;
  837. $slx *= $snum;
  838. }
  839. $slpx[] = $cpsl;
  840. $nr .= '['.$bmsku.implode(" ",$pm).']*'.$slx.'包'.';';//数组转字符串
  841. }
  842. else
  843. {
  844. if($cpsl > 0)
  845. {
  846. $slpx[] = $cpsl;
  847. }
  848. $slx = 1;
  849. $pdpm = $bmsku.implode("",$pm);
  850. if($pdpm != '')
  851. {
  852. $nr .= $bmsku.implode(" ",$pm).';';//数组转字符串
  853. }
  854. }
  855. //以下是特殊类型的匹配
  856. if(stripos($nr,'带绒布内衬半蕾丝头套') !== false && stripos($nr,'#') !== false)
  857. {
  858. $nr = preg_replace('/\#(\d+)/','内衬颜色$1号色',$nr);
  859. }
  860. $weightsku = array();
  861. $weightdata = $this->weight->find_all();
  862. foreach ($weightdata as $w)
  863. {
  864. $weightsku[$w['features']] = $w['weight'];
  865. }
  866. if($number['dc'] != '')
  867. {
  868. if(stripos($pd[$x],'+') !== false)
  869. {
  870. foreach ($cp as $v)
  871. {
  872. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  873. }
  874. }
  875. else
  876. {
  877. foreach ($cpson as $v)
  878. {
  879. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  880. }
  881. }
  882. $dc = explode(' ',trim($number['dc'],' '));
  883. for($i=0;$i<count($dc);$i++)
  884. {
  885. if(isset($dtc[$dc[$i]]['id']))
  886. {
  887. $thisid = $dtc[$dc[$i]]['id'];
  888. /**
  889. $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);
  890. **/
  891. //一样的不再合并
  892. $tha[] = array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  893. }
  894. }
  895. foreach ($tha as $v)
  896. {
  897. $item = array_merge($cp);$weight = 0;
  898. if($cp['16'] == '126')
  899. {
  900. $weight = $weightsku['126'];
  901. }
  902. else if($cp['16'] == '127')
  903. {
  904. if(isset($item[9]))
  905. {
  906. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  907. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  908. if(isset($weightsku[$sku127a]))
  909. {
  910. $weight = $weightsku[$sku127a];
  911. }
  912. else if(isset($weightsku[$sku127b]))
  913. {
  914. $weight = $weightsku[$sku127b];
  915. }
  916. }
  917. }
  918. else if($cp['16'] == '128')
  919. {
  920. if(isset($item[8]))
  921. {
  922. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  923. if(isset($weightsku[$sku128]))
  924. {
  925. $weight = $weightsku[$sku128];
  926. }
  927. }
  928. }
  929. $cpa = $cp;$cpa[14] = $v['id'];$cpa[22] = '';//增加长度ID、去除真人发类型
  930. $whlabel .= implode("",$cpa).'-'.$slx*$v['count'].'-0|';
  931. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  932. $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  933. }
  934. }
  935. if($number['c'] != '')
  936. {
  937. $fk = $cp;
  938. foreach ($cpson as $k=>$v)
  939. {
  940. $fk[$k] = $v;//+号左右ID合并右完整ID
  941. }
  942. foreach ($fk as $v)
  943. {
  944. $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  945. }
  946. $c = explode(' ',trim($number['c'],' '));
  947. for($i=0;$i<count($c);$i++)
  948. {
  949. $thisid = $dtc[$c[$i]]['id'];
  950. /**
  951. $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);
  952. **/
  953. //一样的不再合并
  954. $thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  955. }
  956. foreach ($thb as $v)
  957. {
  958. $item = array_merge($fk);$weight = 0;
  959. if($fk['16'] == '126')
  960. {
  961. $weight = $weightsku[$item[0]];
  962. }
  963. else if($fk['16'] == '127')
  964. {
  965. if(isset($item[9]))
  966. {
  967. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  968. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  969. if(isset($weightsku[$sku127a]))
  970. {
  971. $weight = $weightsku[$sku127a];
  972. }
  973. else if(isset($weightsku[$sku127b]))
  974. {
  975. $weight = $weightsku[$sku127b];
  976. }
  977. }
  978. }
  979. else if($fk['16'] == '128')
  980. {
  981. if(isset($item[8]))
  982. {
  983. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  984. if(isset($weightsku[$sku128]))
  985. {
  986. $weight = $weightsku[$sku128];
  987. }
  988. }
  989. }
  990. $cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型
  991. $whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|';
  992. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  993. $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  994. }
  995. }
  996. if (stripos($pd[$x],'Gift-') !== false)
  997. {
  998. $ptitleg = '';
  999. foreach ($cpson as $v)
  1000. {
  1001. $ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1002. }
  1003. $whlabel .= implode("",$cpson).'-'.$slx.'-0|';
  1004. $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  1005. }
  1006. $x++;
  1007. $purchase += $purchasemy;
  1008. $cost += $costmy;
  1009. }
  1010. $product = str_replace('--','-',$product);
  1011. $qbslpx = 0;$wcslpx = '';
  1012. foreach ($slpx as $v)
  1013. {
  1014. $wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|';
  1015. $qbslpx += $v;
  1016. }
  1017. $nr = str_replace(array('(',')'),array('(',')'),$nr);
  1018. if(stripos($whlabel,'|--|') !== false)
  1019. {
  1020. $whlabel = '';
  1021. $product = '';
  1022. }
  1023. 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'=>$sku);
  1024. }
  1025. public function get_headgear($data)
  1026. {
  1027. $ch = curl_init();
  1028. $url = 'http://54.190.55.35/application/main.php';
  1029. curl_setopt($ch,CURLOPT_URL,$url);
  1030. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1031. curl_setopt($ch,CURLOPT_HEADER,0);
  1032. curl_setopt($ch,CURLOPT_POST, 1);
  1033. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
  1034. //设置post数据
  1035. $post = array();
  1036. $post['timestamp'] = time();
  1037. $post['key'] = substr(md5($post['timestamp'].'.wigs'),1,20);
  1038. $post['data'] = $data;
  1039. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1040. $res = curl_exec($ch);
  1041. curl_close($ch);
  1042. $res = json_decode($res,true);
  1043. if(isset($res))
  1044. {
  1045. return $res;
  1046. }
  1047. }
  1048. } //end class