查看: 449|回复: 0

fastadmin在插件中抛出异常

[复制链接]

748

主题

39

回帖

3907

积分

管理员

总舵主

积分
3907
QQ
发表于 2025-4-15 12:10:21 | 显示全部楼层 |阅读模式
在Mydemo.php中定义登录后的事件函数:

  1. // 行为事件
  2.     public function adminLoginAfter($request)
  3.     {
  4.         // \think\Log::record($this->auth->id);
  5.         $auth = new Auth();
  6.         $admin = $auth->getUserInfo();
  7.         // \think\Log::record($admin);
  8.         $store = Store::where(['admin_id'=>$admin['id']])->find();
  9.         if (!empty($store)) {
  10.             if ($store->status == 2) {
  11.                 $auth->logout();
  12.                 // 抛出异常
  13.                 throw new HttpResponseException(Response::create([
  14.                     'code' => 0,
  15.                     'msg'  => '您绑定的门店已被停用,无权登录',
  16.                     'data' => null,
  17.                 ], 'json', 200));
  18.             } else {
  19.                 Session::set('tushus_store_id', $store->id);
  20.             }
  21.         }
  22.     }
复制代码
该页面引入两个类库:
  1. use think\exception\HttpResponseException;
  2. use think\Response;
复制代码


道不同,不相为谋!理想要有,万一实现了呢?
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关注公众号

相关侵权、举报、投诉及建议等,请发 E-mail:2513533699@qq.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.|鲁ICP备19000917号|鲁公网安备37078302000320号

在本版发帖
关注公众号
QQ客服返回顶部