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