Model_api.php 68 KB

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