user = new User(); } return self::$self; } /** * 获取用户信息 * @param int $user_id * @return User */ public function getUserInfo(int $user_id) { if (!$this->user->id || ($this->user->id != $user_id)) { $data = ApiService::instance()->getDataFromApi(ServiceApiConstants::USER_FIND_BY_UID, [$this->user->pk => $user_id])->data; $this->user->bind($data); } return $this->user; } /** * 获取用户 * @param $channel_id * @param $openid * @return User */ public function getUserInfoByChannelOpenid($channel_id, $openid) { if (!$this->user->id || ($this->user->openid != $openid || $this->user->channel_id != $channel_id)) { $data = ApiService::instance()->getDataFromApi(ServiceApiConstants::USER_FIND_BY_OPENID, ['openid' => $openid, 'channel_id' => $channel_id])->data; $this->user->bind($data); } return $this->user; } /** * 更新用户 * @param $userUpdate UserUpdate * @return User */ public function updateUser(UserUpdate $userUpdate) { $data = ApiService::instance()->getDataFromApi(ServiceApiConstants::USER_UPDATE, $userUpdate->toArray())->data; $cache = CacheConstants::getUserCacheKey($userUpdate->id); Redis::instance()->del($cache); return $this->user->bind($data); } /** * 创建用户 * @param $channel_id * @param $openid * @return User */ public function createUser($channel_id, $openid) { $data = ApiService::instance()->getDataFromApi(ServiceApiConstants::USER_ADD, ['openid' => $openid, 'channel_id' => $channel_id])->data; return $this->user->bind($data); } }