connectUserId != $phone) { $database = get_db_connect($this->table, $phone); $this->setTable($database['table']); $this->connect($database); $this->sequence('id'); $this->connectUserId = $phone; } return $this; } /** * @param $phone * @return array * @throws \think\Exception */ public function getInfoByPhone($phone) { $key = 'UPHONE:' . $phone; $redis = Redis::instance(); LogService::info('[ UserPhone ] [ getInfoByPhone ] [ RedisKey ]' . $key); LogService::info('[ UserPhone ] [ getInfoByPhone ] [ Redis ]' . json_encode(print_r($redis, true))); $data = []; if ($redis->exists($key)) { $data = $redis->get($key); } else { $obj = $this->setConnect($phone)->where('phone', '=', $phone)->find(); if($obj){ $data_arr = $obj->toArray(); $data = json_encode($data_arr); $redis->set($key, $data, 7 * 24 * 60 * 60); } } return $data; } /** * 更改手机号 * @param $uid * @param $oldphone * @param $newphone * @return UserPhone */ public function modifyPhone($uid, $oldphone, $newphone) { try{ $this->setConnect($oldphone)->where(['phone' => $oldphone])->delete(); $result = $this->setConnect($newphone)->save(['uid' => $uid, 'phone' => $newphone]); return $result; }catch (\Exception $e){ LogService::error('[ UserPhone ]'. $e->getMessage()); } } }