Model_api.php 57 KB

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