Model_api.php 63 KB

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