作者 邓超

导航栏 nav

@@ -133,16 +133,36 @@ class NavController extends BaseController @@ -133,16 +133,36 @@ class NavController extends BaseController
133 $id = BNav::_save($this->user['project_id'],$data,$data['id']??0); 133 $id = BNav::_save($this->user['project_id'],$data,$data['id']??0);
134 134
135 if($id===-1){ 135 if($id===-1){
136 - return $this->response('导航数据不存在','B_NAV_NOTFOUND'); 136 + return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
137 } 137 }
138 138
139 return $this->success(BNav::_find($this->user['project_id'],$id,true)); 139 return $this->success(BNav::_find($this->user['project_id'],$id,true));
140 } 140 }
141 141
142 142
  143 + /**
  144 + * 删除数据
  145 + * @return \Illuminate\Http\JsonResponse
  146 + * @author:dc
  147 + * @time 2023/5/9 9:20
  148 + */
  149 + public function delete(){
  150 + $id = $this->param['id']??0;
  151 + $data = BNav::_find($this->user['project_id'],$id);
  152 +
  153 + if(empty($data)){
  154 + return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
  155 + }
143 156
144 157
145 - public function delete(){ 158 + if(BNav::isChild($data['id'],$this->user['project_id'])){
  159 + return $this->response('存在下级无法删除','B_NAV_DELETE_CHILD');
  160 + }
  161 +
  162 +
  163 + if($data->delete()){
  164 + return $this->response('删除成功',Code::SUCCESS);
  165 + }
146 166
147 } 167 }
148 168
@@ -129,4 +129,16 @@ class BNav extends Base @@ -129,4 +129,16 @@ class BNav extends Base
129 return static::where(['id'=>$id,'project_id'=>$project_id])->count(); 129 return static::where(['id'=>$id,'project_id'=>$project_id])->count();
130 } 130 }
131 131
  132 + /**
  133 + * 是否有下级
  134 + * @param int $id
  135 + * @param int $project_id
  136 + * @return mixed
  137 + * @author:dc
  138 + * @time 2023/5/9 9:23
  139 + */
  140 + public static function isChild(int $id,int $project_id=0)
  141 + {
  142 + return static::where(['pid'=>$id,'project_id'=>$project_id])->limit(1)->count();
  143 + }
132 } 144 }