Files
lgp-admin-plus-api/app/Http/Controllers/Api/AdminController.php
LQ bcf54c2727 初始化
缺陷:主题配色需要优化整体的同风格
2026-08-14 23:21:21 +08:00

133 lines
3.3 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Controllers\Api;
use App\BaseApp\BaseController;
use App\Service\AdminService;
use Exception;
use Illuminate\Http\JsonResponse;
class AdminController extends BaseController
{
//
public function __construct()
{
parent::__construct();
$this->service = AdminService::getInstance();
$this->insertField = [ 'phone', 'nick_name', 'password', 'role_id' ];
$this->updateField = [ 'id', 'phone', 'nick_name', 'role_id' ];
$this->notRequest = ['qr_code', 'avatar', 'email', 'status', 'department_id', 'desc'];
}
/**
* 修改密码
* @Method POST
* @return JsonResponse
* @throws Exception
*/
public function changePassword(): JsonResponse
{
$this->insertField = ['old_password', 'new_password', 'confirm_password'];
$params = $this->checkRequiredFields(request()->post());
if ($params['old_password'] === $params['new_password']) {
return jerr('新密码不能与旧密码相同');
} elseif ($params['new_password'] !== $params['confirm_password']) {
return jerr('新密码与确认密码不一致');
}
return jok(
$this->service->changePassword($params['old_password'], $params['new_password']),
'重置密码成功'
);
}
/**
* 重置密码
* @Method POST
* @return JsonResponse
* @throws Exception
*/
public function resetPassword(): JsonResponse
{
$this->insertField = ['id', 'password', 'new_password'];
$params = $this->checkRequiredFields(request()->post());
return jok(
$this->service->resetPassword($params['id'], $params['password'], $params['new_password']),
'重置密码成功'
);
}
/**
* 获取当前用户信息
* @Method GET
* @return JsonResponse
* @throws Exception
*/
public function myInfo(): JsonResponse
{
return jok(
$this->service->myInfo(),
'获取成功'
);
}
/**
* 个人中心更新资料
* @Method POST
*/
public function updateProfile(): JsonResponse
{
return jok($this->service->updateProfile(request()->post()), '保存成功');
}
/**
* 个人中心:登录日志
* @Method GET
*/
public function loginLog(): JsonResponse
{
return jok($this->service->loginLogList(), '获取成功');
}
/**
* 个人中心:操作日志
* @Method GET
*/
public function opLog(): JsonResponse
{
return jok($this->service->opLogList(), '获取成功');
}
/**
* 获取菜单列表
* @Method GET
* @return JsonResponse
* @throws Exception
*/
public function menu(): JsonResponse
{
return jok(
$this->service->menu(),
'获取成功'
);
}
/**
* 获取当前账号的权限码
*
* 码由接口路径推导admin/list → admin:list前端 v-access 与 TableAction 的 auth 用的就是它。
* @Method GET
* @return JsonResponse
* @throws Exception
*/
public function codes(): JsonResponse
{
return jok(
$this->service->codes(),
'获取成功'
);
}
}