| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343 |
- <?php
- defined('BASEPATH') OR exit('No direct script access allowed');
- class Skutoysjm extends Lyapi_Controller
- {
- public function __construct()
- {
- parent::__construct();
- $this->load->_model("Model_api","api");
- $this->load->_model('Model_shopsku', 'shopsku');
- $this->load->_model('Model_classid', 'classid');
- $this->load->_model('Model_typeclass', 'typeclass');
- $this->load->_model('Model_productdescribe','productdescribe');
- $this->load->_model('Model_shopsku','shopsku');
- $this->load->_model("Model_shop","shop");
- $this->load->_model("Model_logic_u9tools","logic_u9tools");
- }
- private $key ="xcly!&20260923HN"; //加密所需要到的key
- private $iv ="dlzsmt@260923wdq";//加密所需要到的iv
- private $salt_str = "xcly!skutoyslh&0923";
- public function getlist(){
- $json_str = $this->input->raw_input_stream;
- $data = json_decode($json_str,true);
-
- $token = $data['token'];
- if(empty($token)){
- $this->_json_error("无权访问该方法",404 ,$data = []);
- }
- $jiemi_str = $this->logic_tools->toolsjiemi($token,$this->key,$this->iv);
- $now_time = time();
- $jiemi_arr = explode("+",$jiemi_str);
- $jiemi_key = isset($jiemi_arr[0])?$jiemi_arr[0]:"";
- $jiemi_time = isset($jiemi_arr[1])?$jiemi_arr[1]:"";
-
- if( $now_time - $jiemi_time > 12){
- $this->_json_error("请求已超时",404 ,$data = []);
- }
-
- if($jiemi_key != $this->salt_str){
- $this->_json_error("凭证不正确",404 ,$data = []);
- }
- if(empty($data['sku_list'])){
- $this->_json_error("请求数据为空",400 ,$data = []);
- }
- $len = count($data['sku_list']);
- if($len > 20){
- $this->_json_error("每次转换不允许超过20个",400 ,$data = []);
- }
-
- $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');
- $dtc = array();
- foreach ($dictionaries as $v) {
- if (stripos($v['spare'], '|') !== false) //如果有多个值
- {
- $v['spare'] = explode('|', $v['spare']);
- foreach ($v['spare'] as $k => $vs) {
- if (stripos($v['zh'], '|') !== false) {
- $vzh = explode('|', $v['zh']);
- $dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $vzh[$k], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
- } else {
- $dtc[strtolower($vs)] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $vs);
- }
- }
- } else {
- $dtc[strtolower($v['spare'])] = array('classid' => $v['classid'], 'zh' => $v['zh'], 'id' => $v['id'], 'jm' => $v['jm'], 'spare' => $v['spare']);
- }
- }
- $dtctitle = [];
- $dictionaries2 = $this->typeclass->find_all();
- foreach ($dictionaries2 as $v) {
- $dtctitle[$v['id']] = $v['title'];
- }
- /* 匹配结束 */
- /* 价格加入 */
- $money = array();
- $productdescribe = $this->productdescribe->find_all('1=1');
- foreach ($productdescribe as $v) {
- $money[$v['number']] = array();
- }
- /* 价格加入 */
- /* 匹配ID加入 */
- $int = array();
- $intdata = $this->typeclass->find_all('classid=14', 'id,spare');
- foreach ($intdata as $v) {
- $v['spare'] = explode('|', $v['spare']);
- $int[$v['id']] = $v['spare'][0];
- }
- /* 匹配ID加入 */
- $zjsku = array();
- $shopsku = $this->shopsku->find_all();
- foreach ($shopsku as $val) {
- $ss = explode(',', trim($val['shop'], ','));
- foreach ($ss as $v) {
- if (isset($zjsku[$v])) {
- $zjsku[$v] .= ',' . trim($val['sku'], ',');
- } else {
- $zjsku[$v] = trim($val['sku'], ',');
- }
- }
- }
- $shop = $this->shop->read(19);
- $final_all = [];
- $typeclass = [];
- $classid = $this->classid->sku();
-
- $tcall = $this->typeclass->find_all();
- foreach ($tcall as $v)
- {
- //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
- $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
- }
- foreach($data['sku_list'] as $k => $v){
- $q = '1;';
- $org_sku = $sku = $v;
- if (isset($zjsku[$shop['id']])) //判断是否找到店铺SKU
- {
- $sku = rtrim($v, ',') . ',' . $zjsku[$shop['id']];
-
- }
- $ret = $this->getU9Lh($q,$sku,$dtc,$money,$int,$dtctitle, $shop,$classid,$typeclass,$org_sku);
- $final_all[] = $ret;
- }
-
- $this->_json_error("获取成功",200 ,$final_all);
- }
- protected function getU9Lh($q,$sku,$dtc,$money,$int,$dtctitle, $shop,$classid,$typeclass,$org_sku){
- $r = $this->api->matching(trim($q, ';'), $sku, $dtc, $money, $int, $dtctitle, $shop);
- $p = '';
- $product = explode(';', trim($r['product'], ';'));
- if ($r['title'] != '' && $product) {
- foreach ($product as $v) {
- $vc = explode('|', $v);
- if(isset($vc[1])){
- $p .= $vc[1] . '<br>';
- }
-
- }
- $tmp_str = $r['product'];
-
- $tmp_arr = explode(";",$tmp_str);
- $tmp_list = [];
- foreach($tmp_arr as $k=>$v){
- if(empty($v)){
- continue;
- }
- $tmp_str1 = str_replace(array('-163-','-164-','-165-','-166-'),'-',$v);
- $tmp_arr1 = explode('|',trim($tmp_str1,'|'));
- if(stripos($tmp_arr1[0],',') !== false){
- $ft = explode(',',$tmp_arr1[0]);
- $features = explode('-',trim($ft[1],'-'));
- $features[] = $ft[0];
- }else{
- $features = explode('-',trim($tmp_arr1[0],'-'));
- }
- $sku = implode("-",$features);
- $u9_data = $this->logic_u9tools->getOneU9bm($sku,$classid,$typeclass);
- $tmp_list[] = $u9_data;
- }
-
-
-
-
- return [
- "sku"=>$org_sku,
- "list"=> $tmp_list,
- ];
- } else {
- return [
- "sku"=>$org_sku,
- "list"=>[],
- ];
- }
-
- }
- //获取订单信息
- public function getorderlist(){
- $this->_json_error("请找公司授权",400 ,$data = []);
- $json_str = $this->input->raw_input_stream;
- $data = json_decode($json_str,true);
- $table_name = "";
- if($data['plat'] == 'dlz'){
- $table_name = "fullorder";
- }
- if($data['plat'] == 'smt'){
- $table_name = "fullordersmt";
- }
- if($data['plat'] == 'tt'){
- $table_name = "fullordertt";
- }
- if($data['plat'] == 'amz'){
- $table_name = "fullorderamz";
- }
- if(empty($data['plat'])){
- $this->_json_error("平台未配置",400 ,$data = []);
- }
- $token = $data['token'];
- if(empty($token)){
- $this->_json_error("无权访问该方法",404 ,$data = []);
- }
- $jiemi_str = $this->logic_tools->toolsjiemi($token,$this->key,$this->iv);
-
- $now_time = time();
- $jiemi_arr = explode("+",$jiemi_str);
- $jiemi_key = isset($jiemi_arr[0])?$jiemi_arr[0]:"";
- $jiemi_time = isset($jiemi_arr[1])?$jiemi_arr[1]:"";
-
- if( $now_time - $jiemi_time > 12){
- $this->_json_error("请求已超时",404 ,$data = []);
- }
-
- if($jiemi_key != $this->salt_str){
- $this->_json_error("凭证不正确",404 ,$data = []);
- }
- if(empty($data['start_time'])){
- $this->_json_error("筛选开始时间不能为空",400 ,$data = []);
- }
- if(empty($data['end_time'])){
- $this->_json_error("结束开始时间不能为空",400 ,$data = []);
- }
- if(!in_array($data['plat'],['dlz','smt','tt','amz'])){
- $this->_json_error("平台参数错误",400 ,$data = []);
- }
- $page = empty($data['page'])?1:$data['page'];
- $size = empty($data['size'])?50:$data['size'];
- $start_ts = ($page - 1) * $size;
- if($start_ts < 0){
- $this->_json_error("页码参数错误",400 ,$data = []);
- }
- if($size > 500){
- $this->_json_error("每次请求条数不能超过500条",400 ,$data = []);
- }
-
- $list = $this->db->select('id,number ,shop, dtime,fpdata')->where("dtime >= ", $data['start_time'])
- ->where("dtime <= ", $data['end_time'])
- ->limit($size,$start_ts)
- ->get($table_name)
- ->result_array();
-
- if(empty($list)){
- $list = [];
- $this->_json_error("SUCCESS",200 ,[]);
- }
- $typeclass = [];
- $classid = $this->classid->sku();
- $tcall = $this->typeclass->find_all();
- foreach ($tcall as $v)
- {
- //$tcjm[$v['id']] = array($v['jm'],$v['classid']);
- $typeclass[$v['id']] = array('zh'=>$v['zh'],'classid'=>$v['classid'],'bm'=>$v['bm'],'title'=>$v['title'],'jm'=>$v['jm']);
- }
- $shop_list = $this->shop->find_all();
- $shop_list = array_column($shop_list,"shopname","id");
-
- $final_all = [];
- foreach($list as $k => $v){
- if(empty($v['fpdata'])){
- $final_all[] = [
- "shop"=>$v['shop'],
- "shop_name"=>isset($shop_list[$v['shop']])?$shop_list[$v['shop']]:"",
- "number"=>$v['number'],
- 'dtime'=>$v['dtime'],
- 'dtime_show'=>date("Y-m-d H:i:s",$v['dtime']),
- "u9_code"=>"",
- "qty"=>0,
- "en"=>"",
- "zh"=>"",
- ];
- continue;
- }
- $tmp = explode(';',trim($v['fpdata'],";"));
- foreach($tmp as $key => $val){
- $arr_tmp = explode('|',$val);
- if(strpos($arr_tmp[0],',')!== false){
- $sku = "-".str_replace(',','-',$arr_tmp[0]);
- }else{
- $sku = $arr_tmp[0];
- }
- $r = $this->logic_u9tools->getOneU9bmHasGift($sku,$classid,$typeclass);
- $final_all[] = [
- "shop"=>$v['shop'],
- "shop_name"=>isset($shop_list[$v['shop']])?$shop_list[$v['shop']]:"",
- "number"=>$v['number'],
- 'dtime'=>$v['dtime'],
- 'dtime_show'=>date("Y-m-d H:i:s",$v['dtime']),
- "u9_code"=>$r['jm'],
- "qty"=>$arr_tmp[2],
- "en"=>$arr_tmp[1],
- "zh"=>$r['zh'],
- ];
- }
- }
- //
- $this->_json_error("SUCCESS",200 ,$final_all);
-
- }
- }
|