Model_api.php 71 KB

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