Model_api.php 58 KB

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