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.
203 lines
7.4 KiB
203 lines
7.4 KiB
<?php
|
|
declare (strict_types=1);
|
|
|
|
/**
|
|
* Created by 安徽云掌.
|
|
* User: 云掌.帮德
|
|
* Date: 2020/3/8 22:30
|
|
* Desc: 字典类型类
|
|
*/
|
|
|
|
namespace app\api\controller;
|
|
|
|
use think\App;
|
|
|
|
|
|
class Dictionary extends Common
|
|
{
|
|
public $model = null;
|
|
|
|
public function __construct(App $app)
|
|
{
|
|
parent::__construct($app);
|
|
$this->model = new \app\api\model\Dictionary();
|
|
}
|
|
|
|
|
|
public function index()
|
|
{
|
|
//接受参数
|
|
$_get = $this->request->get();
|
|
|
|
//验证参数
|
|
// validate(\app\api\validate\Dictionary::class)->scene('lists')->check($_get);
|
|
|
|
//指定搜索参数
|
|
$this->model->search_arr = ['dict_name','dict_value:OR'];
|
|
|
|
//数据处理
|
|
$_data = $this->model->index();
|
|
|
|
//返回数据
|
|
return send_http_status($_data);
|
|
}
|
|
|
|
public function read(int $id = 0)
|
|
{
|
|
//验证参数
|
|
validate(\app\api\validate\Dictionary::class)->scene('read')->check(['id' => $id]);
|
|
|
|
//返回数据
|
|
return send_http_status($this->model->parentRead($id));
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (path="dictionary/add",tags={"测试案例"},summary="添加DEMO数据",description="添加后台DEMO管理数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema(ref="#/components/schemas/DemoField"),
|
|
* ),
|
|
* ),
|
|
* @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] 创建了字典类型:[dict_symbol]:[dict_name]
|
|
*/
|
|
public function add()
|
|
{
|
|
//接收参数
|
|
$_post = $this->request->post();
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Dictionary::class)->check($_post);
|
|
|
|
//处理并返回参数
|
|
$insertId = $this->model->parentAdd($_post);
|
|
return send_http_status($insertId, $insertId ? 201 : 202);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (path="dictionary/edit/id/{id}",tags={"测试案例"},summary="修改DEMO数据",description="修改后台DEMO管理数据",
|
|
* @OA\Parameter(ref="#/components/parameters/token"),
|
|
* @OA\RequestBody(
|
|
* @OA\MediaType(mediaType="application/json",
|
|
* @OA\Schema(ref="#/components/schemas/DemoField"),
|
|
* ),
|
|
* ),
|
|
* @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]修改了字典[dict_symbol]的数据
|
|
*/
|
|
public function edit(int $id = 0)
|
|
{
|
|
//接收参数
|
|
$_post = $this->request->post();
|
|
$_post['id'] = empty($_post['id']) ? $id : 0; //安全赋值,以免客户端没传id,修改需要id字段
|
|
|
|
//验证参数
|
|
validate(\app\api\validate\Dictionary::class)->scene('update')->check($_post);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', $this->model->parentEdit($_post, $id) ? 203 : 204);
|
|
}
|
|
|
|
|
|
/**
|
|
* @OA\Post (
|
|
* path="dictionary/delete",tags={"测试案例"},summary="删除DEMO数据",description="根据ID删除DEMO信息",
|
|
* @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] 删除了字典:[dict_symbol]:[dict_name]
|
|
*/
|
|
public function delete()
|
|
{
|
|
//接收参数
|
|
$ids = $this->request->param('id');
|
|
|
|
//验证参数
|
|
validate(['ids|id' => 'require|length:1,1000'])->check(['ids' => $ids]);
|
|
|
|
//处理并返回数据
|
|
return send_http_status('', $this->model->parentDel($ids) ? 205 : 206);
|
|
}
|
|
|
|
/**
|
|
* @OA\Post (
|
|
* path="dictionary/status",tags={"测试案例"},summary="更新DEMO状态",description="根据ID及status更新DEMO状态",
|
|
* @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] 设置ID为[id]测试账号为:[dictionary_status]
|
|
*/
|
|
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);
|
|
}
|
|
|
|
}
|
|
|