Skutoysjm.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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 > 12){
  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 > 20){
  43. $this->_json_error("每次转换不允许超过20个",400 ,$data = []);
  44. }
  45. $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');
  46. $dtc = array();
  47. foreach ($dictionaries as $v) {
  48. if (stripos($v['spare'], '|') !== false) //如果有多个值
  49. {
  50. $v['spare'] = explode('|', $v['spare']);
  51. foreach ($v['spare'] as $k => $vs) {
  52. if (stripos($v['zh'], '|') !== false) {
  53. $vzh = explode('|', $v['zh']);
  54. $dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $vzh[$k], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
  55. } else {
  56. $dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
  57. }
  58. }
  59. } else {
  60. $dtc[strtolower($v['spare'])] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $v['spare']);
  61. }
  62. }
  63. $dtctitle = [];
  64. $dictionaries2 = $this->typeclass->find_all();
  65. foreach ($dictionaries2 as $v) {
  66. $dtctitle[$v['id']] = $v['title'];
  67. }
  68. /* 匹配结束 */
  69. /* 价格加入 */
  70. $money = array();
  71. $productdescribe = $this->productdescribe->find_all('1=1');
  72. foreach ($productdescribe as $v) {
  73. $money[$v['number']] = array();
  74. }
  75. /* 价格加入 */
  76. /* 匹配ID加入 */
  77. $int = array();
  78. $intdata = $this->typeclass->find_all('classid=14', 'id,spare');
  79. foreach ($intdata as $v) {
  80. $v['spare'] = explode('|', $v['spare']);
  81. $int[$v['id']] = $v['spare'][0];
  82. }
  83. /* 匹配ID加入 */
  84. $zjsku = array();
  85. $shopsku = $this->shopsku->find_all();
  86. foreach ($shopsku as $val) {
  87. $ss = explode(',', trim($val['shop'], ','));
  88. foreach ($ss as $v) {
  89. if (isset($zjsku[$v])) {
  90. $zjsku[$v] .= ',' . trim($val['sku'], ',');
  91. } else {
  92. $zjsku[$v] = trim($val['sku'], ',');
  93. }
  94. }
  95. }
  96. $shop = $this->shop->read(19);
  97. $final_all = [];
  98. $typeclass = [];
  99. $classid = $this->classid->sku();
  100. $tcall = $this->typeclass->find_all();
  101. foreach ($tcall as $v)
  102. {
  103. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  104. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  105. }
  106. foreach($data['sku_list'] as $k => $v){
  107. $q = '1;';
  108. $org_sku = $sku = $v;
  109. if (isset($zjsku[$shop['id']])) //判断是否找到店铺SKU
  110. {
  111. $sku = rtrim($v, ',') . ',' . $zjsku[$shop['id']];
  112. }
  113. $ret = $this->getU9Lh($q,$sku,$dtc,$money,$int,$dtctitle, $shop,$classid,$typeclass,$org_sku);
  114. $final_all[] = $ret;
  115. }
  116. $this->_json_error("获取成功",200 ,$final_all);
  117. }
  118. protected function getU9Lh($q,$sku,$dtc,$money,$int,$dtctitle, $shop,$classid,$typeclass,$org_sku){
  119. $r = $this->api->matching(trim($q, ';'), $sku, $dtc, $money, $int, $dtctitle, $shop);
  120. $p = '';
  121. $product = explode(';', trim($r['product'], ';'));
  122. if ($r['title'] != '' && $product) {
  123. foreach ($product as $v) {
  124. $vc = explode('|', $v);
  125. if(isset($vc[1])){
  126. $p .= $vc[1] . '<br>';
  127. }
  128. }
  129. $tmp_str = $r['product'];
  130. $tmp_arr = explode(";",$tmp_str);
  131. $tmp_list = [];
  132. foreach($tmp_arr as $k=>$v){
  133. if(empty($v)){
  134. continue;
  135. }
  136. $tmp_str1 = str_replace(array('-163-','-164-','-165-','-166-'),'-',$v);
  137. $tmp_arr1 = explode('|',trim($tmp_str1,'|'));
  138. if(stripos($tmp_arr1[0],',') !== false){
  139. $ft = explode(',',$tmp_arr1[0]);
  140. $features = explode('-',trim($ft[1],'-'));
  141. $features[] = $ft[0];
  142. }else{
  143. $features = explode('-',trim($tmp_arr1[0],'-'));
  144. }
  145. $sku = implode("-",$features);
  146. $u9_data = $this->logic_u9tools->getOneU9bm($sku,$classid,$typeclass);
  147. $tmp_list[] = $u9_data;
  148. }
  149. return [
  150. "sku"=>$org_sku,
  151. "list"=> $tmp_list,
  152. ];
  153. } else {
  154. return [
  155. "sku"=>$org_sku,
  156. "list"=>[],
  157. ];
  158. }
  159. }
  160. }