|
@@ -2,7 +2,6 @@
|
|
|
|
|
|
namespace App\Service;
|
|
|
|
|
|
-
|
|
|
use App\Model\SysMenu;
|
|
|
|
|
|
/**
|
|
@@ -11,7 +10,6 @@ use App\Model\SysMenu;
|
|
|
*/
|
|
|
class SysMenuService extends Service
|
|
|
{
|
|
|
-
|
|
|
public function edit($data){
|
|
|
list($status,$msg) = $this->menuRule($data);
|
|
|
if(!$status) return [$status,$msg];
|
|
@@ -28,32 +26,26 @@ class SysMenuService extends Service
|
|
|
$model->sort = $data['sort'] ?? 0;
|
|
|
$model->save();
|
|
|
|
|
|
- return [true,'保存成功!'];
|
|
|
-
|
|
|
+ return [true,''];
|
|
|
}
|
|
|
|
|
|
public function add($data,$user){
|
|
|
-
|
|
|
-
|
|
|
-// if($this->isEmpty($data,'title')) return [201,'名称不存在!'];
|
|
|
list($status,$msg) = $this->menuRule($data);
|
|
|
if(!$status) return [$status,$msg];
|
|
|
$first = SysMenu::where('title',$data['title'])->where('del_time',0)->first();
|
|
|
if(!empty($first))return [false,'名称已存在!'];
|
|
|
|
|
|
$model = new SysMenu();
|
|
|
-
|
|
|
+ $sort = $model->where('parent_id',$data['parent_id'])->max('sort');
|
|
|
$model->title = $data['title'];
|
|
|
$model->icon = $data['icon'] ?? '';
|
|
|
$model->uri = $data['uri'];
|
|
|
$model->parent_id = $data['parent_id'];
|
|
|
- $model->sort = $data['sort'] ?? 0;
|
|
|
-// $model->crt_id = $user->id;
|
|
|
- $model->crt_id = 1;
|
|
|
+ $model->sort = $sort ? $sort + 1 : 1;
|
|
|
+ $model->crt_id = $user['id'];
|
|
|
$model->save();
|
|
|
|
|
|
- return [true,'保存成功!'];
|
|
|
-
|
|
|
+ return [true,''];
|
|
|
}
|
|
|
|
|
|
public function del($data){
|
|
@@ -77,18 +69,56 @@ class SysMenuService extends Service
|
|
|
$return = $this->set_sort_circle($return);
|
|
|
}
|
|
|
|
|
|
-
|
|
|
return [200,$return];
|
|
|
}
|
|
|
|
|
|
public function menuRule($data){
|
|
|
if($this->isEmpty($data,'title')) return [false,'名称不存在!'];
|
|
|
-// if($this->isEmpty($data,'icon')) return [201,'d不存在!'];
|
|
|
-// if($this->isEmpty($data,'uri')) return [false,'路由不存在!'];
|
|
|
if($this->isEmpty($data,'parent_id')) return [false,'父级不存在!'];
|
|
|
|
|
|
return [true,''];
|
|
|
}
|
|
|
|
|
|
+ public function menuMove($data){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
+ if($this->isEmpty($data,'move')) return [false,'移动不能能为空!'];
|
|
|
+
|
|
|
+ //移动项
|
|
|
+ $model = new SysMenu();
|
|
|
+ $res = $model->where('id', $data['id'])->first();
|
|
|
+
|
|
|
+ if($data['move'] == 1 || $data['move'] == -1){
|
|
|
+ //替项目
|
|
|
+ $moveModel = $model->where('del_time',0)->where('parent_id',$res->parent_id);
|
|
|
+
|
|
|
+ //下移-1 上移1
|
|
|
+ $data['move'] == 1 ? $moveModel->orderby('sort','desc')->where('sort','<', $res['sort']) : $moveModel->orderby('sort','asc')->where('sort','>', $res['sort']);
|
|
|
+
|
|
|
+ $moveRes = $moveModel->first();
|
|
|
+ if(! $moveRes) return [false, '移动失败'];
|
|
|
+
|
|
|
+ $weightOne = $res->sort;
|
|
|
+ $weightTwo = $moveRes->sort;
|
|
|
+
|
|
|
+ $res->sort = $weightTwo;
|
|
|
+ $res->save();
|
|
|
+ $moveRes->sort = $weightOne;
|
|
|
+ $moveRes->save();
|
|
|
+ }elseif($data['move'] == 'top' || $data['move'] == 'bottom'){
|
|
|
+ if($data['move'] == 'top'){
|
|
|
+ $sort = $model->where('del_time',0)->where('parent_id',$res->parent_id)->max('sort');
|
|
|
+ if($sort == $res->sort) return [false,'已经置顶,移动失败!'];
|
|
|
+ $res->sort = $sort + 1;
|
|
|
+ }elseif($data['move'] == 'bottom'){
|
|
|
+ $sort = $model->where('del_time',0)->where('parent_id',$res->parent_id)->min('sort');
|
|
|
+ if($sort == $res->sort) return [false,'已经置底部,移动失败!'];
|
|
|
+ $res->sort = $sort - 1;
|
|
|
+ }
|
|
|
+ $res->save();
|
|
|
+ }else{
|
|
|
+ return [false, '移动失败'];
|
|
|
+ }
|
|
|
|
|
|
+ return [true,'移动成功'];
|
|
|
+ }
|
|
|
}
|