Model_api.php 56 KB

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