fastadmin在插件中抛出异常
在Mydemo.php中定义登录后的事件函数:// 行为事件
public function adminLoginAfter($request)
{
// \think\Log::record($this->auth->id);
$auth = new Auth();
$admin = $auth->getUserInfo();
// \think\Log::record($admin);
$store = Store::where(['admin_id'=>$admin['id']])->find();
if (!empty($store)) {
if ($store->status == 2) {
$auth->logout();
// 抛出异常
throw new HttpResponseException(Response::create([
'code' => 0,
'msg'=> '您绑定的门店已被停用,无权登录',
'data' => null,
], 'json', 200));
} else {
Session::set('tushus_store_id', $store->id);
}
}
}该页面引入两个类库:
use think\exception\HttpResponseException;
use think\Response;
页:
[1]