创建模型
This commit is contained in:
75
app/Http/Controllers/Api/AdminController.php
Normal file
75
app/Http/Controllers/Api/AdminController.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?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'];
|
||||
}
|
||||
|
||||
/**
|
||||
* 修改密码
|
||||
* @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(),
|
||||
'获取成功'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user