get($this->prefix . $token); if ($shopUserInfo) { return $shopUserInfo; } //从数据获取信息被设置缓存(可能后台清除缓存) $shophUserInfo = $this->setShopUserInfo($token); if ($shophUserInfo) { return $shophUserInfo; } 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 setShopUserInfo($token) { $shopUserSession = ShopUserSession::where([['token', '=', $token], ['expire_time', '>', time()]])->find(); if (empty($shopUserSession)) { return []; } $shopUser = ShopUser::where('id', '=', $shopUserSession->shop_user_id) ->find(); $shop = Shop::where(['shop_user_id'=>$shopUserSession->shop_user_id]) ->order('id desc') ->field('id,audit_status') ->findOrEmpty(); $shopUserInfo = [ 'shop_user_id' => $shopUser->id, 'shop_id'=> $shop['id'], 'token' => $token, 'sn' => $shopUser->sn, 'account' => $shopUser->account, 'audit_status' => $shop['audit_status'], 'avatar' => $shopUser->avatar, 'terminal' => $shopUserSession->terminal, 'expire_time' => $shopUserSession->expire_time, ]; $this->set($this->prefix . $token, $shopUserInfo, new \DateTime(Date('Y-m-d H:i:s', $shopUserSession->expire_time))); return $this->getShopUserInfo($token); } /** * @notes 删除缓存 * @param $token * @return bool * @author 令狐冲 * @date 2021/7/3 16:57 */ public function deleteShopUserInfo($token) { return $this->delete($this->prefix . $token); } }