作者 liyuhang

gx

@@ -101,7 +101,7 @@ class ComController extends BaseController @@ -101,7 +101,7 @@ class ComController extends BaseController
101 if(empty($info)){ 101 if(empty($info)){
102 $this->response('error',Code::USER_ERROR); 102 $this->response('error',Code::USER_ERROR);
103 } 103 }
104 - $this->response('success',Code::SUCCESS,[$info]); 104 + $this->response('success',Code::SUCCESS,$info);
105 } 105 }
106 106
107 /** 107 /**
1 -<?php  
2 -  
3 -namespace App\Http\Controllers\Bside;  
4 -  
5 -use App\Enums\Common\Code;  
6 -use App\Models\Product as ProductModel;  
7 -use App\Models\ProductClassify as ProductClassifyModel;  
8 -use Illuminate\Support\Facades\Validator;  
9 -  
10 -/**  
11 - * @name:产品分类  
12 - */  
13 -class ProductClassifyController extends BaseController  
14 -{  
15 - /**  
16 - * @name : 获取当前登录的产品分裂  
17 - * @return void  
18 - * @author :liyuhang  
19 - * @method  
20 - */  
21 - public function lists(){  
22 - //TODO::获取当前登录用户  
23 - $this->map['project_id'] = $this->user['project_id'];  
24 - $productClassifyModel = new ProductClassifyModel();  
25 - $lists = $productClassifyModel->lists($this->map,$this->p,$this->row,$this->order);  
26 - $this->allCount = $productClassifyModel->allCount;  
27 - $this->result($lists);  
28 - }  
29 -  
30 - /**  
31 - * @name :添加产品分类  
32 - * @return void  
33 - * @author :liyuhang  
34 - * @method  
35 - */  
36 - public function add(){  
37 - //参数验证  
38 - $rules = [  
39 - 'name'=>'required|max:11',  
40 - 'image'=>'required',  
41 - 'keywords'=>'required|max:50',  
42 - 'describe'=>'required',  
43 - ];  
44 - //验证的提示信息  
45 - $message = [  
46 - 'name.required'=>'名称必须填写',  
47 - 'name.max' => '名称不大于16字符.',  
48 - 'image.required'=>'路由必须填写',  
49 - 'keywords.required'=>'关键字必须填写',  
50 - 'keywords.max'=>'关键字最大50个字符',  
51 - 'describe.required'=>'路由必须填写',  
52 - ];  
53 - $validate = Validator::make($this->param, $rules, $message);  
54 - if($validate->fails()){  
55 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
56 - }  
57 - //TODO::关联项目  
58 - $this->param['project_id'] = $this->user['project_id'];  
59 - $productClassifyModel = new ProductClassifyModel();  
60 - $this->param['image'] = $this->uploads();  
61 - $rs = $productClassifyModel->add($this->param);  
62 - if($rs === false){  
63 - $this->response('error',Code::USER_ERROR);  
64 - }  
65 - $this->response('success',Code::SUCCESS);  
66 - }  
67 -  
68 - /**  
69 - * @name :编辑产品分类  
70 - * @return void  
71 - * @author :liyuhang  
72 - * @method  
73 - */  
74 - public function edit(){  
75 - //参数验证  
76 - $rules = [  
77 - 'id'=>'required',  
78 - 'name'=>'required|max:11',  
79 - 'describe'=>'required',  
80 - ];  
81 - //验证的提示信息  
82 - $message = [  
83 - 'id.required'=>'主键必须填写',  
84 - 'name.required'=>'名称必须填写',  
85 - 'name.max' => '名称不大于16字符.',  
86 - 'describe.required'=>'路由必须填写',  
87 - ];  
88 - $validate = Validator::make($this->param, $rules, $message);  
89 - if($validate->fails()){  
90 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
91 - }  
92 - if(isset($this->param['image'])){  
93 - //TODO::删除上一次的图片  
94 - $this->param['image'] = $this->uploads();  
95 - }  
96 - $productClassifyModel = new ProductClassifyModel();  
97 - $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);  
98 - if($rs === false){  
99 - $this->response('error',Code::USER_ERROR);  
100 - }  
101 - $this->response('success',Code::SUCCESS);  
102 - }  
103 -  
104 - /**  
105 - * @name :编辑当前类  
106 - * @return void  
107 - * @author :liyuhang  
108 - * @method  
109 - */  
110 - public function status(){  
111 - //参数验证  
112 - $rules = [  
113 - 'id'=>'required',  
114 - 'status'=>'required',  
115 - ];  
116 - //验证的提示信息  
117 - $message = [  
118 - 'id.required'=>'主键必须填写',  
119 - 'status.required'=>'状态必须填写',  
120 - ];  
121 - $validate = Validator::make($this->param, $rules, $message);  
122 - if($validate->fails()){  
123 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
124 - }  
125 - $productClassifyModel = new ProductClassifyModel();  
126 - $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]);  
127 - if($rs === false){  
128 - $this->response('error',Code::USER_ERROR);  
129 - }  
130 - $this->response('success',Code::SUCCESS);  
131 - }  
132 - /**  
133 - * @name :删除产品分类  
134 - * @return void  
135 - * @author :liyuhang  
136 - * @method  
137 - */  
138 - public function del(){  
139 - //参数验证  
140 - $rules = [  
141 - 'id'=>'required',  
142 - ];  
143 - //验证的提示信息  
144 - $message = [  
145 - 'id.required'=>'主键必须填写',  
146 - ];  
147 - $validate = Validator::make($this->param, $rules, $message);  
148 - if($validate->fails()){  
149 - return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param);  
150 - }  
151 - $productClassifyModel = new ProductClassifyModel();  
152 - //TODO::判断当前产品无下级  
153 - $info = $productClassifyModel->read(['pid'=>$this->param['id']],['id']);  
154 - if(empty($info)){  
155 - $this->response('当前分类不允许删除',Code::USER_ERROR);  
156 - }  
157 - //TODO::判断当前分类是否关联商品  
158 - $productModel = new ProductModel();  
159 - $classify_info = $productModel->read(['classify_id'=>$this->param['id']]);  
160 - if(empty($classify_info)){  
161 - $this->response('当前分类不允许删除',Code::USER_ERROR);  
162 - }  
163 - $rs = $productClassifyModel->del(['id'=>$this->param['id']]);  
164 - if($rs === false){  
165 - $this->response('error',Code::USER_ERROR);  
166 - }  
167 - $this->response('success',Code::SUCCESS);  
168 - }  
169 -}  
1 -<?php  
2 -  
3 -namespace App\Models;  
4 -  
5 -class ProductClassify extends Base  
6 -{  
7 - //设置关联表名  
8 - protected $table = 'gl_product_classify';  
9 - //自动维护create_at创建时间 updated_at修改时间  
10 - public $timestamps = true;  
11 -}