Model_api.php 57 KB

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