Skutoysjm.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343
  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. //获取订单信息
  161. public function getorderlist(){
  162. $this->_json_error("请找公司授权",400 ,$data = []);
  163. $json_str = $this->input->raw_input_stream;
  164. $data = json_decode($json_str,true);
  165. $table_name = "";
  166. if($data['plat'] == 'dlz'){
  167. $table_name = "fullorder";
  168. }
  169. if($data['plat'] == 'smt'){
  170. $table_name = "fullordersmt";
  171. }
  172. if($data['plat'] == 'tt'){
  173. $table_name = "fullordertt";
  174. }
  175. if($data['plat'] == 'amz'){
  176. $table_name = "fullorderamz";
  177. }
  178. if(empty($data['plat'])){
  179. $this->_json_error("平台未配置",400 ,$data = []);
  180. }
  181. $token = $data['token'];
  182. if(empty($token)){
  183. $this->_json_error("无权访问该方法",404 ,$data = []);
  184. }
  185. $jiemi_str = $this->logic_tools->toolsjiemi($token,$this->key,$this->iv);
  186. $now_time = time();
  187. $jiemi_arr = explode("+",$jiemi_str);
  188. $jiemi_key = isset($jiemi_arr[0])?$jiemi_arr[0]:"";
  189. $jiemi_time = isset($jiemi_arr[1])?$jiemi_arr[1]:"";
  190. if( $now_time - $jiemi_time > 12){
  191. $this->_json_error("请求已超时",404 ,$data = []);
  192. }
  193. if($jiemi_key != $this->salt_str){
  194. $this->_json_error("凭证不正确",404 ,$data = []);
  195. }
  196. if(empty($data['start_time'])){
  197. $this->_json_error("筛选开始时间不能为空",400 ,$data = []);
  198. }
  199. if(empty($data['end_time'])){
  200. $this->_json_error("结束开始时间不能为空",400 ,$data = []);
  201. }
  202. if(!in_array($data['plat'],['dlz','smt','tt','amz'])){
  203. $this->_json_error("平台参数错误",400 ,$data = []);
  204. }
  205. $page = empty($data['page'])?1:$data['page'];
  206. $size = empty($data['size'])?50:$data['size'];
  207. $start_ts = ($page - 1) * $size;
  208. if($start_ts < 0){
  209. $this->_json_error("页码参数错误",400 ,$data = []);
  210. }
  211. if($size > 500){
  212. $this->_json_error("每次请求条数不能超过500条",400 ,$data = []);
  213. }
  214. $list = $this->db->select('id,number ,shop, dtime,fpdata')->where("dtime >= ", $data['start_time'])
  215. ->where("dtime <= ", $data['end_time'])
  216. ->limit($size,$start_ts)
  217. ->get($table_name)
  218. ->result_array();
  219. if(empty($list)){
  220. $list = [];
  221. $this->_json_error("SUCCESS",200 ,[]);
  222. }
  223. $typeclass = [];
  224. $classid = $this->classid->sku();
  225. $tcall = $this->typeclass->find_all();
  226. foreach ($tcall as $v)
  227. {
  228. //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
  229. $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
  230. }
  231. $shop_list = $this->shop->find_all();
  232. $shop_list = array_column($shop_list,"shopname","id");
  233. $final_all = [];
  234. foreach($list as $k => $v){
  235. if(empty($v['fpdata'])){
  236. $final_all[] = [
  237. "shop"=>$v['shop'],
  238. "shop_name"=>isset($shop_list[$v['shop']])?$shop_list[$v['shop']]:"",
  239. "number"=>$v['number'],
  240. 'dtime'=>$v['dtime'],
  241. 'dtime_show'=>date("Y-m-d H:i:s",$v['dtime']),
  242. "u9_code"=>"",
  243. "qty"=>0,
  244. "en"=>"",
  245. "zh"=>"",
  246. ];
  247. continue;
  248. }
  249. $tmp = explode(';',trim($v['fpdata'],";"));
  250. foreach($tmp as $key => $val){
  251. $arr_tmp = explode('|',$val);
  252. if(strpos($arr_tmp[0],',')!== false){
  253. $sku = "-".str_replace(',','-',$arr_tmp[0]);
  254. }else{
  255. $sku = $arr_tmp[0];
  256. }
  257. $r = $this->logic_u9tools->getOneU9bmHasGift($sku,$classid,$typeclass);
  258. $final_all[] = [
  259. "shop"=>$v['shop'],
  260. "shop_name"=>isset($shop_list[$v['shop']])?$shop_list[$v['shop']]:"",
  261. "number"=>$v['number'],
  262. 'dtime'=>$v['dtime'],
  263. 'dtime_show'=>date("Y-m-d H:i:s",$v['dtime']),
  264. "u9_code"=>$r['jm'],
  265. "qty"=>$arr_tmp[2],
  266. "en"=>$arr_tmp[1],
  267. "zh"=>$r['zh'],
  268. ];
  269. }
  270. }
  271. //
  272. $this->_json_error("SUCCESS",200 ,$final_all);
  273. }
  274. }