Model_api.php 77 KB

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