Model_api.php 59 KB

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