|
@@ -3,7 +3,9 @@ declare (strict_types = 1);
|
|
|
|
|
|
namespace app\Admin\controller;
|
|
|
|
|
|
+use app\Admin\model\AdminAccount;
|
|
|
use app\BaseController;
|
|
|
+use think\facade\Db;
|
|
|
use think\Request;
|
|
|
|
|
|
class User extends BaseController
|
|
@@ -31,72 +33,175 @@ class User extends BaseController
|
|
|
if(!empty($data) && $data['code']!=0){
|
|
|
return error_show($effetc['code'],$effetc['message']);
|
|
|
}
|
|
|
+ $list=[];
|
|
|
+ foreach($data['data']['list'] as $key=>$value){
|
|
|
+ $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$value['id'])
|
|
|
+ ->field("roleid,role_name")->find();
|
|
|
+ $value['roleid'] = isset($role['roleid']) ? $role['roleid'] :"";
|
|
|
+ $value['role_name'] = isset($role['role_name']) ? $role['role_name'] :"";
|
|
|
+ $list[]=$value;
|
|
|
+ }
|
|
|
+ $data['data']['list'] = $list;
|
|
|
return app_show($data['code'],$data['message'],$data['data']);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 显示创建资源表单页.
|
|
|
- *
|
|
|
- * @return \think\Response
|
|
|
+ * @param token
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\exception\DbException
|
|
|
*/
|
|
|
- public function info()
|
|
|
- {
|
|
|
+ public function userInfo(){
|
|
|
+ $post =$this->request->post();
|
|
|
+ $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ if($token==""){
|
|
|
+ return app_show(101,'token不能为空');
|
|
|
+ }
|
|
|
|
|
|
+ $effetc = VerifyTokens($token);
|
|
|
+ if(!empty($effetc) && $effetc['code']!=0){
|
|
|
+ return app_show($effetc['code'],$effetc['message']);
|
|
|
+ }
|
|
|
+ $userinfo=GetUserInfo($token);
|
|
|
+ if(empty($userinfo)||$userinfo['code']!=0){
|
|
|
+ return app_show(1002,"员工信息不存在");
|
|
|
+ }
|
|
|
+ $data = $userinfo['data'];
|
|
|
+ $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$data['id'])
|
|
|
+ ->field("roleid,role_name")->find();
|
|
|
+ $data['role_name']=isset($role['role_name']) ? $role['role_name'] :"";
|
|
|
+ $data['roleid']=isset($role['roleid']) ? $role['roleid'] :"";
|
|
|
+ return app_show(0,"获取成功",$data);
|
|
|
}
|
|
|
-
|
|
|
/**
|
|
|
- * 保存新建的资源
|
|
|
- *
|
|
|
- * @param \think\Request $request
|
|
|
- * @return \think\Response
|
|
|
+ * @param token
|
|
|
+ * @param passwd
|
|
|
+ * @return \think\response\Json
|
|
|
+ * @throws \think\exception\DbException
|
|
|
*/
|
|
|
- public function save(Request $request)
|
|
|
- {
|
|
|
- //
|
|
|
- }
|
|
|
+ public function resetPwd(){
|
|
|
+ $post =$this->request->post();
|
|
|
+ $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ if($token==""){
|
|
|
+ return error_show(101,'token不能为空');
|
|
|
+ }
|
|
|
+ $effetc = verfiyToken($token);
|
|
|
+ if(!empty($effetc) && $effetc['code']!=0){
|
|
|
+ return error_show($effetc['code'],$effetc['message']);
|
|
|
+ }
|
|
|
+ $newPwd= isset($post['passwd']) ? trim($post['passwd']) : "";
|
|
|
+ if($newPwd==""){
|
|
|
+ return error_show(1001,'新密码不能为空');
|
|
|
+ }
|
|
|
+ $oldpasswd= isset($post['oldpasswd']) ? trim($post['oldpasswd']) : "";
|
|
|
+ if($oldpasswd==""){
|
|
|
+ return error_show(1001,'旧密码不能为空');
|
|
|
+ }
|
|
|
|
|
|
- /**
|
|
|
- * 显示指定的资源
|
|
|
- *
|
|
|
- * @param int $id
|
|
|
- * @return \think\Response
|
|
|
- */
|
|
|
- public function read($id)
|
|
|
- {
|
|
|
- //
|
|
|
+
|
|
|
+ $account =model("AdminAccount")->GetAccountByUid($effetc['user']['id']);
|
|
|
+ if(!empty ($account) && $account->status!=1){
|
|
|
+ return error_show(10005, '账户已被禁止登录');
|
|
|
+ }
|
|
|
+ if($account->password!=sha1($oldpasswd.$account->salt)){
|
|
|
+ return error_show(10005, '旧密码错误!');
|
|
|
+ }
|
|
|
+ $salt=makeSalt();
|
|
|
+ $data=['password'=>sha1($newPwd.$salt),'salt'=>$salt,"updatetime"=>date("Y-m-d H:i:s")];
|
|
|
+
|
|
|
+ return AdminAccount::update($data,["id"=>$account->id]) ? app_show(0, '密码修改成功') : error_show(1001,"密码修改失败");
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 显示编辑资源表单页.
|
|
|
- *
|
|
|
- * @param int $id
|
|
|
- * @return \think\Response
|
|
|
- */
|
|
|
- public function edit($id)
|
|
|
- {
|
|
|
- //
|
|
|
+ public function userAll(){
|
|
|
+ $post =$this->request->post();
|
|
|
+ $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ if($token==""){
|
|
|
+ return app_show(101,'token不能为空');
|
|
|
+ }
|
|
|
+ $effetc = VerifyTokens($token);
|
|
|
+ if(!empty($effetc) && $effetc['code']!=0){
|
|
|
+ return app_show($effetc['code'],$effetc['message']);
|
|
|
+ }
|
|
|
+ $userinfo=GetAccountall($token);
|
|
|
+
|
|
|
+ if(empty($userinfo)||$userinfo['code']!=0){
|
|
|
+ return app_show(1002,"员工信息不存在");
|
|
|
+ }
|
|
|
+ $data = $userinfo['data'];
|
|
|
+ $role = Db::name("role")->column("role_name","id");
|
|
|
+ $role[0]="";
|
|
|
+ $list=[];
|
|
|
+ foreach ($data as $value){
|
|
|
+ $value["role_name"] = isset($role[$value["roleid"]]) ? $role[$value["roleid"]]:"";
|
|
|
+ $list[]=$value;
|
|
|
+ }
|
|
|
+ return app_show(0,"获取成功",$list);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 保存更新的资源
|
|
|
- *
|
|
|
- * @param \think\Request $request
|
|
|
- * @param int $id
|
|
|
- * @return \think\Response
|
|
|
+ * @return \think\response\Json|void
|
|
|
+ * @throws \think\db\exception\DataNotFoundException
|
|
|
+ * @throws \think\db\exception\DbException
|
|
|
+ * @throws \think\db\exception\ModelNotFoundException
|
|
|
+ * @throws \think\exception\DbException
|
|
|
*/
|
|
|
- public function update(Request $request, $id)
|
|
|
- {
|
|
|
- //
|
|
|
+ public function userList(){
|
|
|
+ $post =$this->request->post();
|
|
|
+ $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ if($token==""){
|
|
|
+ return app_show(101,'token不能为空');
|
|
|
+ }
|
|
|
+ $effetc = VerifyTokens($token);
|
|
|
+ if(!empty($effetc) && $effetc['code']!=0){
|
|
|
+ return app_show($effetc['code'],$effetc['message']);
|
|
|
+ }
|
|
|
+ $userinfo=GetList($token,$post);
|
|
|
+ if(empty($userinfo)||$userinfo['code']!=0){
|
|
|
+ return app_show($userinfo['code'],$userinfo['msg']);
|
|
|
+ }
|
|
|
+ $data = $userinfo['data']['list'];
|
|
|
+ $list=[];
|
|
|
+ foreach ($data as $value){
|
|
|
+ $role = Db::name("user_role")->alias('a')->leftJoin('role b',"a.roleid = b.id")->where("a.uid","=",$value['id'])
|
|
|
+ ->field("roleid,role_name")->find();
|
|
|
+ $value['roleid'] = isset($role['roleid']) ? $role['roleid'] :"";
|
|
|
+ $value['role_name'] = isset($role['role_name']) ? $role['role_name'] :"";
|
|
|
+ $list[]=$value;
|
|
|
+ }
|
|
|
+ return app_show(0,"获取成功",["list"=>$list,"count"=>$userinfo['data']["count"]]);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 删除指定资源
|
|
|
- *
|
|
|
- * @param int $id
|
|
|
- * @return \think\Response
|
|
|
- */
|
|
|
- public function delete($id)
|
|
|
- {
|
|
|
- //
|
|
|
+
|
|
|
+ public function setRole(){
|
|
|
+ $post =$this->request->post();
|
|
|
+ $token = isset($post['token']) ? trim($post['token']) : "";
|
|
|
+ if($token==""){
|
|
|
+ return app_show(101,'token不能为空');
|
|
|
+ }
|
|
|
+ $effetc = VerifyTokens($token);
|
|
|
+ if(!empty($effetc) && $effetc['code']!=0){
|
|
|
+ return app_show($effetc['code'],$effetc['message']);
|
|
|
+ }
|
|
|
+ $uid = isset($post['id'])&&$post['id']!=='' ? intval($post['id']) :"";
|
|
|
+ if($uid===''){
|
|
|
+ return error_show(1004,"参数id 不能为空");
|
|
|
+ }
|
|
|
+ $role =isset($post['roleid']) && $post['roleid']!=="" ? intval($post['roleid']) :"";
|
|
|
+ if($role===''){
|
|
|
+ return error_show(1004,"参数roleid 不能为空");
|
|
|
+ }
|
|
|
+ $isRole = Db::name('role')->where([['id',"=",$role],['status',"=",1]])->find();
|
|
|
+ if(empty($isRole)){
|
|
|
+ return error_show(1004,"所选角色不存在");
|
|
|
+ }
|
|
|
+ $data = [
|
|
|
+ 'uid'=>$uid,
|
|
|
+ 'roleid'=>$role,
|
|
|
+ 'status'=>1,
|
|
|
+ 'addtime'=>date('Y-m-d H:i:s'),
|
|
|
+ 'updatetime'=>date('Y-m-d H:i:s'),
|
|
|
+ ];
|
|
|
+ $insert = Db::name('user_role')->insert($data);
|
|
|
+
|
|
|
+ return $insert? app_show(0,'数据新建成功'):error_show(1004,'数据新建失败');
|
|
|
}
|
|
|
}
|