Model_api.php 59 KB

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