Model_api.php 45 KB

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