Model_apixw.php 36 KB

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