从登陆接口开始
权限管理,是在管理员登录后台后才有的,因此,我们先把管理员登录接口出来。也顺便看一下,写接口的流程。
配置路由
首先在app\adminapi\route\route.php
文件中配置路由
//用户名密码登录
Route::post('login', 'Login/login')->name('AdminLogin');
控制器方法
然后在控制器app\adminapi\controller\Login.php
中写login
方法
public function login()
{
$account = $this->request->post('username');
$password = $this->request->post('password');
return json($this->services->login($account, $password, 'admin'));
}
服务层services业务处理
在然后在服务层app\services\system\admin\systemAdminServices.php
中写login
方法
public function login(string $account, string $password, string $type)
{
$adminInfo = $this->dao->accountByAdmin($account);
if (!$adminInfo) {
throw new AdminException('管理员不存在!');
}
if (!$adminInfo->status) {
throw new AdminException