prefix . $token); if ($adminInfo) { return $adminInfo; } //从数据获取信息被设置缓存(可能后台清除缓存) $adminInfo = $this->setAdminInfo($token); if ($adminInfo) { return $adminInfo; } return false; } /** * @notes 通过有效token设置管理信息缓存 * @param $token * @return array|false|mixed * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException * @author 令狐冲 * @date 2021/7/5 12:12 */ public function setAdminInfo($token) { $adminSession = AdminSession::where([['token', '=', $token], ['expire_time', '>', time()]]) ->find(); if (empty($adminSession)) { return []; } $admin = Admin::where('id', '=', $adminSession->admin_id) ->append(['role_id']) ->find(); $roleName = ''; $roleLists = SystemRole::column('name', 'id'); if ($admin['root'] == 1) { $roleName = '系统管理员'; } else { foreach ($admin['role_id'] as $roleId) { if($roleId==1){ $auth_shop=Db::name('user_auth_shop')->where(['admin_id'=>$admin['id'],'status'=>1,'apply_status'=>1,'type'=>2])->find(); } $roleName .= $roleLists[$roleId] ?? ''; $roleName .= '/'; } $roleName = trim($roleName, '/'); } $supplier_id=0; if(isset($auth_shop)){ $supplier_id=$auth_shop['pid']; } $adminInfo = [ 'admin_id' => $admin->id, 'supplier_id' => $supplier_id, 'root' => $admin->root, 'name' => $admin->name, 'account' => $admin->account, 'role_name' => $roleName, 'role_id' => $admin->role_id, 'token' => $token, 'terminal' => $adminSession->terminal, 'expire_time' => $adminSession->expire_time, ]; Cache::set($this->prefix . $token, $adminInfo); return $this->getAdminInfo($token); } /** * @notes 删除缓存 * @param $token * @return bool * @author 令狐冲 * @date 2021/7/3 16:57 */ public function deleteAdminInfo($token) { return Cache::delete($this->prefix . $token); } }