Model_api.php 59 KB

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