Model_api.php 65 KB

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