Model_api.php 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  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']['captures'])){
  685. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection'])){
  686. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'])){
  687. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'];
  688. }
  689. }
  690. }
  691. }
  692. }
  693. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  694. }
  695. else
  696. {
  697. return array('g'=>0);
  698. }
  699. }
  700. }else{
  701. $end_info = end($a['transactions']);
  702. if($end_info['gateway'] == 'Klarna' ){
  703. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  704. }elseif(stripos($end_info['gateway'],'Payoneer Checkout Klarna') !== false){
  705. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  706. }elseif(stripos($end_info['gateway'],'Afterpay') !== false){
  707. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  708. }elseif(stripos($end_info['gateway'],'Airwallex') !== false){
  709. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  710. }
  711. else{
  712. $a['transactions'] = array_reverse($a['transactions']);
  713. if(isset($a['transactions'][0]['authorization']))
  714. {
  715. $protection_eligibility = "";
  716. if(isset($a['transactions'][0]['receipt'])){
  717. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  718. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  719. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  720. if(!empty($a['transactions'][0]['receipt']['purchase_units']['captures'])){
  721. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection'])){
  722. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'])){
  723. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'];
  724. }
  725. }
  726. }
  727. }
  728. }
  729. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  730. }
  731. else
  732. {
  733. return array('g'=>0);
  734. }
  735. }
  736. }
  737. }
  738. public function authorization_bak($shop,$shopifyid)//shopify获取交易号
  739. {
  740. if($shop['brandname'] == 'yolissahair'){
  741. $shopname = 'xxu7p0-3q';
  742. }elseif ($shop['brandname'] == 'Yolissa') {
  743. $shopname = 'xxu7p0-3q';
  744. }else{
  745. $shopname = $shop['brandname'];
  746. }
  747. $post = [];
  748. $post['shopify_pay'] = [
  749. "url"=> 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json',
  750. "token"=>"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",
  751. ];
  752. $ch = curl_init();
  753. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  754. curl_setopt($ch, CURLOPT_POST, 1);
  755. curl_setopt($ch, CURLOPT_HEADER, 0);
  756. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  757. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  758. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  759. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  760. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  761. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  762. $res = curl_exec($ch);
  763. curl_close($ch);
  764. //$this->logic_ding->sendToDing("独立站获取订单的店铺执行shopfiy支付信息【".$shopifyid."】".$res."}{".json_encode($post));
  765. // $shopifyid = $shopifyid;
  766. // $url = 'https://'.$shop['shopname'].'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/transactions.json';
  767. // $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  768. // $ch = curl_init();
  769. // curl_setopt($ch, CURLOPT_URL, $url);
  770. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  771. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  772. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  773. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  774. // $res = curl_exec($ch);
  775. // $headerA = curl_getinfo($ch)
  776. $a = json_decode($res,true);
  777. if(!isset($a['transactions']))
  778. {
  779. return array('g'=>0);exit;
  780. }
  781. $tmp_pay_list = [];
  782. foreach ($a['transactions'] as $v){
  783. if(stripos($v['gateway'],'gift_card') === false){
  784. $tmp_pay_list[] = $v;
  785. }
  786. }
  787. $a['transactions'] = $tmp_pay_list;
  788. if(count($a['transactions']) < 2){
  789. //
  790. if($a['transactions'][0]['gateway'] == 'Klarna' ){
  791. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  792. }elseif(stripos($a['transactions'][0]['gateway'],'Payoneer Checkout Klarna') !== false){
  793. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  794. }elseif(stripos($a['transactions'][0]['gateway'],'Afterpay') !== false){
  795. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  796. }elseif(stripos($a['transactions'][0]['gateway'],'Airwallex') !== false){
  797. return array('g'=>1,'d'=>$a['transactions'][0]['payment_id'],'protection_eligibility'=>"");
  798. }else{
  799. $a['transactions'] = array_reverse($a['transactions']);
  800. if(isset($a['transactions'][0]['authorization']))
  801. {
  802. $protection_eligibility = "";
  803. if(isset($a['transactions'][0]['receipt'])){
  804. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  805. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  806. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  807. if(!empty($a['transactions'][0]['receipt']['purchase_units']['captures'])){
  808. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection'])){
  809. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'])){
  810. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'];
  811. }
  812. }
  813. }
  814. }
  815. }
  816. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  817. }
  818. else
  819. {
  820. return array('g'=>0);
  821. }
  822. }
  823. }else{
  824. $end_info = end($a['transactions']);
  825. if($end_info['gateway'] == 'Klarna' ){
  826. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  827. }elseif(stripos($end_info['gateway'],'Payoneer Checkout Klarna') !== false){
  828. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  829. }elseif(stripos($end_info['gateway'],'Afterpay') !== false){
  830. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  831. }elseif(stripos($end_info['gateway'],'Airwallex') !== false){
  832. return array('g'=>1,'d'=>$end_info['payment_id'],'protection_eligibility'=>"");
  833. }
  834. else{
  835. $a['transactions'] = array_reverse($a['transactions']);
  836. if(isset($a['transactions'][0]['authorization']))
  837. {
  838. $protection_eligibility = "";
  839. if(isset($a['transactions'][0]['receipt'])){
  840. if(isset($a['transactions'][0]['receipt']['protection_eligibility'])){
  841. $protection_eligibility = $a['transactions'][0]['receipt']['protection_eligibility'];
  842. }elseif(isset($a['transactions'][0]['receipt']['purchase_units'])){
  843. if(!empty($a['transactions'][0]['receipt']['purchase_units']['captures'])){
  844. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection'])){
  845. if(isset($a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'])){
  846. $protection_eligibility = $a['transactions'][0]['receipt']['purchase_units']['captures'][0]['seller_protection']['status'];
  847. }
  848. }
  849. }
  850. }
  851. }
  852. return array('g'=>1,'d'=>$a['transactions'][0]['authorization'],'protection_eligibility'=>$protection_eligibility);
  853. }
  854. else
  855. {
  856. return array('g'=>0);
  857. }
  858. }
  859. }
  860. }
  861. public function su_curl($data,$url,$header=array(),$date_type='json',$timeout=300,$httptype="POST",$userpwd='')
  862. {
  863. if ($date_type == 'http_build_query')
  864. {
  865. $data = http_build_query($data);
  866. }
  867. else if ($date_type == 'json')
  868. {
  869. $data = json_encode($data);
  870. }
  871. $ch = curl_init();
  872. curl_setopt($ch, CURLOPT_URL, $url);
  873. curl_setopt($ch, CURLOPT_POSTFIELDS,$data);
  874. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  875. curl_setopt($ch, CURLOPT_HEADER, false);
  876. switch ($httptype)
  877. {
  878. case "GET":
  879. curl_setopt($ch, CURLOPT_HTTPGET, true);
  880. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
  881. break;
  882. case "POST":
  883. curl_setopt($ch, CURLOPT_POST, true);
  884. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
  885. break;
  886. case "PUT":
  887. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
  888. break;
  889. case "DELETE":
  890. curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "DELETE");
  891. break;
  892. }
  893. $isSecure = strpos($url, "https://");
  894. if ($isSecure === 0)
  895. {
  896. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  897. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  898. }
  899. if(!empty($header))
  900. {
  901. curl_setopt($ch, CURLOPT_SSLVERSION , 6); //NEW ADDITION
  902. curl_setopt($ch,CURLOPT_HTTPHEADER,$header);
  903. }
  904. if(!empty($userpwd))
  905. {
  906. curl_setopt($ch,CURLOPT_USERPWD,$userpwd);
  907. }
  908. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  909. curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $timeout);
  910. $result = curl_exec($ch);
  911. curl_close($ch);
  912. return $result;
  913. }
  914. public function get_hq2($name,$from,$to)
  915. {
  916. $jqtime = ($name=='SuperNova')?9*3600:3600;
  917. $fromTime = strtotime('yesterday')-$jqtime;//昨日0点+1小时保险无漏单
  918. $toTime = time();
  919. $ch = curl_init();
  920. $url = 'http://edm.alipearl.net/soapapi.php';
  921. curl_setopt($ch,CURLOPT_URL,$url);
  922. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  923. curl_setopt($ch,CURLOPT_HEADER,0);
  924. curl_setopt($ch,CURLOPT_POST, 1);
  925. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,600);
  926. //设置post数据
  927. $post = array();
  928. $post['synchronization'] = 1;
  929. $post['name'] = $name;
  930. $post['from'] = $from;
  931. $post['to'] = $to;
  932. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  933. $res = curl_exec($ch);
  934. curl_close($ch);
  935. $res = json_decode($res,true);
  936. if(isset($res))
  937. {
  938. return $res;
  939. }
  940. }
  941. public function get_gx($ddh,$ydh,$xg,$shop,$ex,$msg,$shopifyid)
  942. {
  943. $res = '';
  944. if(in_array($shop['shopname'],['alipearlstore','finsahair','baddiebeautyshop','yolissahair']))
  945. {
  946. if($shop['shopname'] == 'yolissahair'){
  947. $shopname = 'xxu7p0-3q';
  948. }else{
  949. $shopname = $shop['shopname'];
  950. }
  951. $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/orders/'.$shopifyid.'/fulfillment_orders.json';
  952. $headerA[] = "X-Shopify-Access-Token: ".$shop['token'];
  953. // $ch = curl_init();
  954. // curl_setopt($ch, CURLOPT_URL, $url);
  955. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  956. // curl_setopt($ch, CURLOPT_HTTPHEADER, $headerA);
  957. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  958. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  959. // $res = curl_exec($ch);
  960. // $headerA = curl_getinfo($ch);
  961. $post = [];
  962. $post['shopify_yd_one'] = 1;
  963. $post['url'] = $url;
  964. $post['token'] = $shop['token'];
  965. $ch = curl_init();
  966. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  967. curl_setopt($ch, CURLOPT_POST, 1);
  968. curl_setopt($ch, CURLOPT_HEADER, 0);
  969. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  970. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  971. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  972. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  973. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  974. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  975. $res = curl_exec($ch);
  976. curl_close($ch);
  977. $this->logic_ding->sendToDing("shopfiy的运单同步第一步".json_encode($post)."|".$res);
  978. //如果为空 啥都不用执行 直接返回 期待下次执行
  979. if(empty($res)){
  980. return ;
  981. }
  982. $a = json_decode($res,true);
  983. $od = array();
  984. foreach ($a['fulfillment_orders'] as $v)
  985. {
  986. $od[] = array('fulfillment_order_id'=>$v['id']);
  987. }
  988. $data = array('fulfillment'=>array('notify_customer'=>false,'tracking_info'=>array('number'=>$ydh,'company'=>$ex['title']),
  989. 'line_items_by_fulfillment_order'=>$od));
  990. // $url = 'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json';
  991. // $header[] = "Content-Type: application/json";
  992. // $header[] = "X-Shopify-Access-Token: ".$shop['token'];
  993. // $ch = curl_init();
  994. // curl_setopt($ch, CURLOPT_URL, $url);
  995. // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  996. // curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
  997. // curl_setopt($ch, CURLINFO_HEADER_OUT, TRUE);
  998. // curl_setopt($ch, CURLOPT_POST, 1);
  999. // curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
  1000. // curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  1001. // curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
  1002. // $res = curl_exec($ch);
  1003. // $header = curl_getinfo($ch);
  1004. $post = [
  1005. 'shopify_yd_two'=>1,
  1006. 'token'=>$shop['token'],
  1007. 'url'=>'https://'.$shopname.'.myshopify.com/admin/api/2022-10/fulfillments.json',
  1008. 'data'=>$data,
  1009. ];
  1010. $ch = curl_init();
  1011. curl_setopt($ch,CURLOPT_URL,'https://edm.alipearl.net/soapapi.php');
  1012. curl_setopt($ch, CURLOPT_POST, 1);
  1013. curl_setopt($ch, CURLOPT_HEADER, 0);
  1014. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1015. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1016. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1017. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1018. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1019. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  1020. $res = curl_exec($ch);
  1021. curl_close($ch);
  1022. $this->logic_ding->sendToDing("shopfiy的运单同步第二步".json_encode($post)."|".$res);
  1023. $b = json_decode($res,true);
  1024. $this->logic_ding->sendToDing("erp同步独立站的信息_".$ydh."_".json_encode($b,JSON_UNESCAPED_UNICODE));
  1025. if(isset($b['fulfillment']['id']))
  1026. {
  1027. return array('res'=>1,'state'=>216,'cw'=>'');
  1028. }
  1029. else
  1030. {
  1031. return array('res'=>2,'state'=>$xg['state'],'cw'=>$res);
  1032. }
  1033. }
  1034. else
  1035. {
  1036. $post = array();
  1037. $post['update'] = 1;
  1038. $post['ddh'] = $ddh;
  1039. $post['ydh'] = $ydh;
  1040. $post['xg'] = $xg;
  1041. $post['shop'] = $shop;
  1042. $post['ex'] = $ex;
  1043. $post['msg'] = isset($msg)?$msg:2;
  1044. $this->logic_ding->sendToDing("erp同步独立站的信息tijiao1".json_encode($post,JSON_UNESCAPED_UNICODE));
  1045. $ch = curl_init();
  1046. $url = 'http://edm.alipearl.net/soapapi.php';
  1047. curl_setopt($ch,CURLOPT_URL,$url);
  1048. curl_setopt($ch, CURLOPT_POST, 1);
  1049. curl_setopt($ch, CURLOPT_HEADER, 0);
  1050. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1051. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1052. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1053. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1054. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1055. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,900);
  1056. $res = curl_exec($ch);
  1057. curl_close($ch);
  1058. $res = json_decode($res,true);
  1059. $this->logic_ding->sendToDing("erp同步独立站的信息1_".$ydh."_".json_encode($res,JSON_UNESCAPED_UNICODE));
  1060. if($res)
  1061. {
  1062. if($res == 1)
  1063. {
  1064. return array('res'=>1,'state'=>216,'cs'=>$res);
  1065. }
  1066. else
  1067. {
  1068. return array('res'=>2,'state'=>$xg['state'],'cs'=>$res);
  1069. }
  1070. }
  1071. else
  1072. {
  1073. return array('res'=>2,'state'=>$xg['state'],'cs'=>'a');
  1074. }
  1075. }
  1076. }
  1077. public function get_data($shop,$v,$gethl,$time,$country,$is,$num,$lb,$tc,$dtc,$money,$int,$dtctitle,$pay,$zjsku)
  1078. {
  1079. $hl = 0;
  1080. foreach ($v as $kk=>$vv)
  1081. {
  1082. if(!$vv)
  1083. {
  1084. $v[$kk] = "";
  1085. }
  1086. else
  1087. {
  1088. $v[$kk] = str_replace("'","’",$vv);
  1089. }
  1090. }
  1091. if(strcasecmp($v['isstatus'],'pending_Payment') == 0 || strcasecmp($v['isstatus'],'pending') == 0 || strcasecmp($v['isstatus'],'Pending_PayPal') == 0 || strcasecmp($v['isstatus'],'payment_pending') == 0)
  1092. {
  1093. $post['state'] = 203;//订单状态,等待买家付款
  1094. }
  1095. else if(strcasecmp($v['isstatus'],'Payment_Review') == 0 || strcasecmp($v['isstatus'],'payment_processing') == 0)
  1096. {
  1097. $post['state'] = 204;//订单状态,资金未到帐
  1098. }
  1099. else if(strcasecmp($v['isstatus'],'suspected_Fraud') == 0 || strcasecmp($v['isstatus'],' payment_suspected_fraud') == 0)
  1100. {
  1101. $post['state'] = 205;//订单状态,风控保持
  1102. }
  1103. else if(strcasecmp($v['isstatus'],'PayPal_Canceled_Reversal') == 0 || strcasecmp($v['isstatus'],'payment_canceled') == 0 || strcasecmp($v['isstatus'],'refunded') == 0)
  1104. {
  1105. $post['state'] = 206;//订单状态,买家申请取消
  1106. }
  1107. else if(strcasecmp($v['isstatus'],'processing') == 0 || strcasecmp($v['isstatus'],'payment_confirmed') == 0)
  1108. {
  1109. $post['state'] = 207;//订单状态,等待发货
  1110. }
  1111. else if(strcasecmp($v['isstatus'],'on_Hold') == 0 || strcasecmp($v['isstatus'],'holded') == 0)
  1112. {
  1113. $post['state'] = 212;//订单状态,冻结中的订单
  1114. }
  1115. else if(strcasecmp($v['isstatus'],'complete') == 0 || strcasecmp($v['isstatus'],'completed') == 0)
  1116. {
  1117. $post['state'] = 216;//订单状态,已完成
  1118. }
  1119. else if(strcasecmp($v['isstatus'],'closed') == 0 || strcasecmp($v['isstatus'],'canceled') == 0)
  1120. {
  1121. $post['state'] = 217;//订单状态,已关闭
  1122. }
  1123. else if(strcasecmp($v['isstatus'],'paypal_reversed') == 0)
  1124. {
  1125. $post['state'] = 215;//争议
  1126. }
  1127. else
  1128. {
  1129. $post['state'] = 283;//未获取到状态
  1130. }
  1131. if(isset($zjsku[$shop['id']]))//判断是否找到店铺SKU
  1132. {
  1133. $v['sku'] = rtrim($v['sku'],',').','.$zjsku[$shop['id']];
  1134. }
  1135. $post['shop'] = $shop['id'];//店铺ID
  1136. $post['user'] = $shop['shopuser'];//店铺负责人
  1137. $post['orderid'] = isset($v['orderid'])?$v['orderid']:0;//M2ID
  1138. $post['product'] = $v['product_name'];//产品名称
  1139. $post['link'] = $v['link'];//产品链接
  1140. $post['issku'] = $v['sku'];
  1141. $post['quantity'] = rtrim($v['order_quantity'],';');
  1142. $post['clientremarks'] = $v['order_comment'];//客户备注
  1143. $post['paypal'] = $v['paypal_num'];//交易号
  1144. $post['guarantee'] = $v['paypal_protection_eligibility'];//卖家保障
  1145. $post['parameter'] = $v['isparameter'];//属性
  1146. $post['shippingmethod'] = $v['shippingmethod'];//用户选择快递方式及运费金额
  1147. $sc = substr($v['order_id'],0,3);
  1148. if($sc == '600')
  1149. {
  1150. $source = 3; //手机订单
  1151. }
  1152. else
  1153. {
  1154. $source = 2;//PC订单
  1155. }
  1156. $post['source'] = $source;//订单类型
  1157. $post['type'] = 1;//发货仓库
  1158. $post['capital'] = 3;//资金支付状况,全部付款
  1159. $post['number'] = $shop['shortname'].'-'.date('ymd',$time).'-'.(substr(strval($num+1+1000),1,3));//编号
  1160. if($shop['program'] == 'Shopify'){
  1161. $post['orderinfo'] = $v['order_id'];//订单号
  1162. }else{
  1163. $post['orderinfo'] = $shop['id'].$v['order_id'];//订单号
  1164. }
  1165. $post['insurance'] = isset($v['insurance'])?$v['insurance']:0;//运输保险费用
  1166. $post['baddress'] = $v['billing_address'];
  1167. $post['saddress'] = $v['shipping_address'];
  1168. $post['country'] = $country;//此国家的ID
  1169. $post['al'] = $lb;//联邦名称
  1170. $post['bname'] = preg_replace('/( | | |\s)/',' ',$v['bill_to_name']);//名称
  1171. $post['sname'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//名称
  1172. $post['client'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//公司名称
  1173. $post['name'] = preg_replace('/( | | |\s)/',' ',$v['ship_to_name']);//收件人名称
  1174. $post['phone'] = preg_replace('/\D/s','',$v['telephone']);//收件人电话
  1175. $post['email'] = preg_replace('/( | | |\s)+/','',$v['email']);//客户邮箱
  1176. $post['zipcode'] = $v['postcode'];//收件人邮编
  1177. $post['province'] = $v['region'];//收件人省份
  1178. $post['city'] = $v['city'];//收件人城市
  1179. $post['address'] = $v['street'];//收件人地址
  1180. $post['shouldmoney'] = $v['base_grand_total'];//应收金额
  1181. $post['skje'] = $post['shouldmoney'];//收款金额
  1182. $post['ismoney'] = $v['grand_total'];//支付币种金额
  1183. $post['authorid'] = isset($v['authorid'])?$v['authorid']:'';
  1184. $post['wjauthorid'] = isset($v['wjauthorid'])?$v['wjauthorid']:'';
  1185. $post['sourcecontentid'] = isset($v['sourcecontentid'])?$v['sourcecontentid']:'';
  1186. $yga = $post['shouldmoney'];//金额
  1187. $post['budget'] = 0;
  1188. if(isset($v['pay']) && isset($pay[$v['pay']]) && $yga > 0)
  1189. {
  1190. $post['pay'] = $pay[$v['pay']]['id'];
  1191. $ygc = $pay[$v['pay']]['estimaterate'];//预估到账公式
  1192. $post['estimaterate'] = $pay[$v['pay']]['estimaterate'];
  1193. $ifbudget = eval("return $yga*1.$ygc;");
  1194. if($ifbudget > 0)
  1195. {
  1196. $post['budget'] = eval("return $yga*1.$ygc;");//预估到帐金额
  1197. }
  1198. }
  1199. else if($yga > 0)
  1200. {
  1201. $post['pay'] = 0;
  1202. $ygb = $shop['estimaterate'];//店铺默认到账公式
  1203. $post['estimaterate'] = $shop['estimaterate'];
  1204. $ifbudget = eval("return $yga*1.$ygb;");
  1205. if($ifbudget > 0)
  1206. {
  1207. $post['budget'] = eval("return $yga*1.$ygb;");//预估到帐金额
  1208. }
  1209. }
  1210. $post['buytime'] = $time;//格式化付款时间
  1211. $post['dtime'] = $time;//订单时间
  1212. $post['gtime'] = date('Ymd',$time);//格式化订单时间
  1213. $post['currencytitle'] = $v['global_currency_code'];//结算币种名称
  1214. $post['currency'] = $tc;//钱币ID
  1215. $post['time'] = time();//同步时间
  1216. $post['shopify'] = (isset($v['shopify']))?$v['shopify']:0;//同步时间
  1217. /**
  1218. foreach ($gethl as $v)
  1219. {
  1220. $code = str_replace(" ","",$v['code']);
  1221. if($code == $post['currencytitle'])//查找对应汇率值
  1222. {
  1223. $hl = $v['refePrice']/100;
  1224. }
  1225. }
  1226. **/
  1227. $post['hl'] = '6.4';//汇率
  1228. /**
  1229. $pxsku = array();$pxquantity = array();//sku重新排序 头套波波提前
  1230. $newssku = explode(',',trim($post['issku'],','));
  1231. $newquantity = explode(';',trim($post['quantity'],';'));
  1232. foreach ($newssku as $k=>$v)
  1233. {
  1234. if(stripos($v,'wig') !== false || stripos($v,'Bob') !== false)
  1235. {
  1236. $pxsku[$k] = $v;
  1237. $pxquantity[$k] = $newquantity[$k];
  1238. }
  1239. else
  1240. {
  1241. $pxsku[999+$k] = $v;
  1242. $pxquantity[999+$k] = $newquantity[$k];
  1243. }
  1244. }
  1245. ksort($pxsku);
  1246. ksort($pxquantity);
  1247. $post['issku'] = implode(",",$pxsku);
  1248. $post['quantity'] = implode(";",$pxquantity);
  1249. **/
  1250. // if(stripos($post['issku'],'+') !== false){
  1251. // $this->logic_ding->sendToDing("测试获取3+1订单未转化数据".json_encode($v));
  1252. // $this->logic_ding->sendToDing("测试获取3+1订单已转化数据".json_encode($post));
  1253. // }
  1254. //$this->logic_ding->sendToDing("获取独立站的订单".json_encode($v));
  1255. $matching = $this->matching($post['quantity'],$post['issku'],$dtc,$money,$int,$dtctitle,$shop,[
  1256. 'row_total'=>isset($v['row_total'])?$v['row_total']:"0",
  1257. 'price'=>isset($v['price'])?$v['price']:"0",
  1258. ]);
  1259. $price_tmp = isset($v['price'])?$v['price']:"0";
  1260. $row_total_tmp = isset($v['row_total'])?$v['row_total']:"0";
  1261. $tax_amount_tmp = isset($v['tax_amount'])?$v['tax_amount']:"0";
  1262. $discount_amount_tmp = isset($v['discount_amount'])?$v['discount_amount']:"0";
  1263. $product_ids_tmp = isset($v['product_ids'])?$v['product_ids']:"";
  1264. $extra_price = $this->tranExtraPrice($post['issku'],$post['quantity'],$price_tmp,$row_total_tmp,$tax_amount_tmp,$discount_amount_tmp,$product_ids_tmp);
  1265. $post['extra_price'] = json_encode($extra_price,JSON_UNESCAPED_UNICODE);
  1266. $post['shipremarks'] = $matching['title'];
  1267. $post['cost'] = $matching['cost'];
  1268. $post['purchase'] = $matching['purchase'];
  1269. $post['fpdata'] = $matching['product'];
  1270. $post['whlabel'] = $matching['whlabel'];
  1271. $post['slpx'] = $matching['wcslpx'];
  1272. return $post;
  1273. }
  1274. public function tranExtraPrice($issku,$org_qty,$org_price,$org_row_total,$org_tax_amount,$org_discount_amount,$product_ids_tmp){
  1275. $sku = explode(',',$issku);
  1276. $tmp_qty = explode(';',$org_qty);
  1277. $tmp_price = explode(",",$org_price);
  1278. $tmp_row_total = explode(",",$org_row_total);
  1279. $tmp_tax_amount = explode(",",$org_tax_amount);
  1280. $tmp_discount_amount = explode(",",$org_discount_amount);
  1281. $product_ids = explode(",",$product_ids_tmp);
  1282. $extra_price = [];
  1283. foreach ($sku as $k=>$value)
  1284. {
  1285. $qty = isset($tmp_qty[$k])?$tmp_qty[$k]:0;
  1286. $price = isset($tmp_price[$k])?$tmp_price[$k]:0;
  1287. $row_total = isset($tmp_row_total[$k])?$tmp_row_total[$k]:0;
  1288. $tax_amount = isset($tmp_tax_amount[$k])?$tmp_tax_amount[$k]:0;
  1289. $discount_amount = isset($tmp_discount_amount[$k])?$tmp_discount_amount[$k]:0;
  1290. $product_id = empty($product_ids[$k])?"":$product_ids[$k];
  1291. $extra_price[$k] = [
  1292. 'qty'=>$qty,
  1293. 'price'=>sprintf("%.2f",$price),
  1294. 'row_total'=> sprintf("%.2f",($row_total*1 - $discount_amount*1 + $tax_amount*1)) ,
  1295. 'sub_total'=>$price*$qty,
  1296. 'tax_amount'=>$tax_amount,
  1297. 'discount_amount'=>$discount_amount,
  1298. 'product_id'=>$product_id,
  1299. ];
  1300. }
  1301. return $extra_price;
  1302. }
  1303. /**
  1304. *
  1305. *
  1306. *
  1307. 匹配仓库品名、产品、成本
  1308. *
  1309. *
  1310. *
  1311. **/
  1312. public function matching($quantity,$issku,$dtc,$money,$int,$dtctitle,$shop=[],$extra = [])
  1313. {
  1314. $sl = explode(';',$quantity);
  1315. $x=0;$product = '';//product 每单多产品链接组合
  1316. $purchase = 0;$cost = 0;//每单所有产品总成本价格;
  1317. $whlabel = '|';//库存产品码
  1318. $cscs = array();$cscs = $issku;
  1319. $nr = '';$cs = array();
  1320. $t = array('/\-\-/','/\+/','/\#Color/','/\#Long/','/-[1-4]-/','/(\w+)~(\w+)-/');
  1321. $h = array('-','-','','','-','');
  1322. $issku = str_replace(array('(',')'),array('(',')'),$issku);
  1323. $issku = str_replace(array(' <','> '),array('<','>'),$issku);
  1324. $issku = strtolower($issku);
  1325. $varsku = preg_replace($t,$h,$issku);////转大写、匹配更改和删除
  1326. $varsku = strtolower($varsku);//转小写
  1327. $sku = explode(',',$varsku);//多产品分割为多数组
  1328. //根据要求添加了 row_total和商品单价
  1329. $row_total = [];
  1330. $price = [];
  1331. if(isset($extra['row_total'])){
  1332. $row_total_tmp = explode(',',$extra['row_total']);
  1333. foreach($sku as $k=>$v){
  1334. $row_total[$k] = isset($row_total_tmp[$k])?$row_total_tmp[$k]:0;
  1335. }
  1336. }else{
  1337. foreach($sku as $k=>$v){
  1338. $row_total[$k] = 0;
  1339. }
  1340. }
  1341. if(isset($extra['price'])){
  1342. $price_tmp = explode(',',$extra['price']);
  1343. foreach($sku as $k=>$v){
  1344. $price[$k] = isset($price_tmp[$k])?$price_tmp[$k]:0;
  1345. }
  1346. }else{
  1347. foreach($sku as $k=>$v){
  1348. $price[$k] = 0;
  1349. }
  1350. }
  1351. $pd = explode(',',$issku);
  1352. $slpx = array();
  1353. $tqjcskua = array();//先检测是否只匹配品名
  1354. $tqjcskub = array();
  1355. //添加price 和 row_total
  1356. $tqjcpricea = [];
  1357. $tqjcpriceb = [];
  1358. $tqjcrow_totala = [];
  1359. $tqjcrow_totalb = [];
  1360. $tqjcpircegit = [];
  1361. $tqjcqda = array();
  1362. $tqjcqdb = array();
  1363. $tqjcgit = array();//礼物类放SKU顺序中间
  1364. $tqjcgitpd = array();//礼物类放SKU顺序中间
  1365. foreach ($sku as $k=>$value)
  1366. {
  1367. //查找是否有头套和HD开始
  1368. $cid = array();
  1369. $cf = explode('-',trim($value,'-'));
  1370. $cf = array_filter($cf);
  1371. foreach ($cf as $v)
  1372. {
  1373. if(isset($dtc[$v]['id']) && isset($dtc[$v]['jm']))
  1374. {
  1375. $cid[$dtc[$v]['classid']] = array('id'=>$dtc[$v]['id'],'spare'=>$v,'jm'=>$dtc[$v]['jm']);
  1376. }
  1377. }
  1378. if(isset($cid['44']) && isset($cid['18']))
  1379. {
  1380. if(isset($dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['id']))
  1381. {
  1382. $value = '-'.$value.'-';
  1383. $sku[$k] = '-'.$sku[$k].'-';
  1384. $pd[$k] = '-'.$pd[$k].'-';
  1385. $value = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$value);
  1386. $value = str_replace('-'.$cid['44']['spare'],'-',$value);
  1387. $sku[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$sku[$k]);
  1388. $sku[$k] = str_replace('-'.$cid['44']['spare'],'-',$sku[$k]);
  1389. $pd[$k] = str_replace('-'.$cid['18']['spare'].'-','-'.$dtc[strtolower($cid['44']['jm']).$cid['18']['spare']]['spare'].'-',$pd[$k]);
  1390. $pd[$k] = str_replace('-'.$cid['44']['spare'],'-',$pd[$k]);
  1391. $value = strtolower(trim($value,'-'));
  1392. $pd[$k] = strtolower(trim($pd[$k],'-'));
  1393. $sku[$k] = strtolower(trim($sku[$k],'-'));
  1394. }
  1395. else if(stripos($value,'-transparent') !== false || stripos($value,'-tr') === false)
  1396. {
  1397. $value = str_replace(array('-transparent','-tr'),'',$value);
  1398. $sku[$k] = str_replace(array('-transparent','-tr'),'',$sku[$k]);
  1399. $pd[$k] = str_replace(array('-transparent','-tr'),'',$pd[$k]);
  1400. }
  1401. }
  1402. //查找是否有头套和HD结束
  1403. if(isset($dtc[$value]['classid']))
  1404. {
  1405. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  1406. {
  1407. $tqjcskua[$k] = $value;
  1408. $tqjcqda[$k] = $pd[$k];
  1409. $tqjcpricea[$k] = isset($price[$k])?$price[$k]:0;
  1410. $tqjcrow_totala[$k] = isset($row_total[$k])?$row_total[$k]:0;
  1411. continue;
  1412. }
  1413. }
  1414. if(stripos($value,'gift') !== false)
  1415. {
  1416. $tqjcgit[$k] = $value;
  1417. $tqjcpircegit[$k] = 0;
  1418. $tqjcgitpd[$k] = $pd[$k];
  1419. continue;
  1420. }
  1421. $tqjcskub[$k] = $value;
  1422. $tqjcqdb[$k] = $pd[$k];
  1423. $tqjcpriceb[$k] = isset($price[$k])?$price[$k]:0;
  1424. $tqjcrow_totalb[$k] = isset($row_total[$k])?$row_total[$k]:0;
  1425. }
  1426. $sku = $tqjcskub+$tqjcgit+$tqjcskua;
  1427. $price = $tqjcpriceb+$tqjcpircegit+$tqjcpricea;
  1428. $row_total = $tqjcrow_totalb+$tqjcpircegit+$tqjcrow_totala;
  1429. $newsl = array();
  1430. foreach ($sku as $k=>$value)
  1431. {
  1432. if(!isset($sl[$k]))
  1433. {
  1434. $sl[$k] = 1;
  1435. }
  1436. $newsl[] = $sl[$k];
  1437. }
  1438. $sl = array_values($newsl);
  1439. $pd = $tqjcqdb+$tqjcgitpd+$tqjcqda;
  1440. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  1441. $price = array_values($price);
  1442. $row_total = array_values($row_total);
  1443. // $this->logic_ding->sendToDing("测试获取订单数据SKU转化".json_encode($sku));
  1444. // $this->logic_ding->sendToDing("测试获取订单数据price转化".json_encode($price));
  1445. // $this->logic_ding->sendToDing("测试获取订单数据row_total转化".json_encode($row_total));
  1446. $pd = array_values($pd);
  1447. /**
  1448. $tqjcskua = array();//先检测是否只匹配品名
  1449. $tqjcskub = array();
  1450. foreach ($sku as $k=>$value)
  1451. {
  1452. if(isset($dtc[$value]['classid']))
  1453. {
  1454. if($dtc[$value]['classid'] == '999' || $dtc[$value]['classid'] == '9999')
  1455. {
  1456. $tqjcskua[$k] = $value;
  1457. continue;
  1458. }
  1459. }
  1460. $tqjcskub[$k] = $value;
  1461. }
  1462. $sku = $tqjcskub+$tqjcskua;
  1463. $sku = array_values($sku);//按照现有顺序键值重新由0开始
  1464. **/
  1465. foreach ($sku as $index=>$value)
  1466. {
  1467. $bmsku = '';
  1468. if(stripos($value,'-<') !== false && stripos($value,'>-') === false)
  1469. {
  1470. $isskufg = explode('-<',$value);
  1471. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1472. }
  1473. if(stripos($value,'-<') !== false && stripos($value,'>-') !== false)
  1474. {
  1475. $isskufg = explode('-<',$value);
  1476. $isskufgh = explode('>-',$isskufg[1]);
  1477. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1478. }
  1479. if(stripos($value,'-<') === false && stripos($value,'>-') !== false)
  1480. {
  1481. $isskufg = explode('>-',$value);
  1482. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1483. }
  1484. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') === false)
  1485. {
  1486. $isskufg = explode('-&lt;',$value);
  1487. $bmsku = '&lt;'.strtoupper($isskufg[1]);
  1488. }
  1489. if(stripos($value,'-&lt;') !== false && stripos($value,'&gt;-') !== false)
  1490. {
  1491. $isskufg = explode('-&lt;',$value);
  1492. $isskufgh = explode('&gt;-',$isskufg[1]);
  1493. $bmsku = '&lt;'.strtoupper($isskufgh[0]).'&gt;';
  1494. }
  1495. if(stripos($value,'-&lt;') === false && stripos($value,'&gt;-') !== false)
  1496. {
  1497. $isskufg = explode('&gt;-',$value);
  1498. $bmsku = strtoupper($isskufg[0]).'&gt;';
  1499. }
  1500. $value = trim($value,' ');$cpson = array();$cplf = array();
  1501. $thisid='';$tha=array();$thb=array();
  1502. $purchasemy=0;$costmy=0;$salespricemy=0;
  1503. $djay = array();//每单单个产品公司销售价格
  1504. $ptitlea='';$ptitleb='';//每单产品名称
  1505. $cpa='';$cpb='';$fc = 0;
  1506. $number = array('dc'=>'','c'=>'');
  1507. $classid = $this->classid->sku();
  1508. $pm = $classid;//品名顺序
  1509. //等级-真人发类型-化纤发编号-颜色-花型-蕾丝头套种类-化纤头套类型-多尺寸-单尺寸-Clip类型-礼物类型-马尾类型-重量-长度-头路设计-蕾丝尺寸25-蕾丝尺寸26-类型-密度-发帽大小-蕾丝颜色-化纤其它属性-头套其它属性-头套属性 100为头套额外附加
  1510. $cp = array(16=>126,22=>'',13=>80,14=>'',43=>'',8=>57,15=>'');//产品默认ID内容
  1511. //16->类目、22->真人发类型、13->等级、14->长度、8->颜色、15->曲度(花型)
  1512. $cptt = array(16=>128,13=>80,43=>'',8=>'57',15=>'',18=>'',6=>30,10=>72,9=>'',44=>'',39=>'',50=>'',51=>'');//头套
  1513. $cpcp = array(16=>130,13=>80,14=>'',33=>'',8=>57,15=>'',38=>'',7=>'');//卡子发,7=>33重量
  1514. $cpgi = array(16=>131,34=>'');//礼物
  1515. //$cpac = array(16=>133,35=>'',7=>'');//配件
  1516. //类目 等级 13 配件类型 35 配件其它 45 (头发)颜色 8 曲度 15 单包片数 38 重量 7 重新修订 不过需要根据cp来判断
  1517. $cpac = array(16=>133,35=>'',45=>'',38=>'',7=>'');//配件
  1518. $cphxtt = array(16=>1297,13=>80,14=>'',40=>'',8=>57,15=>'',41=>'',42=>'');
  1519. $cphxhair = array(16=>1702,13=>80,14=>'',47=>'',46=>'',8=>57,15=>'',38=>'',48=>'');
  1520. 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)
  1521. {
  1522. $u27 = (stripos($pd[$x],'SilkBaseFrontal') !== false)?199:197;
  1523. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,26=>191,9=>'',44=>'');//蕾丝发块
  1524. $fc = 1;
  1525. }
  1526. 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]))
  1527. {
  1528. $u27 = (stripos($pd[$x],'SilkBaseClosure') !== false)?196:195;
  1529. $cplf = array(16=>127,27=>$u27,12=>75,10=>72,25=>182,9=>'',44=>'');//蕾丝发块
  1530. if(stripos($pd[$x],'2*6') !== false)
  1531. {
  1532. $cplf[12] = 76;
  1533. }
  1534. $fc = 1;
  1535. }
  1536. $cpcppd = 0;
  1537. $cpcptype = $this->typeclass->find_all("classid = 33");
  1538. foreach ($cpcptype as $v)
  1539. {
  1540. $val = explode('|',trim($v['spare'],'|'));
  1541. foreach ($val as $vv)
  1542. {
  1543. if(stripos('-'.$pd[$x].'-','-'.$vv.'-') !== false)
  1544. {
  1545. $cpcppd++;
  1546. }
  1547. }
  1548. }
  1549. if($fc==1)
  1550. {
  1551. $cpson = $cplf;
  1552. }
  1553. 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)//
  1554. {
  1555. $cpson = $cptt;
  1556. }
  1557. else if ((stripos($pd[$x],'SyHair') !== false || (stripos($pd[$x],'SyHair') !== false && stripos($pd[$x],'Syn') !== false)) && $cpcppd == 0)
  1558. {
  1559. $cpson = $cphxhair;
  1560. $cp = $cpson;
  1561. }
  1562. else if (stripos($pd[$x],'Syn') !== false && $cpcppd == 0)
  1563. {
  1564. $cpson = $cphxtt;
  1565. $cp = $cpson;
  1566. }
  1567. else if ($cpcppd > 0)
  1568. {
  1569. $cpson = $cpcp;
  1570. $cp = $cpcp;
  1571. }
  1572. else if (stripos($pd[$x],'Gift') !== false)
  1573. {
  1574. $cpson = $cpgi;
  1575. }
  1576. else if (stripos($pd[$x],'Accs') !== false)
  1577. {
  1578. $cpson = $cpac;
  1579. }
  1580. else
  1581. {
  1582. $cpson = $cp;
  1583. }
  1584. //$cpson = $fc==1?$cplf:((stripos($pd[$x],'wig') !== false || stripos($pd[$x],'Bob') !== false)?$cptt:(stripos($pd[$x],'Clip') !== false?$cpcp:array()));//是否是类似发块或头套产品
  1585. $cs[$x] = $cpson;
  1586. $son = explode('-',$value);//字符串转数组
  1587. $snum = 0;$cpsl = 0;
  1588. foreach ($son as $val)
  1589. {
  1590. if(stripos($val,'^') !== false)
  1591. {
  1592. $snum += str_replace('^','',$val);
  1593. }
  1594. if(isset($dtc[$val]))//如果能匹配到
  1595. {
  1596. if(is_numeric($val) || $dtc[$val]['classid'] == '14')//如果是组合产品
  1597. {
  1598. $cpsl++;
  1599. if(!is_numeric($val))
  1600. {
  1601. $pm['c'] = $dtc[$val]['zh'];
  1602. }
  1603. else
  1604. {
  1605. $pm['c'] = $val.'寸';//尺寸不匹配,并且准备写入到+号后面
  1606. }
  1607. $number['c'] = $val;
  1608. }
  1609. else
  1610. {
  1611. if(isset($cp[$dtc[$val]['classid']]))//判断匹配ID属于头部还是尾部
  1612. {
  1613. $cp[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1614. }
  1615. if(isset($cpson[$dtc[$val]['classid']]))
  1616. {
  1617. if($dtc[$val]['id'] != 66)//按要求暂时不匹配中棕颜色
  1618. {
  1619. $cpson[$dtc[$val]['classid']] = $dtc[$val]['id'];
  1620. }
  1621. }
  1622. /**
  1623. if($pm[15] == '卡子发卡子发' || $dtc[$val]['zh'] == '卡子发卡子发')
  1624. {
  1625. $slpx[] = 1;
  1626. $pm[$dtc[$val]['classid']] = $pm[$dtc[$val]['classid']].' '.$dtc[$val]['zh'];
  1627. }
  1628. else
  1629. **/
  1630. if($dtc[$val]['classid'] == '999')
  1631. {
  1632. $pm[$dtc[$val]['classid']] .= $dtc[$val]['zh'];//其它正常匹配
  1633. }
  1634. else
  1635. {
  1636. $pm[$dtc[$val]['classid']] = $dtc[$val]['zh'];//其它正常匹配
  1637. }
  1638. }
  1639. }
  1640. else if(preg_match('/((\d+)\s+(\d+))/',$val) && stripos($val,'NO') === false)//如果不能匹配是多尺寸字符串
  1641. {
  1642. $j = (stripos($pd[$x],'+') !== false)?' +':'';//判断sku是否是+号类型
  1643. if(isset($cpson[16]))
  1644. {
  1645. if($cpson[16] != 128)
  1646. {
  1647. $cpslnum = explode(' ',trim($val,' '));
  1648. $cpsl += count($cpslnum);
  1649. $pm['dc'] = $val.$j;//写入多尺寸字符串
  1650. }
  1651. }
  1652. else
  1653. {
  1654. $cpslnum = explode(' ',trim($val,' '));
  1655. $cpsl += count($cpslnum);
  1656. $pm['dc'] = $val.$j;
  1657. }
  1658. $number['dc'] = $val;
  1659. }
  1660. }
  1661. if($sl[$x] > 1 || $snum > 1)
  1662. {
  1663. $slx = $sl[$x];
  1664. if($snum>1)
  1665. {
  1666. $slx = ($slx>1)?$slx:1;
  1667. $slx *= $snum;
  1668. }
  1669. $slpx[] = $cpsl;
  1670. $nr .= '['.$bmsku.implode(" ",$pm).']*'.$slx.'包'.';';//数组转字符串
  1671. }
  1672. else
  1673. {
  1674. if($cpsl > 0)
  1675. {
  1676. $slpx[] = $cpsl;
  1677. }
  1678. $slx = 1;
  1679. $pdpm = $bmsku.implode("",$pm);
  1680. if($pdpm != '')
  1681. {
  1682. $nr .= $bmsku.implode(" ",$pm).';';//数组转字符串
  1683. }
  1684. }
  1685. //以下是特殊类型的匹配
  1686. if(stripos($nr,'带绒布内衬半蕾丝头套') !== false && stripos($nr,'#') !== false)
  1687. {
  1688. $nr = preg_replace('/\#(\d+)/','内衬颜色$1号色',$nr);
  1689. }
  1690. $weightsku = array();
  1691. $weightdata = $this->weight->find_all();
  1692. foreach ($weightdata as $w)
  1693. {
  1694. $weightsku[$w['features']] = $w['weight'];
  1695. }
  1696. if($number['dc'] != '')
  1697. {
  1698. if(stripos($pd[$x],'+') !== false)
  1699. {
  1700. foreach ($cp as $v)
  1701. {
  1702. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1703. }
  1704. }
  1705. else
  1706. {
  1707. foreach ($cpson as $v)
  1708. {
  1709. $ptitlea .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1710. }
  1711. }
  1712. $dc = explode(' ',trim($number['dc'],' '));
  1713. for($i=0;$i<count($dc);$i++)
  1714. {
  1715. if(isset($dtc[$dc[$i]]['id']))
  1716. {
  1717. $thisid = $dtc[$dc[$i]]['id'];
  1718. /**
  1719. $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);
  1720. **/
  1721. //一样的不再合并
  1722. $tha[] = array('zh'=>$dc[$i],'id'=>$thisid,'count'=>1);
  1723. }
  1724. }
  1725. foreach ($tha as $v)
  1726. {
  1727. $item = array_merge($cp);$weight = 0;
  1728. if($cp['16'] == '126')
  1729. {
  1730. $weight = $weightsku['126'];
  1731. }
  1732. else if($cp['16'] == '127')
  1733. {
  1734. if(isset($item[9]))
  1735. {
  1736. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  1737. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  1738. if(isset($weightsku[$sku127a]))
  1739. {
  1740. $weight = $weightsku[$sku127a];
  1741. }
  1742. else if(isset($weightsku[$sku127b]))
  1743. {
  1744. $weight = $weightsku[$sku127b];
  1745. }
  1746. }
  1747. }
  1748. else if($cp['16'] == '128')
  1749. {
  1750. if(isset($item[8]))
  1751. {
  1752. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  1753. if(isset($weightsku[$sku128]))
  1754. {
  1755. $weight = $weightsku[$sku128];
  1756. }
  1757. }
  1758. }
  1759. $cpa = $cp;$cpa[14] = $v['id'];$cpa[22] = '';//增加长度ID、去除真人发类型
  1760. $whlabel .= implode("",$cpa).'-'.$slx*$v['count'].'-0|';
  1761. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  1762. $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1763. // if(isset($price[$index])){
  1764. // $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;';
  1765. // }else{
  1766. // $product .= $v['id'].',-'.rtrim(implode("-",$cp),'-').'-|'.$ptitlea.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1767. // }
  1768. }
  1769. }
  1770. if($number['c'] != '')
  1771. {
  1772. $fk = $cp;
  1773. foreach ($cpson as $k=>$v)
  1774. {
  1775. $fk[$k] = $v;//+号左右ID合并右完整ID
  1776. }
  1777. if(isset($fk[16]) && ($fk[16] ==133)){
  1778. $tmp = $this->logic_match->doAction($fk);
  1779. if(!empty($tmp)){
  1780. $fk = $tmp;
  1781. }
  1782. }
  1783. foreach ($fk as $v)
  1784. {
  1785. $ptitleb .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1786. }
  1787. $c = explode(' ',trim($number['c'],' '));
  1788. for($i=0;$i<count($c);$i++)
  1789. {
  1790. $thisid = $dtc[$c[$i]]['id'];
  1791. /**
  1792. $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);
  1793. **/
  1794. //一样的不再合并
  1795. $thb[] = array('zh'=>$c[$i],'id'=>$thisid,'count'=>1);
  1796. }
  1797. foreach ($thb as $v)
  1798. {
  1799. $item = array_merge($fk);$weight = 0;
  1800. if($fk['16'] == '126')
  1801. {
  1802. $weight = $weightsku[$item[0]];
  1803. }
  1804. else if($fk['16'] == '127')
  1805. {
  1806. if(isset($item[9]))
  1807. {
  1808. $sku127a = $item[0].'-'.$v['id'].'-'.$item[3].'-'.$item[6].'-'.$item[9];
  1809. $sku127b = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[9];
  1810. if(isset($weightsku[$sku127a]))
  1811. {
  1812. $weight = $weightsku[$sku127a];
  1813. }
  1814. else if(isset($weightsku[$sku127b]))
  1815. {
  1816. $weight = $weightsku[$sku127b];
  1817. }
  1818. }
  1819. }
  1820. else if($fk['16'] == '128')
  1821. {
  1822. if(isset($item[8]))
  1823. {
  1824. $sku128 = $item[0].'-'.$v['id'].'-'.$item[6].'-'.$item[8];
  1825. if(isset($weightsku[$sku128]))
  1826. {
  1827. $weight = $weightsku[$sku128];
  1828. }
  1829. }
  1830. }
  1831. //var_dump($fk);
  1832. $cpb = $fk;$cpb[14] = $v['id'];$cpb[22] = '';//增加长度ID、去除真人发类型
  1833. $whlabel .= implode("",$cpb).'-'.$slx*$v['count'].'-0|';
  1834. $pdcc = (is_numeric($v['zh']))?$v['zh'].'inch |':strtoupper($v['zh']).'|';
  1835. // if(isset($price[$index])){
  1836. // $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;';
  1837. // }else{
  1838. // $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1839. // }
  1840. $product .= $v['id'].',-'.rtrim(implode("-",$fk),'-').'-|'.$ptitleb.$pdcc.$slx*$v['count'].'|0|0|'.$v['zh'].'|0|0|'.$slx*$v['count']*$weight.'|0;';
  1841. }
  1842. }
  1843. if (stripos($pd[$x],'Gift-') !== false)
  1844. {
  1845. $ptitleg = '';
  1846. foreach ($cpson as $v)
  1847. {
  1848. $ptitleg .= isset($dtctitle[$v])?$dtctitle[$v].' ':'';
  1849. }
  1850. $whlabel .= implode("",$cpson).'-'.$slx.'-0|';
  1851. // if(isset($price[$index])){
  1852. // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|'.$price[$index].'|'.$row_total[$index].'||0|0|0|0;';
  1853. // }else{
  1854. // $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  1855. // }
  1856. $product .= '-'.rtrim(implode("-",$cpson),'-').'-|'.$ptitleg.'|'.$slx.'|0|0||0|0|0|0;';
  1857. }
  1858. $x++;
  1859. $purchase += $purchasemy;
  1860. $cost += $costmy;
  1861. }
  1862. $product = str_replace('--','-',$product);
  1863. $qbslpx = 0;$wcslpx = '';
  1864. foreach ($slpx as $v)
  1865. {
  1866. $wcslpx .= $qbslpx.'-'.($qbslpx+$v).'|';
  1867. $qbslpx += $v;
  1868. }
  1869. $nr = str_replace(array('(',')'),array('(',')'),$nr);
  1870. if(stripos($whlabel,'|--|') !== false)
  1871. {
  1872. $whlabel = '';
  1873. $product = '';
  1874. }
  1875. 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);
  1876. }
  1877. public function get_headgear($data)
  1878. {
  1879. $ch = curl_init();
  1880. $url = 'http://54.190.55.35/application/main.php';
  1881. curl_setopt($ch,CURLOPT_URL,$url);
  1882. curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
  1883. curl_setopt($ch,CURLOPT_HEADER,0);
  1884. curl_setopt($ch,CURLOPT_POST, 1);
  1885. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,120);
  1886. //设置post数据
  1887. $post = array();
  1888. $post['timestamp'] = time();
  1889. $post['key'] = substr(md5($post['timestamp'].'.wigs'),1,20);
  1890. $post['data'] = $data;
  1891. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1892. $res = curl_exec($ch);
  1893. curl_close($ch);
  1894. $res = json_decode($res,true);
  1895. if(isset($res))
  1896. {
  1897. return $res;
  1898. }
  1899. }
  1900. public function get_paypal($v)
  1901. {
  1902. if($v['express'] == 7 || $v['express'] == 51)
  1903. {
  1904. return 'GES不需要发送';exit;
  1905. }
  1906. if($v['shop'] == 5){
  1907. return "Shopify不需要发送";
  1908. }
  1909. $post = array();
  1910. $orderinfo = preg_replace('/^' . preg_quote($v['shop'], '/') . '/', '', $v['orderinfo']);
  1911. $post['incrementId'] = $orderinfo;
  1912. $post['trackingNumber'] = $v['waybill'];
  1913. $post['carrier'] = $v['iscode'];
  1914. $url = 'https://www.'.$v['url'].'.com/applepay/payment/addTrack';
  1915. $ch = curl_init();
  1916. curl_setopt($ch,CURLOPT_URL,$url);
  1917. curl_setopt($ch, CURLOPT_POST, 1);
  1918. curl_setopt($ch, CURLOPT_HEADER, 0);
  1919. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
  1920. curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
  1921. curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
  1922. curl_setopt($ch, CURLOPT_POSTFIELDS,http_build_query($post));
  1923. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  1924. curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,1800000);
  1925. $res = curl_exec($ch);
  1926. curl_close($ch);
  1927. return $res;
  1928. }
  1929. } //end class