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.
182 lines
6.3 KiB
182 lines
6.3 KiB
<?php
|
|
|
|
namespace App\Http\Controllers\Admin;
|
|
|
|
use App\Helpers\StarterResponseCode;
|
|
use App\Models\AuthNode;
|
|
use Illuminate\Support\Facades\Validator;
|
|
|
|
class AuthNodeController extends CommonController
|
|
{
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/admin/auth-node/index",
|
|
* tags={"权限"},
|
|
* summary="列表",
|
|
* description="",
|
|
* @OA\Parameter(name="page_size", in="query", @OA\Schema(type="string"), required=false, description="每页显示的条数"),
|
|
* @OA\Parameter(name="page", in="query", @OA\Schema(type="string"), required=false, description="页码"),
|
|
* @OA\Parameter(name="sort_name", in="query", @OA\Schema(type="string"), required=false, description="排序字段名字"),
|
|
* @OA\Parameter(name="sort_type", in="query", @OA\Schema(type="string"), required=false, description="排序类型"),
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
* @OA\Response(
|
|
* response="200",
|
|
* description="暂无"
|
|
* )
|
|
* )
|
|
*/
|
|
public function index()
|
|
{
|
|
$all = request()->all();
|
|
$list = AuthNode::orderBy($all['sort_name'] ?? 'id', $all['sort_type'] ?? 'desc')
|
|
->paginate($all['page_size'] ?? 20);
|
|
return $this->success($list);
|
|
}
|
|
|
|
|
|
/**
|
|
* @OA\Post(
|
|
* path="/api/admin/auth-node/store",
|
|
* tags={"权限"},
|
|
* summary="添加",
|
|
* description="",
|
|
* @OA\Parameter(name="tag", in="query", @OA\Schema(type="int"), required=true, description="标示"),
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=true, description="名字"),
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
* @OA\Response(
|
|
* response="200",
|
|
* description="暂无"
|
|
* )
|
|
* )
|
|
*/
|
|
public function store()
|
|
{
|
|
$all = \request()->all();
|
|
$messages = [
|
|
'tag.required' => '标示必填',
|
|
'name.required' => '名称必填',
|
|
];
|
|
$validator = Validator::make($all, [
|
|
'tag' => 'required',
|
|
'name' => 'required',
|
|
], $messages);
|
|
if ($validator->fails()) {
|
|
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
}
|
|
$model = new AuthNode();
|
|
$check = $model->where('tag', $all['tag'])->first();
|
|
if ($check) {
|
|
return $this->fail([StarterResponseCode::START_ERROR_BUSINESS, '标示已存在']);
|
|
}
|
|
$model->fill($all);
|
|
$model->save();
|
|
return $this->success('添加成功');
|
|
}
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/admin/auth-node/show",
|
|
* tags={"权限"},
|
|
* summary="详情",
|
|
* description="",
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=false, description="id"),
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
* @OA\Response(
|
|
* response="200",
|
|
* description="暂无"
|
|
* )
|
|
* )
|
|
*/
|
|
public function show()
|
|
{
|
|
$all = \request()->all();
|
|
$messages = [
|
|
'id.required' => 'id必填'
|
|
];
|
|
$validator = Validator::make($all, [
|
|
'id' => 'required'
|
|
], $messages);
|
|
if ($validator->fails()) {
|
|
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
}
|
|
$detail = AuthNode::find($all['id']);
|
|
return $this->success($detail);
|
|
}
|
|
|
|
|
|
/**
|
|
* @OA\Post(
|
|
* path="/api/admin/auth-node/save",
|
|
* tags={"权限"},
|
|
* summary="更新",
|
|
* description="",
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="int"), required=true, description="Id"),
|
|
* @OA\Parameter(name="tag", in="query", @OA\Schema(type="int"), required=true, description="标示"),
|
|
* @OA\Parameter(name="name", in="query", @OA\Schema(type="string"), required=true, description="名字"),
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
* @OA\Response(
|
|
* response="200",
|
|
* description="暂无"
|
|
* )
|
|
* )
|
|
*/
|
|
public function save()
|
|
{
|
|
$all = \request()->all();
|
|
$messages = [
|
|
'id.required' => 'Id必填',
|
|
'tag.required' => '标示必填',
|
|
'name.required' => '名称必填',
|
|
];
|
|
$validator = Validator::make($all, [
|
|
'id' => 'required',
|
|
'tag' => 'required',
|
|
'name' => 'required',
|
|
], $messages);
|
|
if ($validator->fails()) {
|
|
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
}
|
|
|
|
$check = AuthNode::where('tag', $all['tag'])->where('id', '!=', $all['id'])->first();
|
|
if ($check) {
|
|
return $this->fail([StarterResponseCode::START_ERROR_BUSINESS, '标示已存在']);
|
|
}
|
|
|
|
$model = AuthNode::find($all['id']);
|
|
$model->fill($all);
|
|
$model->save();
|
|
return $this->success('更新成功');
|
|
}
|
|
|
|
/**
|
|
* @OA\Get(
|
|
* path="/api/admin/auth-node/delete",
|
|
* tags={"权限"},
|
|
* summary="删除",
|
|
* description="",
|
|
* @OA\Parameter(name="id", in="query", @OA\Schema(type="string"), required=true, description="id"),
|
|
* @OA\Parameter(name="token", in="query", @OA\Schema(type="string"), required=true, description="token"),
|
|
* @OA\Response(
|
|
* response="200",
|
|
* description="暂无"
|
|
* )
|
|
* )
|
|
*/
|
|
public function delete()
|
|
{
|
|
$all = \request()->all();
|
|
$messages = [
|
|
'id.required' => 'Id必填',
|
|
];
|
|
$validator = Validator::make($all, [
|
|
'id' => 'required'
|
|
], $messages);
|
|
if ($validator->fails()) {
|
|
return $this->fail([StarterResponseCode::START_ERROR_PARAMETER, implode(',', $validator->errors()->all())]);
|
|
}
|
|
AuthNode::where('id', $all['id'])->delete();
|
|
return $this->success('删除成功');
|
|
}
|
|
}
|