更新
This commit is contained in:
124
app/controller/auth/Department.php
Normal file
124
app/controller/auth/Department.php
Normal file
@@ -0,0 +1,124 @@
|
||||
<?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\auth;
|
||||
|
||||
use think\facade\Request;
|
||||
use app\model\auth\Departments;
|
||||
use app\services\auth\DepartmentService;
|
||||
use sent\tree\Tree;
|
||||
use app\controller\Base;
|
||||
|
||||
class Department extends Base {
|
||||
/**
|
||||
* @title 部门列表
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @param Departments $department
|
||||
* @return Array
|
||||
*/
|
||||
public function index() {
|
||||
$list = app()->make(DepartmentService::class)->getDepartmentList($this->request)->toArray();
|
||||
if(count($list) > 0){
|
||||
$root = '';
|
||||
foreach ($list as $value) {
|
||||
if($root == ''){
|
||||
$root = $value['parent_id'];
|
||||
}else{
|
||||
if($root > $value['parent_id']){
|
||||
$root = $value['parent_id'];
|
||||
}
|
||||
}
|
||||
}
|
||||
$tree = (new Tree())->listToTree($list, 'id', 'parent_id', 'children', $root);
|
||||
if(empty($tree)){
|
||||
$this->data['data'] = $list;
|
||||
}else{
|
||||
$this->data['data'] = $tree;
|
||||
}
|
||||
}else{
|
||||
$this->data['data'] = [];
|
||||
}
|
||||
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 添加部门
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @return Array
|
||||
*/
|
||||
public function add() {
|
||||
$data = request()->post();
|
||||
$data['creator_id'] = request()->user['uid'];
|
||||
try {
|
||||
$result = Departments::create($data);
|
||||
$this->data['message'] = '添加成功!';
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 更新部门
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @param $id
|
||||
* @param Request $request
|
||||
* @return Array
|
||||
*/
|
||||
public function edit() {
|
||||
$data = request()->post();
|
||||
$data['creator_id'] = request()->user['uid'];
|
||||
try {
|
||||
$result = Departments::update($data);
|
||||
$this->data['message'] = '更新成功!';
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 删除部门
|
||||
*
|
||||
* @time 2020年01月09日
|
||||
* @param $id
|
||||
* @return Array
|
||||
*/
|
||||
public function delete() {
|
||||
$data = request()->post('id');
|
||||
$map = [];
|
||||
if(is_array($data)){
|
||||
$map[] = ['id', 'IN', $data];
|
||||
}else if(is_numeric($data)){
|
||||
$map[] = ['id', '=', $data];
|
||||
}
|
||||
try {
|
||||
$result = Departments::destroy(function($query) use ($map){
|
||||
$query->where($map);
|
||||
});
|
||||
$this->data['message'] = '删除成功!';
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
/**
|
||||
* @title 获取班级
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function studentclass(){
|
||||
$this->data['data'] = app()->make(DepartmentService::class)->getStudentClassList();
|
||||
$this->data['code'] = 1;
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,14 @@
|
||||
namespace app\controller\auth;
|
||||
|
||||
use app\controller\Base;
|
||||
use app\services\auth\LoginService;
|
||||
use app\services\auth\AuthService;
|
||||
use app\services\SocialiteService;
|
||||
|
||||
class Index extends Base{
|
||||
|
||||
public function login(LoginService $service){
|
||||
public function login(AuthService $service){
|
||||
try {
|
||||
$data = $service->authLogin($this->request);
|
||||
$data = $service->login($this->request);
|
||||
$this->data['data'] = $data;
|
||||
} catch (\think\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
@@ -23,4 +24,14 @@ class Index extends Base{
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 第三方账号登录
|
||||
*/
|
||||
public function socialite(){
|
||||
//实例化第三方登录服务
|
||||
$service = new SocialiteService();
|
||||
|
||||
return $service->login();
|
||||
}
|
||||
}
|
||||
|
||||
73
app/controller/auth/Role.php
Normal file
73
app/controller/auth/Role.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?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\auth;
|
||||
|
||||
use app\controller\Base;
|
||||
use app\services\auth\RoleService;
|
||||
|
||||
class Role extends Base{
|
||||
|
||||
/**
|
||||
* @title 角色列表
|
||||
*
|
||||
* @time 2019年12月09日
|
||||
* @return string|Json
|
||||
*/
|
||||
public function index() {
|
||||
$tree = app()->make(RoleService::class)->getRolesList($this->request, true);
|
||||
|
||||
$this->data['code'] = 1;
|
||||
$this->data['data'] = $tree;
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 角色授权
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @param Request $request
|
||||
* @return Array
|
||||
*/
|
||||
public function auth() {
|
||||
$role_id = $this->request->param('role_id', '');
|
||||
$auth = $this->request->param('auth', '');
|
||||
$service = app()->make(RoleService::class);
|
||||
try {
|
||||
$service->updateRolePermission($role_id, $auth);
|
||||
$service->updateRoleAuth($this->request);
|
||||
$this->data['code'] = 1;
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 删除角色
|
||||
*
|
||||
* @time 2019年12月11日
|
||||
* @param $id
|
||||
* @throws FailedException
|
||||
* @throws \think\db\exception\DataNotFoundException
|
||||
* @throws \think\db\exception\DbException
|
||||
* @throws \think\db\exception\ModelNotFoundException
|
||||
* @return Json
|
||||
*/
|
||||
public function delete(){
|
||||
try {
|
||||
$service = app()->make(RoleService::class)->deleteRole($this->request);
|
||||
$this->data['code'] = 1;
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
101
app/controller/auth/User.php
Normal file
101
app/controller/auth/User.php
Normal file
@@ -0,0 +1,101 @@
|
||||
<?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\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;
|
||||
} 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');
|
||||
$manage_class = $this->request->param('manage_class');
|
||||
app()->make(UsersService::class)->updateRoles($uid, $role, $manage_class);
|
||||
$this->data['message'] = '更新成功!';
|
||||
} catch (\Exception $e) {
|
||||
$this->data['code'] = 0;
|
||||
$this->data['message'] = $e->getMessage();
|
||||
}
|
||||
return $this->data;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user