Model_api.php 66 KB

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