Model_api.php 63 KB

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