Model_api.php 76 KB

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