Files
swiftadmin/app/admin/controller/system/User.php

103 lines
2.9 KiB
PHP
Raw Normal View History

2022-08-19 19:48:37 +08:00
<?php
declare (strict_types=1);
// +----------------------------------------------------------------------
// | swiftAdmin 极速开发框架 [基于WebMan开发]
// +----------------------------------------------------------------------
// | Copyright (c) 2020-2030 http://www.swiftadmin.net
// +----------------------------------------------------------------------
// | swiftAdmin.net High Speed Development Framework
// +----------------------------------------------------------------------
// | Author: meystack <coolsec@foxmail.com> Apache 2.0 License
// +----------------------------------------------------------------------
namespace app\admin\controller\system;
2023-07-03 10:08:34 +08:00
use app\admin\service\UserService;
2022-08-19 19:48:37 +08:00
use app\AdminController;
2023-07-03 10:08:34 +08:00
use app\common\exception\OperateException;
2022-08-19 19:48:37 +08:00
use app\common\model\system\User as UserModel;
use app\common\model\system\UserGroup as UserGroupModel;
use support\Response;
use think\db\exception\DataNotFoundException;
use think\db\exception\DbException;
use think\db\exception\ModelNotFoundException;
/**
* 用户管理
* Class User
* @package app\admin\controller\system
*/
class User extends AdminController
{
// 初始化函数
public function __construct()
{
parent::__construct();
$this->model = new UserModel();
}
/**
* 获取资源
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
*/
2023-07-03 10:08:34 +08:00
public function index(): Response
2022-08-19 19:48:37 +08:00
{
if (request()->isAjax()) {
2023-07-03 10:08:34 +08:00
$post = request()->all();
list($count, $list) = UserService::dataList($post);
return $this->success('查询成功', "/", $list, $count);
2022-08-19 19:48:37 +08:00
}
return view('/system/user/index', [
2023-07-03 10:08:34 +08:00
'UserGroup' => UserGroupModel::select()->toArray()
2022-08-19 19:48:37 +08:00
]);
}
/**
* 添加会员
2023-07-03 10:08:34 +08:00
* @return Response
* @throws OperateException
2022-08-19 19:48:37 +08:00
*/
2023-07-03 10:08:34 +08:00
public function add(): Response
2022-08-19 19:48:37 +08:00
{
if (request()->isPost()) {
$post = request()->post();
2023-07-03 10:08:34 +08:00
validate(\app\common\validate\system\User::class)->scene('add')->check($post);
UserService::add($post);
return $this->success('注册成功!');
2022-08-19 19:48:37 +08:00
}
2023-07-03 10:08:34 +08:00
return $this->error('注册失败!');
2022-08-19 19:48:37 +08:00
}
/**
* 编辑会员
2023-07-03 10:08:34 +08:00
* @return Response
* @throws DataNotFoundException
* @throws DbException
* @throws ModelNotFoundException
* @throws OperateException
2022-08-19 19:48:37 +08:00
*/
2023-07-03 10:08:34 +08:00
public function edit(): Response
2022-08-19 19:48:37 +08:00
{
if (request()->isPost()) {
2023-07-03 10:08:34 +08:00
$post = request()->post();
validate(\app\common\validate\system\User::class)->scene('edit')->check($post);
UserService::edit($post);
return $this->success('更新成功!');
2022-08-19 19:48:37 +08:00
}
2023-07-03 10:08:34 +08:00
return $this->error('更新失败!');
2022-08-19 19:48:37 +08:00
}
/**
* 删除会员
*/
2022-11-28 19:11:12 +08:00
public function del(): Response
2022-08-19 19:48:37 +08:00
{
return $this->error('不允许删除会员');
}
}