Files
sentos/app/controller/admin/auth/User.php
2023-10-21 21:18:46 +08:00

120 lines
3.0 KiB
PHP

<?php
// +----------------------------------------------------------------------
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
// +----------------------------------------------------------------------
namespace app\controller\admin\auth;
use app\services\auth\UsersService;
use app\controller\Base;
class User extends Base{
/**
* @title 用户列表
* @param int $uid
* @return array
*/
public function index(UsersService $user){
$list = $user->getUserList($this->request);
$this->data['data'] = $list;
return $this->data;
}
/**
* @title 添加用户
* @param int $uid
* @return array
*/
public function add(){
try {
$res = app()->make(UsersService::class)->createUsers($this->request);
$this->data['code'] = 1;
$this->data['data'] = $res;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 修改用户信息
* @param int $uid
* @return array
*/
public function edit(){
try {
$res = app()->make(UsersService::class)->updateUsers($this->request);
$this->data['code'] = 1;
$this->data['data'] = $res;
$this->data['message'] = "更新成功!";
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 修改密码
*
* @return void
*/
public function passwd(){
try {
$res = app()->make(UsersService::class)->updateUserPassword($this->request);
$this->data['code'] = 1;
$this->data['data'] = $res;
$this->data['message'] = "修改成功";
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 批量导入用户
* @param int $uid
* @return array
*/
public function insert(){
try {
$users = app()->make(UsersService::class)->insertAll($this->request);
$this->data['data'] = $users;
$this->data['code'] = 1;
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
/**
* @title 用户信息
* @param int $uid
* @return array
*/
public function info(){
$this->data['data'] = app()->make(UsersService::class)->userInfo($this->request->user['uid']);
$this->data['code'] = 1;
return $this->data;
}
/**
* @title 用户授权
* @return array
*/
public function auth(){
try {
$uid = $this->request->param('uid');
$role = $this->request->param('role');
app()->make(UsersService::class)->updateRoles($uid, $role);
$this->data['message'] = '更新成功!';
} catch (\Exception $e) {
$this->data['code'] = 0;
$this->data['message'] = $e->getMessage();
}
return $this->data;
}
}