捕梦者基础框架API接口
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

439 lines
18 KiB

<?php
declare (strict_types=1);
/**
* Created by 安徽云掌.
* User: 云掌.帮德
* Date: 2020/3/8 22:30
* Desc: 管理员类
*/
namespace app\api\controller;
use auth\PermissAuth;
use think\App;
/**
* Manager类添加、修改等公共请求参数
* @OA\Schema (
* schema = "ManagerField",
* required={"username","password","sex","phone"},
* @OA\Property(property="username",type="string",minLength=2,maxLength=20,mock={"mock":"@word"},default="Jessica Smitch",description="管理员名称"),
* @OA\Property(property="truename",type="string",minLength=2,maxLength=20,mock={"mock":"@cname"},default="jack ",description="管理员真实姓名"),
* @OA\Property(property="password",type="string",minLength=6,maxLength=20,mock={"mock":"@string"},default="",description="管理员密码"),
* @OA\Property(property="sex",type="integer",format="int15",minLength=1,maxLength=1,default="0",description="性别"),
* @OA\Property(property="phone",type="integer",format="int15",minLength=11,maxLength=11,default="",description="手机号"),
* @OA\Property(property="email",type="string",minLength=5,maxLength=50,mock={"mock":"@email"},default="",description="管理员邮箱"),
* @OA\Property(property="status",type="integer",format="int15",minLength=1,maxLength=1,default="1",description="状态"),
* @OA\Property(property="introduction",type="string",minLength=1,maxLength=200,mock={"mock":"@cparagraph"},default=" ",description="管理员简介"),
* ),
*/
class Manager extends Common
{
public $model = null;
public function __construct(App $app)
{
parent::__construct($app);
$this->model = new \app\api\model\Manager();
}
/**
* @OA\Get (
* path="manager/index",tags={"用户管理"},summary="获取用户列表",description="根据相关参数获取用户列表",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\Parameter(name="username",in="query",description="管理员名称",@OA\Schema (type="string")),
* @OA\Parameter(name="truename",in="query",description="真实姓名",@OA\Schema (type="string")),
* @OA\Parameter (name="phone",in="query",description="手机号",@OA\Schema (type="integer",format="int15")),
* @OA\Parameter (name="sex",in="query",description="性别",@OA\Schema (type="integer",format="int15")),
* @OA\Parameter (name="page",in="query",description="当前页码",@OA\Schema (type="integer",format="int15")),
* @OA\Parameter (name="limit",in="query",description="分页数量",@OA\Schema (type="integer",format="int15")),
* @OA\Response(
* response=200,
* description="返回管理员用户数据信息",
* @OA\JsonContent(ref="#/components/schemas/ManagerMsgExport"),
* ),
* )
*/
public function index()
{
//接受参数
$_get = $this->request->get();
//验证参数
validate(\app\api\validate\Manager::class)->scene('lists')->check($_get);
//指定搜索参数
$this->model->search_arr = ['username', 'phone', 'sex', 'truename'];
//数据处理
$_data = $this->model->index();
//返回数据
return send_http_status($_data);
}
/**
* @OA\Get (
* path="manager/read/id/{id}",tags={"用户管理"},summary="获取用户详情",description="根据ID查询用户信息",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\Parameter(name="id",in="path",required=true,description="ID",@OA\Schema (type="integer",format="int32")),
* @OA\Response(
* response=200,
* description="返回管理员用户数据信息",
* @OA\JsonContent(ref="#/components/schemas/ManagerMsgExport"),
* ),
* )
*/
public function read(int $id = UID)
{
//验证参数
validate(\app\api\validate\Manager::class)->scene('read')->check(['id' => $id]);
//返回数据
return send_http_status($this->model->parentRead($id));
}
/**
* @OA\Get (
* path="manager/readPersional",tags={"用户管理"},summary="获取个人详情",description="获取当前登录用户的个人资料",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\Response(
* response=200,
* description="返回当前登录用户的数据信息",
* @OA\JsonContent(ref="#/components/schemas/ManagerMsgExport"),
* ),
* )
*/
public function readPersional()
{
//验证参数
validate(\app\api\validate\Manager::class)->scene('read')->check(['id' => UID]);
//返回数据
return send_http_status($this->model->parentRead(UID));
}
/**
* @OA\Get (
* path="manager/permissMenu",tags={"用户管理"},summary="获取用户权限",description="根据当前登录用户UID获取当前用户权限菜单",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\Response(
* response=200,
* description="返回管理员权限菜单数据",
* @OA\JsonContent(ref="#/components/schemas/MenuMsgExport"),
* ),
* )
*/
public function permissMenu()
{
$_data = PermissAuth::getInstance()->getAuthList(UID, 1, true);
//用户权限
$_data = get_tree($_data, 0, 'children');
//返回数据
return send_http_status($_data);
}
/**
* @OA\Post (path="manager/add",tags={"用户管理"},summary="添加管理员数据",description="添加后台管理员数据",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\RequestBody(
* @OA\MediaType(mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ManagerField"),
* ),
* ),
* @OA\Response(
* response=200,
* description="添加成功",
* @OA\JsonContent(type="object",
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
* @OA\Property(property="msg", type="string",description="提示信息"),
* @OA\Property(property="count", type="integer",format="int32",description="记录总数"),
* @OA\Property(property="data", type="integer",format="int32",description="添加成功的的数据ID"),
* ),
* ),
* )
* @Log [sys_name] 在 [sys_time] 创建了管理员:[username]
*/
public function add()
{
//接收参数
$_post = $this->request->post();
//验证参数
validate(\app\api\validate\Manager::class)->check($_post);
//处理并返回参数
$insertId = $this->model->parentAdd($_post);
return send_http_status($insertId, $insertId ? 201 : 202);
}
/**
* @OA\Post (path="manager/edit/id/{id}",tags={"用户管理"},summary="修改用户数据",description="修改管理员数据",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\RequestBody(
* @OA\MediaType(mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ManagerField"),
* ),
* ),
* @OA\Response(
* response=200,
* description="修改数据状态",
* @OA\JsonContent(type="object",
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
* @OA\Property(property="msg", type="string",description="提示信息"),
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
* @OA\Property(property="data", type="string",description="不返回"),
* ),
* ),
* )
* @Log [sys_name]在[sys_time] 修改了管理员账号[username]的数据
*/
public function edit($id = 0)
{
//接收参数
$_post = $this->request->param();
//验证参数
validate(\app\api\validate\Manager::class)->scene('update')->check($_post);
//处理并返回数据
return send_http_status('', $this->model->parentEdit($_post, $id) ? 203 : 204);
}
/**
* @OA\Post (path="manager/editPersional",tags={"用户管理"},summary="修改个人数据",description="修改自己的个人资料",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\RequestBody(
* @OA\MediaType(mediaType="application/json",
* @OA\Schema(ref="#/components/schemas/ManagerField"),
* ),
* ),
* @OA\Response(
* response=200,
* description="修改数据状态",
* @OA\JsonContent(type="object",
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
* @OA\Property(property="msg", type="string",description="提示信息"),
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
* @OA\Property(property="data", type="string",description="不返回"),
* ),
* ),
* )
* @Log [sys_name]在[sys_time] 修改了管理员账号[username]的数据
*/
public function editPersional()
{
//接收参数
$_post = $this->request->param();
//验证参数
validate(\app\api\validate\Manager::class)->scene('update')->check($_post);
//处理并返回数据
return send_http_status('', $this->model->parentEdit($_post, UID) ? 203 : 204);
}
/**
* @OA\Post (
* path="manager/passwordEdit",tags={"用户管理"},summary="重置用户密码",description="根据ID重置用户密码",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\RequestBody(
* @OA\MediaType(mediaType="application/json",
* @OA\Schema (
* required={"id","password","old_password","username"},
* @OA\Property(property="id",type="integer",format="int15",description="用户ID"),
* @OA\Property(property="password",type="string",minLength=6,maxLength=20,description="新密码"),
* @OA\Property(property="old_password",type="string",minLength=6,maxLength=20,description="原始密码"),
* @OA\Property(property="username",type="string",minLength=2,maxLength=20,description="管理员账号"),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="删除数据状态",
* @OA\JsonContent(type="object",
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
* @OA\Property(property="msg", type="string",description="提示信息"),
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
* @OA\Property(property="data", type="string",description="不返回"),
* ),
* ),
* )
* @Log [sys_name]在[sys_time] 修改了账号密码
*/
public function passwordEdit()
{
//接收参数
$_post = $this->request->param();
$_post['id'] = UID;
//验证参数
validate(\app\api\validate\Manager::class)->scene('UpdatePassword')->check($_post);
//处理并返回数据
return send_http_status('', $this->model->parentEdit($_post, UID) ? 203 : 204);
}
/**
* @OA\Post (
* path="manager/passwordReset",tags={"用户管理"},summary="重置用户密码",description="根据ID重置用户密码",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\RequestBody(
* @OA\MediaType(mediaType="application/json",
* @OA\Schema (
* required={"id","password","username"},
* @OA\Property(property="id",type="integer",format="int15",description="用户ID"),
* @OA\Property(property="password",type="string",minLength=6,maxLength=20,description="管理员密码"),
* @OA\Property(property="username",type="string",minLength=2,maxLength=20,description="管理员账号"),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="删除数据状态",
* @OA\JsonContent(type="object",
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
* @OA\Property(property="msg", type="string",description="提示信息"),
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
* @OA\Property(property="data", type="string",description="不返回"),
* ),
* ),
* )
* @Log [sys_name]在[sys_time] 重置了[username]的账号密码为:[password]
*/
public function passwordReset()
{
//接收参数
$_post = $this->request->only(['id', 'password', 'username']);
//验证参数
validate(\app\api\validate\Manager::class)->scene('ResetPassword')->check($_post);
//处理并返回数据
return send_http_status('', $this->model->parentEdit($_post, $_post['id']) ? 203 : 204);
}
/**
* @OA\Post (
* path="manager/delete",tags={"用户管理"},summary="删除用户数据",description="根据ID删除用户数据",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\RequestBody(
* @OA\MediaType(mediaType="application/json",
* @OA\Schema (
* required={"id"},
* @OA\Property(property="id",type="string",description="数据ID或数据ID集合 id=1或 id=1,2,8"),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="删除数据状态",
* @OA\JsonContent(type="object",
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
* @OA\Property(property="msg", type="string",description="提示信息"),
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
* @OA\Property(property="data", type="string",description="不返回"),
* ),
* ),
* )
* @Log [sys_name] 在 [sys_time] 删除了管理员账号:[username]
*/
public function delete()
{
//接收参数
$ids = $this->request->post('id');
//验证参数
validate(['ids|id' => 'require|length:1,100'])->check(['ids' => $ids]);
//处理并返回数据
return send_http_status('', $this->model->parentDel($ids) ? 205 : 206);
}
/**
* @OA\Post (
* path="manager/status",tags={"用户管理"},summary="更新用户状态",description="根据ID及status更新用户状态",
* @OA\Parameter(ref="#/components/parameters/token"),
* @OA\RequestBody(
* @OA\MediaType(mediaType="application/json",
* @OA\Schema (
* required={"id","status"},
* @OA\Property(property="id",type="string",description="数据ID或数据ID集合 id=1或 id=1,2,8"),
* @OA\Property(property="status",type="integer",format="int15",description="数据状态 0禁用 1启用"),
* ),
* ),
* ),
* @OA\Response(
* response=200,
* description="删除数据状态",
* @OA\JsonContent(type="object",
* @OA\Property(property="code", type="integer",format="int32",description="状态码"),
* @OA\Property(property="msg", type="string",description="提示信息"),
* @OA\Property(property="count", type="integer",format="int32",description="记录数"),
* @OA\Property(property="data", type="string",description="不返回"),
* ),
* ),
* )
* @Log [sys_name] 在 [sys_time] [dictionary_status]了管理员:[username], 管理员ID为:[id]
*/
public function status()
{
//接收参数
$ids = $this->request->param('id');
$status = $this->request->param('status');
//验证参数
$_rules = [
'ids|id' => 'require|length:1,100',
'status|状态值' => 'require|number|length:1',
];
validate($_rules)->check(['ids' => $ids, 'status' => $status]);
//处理并返回数据
return send_http_status('', $this->model->parentStatus($ids, $status) !== false ? 207 : 208);
}
public function getMessage(){
$type = $this->request->param('type','98');
$model = new \app\api\model\Message();
$_data = $model->getUserMessage($type);
return send_http_status($_data);
}
public function messageStatus()
{
//接收参数
$ids = $this->request->param('id');
$type = $this->request->param('type');
$model = new \app\api\model\Message();
//处理并返回数据
return send_http_status('',$model->setMessageRead($ids,$type) !== false ? 207 : 208);
}
public function messageDelete(){
//接收参数
$ids = $this->request->param('id');
$model = new \app\api\model\Message();
//处理并返回数据
return send_http_status('',$model->setMessageDelete($ids) ? 205 : 206);
}
public function setMessage(){
//获取未读系统邮件
$message = new \app\api\model\Message();
$message->setUserMessage();
return send_http_status('', 200);
}
}