c; return $result; } public function Save($arr){ $result=[]; if($arr['info']['id']){ $query=DB::table('users')->where(['id'=>$arr['info']['id']])->update([ 'group' => $arr['info']['groupId'], 'cn_name' => $arr['info']['cname'], 'username' => $arr['info']['uname'], 'status'=>$arr['info']['status'], ]); if($query){ $result['status']='ok'; $result['msg']='操作成功'; }else{ $result['status']='no'; $result['msg']='操作失败,没有记录被更新'; } }else{ $hash = password_hash('111111', PASSWORD_DEFAULT); $c=DB::table('users')->where(['username'=>$arr['info']['uname']])->get(); if(count($c)){ $result['status']='no'; $result['msg']='用户名已存在'; return $result; } DB::beginTransaction(); try { $id=DB::table('users')->insertGetId([ 'group' => $arr['info']['groupId'], 'cn_name' => $arr['info']['cname'], 'username' => $arr['info']['uname'], 'pwd' => $hash, 'status'=>1 ]); DB::commit(); // 手动提交事务 if($id){ $result['status']='ok'; $result['msg']='操作成功'; } } catch (\Exception $e) { DB::rollback(); // 发生异常时手动回滚事务 $result['status']='no'; $result['msg']='操作失败'; } } return $result; } public function GetDetail($arr){ $c=DB::table('users')->select(['id','cn_name','username','status','group','img'])->where(['id'=>$arr['id']])->whereIn('status',[0,1])->get(); if(count($c)){ $result['info']=$c; $result['status']='ok'; $result['msg']='成功'; }else{ $result['status']='no'; $result['msg']='获取详情失败'; } return $result; } public function ChangePwd($arr){ $result=array(); $s=app()->make(LoginService::class); $check=$s->CheckPwd(['userid'=>$arr['id'],'password'=>$arr['oldpwd']]); if($check['status']){ $hash = password_hash($arr['newpwd'], PASSWORD_DEFAULT); $u=DB::table('users')->where(['id'=>$arr['id'],'status'=>1])->update(['pwd'=>$hash]); if($u){ $result['status']='ok'; }else{ $result['status']='no'; $result['msg']='修改密码失败'; } }else{ $result=$check; } return $result; } //检查用户是否有某个目录的权限 //参数['userid'=>$userid,'group'=>$group,'url'=>$url] public function CheckMenuAuth($arr){ $list=['index','dashboard']; $q=DB::select("select * from users where id=? and `group` =?",[$arr['userid'],$arr['group']]); if(count($q)==1){ if(in_array($arr['url'],$list)){ return \Yz::Return(true,'',[]); } $check=DB::select("select * from (select menu_id from group_menu where group_id=? ) as a inner JOIN (select id from menu where url = ? ) as b on a.menu_id=b.id ",[$arr['group'],$arr['url']]); if(count($check)>0){ return \Yz::Return(true,'',[]); }else{ return \Yz::echoError1('暂无权限'); } }else{ return \Yz::echoError1('权限不匹配'); } } //修改自身信息 public function ChangInfo($arr){ $u=DB::table('users')->where(['id'=>$arr['userid']])->update([ 'cn_name'=>$arr['name'], 'img'=>$arr['headimg'], ]); if($u>0){ return \Yz::Return(true,'操作成功',[]); }else{ return \Yz::echoError1('更新失败'); } } }