Model_api.php 58 KB

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