get($this->prefix . $token); if ($info) { return $info; } //从数据获取信息被设置缓存(可能后台清除缓存) $info = $this->setKefuInfo($token); if ($info) { return $info; } return false; } /** * @notes 通过有效token设置管理信息缓存 * @param $token * @return array|false|mixed * @throws \Exception * @author 段誉 * @date 2022/3/9 18:57 */ public function setKefuInfo($token) { $kefuSession = KefuSession::where([['token', '=', $token], ['expire_time', '>', time()]])->findOrEmpty(); if ($kefuSession->isEmpty()) { return []; } $kefu = Kefu::with('admin') ->where('id', '=', $kefuSession->kefu_id) ->findOrEmpty(); $kefuInfo = [ 'id' => $kefu['id'], 'admin_id' => $kefu['admin_id'], 'nickname' => $kefu['nickname'], 'account' => $kefu['admin']['account'] ?? '', 'token' => $token, 'terminal' => $kefuSession['terminal'], 'expire_time' => $kefuSession['expire_time'], ]; $this->set($this->prefix . $token, $kefuInfo, new \DateTime(Date('Y-m-d H:i:s', $kefuSession->expire_time))); return $this->getKefuInfo($token); } /** * @notes 删除缓存 * @param $token * @return bool * @author 段誉 * @date 2022/3/9 18:57 */ public function deleteKefuInfo($token) { return $this->delete($this->prefix . $token); } }