get($this->prefix . $token); if ($coachUserInfo) { return $coachUserInfo; } //从数据获取信息被设置缓存(可能后台清除缓存) $coachUserInfo = $this->setCoachUserInfo($token); if ($coachUserInfo) { return $coachUserInfo; } 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 setCoachUserInfo($token) { $coachUserSession = CoachUserSession::where([['token', '=', $token], ['expire_time', '>', time()]])->find(); if (empty($coachUserSession)) { return []; } $coachUser = CoachUser::where('id', '=', $coachUserSession->coach_user_id) ->find(); $coachInfo = Coach::where(['coach_user_id'=>$coachUserSession->coach_user_id]) ->order('id desc') ->field('id,audit_status') ->findOrEmpty(); $coachUserInfo = [ 'coach_user_id' => $coachUser->id, 'coach_id'=> $coachInfo['id'], 'token' => $token, 'sn' => $coachUser->sn, 'account' => $coachUser->account, 'avatar' => $coachUser->avatar, 'terminal' => $coachUserSession->terminal, 'audit_status' => $coachInfo['audit_status'], 'expire_time' => $coachUserSession->expire_time, ]; $this->set($this->prefix . $token, $coachUserInfo, new \DateTime(Date('Y-m-d H:i:s', $coachUserSession->expire_time))); return $this->getCoachUserInfo($token); } /** * @notes 删除缓存 * @param $token * @return bool * @author 令狐冲 * @date 2021/7/3 16:57 */ public function deleteCoachUserInfo($token) { return $this->delete($this->prefix . $token); } }