Model_api.php 61 KB

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