正在显示
8 个修改的文件
包含
358 行增加
和
30 行删除
| @@ -13,5 +13,21 @@ class Image | @@ -13,5 +13,21 @@ class Image | ||
| 13 | $this->request = $request; | 13 | $this->request = $request; |
| 14 | } | 14 | } |
| 15 | 15 | ||
| 16 | - | 16 | + /** |
| 17 | + * @name :上传图片 | ||
| 18 | + * @return void | ||
| 19 | + * @author :liyuhang | ||
| 20 | + * @method | ||
| 21 | + */ | ||
| 22 | + public function uploads(){ | ||
| 23 | + $url = './uploads/images/'; | ||
| 24 | + $param = $this->request->post(); | ||
| 25 | + if($this->request->hasFile('image') && $this->request->file('image')->isValid()){ | ||
| 26 | + $filename = date('ymdHis').rand(10000,99999).$this->request->file('image'); | ||
| 27 | + $this->request->file('image')->move('./uploads/images/',$filename); | ||
| 28 | + }else{ | ||
| 29 | + return false; | ||
| 30 | + } | ||
| 31 | + return $url.$filename; | ||
| 32 | + } | ||
| 17 | } | 33 | } |
| @@ -167,9 +167,13 @@ class BaseController extends Controller | @@ -167,9 +167,13 @@ class BaseController extends Controller | ||
| 167 | * @method | 167 | * @method |
| 168 | */ | 168 | */ |
| 169 | public function uploads(){ | 169 | public function uploads(){ |
| 170 | + $files = $this->request->file('file'); | ||
| 171 | + if(empty($files)){ | ||
| 172 | + return $this->response('没有上传文件',Code::USER_ERROR); | ||
| 173 | + } | ||
| 170 | $url = './uploads/images/'; | 174 | $url = './uploads/images/'; |
| 171 | $param = $this->request->post(); | 175 | $param = $this->request->post(); |
| 172 | - if($this->request->hasFile('image') && $this->request->file('image')->isValid()){ | 176 | + if($this->request->hasFile('image') && $files->isValid()){ |
| 173 | $filename = date('ymdHis').rand(10000,99999).$this->request->file('image'); | 177 | $filename = date('ymdHis').rand(10000,99999).$this->request->file('image'); |
| 174 | $this->request->file('image')->move('./uploads/images/',$filename); | 178 | $this->request->file('image')->move('./uploads/images/',$filename); |
| 175 | }else{ | 179 | }else{ |
| 1 | -<?php | ||
| 2 | - | ||
| 3 | -namespace App\Http\Controllers\Bside; | ||
| 4 | - | ||
| 5 | -use App\Models\ProductClassify as ProductClassifyModel; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * @name:产品分类 | ||
| 9 | - */ | ||
| 10 | -class ProductClassify extends BaseController | ||
| 11 | -{ | ||
| 12 | - /** | ||
| 13 | - * @name : 获取当前登录的产品分裂 | ||
| 14 | - * @return void | ||
| 15 | - * @author :liyuhang | ||
| 16 | - * @method | ||
| 17 | - */ | ||
| 18 | - public function lists(){ | ||
| 19 | - //TODO::获取当前登录用户 | ||
| 20 | - $this->map['project_id'] = $this->user['project_id']; | ||
| 21 | - $productClassifyModel = new ProductClassifyModel(); | ||
| 22 | - $lists = $productClassifyModel->lists($this->map,$this->p,$this->row,$this->order); | ||
| 23 | - } | ||
| 24 | -} |
| 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->result($lists); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @name :添加产品分类 | ||
| 31 | + * @return void | ||
| 32 | + * @author :liyuhang | ||
| 33 | + * @method | ||
| 34 | + */ | ||
| 35 | + public function add(){ | ||
| 36 | + //参数验证 | ||
| 37 | + $rules = [ | ||
| 38 | + 'name'=>'required|max:11', | ||
| 39 | + 'image'=>'required', | ||
| 40 | + 'keywords'=>'required|max:50', | ||
| 41 | + 'describe'=>'required', | ||
| 42 | + ]; | ||
| 43 | + //验证的提示信息 | ||
| 44 | + $message = [ | ||
| 45 | + 'name.required'=>'名称必须填写', | ||
| 46 | + 'name.max' => '名称不大于16字符.', | ||
| 47 | + 'image.required'=>'路由必须填写', | ||
| 48 | + 'keywords.required'=>'关键字必须填写', | ||
| 49 | + 'keywords.max'=>'关键字最大50个字符', | ||
| 50 | + 'describe.required'=>'路由必须填写', | ||
| 51 | + ]; | ||
| 52 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 53 | + if($validate->fails()){ | ||
| 54 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 55 | + } | ||
| 56 | + //TODO::关联项目 | ||
| 57 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 58 | + $productClassifyModel = new ProductClassifyModel(); | ||
| 59 | + $this->param['image'] = $this->uploads(); | ||
| 60 | + $rs = $productClassifyModel->add($this->param); | ||
| 61 | + if($rs === false){ | ||
| 62 | + $this->response('error',Code::USER_ERROR); | ||
| 63 | + } | ||
| 64 | + $this->response('success',Code::SUCCESS); | ||
| 65 | + } | ||
| 66 | + | ||
| 67 | + /** | ||
| 68 | + * @name :编辑产品分类 | ||
| 69 | + * @return void | ||
| 70 | + * @author :liyuhang | ||
| 71 | + * @method | ||
| 72 | + */ | ||
| 73 | + public function edit(){ | ||
| 74 | + //参数验证 | ||
| 75 | + $rules = [ | ||
| 76 | + 'id'=>'required', | ||
| 77 | + 'name'=>'required|max:11', | ||
| 78 | + 'describe'=>'required', | ||
| 79 | + ]; | ||
| 80 | + //验证的提示信息 | ||
| 81 | + $message = [ | ||
| 82 | + 'id.required'=>'主键必须填写', | ||
| 83 | + 'name.required'=>'名称必须填写', | ||
| 84 | + 'name.max' => '名称不大于16字符.', | ||
| 85 | + 'describe.required'=>'路由必须填写', | ||
| 86 | + ]; | ||
| 87 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 88 | + if($validate->fails()){ | ||
| 89 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 90 | + } | ||
| 91 | + if(isset($this->param['image'])){ | ||
| 92 | + //TODO::删除上一次的图片 | ||
| 93 | + $this->param['image'] = $this->uploads(); | ||
| 94 | + } | ||
| 95 | + $productClassifyModel = new ProductClassifyModel(); | ||
| 96 | + $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]); | ||
| 97 | + if($rs === false){ | ||
| 98 | + $this->response('error',Code::USER_ERROR); | ||
| 99 | + } | ||
| 100 | + $this->response('success',Code::SUCCESS); | ||
| 101 | + } | ||
| 102 | + | ||
| 103 | + /** | ||
| 104 | + * @name :编辑当前类 | ||
| 105 | + * @return void | ||
| 106 | + * @author :liyuhang | ||
| 107 | + * @method | ||
| 108 | + */ | ||
| 109 | + public function status(){ | ||
| 110 | + //参数验证 | ||
| 111 | + $rules = [ | ||
| 112 | + 'id'=>'required', | ||
| 113 | + 'status'=>'required', | ||
| 114 | + ]; | ||
| 115 | + //验证的提示信息 | ||
| 116 | + $message = [ | ||
| 117 | + 'id.required'=>'主键必须填写', | ||
| 118 | + 'status.required'=>'状态必须填写', | ||
| 119 | + ]; | ||
| 120 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 121 | + if($validate->fails()){ | ||
| 122 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 123 | + } | ||
| 124 | + $productClassifyModel = new ProductClassifyModel(); | ||
| 125 | + $rs = $productClassifyModel->edit($this->param,['id'=>$this->param['id']]); | ||
| 126 | + if($rs === false){ | ||
| 127 | + $this->response('error',Code::USER_ERROR); | ||
| 128 | + } | ||
| 129 | + $this->response('success',Code::SUCCESS); | ||
| 130 | + } | ||
| 131 | + /** | ||
| 132 | + * @name :删除产品分类 | ||
| 133 | + * @return void | ||
| 134 | + * @author :liyuhang | ||
| 135 | + * @method | ||
| 136 | + */ | ||
| 137 | + public function del(){ | ||
| 138 | + //参数验证 | ||
| 139 | + $rules = [ | ||
| 140 | + 'id'=>'required', | ||
| 141 | + ]; | ||
| 142 | + //验证的提示信息 | ||
| 143 | + $message = [ | ||
| 144 | + 'id.required'=>'主键必须填写', | ||
| 145 | + ]; | ||
| 146 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 147 | + if($validate->fails()){ | ||
| 148 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 149 | + } | ||
| 150 | + $productClassifyModel = new ProductClassifyModel(); | ||
| 151 | + //TODO::判断当前产品无下级 | ||
| 152 | + $info = $productClassifyModel->read(['pid'=>$this->param['id']],['id']); | ||
| 153 | + if(empty($info)){ | ||
| 154 | + $this->response('当前分类不允许删除',Code::USER_ERROR); | ||
| 155 | + } | ||
| 156 | + //TODO::判断当前分类是否关联商品 | ||
| 157 | + $productModel = new ProductModel(); | ||
| 158 | + $classify_info = $productModel->read(['classify_id'=>$this->param['id']]); | ||
| 159 | + if(empty($classify_info)){ | ||
| 160 | + $this->response('当前分类不允许删除',Code::USER_ERROR); | ||
| 161 | + } | ||
| 162 | + $rs = $productClassifyModel->del(['id'=>$this->param['id']]); | ||
| 163 | + if($rs === false){ | ||
| 164 | + $this->response('error',Code::USER_ERROR); | ||
| 165 | + } | ||
| 166 | + $this->response('success',Code::SUCCESS); | ||
| 167 | + } | ||
| 168 | +} |
| @@ -2,6 +2,11 @@ | @@ -2,6 +2,11 @@ | ||
| 2 | 2 | ||
| 3 | namespace App\Http\Controllers\Bside; | 3 | namespace App\Http\Controllers\Bside; |
| 4 | 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 | + | ||
| 5 | /** | 10 | /** |
| 6 | * @name:产品表 | 11 | * @name:产品表 |
| 7 | */ | 12 | */ |
| @@ -15,6 +20,137 @@ class ProductController extends BaseController | @@ -15,6 +20,137 @@ class ProductController extends BaseController | ||
| 15 | */ | 20 | */ |
| 16 | public function lists(){ | 21 | public function lists(){ |
| 17 | //获取当前登录用户下的产品列表 | 22 | //获取当前登录用户下的产品列表 |
| 23 | + $this->map['project_id'] = $this->user['project_id']; | ||
| 24 | + $productModel = new ProductModel(); | ||
| 25 | + $lists = $productModel->lists($this->map,$this->p,$this->row,$this->order); | ||
| 26 | + $this->result($lists); | ||
| 27 | + } | ||
| 28 | + | ||
| 29 | + /** | ||
| 30 | + * @name :添加产品 | ||
| 31 | + * @return void | ||
| 32 | + * @author :liyuhang | ||
| 33 | + * @method | ||
| 34 | + */ | ||
| 35 | + public function add(){ | ||
| 36 | + //参数验证 | ||
| 37 | + $rules = [ | ||
| 38 | + 'name'=>'required|max:11', | ||
| 39 | + 'image'=>'required', | ||
| 40 | + 'describe'=>'required', | ||
| 41 | + 'keywords'=>'required|max:50', | ||
| 42 | + ]; | ||
| 43 | + //验证的提示信息 | ||
| 44 | + $message = [ | ||
| 45 | + 'name.required'=>'名称必须填写', | ||
| 46 | + 'name.max' => '名称不大于16字符.', | ||
| 47 | + 'image.required'=>'图片必须上传', | ||
| 48 | + 'describe.required'=>'描述必须填写', | ||
| 49 | + 'keywords.required'=>'关键字必须填写', | ||
| 50 | + ]; | ||
| 51 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 52 | + if($validate->fails()){ | ||
| 53 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 54 | + } | ||
| 55 | + //TODO::关联项目 | ||
| 56 | + $this->param['project_id'] = $this->user['project_id']; | ||
| 57 | + $productModel = new ProductModel(); | ||
| 58 | + $this->param['image'] = $this->uploads(); | ||
| 59 | + $rs = $productModel->add($this->param); | ||
| 60 | + if($rs === false){ | ||
| 61 | + $this->response('error',Code::USER_ERROR); | ||
| 62 | + } | ||
| 63 | + $this->response('success',Code::SUCCESS); | ||
| 64 | + } | ||
| 18 | 65 | ||
| 66 | + public function edit(){ | ||
| 67 | + //参数验证 | ||
| 68 | + $rules = [ | ||
| 69 | + 'name'=>'required|max:11', | ||
| 70 | + 'image'=>'required', | ||
| 71 | + 'describe'=>'required', | ||
| 72 | + 'keywords'=>'required|max:50', | ||
| 73 | + ]; | ||
| 74 | + //验证的提示信息 | ||
| 75 | + $message = [ | ||
| 76 | + 'name.required'=>'名称必须填写', | ||
| 77 | + 'name.max' => '名称不大于16字符.', | ||
| 78 | + 'image.required'=>'图片必须上传', | ||
| 79 | + 'describe.required'=>'描述必须填写', | ||
| 80 | + 'keywords.required'=>'关键字必须填写', | ||
| 81 | + ]; | ||
| 82 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 83 | + if($validate->fails()){ | ||
| 84 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 85 | + } | ||
| 86 | + if(isset($this->param['image'])){ | ||
| 87 | + //TODO::删除上一次的图片 | ||
| 88 | + $this->param['image'] = $this->uploads(); | ||
| 89 | + } | ||
| 90 | + $productModel = new ProductModel(); | ||
| 91 | + $rs = $productModel->edit($this->param,['id'=>$this->param['id']]); | ||
| 92 | + if($rs === false){ | ||
| 93 | + $this->response('error',Code::USER_ERROR); | ||
| 94 | + } | ||
| 95 | + $this->response('success',Code::SUCCESS); | ||
| 96 | + } | ||
| 97 | + | ||
| 98 | + /** | ||
| 99 | + * @name :修改产品状态 | ||
| 100 | + * @return void | ||
| 101 | + * @author :liyuhang | ||
| 102 | + * @method | ||
| 103 | + */ | ||
| 104 | + public function status(){ | ||
| 105 | + //参数验证 | ||
| 106 | + $rules = [ | ||
| 107 | + 'id'=>'required', | ||
| 108 | + 'status'=>'required', | ||
| 109 | + ]; | ||
| 110 | + //验证的提示信息 | ||
| 111 | + $message = [ | ||
| 112 | + 'id.required'=>'主键必须填写', | ||
| 113 | + 'status.required'=>'状态必须填写', | ||
| 114 | + ]; | ||
| 115 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 116 | + if($validate->fails()){ | ||
| 117 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 118 | + } | ||
| 119 | + $productModel = new ProductModel(); | ||
| 120 | + $rs = $productModel->edit(['status'=>$this->param['status']],['id'=>$this->param['id']]); | ||
| 121 | + if($rs === false){ | ||
| 122 | + $this->response('error',Code::USER_ERROR); | ||
| 123 | + } | ||
| 124 | + $this->response('success',Code::SUCCESS); | ||
| 125 | + } | ||
| 126 | + | ||
| 127 | + /** | ||
| 128 | + * @name :删除产品 | ||
| 129 | + * @return void | ||
| 130 | + * @author :liyuhang | ||
| 131 | + * @method | ||
| 132 | + */ | ||
| 133 | + public function del(){ | ||
| 134 | + //参数验证 | ||
| 135 | + $rules = [ | ||
| 136 | + 'id'=>'required', | ||
| 137 | + ]; | ||
| 138 | + //验证的提示信息 | ||
| 139 | + $message = [ | ||
| 140 | + 'id.required'=>'主键必须填写', | ||
| 141 | + ]; | ||
| 142 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 143 | + if($validate->fails()){ | ||
| 144 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 145 | + } | ||
| 146 | + $productModel = new ProductModel(); | ||
| 147 | + $info = $productModel->read(['id'=>$this->param['id']],['image']); | ||
| 148 | + //TODO::删除添加的图片 | ||
| 149 | + shell_exec('rm -rf '.request()->path().$info['image']); | ||
| 150 | + $rs = $productModel->del(['id'=>$this->param['id']]); | ||
| 151 | + if($rs === false){ | ||
| 152 | + $this->response('error',Code::USER_ERROR); | ||
| 153 | + } | ||
| 154 | + $this->response('success',Code::SUCCESS); | ||
| 19 | } | 155 | } |
| 20 | } | 156 | } |
| @@ -93,7 +93,7 @@ class UserController extends BaseController | @@ -93,7 +93,7 @@ class UserController extends BaseController | ||
| 93 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | 93 | return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); |
| 94 | } | 94 | } |
| 95 | $userLogic = new UserLogic(); | 95 | $userLogic = new UserLogic(); |
| 96 | - $rs = $userLogic->edit($this->param); | 96 | + $rs = $userLogic->edits($this->param); |
| 97 | if($rs === false){ | 97 | if($rs === false){ |
| 98 | $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); | 98 | $this->response('参数错误或其他服务器原因,编辑失败',Code::USER_ERROR,[]); |
| 99 | } | 99 | } |
| @@ -101,6 +101,34 @@ class UserController extends BaseController | @@ -101,6 +101,34 @@ class UserController extends BaseController | ||
| 101 | } | 101 | } |
| 102 | 102 | ||
| 103 | /** | 103 | /** |
| 104 | + * @name :修改当前用户状态 | ||
| 105 | + * @return void | ||
| 106 | + * @author :liyuhang | ||
| 107 | + * @method | ||
| 108 | + */ | ||
| 109 | + public function status(){ | ||
| 110 | + //参数验证 | ||
| 111 | + $rules = [ | ||
| 112 | + 'id'=>'required', | ||
| 113 | + 'status'=>'required', | ||
| 114 | + ]; | ||
| 115 | + //验证的提示信息 | ||
| 116 | + $message = [ | ||
| 117 | + 'id.required'=>'主键必须填写', | ||
| 118 | + 'status.required'=>'状态必须填写', | ||
| 119 | + ]; | ||
| 120 | + $validate = Validator::make($this->param, $rules, $message); | ||
| 121 | + if($validate->fails()){ | ||
| 122 | + return $this->response($validate->errors()->first(),Code::USER_PARAMS_ERROE,$this->param); | ||
| 123 | + } | ||
| 124 | + $userLogic = new UserModel(); | ||
| 125 | + $rs = $userLogic->edit($this->param,['id'=>$this->param['id']]); | ||
| 126 | + if($rs === false){ | ||
| 127 | + $this->response('error',Code::USER_ERROR); | ||
| 128 | + } | ||
| 129 | + $this->response($this->param['status'] == 0 ? '启用成功' : '禁用成功',Code::SUCCESS); | ||
| 130 | + } | ||
| 131 | + /** | ||
| 104 | * @name :删除管理员 | 132 | * @name :删除管理员 |
| 105 | * @return void | 133 | * @return void |
| 106 | * @author :liyuhang | 134 | * @author :liyuhang |
| @@ -41,7 +41,7 @@ class UserLogic extends BaseLogic | @@ -41,7 +41,7 @@ class UserLogic extends BaseLogic | ||
| 41 | * @author :liyuhang | 41 | * @author :liyuhang |
| 42 | * @method | 42 | * @method |
| 43 | */ | 43 | */ |
| 44 | - public function edit($param){ | 44 | + public function edits($param){ |
| 45 | $userModel = new UserModel(); | 45 | $userModel = new UserModel(); |
| 46 | //验证当前用户是否存在 | 46 | //验证当前用户是否存在 |
| 47 | $info = $userModel->read(['mobile'=>$param['mobile']]); | 47 | $info = $userModel->read(['mobile'=>$param['mobile']]); |
| @@ -67,7 +67,7 @@ class Base extends Model | @@ -67,7 +67,7 @@ class Base extends Model | ||
| 67 | * @author :liyuhang | 67 | * @author :liyuhang |
| 68 | * @method | 68 | * @method |
| 69 | */ | 69 | */ |
| 70 | - public function del(){ | ||
| 71 | - | 70 | + public function del($condition){ |
| 71 | + return DB::table($this->table)->where($condition)->delete(); | ||
| 72 | } | 72 | } |
| 73 | } | 73 | } |
-
请 注册 或 登录 后发表评论