Model_api.php 68 KB

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