init: 项目初始代码

This commit is contained in:
2026-10-14 14:00:29 +08:00
commit cc434cf89f
464 changed files with 66984 additions and 0 deletions

View File

@@ -0,0 +1,90 @@
<?php
namespace app\api\controller\v1;
use app\api\model\Admin as AdminModel;
use app\api\validate\Admin as AdminValidate;
/**
* 后台管理员类
* Class Admin
* @package app\api\controller
*/
class Admin extends Base
{
const EMPTY_ADMINID = '-100';
const EMPTY_ADMIN = '-101';
const ERR_ADD = '-300';
const ERR_EDIT = '-301';
const ERR_FORBIDDEN = '-302';
const ERROR = [
self::ERR_ADD => '添加管理员失败',
self::ERR_EDIT => '编辑管理员失败',
self::ERR_FORBIDDEN => '禁用管理员失败',
self::EMPTY_ADMINID => 'id不能为空',
self::EMPTY_ADMIN => '没有找到该管理员'
];
public function initialize()
{
parent::initialize();
$this->validate = new AdminValidate();
$this->model = new AdminModel();
}
protected $errorMsg = [
self::EMPTY_ADMINID
];
/**
* 显示指定的资源
*
* @return \think\Response
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
*/
public function read()
{
$inputData = $this->request->param(['admin_id']);
if ($inputData['admin_id'] <= 0) {
return $this->msg(self::EMPTY_ADMINID, self::ERROR[self::EMPTY_ADMINID]);
}
$info = $this->model->getInfo($inputData['admin_id']);
if (empty($info)) {
return $this->msg(self::EMPTY_ADMIN, self::ERROR[self::EMPTY_ADMIN]);
}
return $this->msg(200, '获取管理员信息成功', $info);
}
/**
* 保存更新的资源
*
* @return \think\Response
*/
public function update()
{
$inputData = $this->request->param(['admin_id', 'password', 'role_id', 'mobile']);
$inputData['password'] = md5($inputData['password']);
if (!$this->commonValidate(__FUNCTION__,$inputData)) {
return $this->msg(-1,$this->validate->getError());
}
if ($inputData['password'] == '') {
unset($inputData['password']);
}
$result = $this->model->edit($inputData);
if ($result) {
return $this->msg(200, '编辑管理员成功');
} else {
return $this->msg(504, '编辑管理员失败');
}
}
}