Model_api.php 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511
  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. $matching = $this->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle,$shop,[
  850. 'row_total'=>isset($v['row_total'])?$v['row_total']:"0",
  851. 'price'=>isset($v['price'])?$v['price']:"0",
  852. ]);
  853. $post['shipremarks'] = $matching['title'];
  854. $post['cost'] = $matching['cost'];
  855. $post['purchase'] = $matching['purchase'];
  856. $post['fpdata'] = $matching['product'];
  857. $post['whlabel'] = $matching['whlabel'];
  858. $post['slpx'] = $matching['wcslpx'];
  859. return $post;
  860. }
  861. /**
  862. *
  863. *
  864. *
  865. 匹配仓库品名、产品、成本
  866. *
  867. *
  868. *
  869. **/
  870. public function matching($quantity,$issku,$dtc,$money,$int,$dtctitle,$shop=[],$extra = [])
  871. {
  872. $sl = explode(';',$quantity);
  873. $x=0;$product = '';//product 每单多产品链接组合
  874. $purchase = 0;$cost = 0;//每单所有产品总成本价格;
  875. $whlabel = '|';//库存产品码
  876. $cscs = array();$cscs = $issku;
  877. $nr = '';$cs = array();
  878. $t = array('/\-\-/','/\+/','/\#Color/','/\#Long/','/-[1-4]-/','/(\w+)~(\w+)-/');
  879. $h = array('-','-','','','-','');
  880. $issku = str_replace(array('(',')'),array('(',')'),$issku);
  881. $issku = str_replace(array(' <','> '),array('<','>'),$issku);
  882. $issku = strtolower($issku);
  883. $varsku = preg_replace($t,$h,$issku);////转大写、匹配更改和删除
  884. $varsku = strtolower($varsku);//转小写
  885. $sku = explode(',',$varsku);//多产品分割为多数组
  886. //根据要求添加了 row_total和商品单价
  887. $row_total = [];
  888. $price = [];
  889. if(isset($extra['row_total'])){
  890. $row_total_tmp = explode(',',$extra['row_total']);
  891. foreach($sku as $k=>$v){
  892. $row_total[$k] = isset($row_total_tmp[$k])?$row_total_tmp[$k]:0;
  893. }
  894. }else{
  895. foreach($sku as $k=>$v){
  896. $row_total[$k] = 0;
  897. }
  898. }
  899. if(isset($extra['price'])){
  900. $price_tmp = explode(',',$extra['price']);
  901. foreach($sku as $k=>$v){
  902. $price[$k] = isset($price_tmp[$k])?$price_tmp[$k]:0;
  903. }
  904. }else{
  905. foreach($sku as $k=>$v){
  906. $price[$k] = 0;
  907. }
  908. }
  909. $pd = explode(',',$issku);
  910. $slpx = array();
  911. $tqjcskua = array();//先检测是否只匹配品名
  912. $tqjcskub = array();
  913. //添加price 和 row_total
  914. $tqjcpricea = [];
  915. $tqjcpriceb = [];
  916. $tqjcrow_totala = [];
  917. $tqjcrow_totalb = [];
  918. $tqjcpircegit = [];
  919. $tqjcqda = array();
  920. $tqjcqdb = array();
  921. $tqjcgit = array();//礼物类放SKU顺序中间
  922. $tqjcgitpd = array();//礼物类放SKU顺序中间
  923. foreach ($sku as $k=>$value)
  924. {
  925. //查找是否有头套和HD开始
  926. $cid = array();
  927. $cf = explode('-',trim($value,'-'));
  928. $cf = array_filter($cf);
  929. foreach ($cf as $v)
  930. {
  931. if(isset($dtc[$v]['id']) && isset($dtc[$v]['jm']))
  932. {
  933. $cid[$dtc[$v]['classid']] = array('id'=>$dtc[$v]['id'],'spare'=>$v,'jm'=>$dtc[$v]['jm']);
  934. }
  935. }
  936. if(isset($cid['44']) && isset($cid['18']))
  937. {
  938. if(isset($dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['id']))
  939. {
  940. $value = '-'.$value.'-';
  941. $sku[$k] = '-'.$sku[$k].'-';
  942. $pd[$k] = '-'.$pd[$k].'-';
  943. $value = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$value);
  944. $value = str_replace('-'.$cid['44']['spare'],'-',$value);
  945. $sku[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$sku[$k]);
  946. $sku[$k] = str_replace('-'.$cid['44']['spare'],'-',$sku[$k]);
  947. $pd[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$pd[$k]);
  948. $pd[$k] = str_replace('-'.$cid['44']['spare'],'-',$pd[$k]);
  949. $value = strtolower(trim($value,'-'));
  950. $pd[$k] = strtolower(trim($pd[$k],'-'));
  951. $sku[$k] = strtolower(trim($sku[$k],'-'));
  952. }
  953. else if(stripos($value,'-transparent') !== false || stripos($value,'-tr') === false)
  954. {
  955. $value = str_replace(array('-transparent','-tr'),'',$value);
  956. $sku[$k] = str_replace(array('-transparent','-tr'),'',$sku[$k]);
  957. $pd[$k] = str_replace(array('-transparent','-tr'),'',$pd[$k]);
  958. }
  959. }
  960. //查找是否有头套和HD结束
  961. if(isset($dtc[$value]['classid']))
  962. {
  963. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  964. {
  965. $tqjcskua[$k] = $value;
  966. $tqjcqda[$k] = $pd[$k];
  967. $tqjcpricea[$k] = isset($price[$k])?$price[$k]:0;
  968. $tqjcrow_totala[$k] = isset($row_total[$k])?$row_total[$k]:0;
  969. continue;
  970. }
  971. }
  972. if(stripos($value,'gift') !== false)
  973. {
  974. $tqjcgit[$k] = $value;
  975. $tqjcpircegit[$k] = 0;
  976. $tqjcgitpd[$k] = $pd[$k];
  977. continue;
  978. }
  979. $tqjcskub[$k] = $value;
  980. $tqjcqdb[$k] = $pd[$k];
  981. $tqjcpriceb[$k] = isset($price[$k])?$price[$k]:0;
  982. $tqjcrow_totalb[$k] = isset($row_total[$k])?$row_total[$k]:0;
  983. }
  984. $sku = $tqjcskub+$tqjcgit+$tqjcskua;
  985. $price = $tqjcpriceb+$tqjcpircegit+$tqjcpricea;
  986. $row_total = $tqjcrow_totalb+$tqjcpircegit+$tqjcrow_totala;
  987. $newsl = array();
  988. foreach ($sku as $k=>$value)
  989. {
  990. if(!isset($sl[$k]))
  991. {
  992. $sl[$k] = 1;
  993. }
  994. $newsl[] = $sl[$k];
  995. }
  996. $sl = array_values($newsl);
  997. $pd = $tqjcqdb+$tqjcgitpd+$tqjcqda;
  998. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  999. $price = array_values($price);
  1000. $row_total = array_values($row_total);
  1001. // $this->logic_ding->sendToDing("测试获取订单数据SKU转化".json_encode($sku));
  1002. // $this->logic_ding->sendToDing("测试获取订单数据price转化".json_encode($price));
  1003. // $this->logic_ding->sendToDing("测试获取订单数据row_total转化".json_encode($row_total));
  1004. $pd = array_values($pd);
  1005. /**
  1006. $tqjcskua = array();//先检测是否只匹配品名
  1007. $tqjcskub = array();
  1008. foreach ($sku as $k=>$value)
  1009. {
  1010. if(isset($dtc[$value]['classid']))
  1011. {
  1012. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  1013. {
  1014. $tqjcskua[$k] = $value;
  1015. continue;
  1016. }
  1017. }
  1018. $tqjcskub[$k] = $value;
  1019. }
  1020. $sku = $tqjcskub+$tqjcskua;
  1021. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  1022. **/
  1023. foreach ($sku as $index=>$value)
  1024. {
  1025. $bmsku = '';
  1026. if(stripos($value,'-<') !== false && stripos($value,'>-') === false)
  1027. {
  1028. $isskufg = explode('-<',$value);
  1029. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1030. }
  1031. if(stripos($value,'-<') !== false && stripos($value,'>-') !== false)
  1032. {
  1033. $isskufg = explode('-<',$value);
  1034. $isskufgh = explode('>-',$isskufg[1]);
  1035. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1036. }
  1037. if(stripos($value,'-<') === false && stripos($value,'>-') !== false)
  1038. {
  1039. $isskufg = explode('>-',$value);
  1040. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1041. }
  1042. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') === false)
  1043. {
  1044. $isskufg = explode('-&lt;',$value);
  1045. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1046. }
  1047. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') !== false)
  1048. {
  1049. $isskufg = explode('-&lt;',$value);
  1050. $isskufgh = explode('&gt;-',$isskufg[1]);
  1051. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1052. }
  1053. if(stripos($value,'-&lt;') === false && stripos($value,'&gt;-') !== false)
  1054. {
  1055. $isskufg = explode('&gt;-',$value);
  1056. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1057. }
  1058. $value = trim($value,' ');$cpson = array();$cplf = array();
  1059. $thisid='';$tha=array();$thb=array();
  1060. $purchasemy=0;$costmy=0;$salespricemy=0;
  1061. $djay = array();//每单单个产品公司销售价格
  1062. $ptitlea='';$ptitleb='';//每单产品名称
  1063. $cpa='';$cpb='';$fc = 0;
  1064. $number = array('dc'=>'','c'=>'');
  1065. $classid = $this->classid->sku();
  1066. $pm = $classid;//品名顺序
  1067. //等级-真人发类型-化纤发编号-颜色-花型-蕾丝头套种类-化纤头套类型-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-化纤其它属性-头套其它属性-头套属性 100为头套额外附加
  1068. $cp = array(16=>126,22=>'',13=>80,14=>'',43=>'',8=>57,15=>'');//产品默认ID内容
  1069. //16->类目、22->真人发类型、13->等级、14->长度、8->颜色、15->曲度(花型)
  1070. $cptt = array(16=>128,13=>80,43=>'',8=>'57',15=>'',18=>'',6=>30,10=>72,9=>'',44=>'',39=>'');//头套
  1071. $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'',7=>'');//卡子发,7=>33重量
  1072. $cpgi = array(16=>131,34=>'');//礼物
  1073. $cpac = array(16=>133,35=>'');//配件
  1074. $cphxtt = array(16=>1297,13=>80,14=>'',40=>'',8=>57,15=>'',41=>'',42=>'');
  1075. $cphxhair = array(16=>1702,13=>80,14=>'',47=>'',46=>'',8=>57,15=>'',38=>'',48=>'');
  1076. 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)
  1077. {
  1078. $u27 = (stripos($pd[$x],'SilkBaseFrontal') !== false)?199:197;
  1079. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,26=>191,9=>'',44=>'');//蕾丝发块
  1080. $fc = 1;
  1081. }
  1082. 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)
  1083. {
  1084. $u27 = (stripos($pd[$x],'SilkBaseClosure') !== false)?196:195;
  1085. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,25=>182,9=>'',44=>'');//蕾丝发块
  1086. if(stripos($pd[$x],'2*6') !== false)
  1087. {
  1088. $cplf[12] = 76;
  1089. }
  1090. $fc = 1;
  1091. }
  1092. $cpcppd = 0;
  1093. $cpcptype = $this->typeclass->find_all("classid = 33");
  1094. foreach ($cpcptype as $v)
  1095. {
  1096. $val = explode('|',trim($v['spare'],'|'));
  1097. foreach ($val as $vv)
  1098. {
  1099. if(stripos('-'.$pd[$x].'-','-'.$vv.'-') !== false)
  1100. {
  1101. $cpcppd++;
  1102. }
  1103. }
  1104. }
  1105. if($fc==1)
  1106. {
  1107. $cpson = $cplf;
  1108. }
  1109. else if ((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false) && stripos($pd[$x],'Syn') === false && stripos($pd[$x],'Gift') === false)//
  1110. {
  1111. $cpson = $cptt;
  1112. }
  1113. else if ((stripos($pd[$x],'SyHair') !== false || (stripos($pd[$x],'SyHair') !== false && stripos($pd[$x],'Syn') !== false)) && $cpcppd == 0)
  1114. {
  1115. $cpson = $cphxhair;
  1116. $cp = $cpson;
  1117. }
  1118. else if (stripos($pd[$x],'Syn') !== false && $cpcppd == 0)
  1119. {
  1120. $cpson = $cphxtt;
  1121. $cp = $cpson;
  1122. }
  1123. else if ($cpcppd > 0)
  1124. {
  1125. $cpson = $cpcp;
  1126. $cp = $cpcp;
  1127. }
  1128. else if (stripos($pd[$x],'Gift') !== false)
  1129. {
  1130. $cpson = $cpgi;
  1131. }
  1132. else if (stripos($pd[$x],'Accs') !== false)
  1133. {
  1134. $cpson = $cpac;
  1135. }
  1136. else
  1137. {
  1138. $cpson = $cp;
  1139. }
  1140. //$cpson = $fc==1?$cplf:((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false)?$cptt:(stripos($pd[$x],'Clip') !== false?$cpcp:array()));//是否是类似发块或头套产品
  1141. $cs[$x] = $cpson;
  1142. $son = explode('-',$value);//字符串转数组
  1143. $snum = 0;$cpsl = 0;
  1144. foreach ($son as $val)
  1145. {
  1146. if(stripos($val,'^') !== false)
  1147. {
  1148. $snum += str_replace('^','',$val);
  1149. }
  1150. if(isset($dtc[$val]))//如果能匹配到
  1151. {
  1152. if(is_numeric($val) || $dtc[$val]['classid'] == '14')//如果是组合产品
  1153. {
  1154. $cpsl++;
  1155. if(!is_numeric($val))
  1156. {
  1157. $pm['c'] = $dtc[$val]['zh'];
  1158. }
  1159. else
  1160. {
  1161. $pm['c'] = $val.'寸';//尺寸不匹配,并且准备写入到+号后面
  1162. }
  1163. $number['c'] = $val;
  1164. }
  1165. else
  1166. {
  1167. if(isset($cp[$dtc[$val]['classid']]))//判断匹配ID属于头部还是尾部
  1168. {
  1169. $cp[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1170. }
  1171. if(isset($cpson[$dtc[$val]['classid']]))
  1172. {
  1173. if($dtc[$val]['id'] != 66)//按要求暂时不匹配中棕颜色
  1174. {
  1175. $cpson[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1176. }
  1177. }
  1178. /**
  1179. if($pm[15] == '卡子发卡子发' || $dtc[$val]['zh'] == '卡子发卡子发')
  1180. {
  1181. $slpx[] = 1;
  1182. $pm[$dtc[$val]['classid']] = $pm[$dtc[$val]['classid']].' '.$dtc[$val]['zh'];
  1183. }
  1184. else
  1185. **/
  1186. if($dtc[$val]['classid'] == '999')
  1187. {
  1188. $pm[$dtc[$val]['classid']] .= $dtc[$val]['zh'];//其它正常匹配
  1189. }
  1190. else
  1191. {
  1192. $pm[$dtc[$val]['classid']] = $dtc[$val]['zh'];//其它正常匹配
  1193. }
  1194. }
  1195. }
  1196. else if(preg_match('/((\d+)\s+(\d+))/',$val) && stripos($val,'NO') === false)//如果不能匹配是多尺寸字符串
  1197. {
  1198. $j = (stripos($pd[$x],'+') !== false)?' +':'';//判断sku是否是+号类型
  1199. if(isset($cpson[16]))
  1200. {
  1201. if($cpson[16] != 128)
  1202. {
  1203. $cpslnum = explode(' ',trim($val,' '));
  1204. $cpsl += count($cpslnum);
  1205. $pm['dc'] = $val.$j;//写入多尺寸字符串
  1206. }
  1207. }
  1208. else
  1209. {
  1210. $cpslnum = explode(' ',trim($val,' '));
  1211. $cpsl += count($cpslnum);
  1212. $pm['dc'] = $val.$j;
  1213. }
  1214. $number['dc'] = $val;
  1215. }
  1216. }
  1217. if($sl[$x] > 1 || $snum > 1)
  1218. {
  1219. $slx = $sl[$x];
  1220. if($snum>1)
  1221. {
  1222. $slx = ($slx>1)?$slx:1;
  1223. $slx *= $snum;
  1224. }
  1225. $slpx[] = $cpsl;
  1226. $nr .= '['.$bmsku.implode(" ",$pm).']*'.$slx.'包'.';';//数组转字符串
  1227. }
  1228. else
  1229. {
  1230. if($cpsl > 0)
  1231. {
  1232. $slpx[] = $cpsl;
  1233. }
  1234. $slx = 1;
  1235. $pdpm = $bmsku.implode("",$pm);
  1236. if($pdpm != '')
  1237. {
  1238. $nr .= $bmsku.implode(" ",$pm).';';//数组转字符串
  1239. }
  1240. }
  1241. //以下是特殊类型的匹配
  1242. if(stripos($nr,'带绒布内衬半蕾丝头套') !== false && stripos($nr,'#') !== false)
  1243. {
  1244. $nr = preg_replace('/\#(\d+)/','内衬颜色$1号色',$nr);
  1245. }
  1246. $weightsku = array();
  1247. $weightdata = $this->weight->find_all();
  1248. foreach ($weightdata as $w)
  1249. {
  1250. $weightsku[$w['features']] = $w['weight'];
  1251. }
  1252. if($number['dc'] != '')
  1253. {
  1254. if(stripos($pd[$x],'+') !== false)
  1255. {
  1256. foreach ($cp as $v)
  1257. {
  1258. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1259. }
  1260. }
  1261. else
  1262. {
  1263. foreach ($cpson as $v)
  1264. {
  1265. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1266. }
  1267. }
  1268. $dc = explode(' ',trim($number['dc'],' '));
  1269. for($i=0;$i<count($dc);$i++)
  1270. {
  1271. if(isset($dtc[$dc[$i]]['id']))
  1272. {
  1273. $thisid = $dtc[$dc[$i]]['id'];
  1274. /**
  1275. $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);
  1276. **/
  1277. //一样的不再合并
  1278. $tha[] = array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  1279. }
  1280. }
  1281. foreach ($tha as $v)
  1282. {
  1283. $item = array_merge($cp);$weight = 0;
  1284. if($cp['16'] == '126')
  1285. {
  1286. $weight = $weightsku['126'];
  1287. }
  1288. else if($cp['16'] == '127')
  1289. {
  1290. if(isset($item[9]))
  1291. {
  1292. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  1293. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  1294. if(isset($weightsku[$sku127a]))
  1295. {
  1296. $weight = $weightsku[$sku127a];
  1297. }
  1298. else if(isset($weightsku[$sku127b]))
  1299. {
  1300. $weight = $weightsku[$sku127b];
  1301. }
  1302. }
  1303. }
  1304. else if($cp['16'] == '128')
  1305. {
  1306. if(isset($item[8]))
  1307. {
  1308. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  1309. if(isset($weightsku[$sku128]))
  1310. {
  1311. $weight = $weightsku[$sku128];
  1312. }
  1313. }
  1314. }
  1315. $cpa = $cp;$cpa[14] = $v['id'];$cpa[22] = '';//增加长度ID、去除真人发类型
  1316. $whlabel .= implode("",$cpa).'-'.$slx*$v['count'].'-0|';
  1317. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  1318. //$product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1319. if(isset($price[$index])){
  1320. $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;';
  1321. }else{
  1322. $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1323. }
  1324. }
  1325. }
  1326. if($number['c'] != '')
  1327. {
  1328. $fk = $cp;
  1329. foreach ($cpson as $k=>$v)
  1330. {
  1331. $fk[$k] = $v;//+号左右ID合并右完整ID
  1332. }
  1333. foreach ($fk as $v)
  1334. {
  1335. $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1336. }
  1337. $c = explode(' ',trim($number['c'],' '));
  1338. for($i=0;$i<count($c);$i++)
  1339. {
  1340. $thisid = $dtc[$c[$i]]['id'];
  1341. /**
  1342. $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);
  1343. **/
  1344. //一样的不再合并
  1345. $thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  1346. }
  1347. foreach ($thb as $v)
  1348. {
  1349. $item = array_merge($fk);$weight = 0;
  1350. if($fk['16'] == '126')
  1351. {
  1352. $weight = $weightsku[$item[0]];
  1353. }
  1354. else if($fk['16'] == '127')
  1355. {
  1356. if(isset($item[9]))
  1357. {
  1358. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  1359. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  1360. if(isset($weightsku[$sku127a]))
  1361. {
  1362. $weight = $weightsku[$sku127a];
  1363. }
  1364. else if(isset($weightsku[$sku127b]))
  1365. {
  1366. $weight = $weightsku[$sku127b];
  1367. }
  1368. }
  1369. }
  1370. else if($fk['16'] == '128')
  1371. {
  1372. if(isset($item[8]))
  1373. {
  1374. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  1375. if(isset($weightsku[$sku128]))
  1376. {
  1377. $weight = $weightsku[$sku128];
  1378. }
  1379. }
  1380. }
  1381. $cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型
  1382. $whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|';
  1383. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  1384. if(isset($price[$index])){
  1385. $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;';
  1386. }else{
  1387. $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1388. }
  1389. //$product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1390. }
  1391. }
  1392. if (stripos($pd[$x],'Gift-') !== false)
  1393. {
  1394. $ptitleg = '';
  1395. foreach ($cpson as $v)
  1396. {
  1397. $ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1398. }
  1399. $whlabel .= implode("",$cpson).'-'.$slx.'-0|';
  1400. if(isset($price[$index])){
  1401. $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|'.$price[$index].'|'.$row_total[$index].'||0|0|0|0;';
  1402. }else{
  1403. $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  1404. }
  1405. //$product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  1406. }
  1407. $x++;
  1408. $purchase += $purchasemy;
  1409. $cost += $costmy;
  1410. }
  1411. $product = str_replace('--','-',$product);
  1412. $qbslpx = 0;$wcslpx = '';
  1413. foreach ($slpx as $v)
  1414. {
  1415. $wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|';
  1416. $qbslpx += $v;
  1417. }
  1418. $nr = str_replace(array('(',')'),array('(',')'),$nr);
  1419. if(stripos($whlabel,'|--|') !== false)
  1420. {
  1421. $whlabel = '';
  1422. $product = '';
  1423. }
  1424. 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);
  1425. }
  1426. public function get_headgear($data)
  1427. {
  1428. $ch = curl_init();
  1429. $url = 'http://54.190.55.35/application/main.php';
  1430. curl_setopt($ch,CURLOPT_URL,$url);
  1431. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1432. curl_setopt($ch,CURLOPT_HEADER,0);
  1433. curl_setopt($ch,CURLOPT_POST, 1);
  1434. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
  1435. //设置post数据
  1436. $post = array();
  1437. $post['timestamp'] = time();
  1438. $post['key'] = substr(md5($post['timestamp'].'.wigs'),1,20);
  1439. $post['data'] = $data;
  1440. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1441. $res = curl_exec($ch);
  1442. curl_close($ch);
  1443. $res = json_decode($res,true);
  1444. if(isset($res))
  1445. {
  1446. return $res;
  1447. }
  1448. }
  1449. public function get_paypal($v)
  1450. {
  1451. if($v['shop'] == 7 || $v['shop'] == 51)
  1452. {
  1453. return 'GES不需要发送';exit;
  1454. }
  1455. $post = array();
  1456. $orderinfo = preg_replace('/^' . preg_quote($v['shop'], '/') . '/', '', $v['orderinfo']);
  1457. $post['incrementId'] = $orderinfo;
  1458. $post['trackingNumber'] = $v['waybill'];
  1459. $post['carrier'] = $v['iscode'];
  1460. $url = 'https://www.'.$v['url'].'.com/applepay/payment/addTrack';
  1461. $ch = curl_init();
  1462. curl_setopt($ch,CURLOPT_URL,$url);
  1463. curl_setopt($ch, CURLOPT_POST, 1);
  1464. curl_setopt($ch, CURLOPT_HEADER, 0);
  1465. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1466. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1467. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1468. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1469. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1470. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  1471. $res = curl_exec($ch);
  1472. curl_close($ch);
  1473. return $res;
  1474. }
  1475. } //end class