Model_api.php 63 KB

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