Model_api.php 60 KB

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