Model_api.php 65 KB

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