正在显示
4 个修改的文件
包含
67 行增加
和
14 行删除
| @@ -43,7 +43,7 @@ class DeptController extends BaseController | @@ -43,7 +43,7 @@ class DeptController extends BaseController | ||
| 43 | public function save(DeptRequest $request, DeptLogic $logic) | 43 | public function save(DeptRequest $request, DeptLogic $logic) |
| 44 | { | 44 | { |
| 45 | $request->validated(); | 45 | $request->validated(); |
| 46 | - $logic->save($this->param); | 46 | + $logic->deptSave(); |
| 47 | $this->response('success'); | 47 | $this->response('success'); |
| 48 | } | 48 | } |
| 49 | 49 |
| @@ -25,9 +25,28 @@ class BaseLogic extends Logic | @@ -25,9 +25,28 @@ class BaseLogic extends Logic | ||
| 25 | public function __construct() | 25 | public function __construct() |
| 26 | { | 26 | { |
| 27 | $this->request = request(); | 27 | $this->request = request(); |
| 28 | - $this->requestAll = $this->request->all(); | 28 | + $this->requestAll = $this->getParam(); |
| 29 | $this->manager = Cache::get(Common::MANAGE_TOKEN . $this->request->header('token')); | 29 | $this->manager = Cache::get(Common::MANAGE_TOKEN . $this->request->header('token')); |
| 30 | } | 30 | } |
| 31 | 31 | ||
| 32 | - | 32 | + /** |
| 33 | + * @remark :请求参数处理 | ||
| 34 | + * @name :getParam | ||
| 35 | + * @author :lyh | ||
| 36 | + * @method :post | ||
| 37 | + * @time :2023/6/17 16:34 | ||
| 38 | + */ | ||
| 39 | + public function getParam(){ | ||
| 40 | + $requestAll = $this->request->all(); | ||
| 41 | + foreach ($requestAll as $k => $v){ | ||
| 42 | + if(is_array($v)){ | ||
| 43 | + continue; | ||
| 44 | + }else{ | ||
| 45 | + if(empty($v) && ($v != 0)){ | ||
| 46 | + unset($requestAll[$k]); | ||
| 47 | + } | ||
| 48 | + } | ||
| 49 | + } | ||
| 50 | + return $this->success($requestAll); | ||
| 51 | + } | ||
| 33 | } | 52 | } |
| @@ -17,23 +17,36 @@ class DeptLogic extends BaseLogic | @@ -17,23 +17,36 @@ class DeptLogic extends BaseLogic | ||
| 17 | public function __construct() | 17 | public function __construct() |
| 18 | { | 18 | { |
| 19 | parent::__construct(); | 19 | parent::__construct(); |
| 20 | - | 20 | + $this->param = $this->requestAll; |
| 21 | $this->model = new Dept(); | 21 | $this->model = new Dept(); |
| 22 | } | 22 | } |
| 23 | 23 | ||
| 24 | - public function save($param){ | ||
| 25 | - if(!empty($param['pid'])){ | ||
| 26 | - if(!empty($param['id']) && $param['pid'] == $param['id']){ | ||
| 27 | - $this->fail('上级部门不能是本部门'); | ||
| 28 | - } | ||
| 29 | - $p_cate = $this->getCacheInfo($param['pid']); | ||
| 30 | - if(!$p_cate){ | ||
| 31 | - $this->fail('上级部门不存在'); | 24 | + /** |
| 25 | + * @remark :保存 | ||
| 26 | + * @name :save | ||
| 27 | + * @author :lyh | ||
| 28 | + * @method :post | ||
| 29 | + * @time :2023/8/28 15:10 | ||
| 30 | + */ | ||
| 31 | + public function deptSave(){ | ||
| 32 | + if(isset($this->param['id']) && !empty($this->param['id'])){ | ||
| 33 | + if($this->param['pid'] == $this->param['id']){ | ||
| 34 | + $this->fail('当前上级分类不能为自己'); | ||
| 32 | } | 35 | } |
| 36 | + $this->model->edit($this->param,['id'=>$this->param]); | ||
| 37 | + }else{ | ||
| 38 | + $this->model->add($this->param); | ||
| 33 | } | 39 | } |
| 34 | - return parent::save($param); | 40 | + return $this->success(); |
| 35 | } | 41 | } |
| 36 | 42 | ||
| 43 | + /** | ||
| 44 | + * @remark :删除 | ||
| 45 | + * @name :delete | ||
| 46 | + * @author :lyh | ||
| 47 | + * @method :post | ||
| 48 | + * @time :2023/8/28 15:22 | ||
| 49 | + */ | ||
| 37 | public function delete($ids, $map = []){ | 50 | public function delete($ids, $map = []){ |
| 38 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); | 51 | $ids= array_filter(Arr::splitFilterToArray($ids), 'intval'); |
| 39 | foreach ($ids as $id){ | 52 | foreach ($ids as $id){ |
| @@ -30,7 +30,7 @@ class BaseLogic extends Logic | @@ -30,7 +30,7 @@ class BaseLogic extends Logic | ||
| 30 | public function __construct() | 30 | public function __construct() |
| 31 | { | 31 | { |
| 32 | $this->request = request(); | 32 | $this->request = request(); |
| 33 | - $this->requestAll = request()->all(); | 33 | + $this->requestAll = $this->getParam(); |
| 34 | $this->user = Cache::get(request()->header('token')); | 34 | $this->user = Cache::get(request()->header('token')); |
| 35 | if(!empty($this->user)){ | 35 | if(!empty($this->user)){ |
| 36 | $this->project = Cache::get('user-'.$this->user['project_id']); | 36 | $this->project = Cache::get('user-'.$this->user['project_id']); |
| @@ -38,6 +38,27 @@ class BaseLogic extends Logic | @@ -38,6 +38,27 @@ class BaseLogic extends Logic | ||
| 38 | } | 38 | } |
| 39 | 39 | ||
| 40 | /** | 40 | /** |
| 41 | + * @remark :请求参数处理 | ||
| 42 | + * @name :getParam | ||
| 43 | + * @author :lyh | ||
| 44 | + * @method :post | ||
| 45 | + * @time :2023/6/17 16:34 | ||
| 46 | + */ | ||
| 47 | + public function getParam(){ | ||
| 48 | + $requestAll = $this->request->all(); | ||
| 49 | + foreach ($requestAll as $k => $v){ | ||
| 50 | + if(is_array($v)){ | ||
| 51 | + continue; | ||
| 52 | + }else{ | ||
| 53 | + if(empty($v) && ($v != 0)){ | ||
| 54 | + unset($requestAll[$k]); | ||
| 55 | + } | ||
| 56 | + } | ||
| 57 | + } | ||
| 58 | + return $this->success($requestAll); | ||
| 59 | + } | ||
| 60 | + | ||
| 61 | + /** | ||
| 41 | * 列表 | 62 | * 列表 |
| 42 | * @param array $map | 63 | * @param array $map |
| 43 | * @param array $sort | 64 | * @param array $sort |
-
请 注册 或 登录 后发表评论