作者 lyh

gx

@@ -3,6 +3,7 @@ @@ -3,6 +3,7 @@
3 namespace App\Http\Controllers\Bside\Nav; 3 namespace App\Http\Controllers\Bside\Nav;
4 4
5 5
  6 +use App\Enums\Common\Code;
6 use App\Http\Controllers\Bside\BaseController; 7 use App\Http\Controllers\Bside\BaseController;
7 use App\Http\Logic\Bside\Nav\NavLogic; 8 use App\Http\Logic\Bside\Nav\NavLogic;
8 use App\Http\Requests\Bside\Nav\NavRequest; 9 use App\Http\Requests\Bside\Nav\NavRequest;
@@ -41,9 +42,10 @@ class NavController extends BaseController @@ -41,9 +42,10 @@ class NavController extends BaseController
41 * @author:dc 42 * @author:dc
42 * @time 2023/5/8 17:06 43 * @time 2023/5/8 17:06
43 */ 44 */
44 - public function save(NavRequest $request){  
45 - $data = $request->validated();  
46 - return $this->success(NavLogic::instance()->save($data)); 45 + public function save(NavRequest $request,NavLogic $logic){
  46 + $request->validated();
  47 + $logic->navSave();
  48 + $this->response('success');
47 49
48 } 50 }
49 51
@@ -19,7 +19,7 @@ class NavLogic extends BaseLogic @@ -19,7 +19,7 @@ class NavLogic extends BaseLogic
19 public function __construct() 19 public function __construct()
20 { 20 {
21 parent::__construct(); 21 parent::__construct();
22 - 22 + $this->param = $this->requestAll;
23 $this->model = new BNav(); 23 $this->model = new BNav();
24 } 24 }
25 25
@@ -33,41 +33,35 @@ class NavLogic extends BaseLogic @@ -33,41 +33,35 @@ class NavLogic extends BaseLogic
33 if(!empty($this->requestAll['location'])){ 33 if(!empty($this->requestAll['location'])){
34 $where[] = ['location','=',$this->requestAll['location']]; 34 $where[] = ['location','=',$this->requestAll['location']];
35 } 35 }
36 -  
37 $lists = $this->getList($where,['sort'=>'asc'],['*'],false); 36 $lists = $this->getList($where,['sort'=>'asc'],['*'],false);
38 -  
39 $isTree = $this->requestAll['tree']??false; 37 $isTree = $this->requestAll['tree']??false;
40 -  
41 if($isTree){ 38 if($isTree){
42 $lists = list_to_tree($lists); 39 $lists = list_to_tree($lists);
43 } 40 }
44 -  
45 return $lists; 41 return $lists;
46 } 42 }
47 43
48 44
49 - public function save($data) 45 + public function navSave()
50 { 46 {
51 - if($data['pid']){  
52 - // 验证是否存在上级  
53 - $all = BNav::_all($this->user['project_id'],$data['location']);  
54 - if(!$all->where('id',$data['pid'])->count()){  
55 - $this->fail('上级栏目不存在'); 47 + if(isset($this->param['id']) && !empty($this->param['id'])){
  48 +
  49 + $info = $this->model->read(['id'=>$this->param['id']]);
  50 + if($this->param['pid'] == $info['id']){
  51 + $this->fail('不允许成为自己的上级');
56 } 52 }
57 - // 上级不允许是自己的下级  
58 - if(!empty($data['id'])){  
59 - $all = list_to_tree($all->toArray(),$data['id']);  
60 - $all = tree_to_list($all);  
61 - if(in_array($data['pid'],array_column($all,'id'))){  
62 - $this->fail('上级栏目不允许为本身的下级'); 53 + $pid_info = $this->model->read(['pid'=>$this->param['id']]);
  54 + if(($pid_info !== false) && $this->param['pid'] != $info['pid']){
  55 + $this->fail('当前菜单拥有子集不允许修改上级');
63 } 56 }
  57 + $rs = $this->model->edit($this->param,['id'=>$this->param['id']]);
  58 + }else{
  59 + $rs = $this->model->add($this->param);
64 } 60 }
  61 + if($rs === false){
  62 + $this->fail('error');
65 } 63 }
66 - $data['url'] = $data['url'] ?: '';  
67 - // 保存  
68 - $id = parent::save($data);  
69 -  
70 - return $this->getInfo($id['id']); 64 + return $this->success();
71 } 65 }
72 66
73 /** 67 /**
@@ -40,17 +40,6 @@ class NavRequest extends FormRequest @@ -40,17 +40,6 @@ class NavRequest extends FormRequest
40 'target' => ['required','in:0,1'], 40 'target' => ['required','in:0,1'],
41 'sort' => ['required','integer','gte:0'] 41 'sort' => ['required','integer','gte:0']
42 ]; 42 ];
43 -  
44 - // 修改  
45 - if($this->is('b/nav/update')){  
46 - $rule['id'] = ['required','integer'];  
47 - }  
48 -  
49 - // 删除  
50 - if($this->is('b/nav/delete')){  
51 - $rule = ['id' => ['required','integer']];  
52 - }  
53 -  
54 return $rule; 43 return $rule;
55 } 44 }
56 45