作者 邓超

导航栏 nav

... ... @@ -133,16 +133,36 @@ class NavController extends BaseController
$id = BNav::_save($this->user['project_id'],$data,$data['id']??0);
if($id===-1){
return $this->response('导航数据不存在','B_NAV_NOTFOUND');
return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
}
return $this->success(BNav::_find($this->user['project_id'],$id,true));
}
/**
* 删除数据
* @return \Illuminate\Http\JsonResponse
* @author:dc
* @time 2023/5/9 9:20
*/
public function delete(){
$id = $this->param['id']??0;
$data = BNav::_find($this->user['project_id'],$id);
if(empty($data)){
return $this->response('导航菜单不存在','B_NAV_NOTFOUND');
}
public function delete(){
if(BNav::isChild($data['id'],$this->user['project_id'])){
return $this->response('存在下级无法删除','B_NAV_DELETE_CHILD');
}
if($data->delete()){
return $this->response('删除成功',Code::SUCCESS);
}
}
... ...
... ... @@ -129,4 +129,16 @@ class BNav extends Base
return static::where(['id'=>$id,'project_id'=>$project_id])->count();
}
/**
* 是否有下级
* @param int $id
* @param int $project_id
* @return mixed
* @author:dc
* @time 2023/5/9 9:23
*/
public static function isChild(int $id,int $project_id=0)
{
return static::where(['pid'=>$id,'project_id'=>$project_id])->limit(1)->count();
}
}
... ...