utils = UtilsService::getInstance(); $token = WxTokenService::getInstance(); if ($this->needLogin) { $this->userInfo = $token->requireUser(); } else { $this->userInfo = $token->resolveUser(request()->bearerToken()) ?? []; } $this->userId = (int) ($this->userInfo['id'] ?? 0); } /** * 当前用户是否可见价格 */ protected function canSeePrice(): bool { return (bool) ($this->userInfo['show_price'] ?? 0); } /** * 当前用户的价格倍率 */ protected function priceMultiplier(): mixed { return $this->userInfo['price_number'] ?? 1; } /** * 打开分享链接时继承代理商倍率 * * 商品详情、套餐详情共用:只有「还没有上级、自己也不是代理商」的已登录用户会被绑定; * 已绑同一上级时同步最新倍率。未登录不写库,只影响本次会话价。 */ protected function inheritAgentPrice(int $shareUserId): void { if ($shareUserId <= 0) { return; } $isAgent = (int) ($this->userInfo['is_p'] ?? 0) === 1; $pid = (int) ($this->userInfo['pid'] ?? 0); if ($isAgent) { return; } if ($pid !== 0 && $pid !== $shareUserId) { return; } $agent = WxUserModel::where('id', $shareUserId)->where('deleted_at', 0)->first(); if (empty($agent) || (int) $agent['is_p'] !== 1) { return; } $this->userInfo['show_price'] = 1; $this->userInfo['price_number'] = $agent['price_number']; if ($this->userId <= 0) { return; } WxUserModel::where('id', $this->userId)->update([ 'pid' => $shareUserId, 'show_price' => 1, 'price_number' => $agent['price_number'], 'updated_at' => time(), ]); } }