133 lines
3.3 KiB
PHP
133 lines
3.3 KiB
PHP
<?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(),
|
||
'获取成功'
|
||
);
|
||
}
|
||
}
|