Model_api.php 64 KB

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