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