|
|
@@ -77,13 +77,14 @@ class AuthorityService implements AuthorityServiceInterface
|
|
|
Db::beginTransaction();
|
|
|
try{
|
|
|
$child_key = 0;
|
|
|
- if($data['pid_arr'] != $menu['pid_arr']){
|
|
|
- $all_child_pid = Menu::where('pid','!=',0)->where('id','!=',$where['id'])->select('pid_arr','id','pid')->orderByRaw("JSON_LENGTH(pid_arr)")->get()->toArray();
|
|
|
- if($data['pid'] == 0){
|
|
|
- $pid_arr = [];
|
|
|
- }
|
|
|
- $child_id = array_keys($all_child_pid);
|
|
|
- $ids = array_column($all_child_pid,'id');
|
|
|
+ $all_child_pid = Menu::where('pid','!=',0)->where('id','!=',$where['id'])->select('pid_arr','id','pid')->orderByRaw("JSON_LENGTH(pid_arr)")->get()->toArray();
|
|
|
+ if($data['pid'] == 0){
|
|
|
+ $pid_arr = [];
|
|
|
+ }
|
|
|
+ $child_id = array_keys($all_child_pid);
|
|
|
+ $ids = array_column($all_child_pid,'id');
|
|
|
+ $pids = array_column($all_child_pid,'pid');
|
|
|
+ if($data['pid_arr'] != $menu['pid_arr'] && in_array($where['id'],$pids)){
|
|
|
$child_pid = [];
|
|
|
$one_pidarr = [];
|
|
|
$pid_arrnum = [];
|
|
|
@@ -128,23 +129,14 @@ class AuthorityService implements AuthorityServiceInterface
|
|
|
Db::rollBack();
|
|
|
return Result::error('更新子菜单失败');
|
|
|
}
|
|
|
- $result = Menu::where($where)->update($data);
|
|
|
- if(empty($result)){
|
|
|
- Db::rollBack();
|
|
|
- return Result::error('更新菜单失败');
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- return Result::success($result);
|
|
|
- }else{
|
|
|
- // 当 pid_arr 没有变化时,也要执行更新并返回结果
|
|
|
- $result = Menu::where($where)->update($data);
|
|
|
- if(empty($result)){
|
|
|
- Db::rollBack();
|
|
|
- return Result::error('更新菜单失败');
|
|
|
- }
|
|
|
- Db::commit();
|
|
|
- return Result::success($result);
|
|
|
}
|
|
|
+ $result = Menu::where($where)->update($data);
|
|
|
+ if(empty($result)){
|
|
|
+ Db::rollBack();
|
|
|
+ return Result::error('更新菜单失败');
|
|
|
+ }
|
|
|
+ Db::commit();
|
|
|
+ return Result::success($result);
|
|
|
}catch (\Exception $e){
|
|
|
Db::rollBack();
|
|
|
return Result::error($e->getMessage());
|