lvhao hai 1 día
pai
achega
144c004ee7
Modificáronse 1 ficheiros con 293 adicións e 1 borrados
  1. 293 1
      core/CoreApp/controllers/Goodimglibrary.php

+ 293 - 1
core/CoreApp/controllers/Goodimglibrary.php

@@ -9,6 +9,9 @@ class Goodimglibrary extends Start_Controller {
         $this->load->_model("Model_logic_zhlp","logic_zhlp");
         $this->load->_model("Model_classid","classid");
         $this->load->_model("Model_logic_u9tools","logic_u9tools");
+        $this->load->_model("Model_typeclass","typeclass");
+        $this->load->_model("Model_settingtest","settingtest");
+        $this->load->_model("Model_apiyyv1","apiyyv1");
     }
 	private $show_url = "https://lyerposs.wepolicy.cn";	
     public function _remap($arg,$arg_array)
@@ -23,6 +26,10 @@ class Goodimglibrary extends Start_Controller {
             $this->_showSku($arg_array);
         }elseif($arg == 'bcedit'){
             $this->_bcedit($arg_array);
+        }elseif($arg == 'indexnoimg'){
+            $this->_indexnoimg();
+        }elseif($arg == 'add'){
+            $this->_add();
         }else{
 			$this->_index();
 		}
@@ -206,6 +213,291 @@ class Goodimglibrary extends Start_Controller {
         }
 	}
 
+    private function _add(){
+        if($this->input->method() == 'post'){
+            $post = $this->input->post(null,true);
+            if(empty($post['category'])){
+                echo json_encode(['success' => false,'msg' => '请选择分类']);exit;
+            }
+            if($post['category'] != '131' &&  empty($post['size'])){
+                echo json_encode(['success' => false,'msg' => '请选择尺寸']);exit;
+            }
+            if(isset($post['size'])){
+                $post['size'] = trim($post['size'],",");
+            }
+            $typeclass = $this->logic_u9tools->getTypeClass();
+            
+            $classid = $this->logic_u9tools->getClass();
+            $scsku = $classid;
+            foreach($post as $k=>$v){
+                if (!empty($v)) {
+                    $type_info = $this->typeclass->read($v);
+                    $scsku[$type_info['classid']] = $type_info['bqsku'];
+                }
+            }
+            $scsku = implode("-", $scsku);
+            $scsku = str_replace('- ', '-', trim($scsku, '-'));
+			$scsku = str_replace(array('--------', '-------', '------', '-----', '----', '---', '--'), '-', $scsku);
+            
+
+            $res = $this->logic_zhlp->sortByName($post);
+            if($res['code'] != 1){
+                echo json_encode(['success' => false,'msg' => $res['msg']]);exit;
+            }
+            if(empty($res)){
+                echo json_encode(['success' => false,'msg' => '分类异常']);exit;
+            }
+            $final_list = $res['data'];
+
+            $tmp_arr = array_values($final_list);
+            $size = array_pop($tmp_arr);
+            $sku_tmp_arr = [];
+            foreach($tmp_arr as $k=>$v){
+                if($k == 1 && (!isset($final_list['hairtype']))){
+                    $sku_tmp_arr[] = $v;
+                    $sku_tmp_arr[] = $size;
+                }
+                elseif($k == 2 && (isset($final_list['hairtype']))){
+                    $sku_tmp_arr[] = $v;
+                    $sku_tmp_arr[] = $size;
+                }else{
+                    $sku_tmp_arr[] = $v;
+                }
+            }
+
+            $en_title = "";
+            foreach($post as $k=>$v){
+                if(in_array($v,[163,164,165,166])){
+                    continue;
+                }
+                if(isset($typeclass[$v])){
+                    $en_title.= $typeclass[$v]['title']." ";
+                }
+            }
+            $en_title = trim($en_title);
+           
+            $sku = "-".implode("-",$sku_tmp_arr)."-";
+           
+            $org_sku = implode("-",$final_list);
+            
+            $u9_info = $this->logic_u9tools->getOneU9bmHasGift($org_sku,$classid,$typeclass);
+            $u9_info['title'] = $en_title;
+            $u9_info['sku'] = $scsku;
+            $u9_info['features'] = $sku;
+            $u9_info['org_sku'] = $org_sku;
+            $r = $this->goods->find("features = '".$u9_info['features']."'");
+            if(!empty($r)){
+                if($r['u9_check'] != 1){
+                    //查询u9是否存在
+                    $u9_jm = $this->_getU9GoodInfoByJm($r['jm']);
+                    if(empty($u9_jm)){
+                        echo json_encode(['success' => false,'msg' => $r['jm'].':未同步到u9系统,请联系管理员同步到u9系统。']);exit;
+                    }else{
+                        $this->goods->save([
+                            'u9_check'=>1,
+                            'jm'=>$u9_jm
+                        ],$r['id']);
+                    }
+                }
+                echo json_encode(['success' => false,'msg' => '商品已录入']);exit;
+            }
+            //u9已经创建 但是erp没创建
+            $u9_jm = $this->_getU9GoodInfoByJm($u9_info['jm']);
+            if(!empty($u9_jm)){
+                $rr = $this->goods->insert([
+                    'features'=>$u9_info['features'],
+                    'title'=>$u9_info['title'],
+                    'sku'=>$u9_info['sku'],
+                    'zh'=>$u9_info['zh'],
+                    'jm'=>$u9_jm,
+                    'u9_check'=>1,
+                ]);
+                if($rr){
+                    echo json_encode(['success' => true,'msg' => '商品添加成功']);
+                    exit;
+                }else{
+                    echo json_encode(['success' => false,'msg' => '商品添加失败']);
+                    exit;
+                }
+            }
+            $info = [
+                'jm'=>$u9_info['jm'],
+                'zh'=>$u9_info['zh'],
+                'bm'=>$u9_info['bm'],
+                'ztcode'=>'001',
+                'title'=>$u9_info['title'],
+                'owner_code'=>120,
+            ];
+            //u9没创建 erp也没有创建
+            $token = $this->settingtest->get_yytoken_120();
+            $res = $this->apiyyv1->cjLpAndtbLp($info,$token);
+            if(empty($res[0]['Data'])){
+                echo $res[0]['ResMsg'];
+                exit;
+            }
+            if(empty($res[0]['Data'][0])){
+                echo $res[0]['ResMsg'];
+                exit;
+            }
+            if(!empty($res[0]['Data'][0]['ResMsg'])){
+                echo $res[0]['Data'][0]['ResMsg'];
+                exit;
+            }
+            $token = $this->settingtest->get_yytoken_120();
+            $res = $this->apiyyv1->tbLpNew($info,$token);
+            
+            $rr = $this->goods->insert([
+                'features'=>$u9_info['features'],
+                'title'=>$u9_info['title'],
+                'sku'=>$u9_info['sku'],
+                'zh'=>$u9_info['zh'],
+                'jm'=>$u9_info['jm'],
+                'u9_check'=>1,
+            ]);
+            if($rr){
+                echo json_encode(['success' => true,'msg' => '商品添加成功']);
+                exit;
+            }else{
+                echo json_encode(['success' => false,'msg' => '商品添加失败']);
+                exit;
+            }
+            
+           
+        }else{
+            $this->data['data'] = "";
+            $this->_Template('goodimglibrary_add',$this->data);
+        }
+    }
+
+    private function _getU9GoodInfoByJm($jm){
+        $u9_jm = "";
+        //查询u9是否存在
+        $token = $this->settingtest->get_yytoken_120();
+        $res = $this->apiyyv1->cxLpByJm($jm,$token);
+        if(!empty($res['Data'])){
+            if(!empty($res['Data']['0'])){
+                if(!empty($res['Data']['0']['m_code'])){
+                    $u9_jm = $res['Data']['0']['m_code'];                        
+                }
+            }
+        }
+        return $u9_jm;
+    }
+    private function _indexnoimg(){
+		if($this->input->method() == 'post'){
+            $page = $this->input->post('page',true);
+		    $perpage = $this->input->post('perpage',true);
+			$title = $this->input->post('title',true);
+            $zh= $this->input->post('zh',true);
+            $sku = $this->input->post('sku',true);
+            $category = $this->input->post('category',true);
+            $category = trim($category);
+            $grade = $this->input->post('grade',true);
+            $grade = trim($grade);
+            $color = $this->input->post('color',true);
+            $color = trim($color);
+            $lowe = $this->input->post('lowe',true);
+            $lowe =  trim($lowe);
+            $lacetype = $this->input->post('lacetype',true);
+            $lacetype =  trim($lacetype);
+            $lacecolor = $this->input->post('lacecolor',true);
+            $lacecolor =  trim($lacecolor);
+            $size = $this->input->post('size',true);
+            $size = trim($size);
+            $density = $this->input->post('density',true);
+            $density = trim($density);
+            $haircap = $this->input->post('haircap',true);
+            $haircap = trim($haircap);
+            $hairnumber = $this->input->post('hairnumber',true);
+            $hairnumber = trim($hairnumber);
+          
+            if(empty($page))
+		    {
+                $start = 0;
+		    	$perpage = 1;
+            }
+		    else
+		    {
+                $start = ($page - 1)*$perpage;
+            }
+
+            $where =  '1 = 1';
+            if($title){
+                $title = trim($title);
+                $where .= ' AND title LIKE "%'.trim($title).'%" ';
+               
+            }
+            if($zh){
+                $zh = trim($zh);
+                $where .= ' AND zh LIKE "%'.trim($zh).'%" ';
+            }
+            if($sku){
+                $sku = trim($sku);
+                $where .= ' AND sku LIKE "%'.trim($sku).'%" ';
+            }
+            if($category){
+                $category = trim($category);
+                $where .= ' AND features LIKE "%'.trim($category).'%" ';
+            }
+            if($grade){
+                $grade = trim($grade);
+                $where .= ' AND features LIKE "%'.trim($grade).'%" ';
+            }
+            if($color){
+                $color = trim($color);
+                $where .= ' AND features LIKE "%'.trim($color).'%" ';
+            }
+            if($lowe){
+                $lowe = trim($lowe);
+                $where .= ' AND features LIKE "%'.trim($lowe).'%" ';
+            }
+            if($lacetype){
+                $lacetype = trim($lacetype);
+                $where .= ' AND features LIKE "%'.trim($lacetype).'%" ';
+            }
+            if($lacecolor){
+                $lacecolor = trim($lacecolor);
+                $where .= ' AND features LIKE "%'.trim($lacecolor).'%" ';
+            }
+            if($size){
+                $size = trim($size);
+                $where .= ' AND features LIKE "%'.trim($size).'%" ';
+            }
+            if($density){
+                $density = trim($density);
+                $where .= ' AND features LIKE "%'.trim($density).'%" ';
+            }
+            if($haircap){
+                $haircap = trim($haircap);
+                $where .= ' AND features LIKE "%'.trim($haircap).'%" ';
+            }
+            if($hairnumber){
+                $hairnumber = trim($hairnumber);
+                $where .= ' AND features LIKE "%'.trim($hairnumber).'%" ';
+            }
+
+            $list = $this->goods->find_all($where,'id,sku,title,zh,jm,update_time','id DESC',$start,$perpage);
+            $info_list = [];
+            foreach($list as $k => $v){
+                $info_list[$k]['id'] = $v['id'];
+                $info_list[$k]['sku'] = $v['sku']."  <i class='fa fa-copy' data-text='".$v['sku']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
+                $info_list[$k]['title'] = $v['title']."  <i class='fa fa-copy' data-text='".$v['title']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
+                $info_list[$k]['zh'] = $v['zh']."  <i class='fa fa-copy' data-text='".$v['zh']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
+                $info_list[$k]['jm'] = $v['jm']."  <i class='fa fa-copy' data-text='".$v['jm']."' onclick='fuzhi(this)' style='background-color:#FFE4C4'></i>";
+
+            }
+			
+            $total = $this->goods->find_count($where);
+			
+		    $pagenum = ceil($total/$perpage);
+		    $over = $total-($start+$perpage);
+		    $rows = array('total'=>$total,'over'=>$over,'pagenum'=>$pagenum,'rows'=>($info_list));
+		    echo json_encode($rows);exit;
+        }else{
+            $this->_Template('goodimglibrary_noimg',$this->data);
+        }
+	}
+
     private function transimg($source_cont){
         $str = ' ';
         if(!empty($source_cont)){
@@ -222,7 +514,7 @@ class Goodimglibrary extends Start_Controller {
             }
            
         }
-       return$str;
+       return $str;
     }
 	private function _editData($arg_array){
         if($this->input->method() == 'post'){