Skutoysjm.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. defined('BASEPATH') OR exit('No direct script access allowed');
  3. class Skutoysjm extends Lyapi_Controller
  4. {
  5. public function __construct()
  6. {
  7. parent::__construct();
  8. $this->load->_model("Model_api","api");
  9. $this->load->_model('Model_shopsku', 'shopsku');
  10. $this->load->_model('Model_classid', 'classid');
  11. $this->load->_model('Model_typeclass', 'typeclass');
  12. $this->load->_model('Model_productdescribe','productdescribe');
  13. $this->load->_model('Model_shopsku','shopsku');
  14. $this->load->_model("Model_shop","shop");
  15. $this->load->_model("Model_logic_u9tools","logic_u9tools");
  16. }
  17. private $key ="xcly!&20260923HN"; //加密所需要到的key
  18. private $iv ="dlzsmt@260923wdq";//加密所需要到的iv
  19. private $salt_str = "xcly!skutoyslh&0923";
  20. public function getlist(){
  21. $json_str = $this->input->raw_input_stream;
  22. $data = json_decode($json_str,true);
  23. $token = $data['token'];
  24. if(empty($token)){
  25. $this->_json_error("无权访问该方法",404 ,$data = []);
  26. }
  27. $jiemi_str = $this->logic_tools->toolsjiemi($token,$this->key,$this->iv);
  28. $now_time = time();
  29. $jiemi_arr = explode("+",$jiemi_str);
  30. $jiemi_key = isset($jiemi_arr[0])?$jiemi_arr[0]:"";
  31. $jiemi_time = isset($jiemi_arr[1])?$jiemi_arr[1]:"";
  32. // if( $now_time - $jiemi_time > 2){
  33. // $this->_json_error("请求已超时",404 ,$data = []);
  34. // }
  35. if($jiemi_key != $this->salt_str){
  36. $this->_json_error("凭证不正确",404 ,$data = []);
  37. }
  38. if(empty($data['sku_list'])){
  39. $this->_json_error("请求数据为空",400 ,$data = []);
  40. }
  41. $len = count($data['sku_list']);
  42. if($len > 1){
  43. $this->_json_error("每次转换不允许超过1个",400 ,$data = []);
  44. }
  45. $sku = implode(",",$data['sku_list']);
  46. $dictionaries = $this->typeclass->find_all('spare!= "" and classid != 1 and classid != 2 and classid != 3 and classid != 4 and classid != 5 and classid != 11 and classid != 16 and classid != 17 and classid != 20 and classid != 21 and classid != 23 and classid != 24 and classid != 29 and classid != 30 and classid != 31 and classid != 32');
  47. $dtc = array();
  48. foreach ($dictionaries as $v) {
  49. if (stripos($v['spare'], '|') !== false) //如果有多个值
  50. {
  51. $v['spare'] = explode('|', $v['spare']);
  52. foreach ($v['spare'] as $k => $vs) {
  53. if (stripos($v['zh'], '|') !== false) {
  54. $vzh = explode('|', $v['zh']);
  55. $dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $vzh[$k], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
  56. } else {
  57. $dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
  58. }
  59. }
  60. } else {
  61. $dtc[strtolower($v['spare'])] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $v['spare']);
  62. }
  63. }
  64. $dtctitle = [];
  65. $dictionaries2 = $this->typeclass->find_all();
  66. foreach ($dictionaries2 as $v) {
  67. $dtctitle[$v['id']] = $v['title'];
  68. }
  69. /* 匹配结束 */
  70. /* 价格加入 */
  71. $money = array();
  72. $productdescribe = $this->productdescribe->find_all('1=1');
  73. foreach ($productdescribe as $v) {
  74. $money[$v['number']] = array();
  75. }
  76. /* 价格加入 */
  77. /* 匹配ID加入 */
  78. $int = array();
  79. $intdata = $this->typeclass->find_all('classid=14', 'id,spare');
  80. foreach ($intdata as $v) {
  81. $v['spare'] = explode('|', $v['spare']);
  82. $int[$v['id']] = $v['spare'][0];
  83. }
  84. /* 匹配ID加入 */
  85. $zjsku = array();
  86. $shopsku = $this->shopsku->find_all();
  87. foreach ($shopsku as $val) {
  88. $ss = explode(',', trim($val['shop'], ','));
  89. foreach ($ss as $v) {
  90. if (isset($zjsku[$v])) {
  91. $zjsku[$v] .= ',' . trim($val['sku'], ',');
  92. } else {
  93. $zjsku[$v] = trim($val['sku'], ',');
  94. }
  95. }
  96. }
  97. /* 匹配ID结束 */
  98. $q = '';
  99. $quantity = explode(',', trim($sku, ','));
  100. foreach ($quantity as $v) {
  101. $q .= '1;';
  102. }
  103. $shop = $this->shop->read(19);
  104. if (isset($zjsku[$shop['id']])) //判断是否找到店铺SKU
  105. {
  106. $sku = rtrim($sku, ',') . ',' . $zjsku[$shop['id']];
  107. }
  108. $r = $this->api->matching(trim($q, ';'), $sku, $dtc, $money, $int, $dtctitle, $shop);
  109. $p = '';
  110. $product = explode(';', trim($r['product'], ';'));
  111. if ($r['title'] != '' && $product) {
  112. foreach ($product as $v) {
  113. $vc = explode('|', $v);
  114. if(isset($vc[1])){
  115. $p .= $vc[1] . '<br>';
  116. }
  117. }
  118. $tmp_str = $r['product'];
  119. $tmp_arr = explode(";",$tmp_str);
  120. $list = [];
  121. foreach($tmp_arr as $k=>$v){
  122. $tmp_str1 = str_replace(array('-163-','-164-','-165-','-166-'),'-',$v);
  123. $tmp_arr1 = explode('|',trim($tmp_str1,'|'));
  124. if(stripos($tmp_arr1[0],',') !== false){
  125. $ft = explode(',',$tmp_arr1[0]);
  126. $features = explode('-',trim($ft[1],'-'));
  127. $features[] = $ft[0];
  128. }else{
  129. $features = explode('-',trim($tmp_arr1[0],'-'));
  130. }
  131. $sku = implode("-",$features);
  132. if(!empty($sku)){
  133. $list[] = [
  134. 'sku2'=>$sku,
  135. ];
  136. }
  137. }
  138. $u9_data = $this->logic_u9tools->getU9bm($list,'sku2');
  139. foreach($u9_data as $k => $v){
  140. unset($u9_data[$k]['sku2']);
  141. }
  142. $this->_json_error("获取成功",200 ,$data = [
  143. "sku"=>$data['sku_list'][0],
  144. "goods_list"=>$u9_data
  145. ]);
  146. } else {
  147. $this->_json_error("数据异常,请联系技术",400 ,$data = []);
  148. }
  149. }
  150. }