Model_api.php 68 KB

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