Model_api.php 60 KB

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