fix(order): 开放普通等级租用极品专区
This commit is contained in:
@@ -22,8 +22,6 @@ func writeOrderError(c *gin.Context, err error) {
|
||||
response.Error(c, http.StatusConflict, "listing_unavailable", "该账号暂不可租")
|
||||
case errors.Is(err, ErrCannotRentOwnListing):
|
||||
response.BadRequest(c, "不能租用自己发布的账号")
|
||||
case errors.Is(err, ErrPremiumLevelRequired):
|
||||
response.Error(c, http.StatusForbidden, "platinum_level_required", "成长等级达到铂金及以上才能租用极品专区账号")
|
||||
case errors.Is(err, ErrInsufficientBalance):
|
||||
response.Error(c, http.StatusConflict, "insufficient_balance", "钱包余额不足,请先充值")
|
||||
case errors.Is(err, ErrChannelPaymentRequired):
|
||||
|
||||
@@ -134,9 +134,6 @@ func (r *Repository) Create(ctx context.Context, renterID uint64, req CreateRequ
|
||||
DiscountBps: rentergrowth.DefaultDiscountBps,
|
||||
}
|
||||
}
|
||||
if listing.IsPremium && !rentergrowth.CanViewPremiumLevel(growthSnapshot.LevelCode) {
|
||||
return ErrPremiumLevelRequired
|
||||
}
|
||||
rentDiscountAmountCent := rentergrowth.CalculateDiscountCent(pricing.PureCoinAmountCent, pricing.PureCoinPlatformFeeCent, growthSnapshot.DiscountBps)
|
||||
if rentDiscountAmountCent > 0 {
|
||||
pricing.PlatformFeeCent -= rentDiscountAmountCent
|
||||
|
||||
@@ -282,6 +282,49 @@ func TestRepositoryCreateAppliesRenterGrowthDiscount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestRepositoryCreateAllowsNormalRenterForPremiumListing(t *testing.T) {
|
||||
db := setupOrderTestDB(t)
|
||||
repo := NewRepository(db)
|
||||
|
||||
owner := model.User{Phone: "13800001201"}
|
||||
renter := model.User{Phone: "13800001202", RenterGrowthLevel: "normal"}
|
||||
if err := db.Create(&owner).Error; err != nil {
|
||||
t.Fatalf("create owner failed: %v", err)
|
||||
}
|
||||
if err := db.Create(&renter).Error; err != nil {
|
||||
t.Fatalf("create renter failed: %v", err)
|
||||
}
|
||||
account := model.GameAccount{
|
||||
OwnerID: owner.ID,
|
||||
ServerRegion: "国服",
|
||||
LoginPlatform: "steam",
|
||||
Title: "极品专区测试账号",
|
||||
}
|
||||
if err := db.Create(&account).Error; err != nil {
|
||||
t.Fatalf("create account failed: %v", err)
|
||||
}
|
||||
listing := model.RentalListing{
|
||||
AccountID: account.ID,
|
||||
OwnerID: owner.ID,
|
||||
PriceCent: 10000,
|
||||
Status: listingStatusPublished,
|
||||
ReviewStatus: listingReviewStatusApproved,
|
||||
IsPremium: true,
|
||||
InTransaction: false,
|
||||
}
|
||||
if err := db.Create(&listing).Error; err != nil {
|
||||
t.Fatalf("create listing failed: %v", err)
|
||||
}
|
||||
|
||||
dto, err := repo.Create(t.Context(), renter.ID, CreateRequest{ListingID: listing.ID})
|
||||
if err != nil {
|
||||
t.Fatalf("normal renter Create() error = %v", err)
|
||||
}
|
||||
if !dto.IsPremium {
|
||||
t.Fatal("premium listing order should keep is_premium snapshot")
|
||||
}
|
||||
}
|
||||
|
||||
func TestCreateOrderSnapshotsShelfMarkup(t *testing.T) {
|
||||
db := setupOrderTestDB(t)
|
||||
if err := database.AutoMigrateIfMissing(db, &model.DistributionSite{}, &model.DistributionSiteAccount{}, &model.DistributionRuleVersion{}, &model.DistributionOrderFinancial{}, &model.DistributionOrderParty{}); err != nil {
|
||||
|
||||
@@ -10,7 +10,6 @@ var (
|
||||
ErrInvalidRentHours = errors.New("invalid rent hours")
|
||||
ErrListingUnavailable = errors.New("listing unavailable")
|
||||
ErrCannotRentOwnListing = errors.New("cannot rent own listing")
|
||||
ErrPremiumLevelRequired = errors.New("platinum level required for premium listing")
|
||||
ErrInsufficientBalance = errors.New("insufficient balance")
|
||||
ErrOrderCannotPay = errors.New("order cannot pay")
|
||||
ErrChannelPaymentRequired = errors.New("channel payment required")
|
||||
|
||||
@@ -52,10 +52,10 @@ func DefaultRules() Rules {
|
||||
| 术语 | 定义 |
|
||||
|---|---|
|
||||
| 优质号主 | 通过平台认证、完成200元信用保证金冻结并遵守本协议的高信誉号主 |
|
||||
| 《极品专区》 | 优质号主可选择发布的专属渠道,仅限大锤商行至尊SVIP用户租用;优质号主在该渠道发布账号可享有专项收益比例及专属标识 |
|
||||
| 《极品专区》 | 优质号主可选择发布的精选渠道,所有符合平台基础租赁规则的注册用户均可查看和租用;优质号主在该渠道发布账号可享有专项收益比例及专属标识 |
|
||||
| 《大锤商行》 | 优质号主可选择发布的公开渠道,面向全平台注册用户租用 |
|
||||
| 信用保证金(押金) | 号主为获得优质号主发布资格而授权平台冻结的200元信用保证金,仅冻结、不扣除 |
|
||||
| 大锤商行至尊SVIP | 平台最高等级VIP用户,须同时满足租客免押资格方可租用《极品专区》渠道账号 |
|
||||
| 极品专区租客 | 符合平台基础租赁规则的注册用户,不设成长等级门槛 |
|
||||
|
||||
三、成为优质号主的条件
|
||||
|
||||
@@ -106,17 +106,17 @@ func DefaultRules() Rules {
|
||||
|
||||
| 对比项 | 《极品专区》 | 《大锤商行》 |
|
||||
|---|---|---|
|
||||
| 租用资格 | 仅限大锤商行至尊SVIP,且须具备租客免押资格 | 全平台注册用户 |
|
||||
| 租客筛选标准 | 累计消费≥1万元 + 无纠纷记录 + 无封禁记录 | 无特殊限制 |
|
||||
| 租用资格 | 全平台符合基础租赁规则的注册用户 | 全平台注册用户 |
|
||||
| 租客筛选标准 | 不设成长等级门槛,统一遵守平台实名、支付及风控规则 | 无特殊限制 |
|
||||
| 适用场景 | 高客单价、极致安全、专项收益比例 | 高曝光、快速出单 |
|
||||
|
||||
5.2 关于《极品专区》渠道
|
||||
|
||||
5.2.1 选择该渠道的账号,将展示“极品专区”专属标签。
|
||||
|
||||
5.2.2 非大锤商行至尊SVIP用户,或虽为大锤商行至尊SVIP但无租客免押资格的,不可查看及租用该渠道账号。
|
||||
5.2.2 所有符合平台基础租赁规则的注册用户均可查看及租用该渠道账号,不设成长等级门槛。
|
||||
|
||||
5.2.3 该渠道租客均为平台严选的优质租客,号主可享受“基本绝对安全”的出租体验。
|
||||
5.2.3 该渠道账号仍须遵守平台统一的实名、支付、交付、售后及风控规则。
|
||||
|
||||
5.2.4 优质号主在该渠道发布账号,可按本协议第4.1款享有专项收益比例。
|
||||
|
||||
@@ -214,6 +214,7 @@ func ParseConfigValue(value string) (Rules, error) {
|
||||
}
|
||||
rules.AgreementTitle = strings.TrimSpace(rules.AgreementTitle)
|
||||
rules.AgreementContent = strings.TrimSpace(rules.AgreementContent)
|
||||
rules.AgreementContent = migrateLegacyPremiumRentalCopy(rules.AgreementContent)
|
||||
if rules.AgreementTitle == "" || rules.AgreementContent == "" {
|
||||
return Rules{}, ErrInvalidRules
|
||||
}
|
||||
@@ -224,6 +225,24 @@ func ParseConfigValue(value string) (Rules, error) {
|
||||
return rules, nil
|
||||
}
|
||||
|
||||
func migrateLegacyPremiumRentalCopy(content string) string {
|
||||
replacer := strings.NewReplacer(
|
||||
"| 《极品专区》 | 优质号主可选择发布的专属渠道,仅限大锤商行至尊SVIP用户租用;优质号主在该渠道发布账号可享有专项收益比例及专属标识 |",
|
||||
"| 《极品专区》 | 优质号主可选择发布的精选渠道,所有符合平台基础租赁规则的注册用户均可查看和租用;优质号主在该渠道发布账号可享有专项收益比例及专属标识 |",
|
||||
"| 大锤商行至尊SVIP | 平台最高等级VIP用户,须同时满足租客免押资格方可租用《极品专区》渠道账号 |",
|
||||
"| 极品专区租客 | 符合平台基础租赁规则的注册用户,不设成长等级门槛 |",
|
||||
"| 租用资格 | 仅限大锤商行至尊SVIP,且须具备租客免押资格 | 全平台注册用户 |",
|
||||
"| 租用资格 | 全平台符合基础租赁规则的注册用户 | 全平台注册用户 |",
|
||||
"| 租客筛选标准 | 累计消费≥1万元 + 无纠纷记录 + 无封禁记录 | 无特殊限制 |",
|
||||
"| 租客筛选标准 | 不设成长等级门槛,统一遵守平台实名、支付及风控规则 | 无特殊限制 |",
|
||||
"5.2.2 非大锤商行至尊SVIP用户,或虽为大锤商行至尊SVIP但无租客免押资格的,不可查看及租用该渠道账号。",
|
||||
"5.2.2 所有符合平台基础租赁规则的注册用户均可查看及租用该渠道账号,不设成长等级门槛。",
|
||||
"5.2.3 该渠道租客均为平台严选的优质租客,号主可享受“基本绝对安全”的出租体验。",
|
||||
"5.2.3 该渠道账号仍须遵守平台统一的实名、支付、交付、售后及风控规则。",
|
||||
)
|
||||
return replacer.Replace(content)
|
||||
}
|
||||
|
||||
func MarshalConfig(rules Rules) (string, error) {
|
||||
raw, err := json.Marshal(rules)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,6 +1,9 @@
|
||||
package qualityowner
|
||||
|
||||
import "testing"
|
||||
import (
|
||||
"strings"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestParseConfigValueDefaultsAndValidation(t *testing.T) {
|
||||
rules, err := ParseConfigValue(`{"insurance_fee_bps":800,"premium_insurance_fee_bps":400}`)
|
||||
@@ -39,3 +42,28 @@ func TestDefaultConfigValueCanBeParsed(t *testing.T) {
|
||||
t.Fatalf("unexpected default agreement: %+v", rules)
|
||||
}
|
||||
}
|
||||
|
||||
func TestParseConfigValueMigratesLegacyPremiumRentalCopy(t *testing.T) {
|
||||
rules := DefaultRules()
|
||||
rules.AgreementContent = `| 《极品专区》 | 优质号主可选择发布的专属渠道,仅限大锤商行至尊SVIP用户租用;优质号主在该渠道发布账号可享有专项收益比例及专属标识 |
|
||||
| 大锤商行至尊SVIP | 平台最高等级VIP用户,须同时满足租客免押资格方可租用《极品专区》渠道账号 |
|
||||
| 租用资格 | 仅限大锤商行至尊SVIP,且须具备租客免押资格 | 全平台注册用户 |
|
||||
| 租客筛选标准 | 累计消费≥1万元 + 无纠纷记录 + 无封禁记录 | 无特殊限制 |
|
||||
5.2.2 非大锤商行至尊SVIP用户,或虽为大锤商行至尊SVIP但无租客免押资格的,不可查看及租用该渠道账号。
|
||||
5.2.3 该渠道租客均为平台严选的优质租客,号主可享受“基本绝对安全”的出租体验。`
|
||||
raw, err := MarshalConfig(rules)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
parsed, err := ParseConfigValue(raw)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if strings.Contains(parsed.AgreementContent, "至尊SVIP") ||
|
||||
strings.Contains(parsed.AgreementContent, "不可查看及租用") {
|
||||
t.Fatalf("legacy premium rental copy was not migrated: %s", parsed.AgreementContent)
|
||||
}
|
||||
if !strings.Contains(parsed.AgreementContent, "不设成长等级门槛") {
|
||||
t.Fatalf("new premium rental copy missing: %s", parsed.AgreementContent)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -629,13 +629,9 @@ func LevelForUserAfterPoints(cfg Config, points int64, override string) LevelRul
|
||||
return LevelForPoints(cfg, points)
|
||||
}
|
||||
|
||||
func CanViewPremiumLevel(code string) bool {
|
||||
switch strings.TrimSpace(code) {
|
||||
case "platinum", "diamond", "peak":
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
// CanViewPremiumLevel 保留兼容语义,极品专区不再设置成长等级门槛。
|
||||
func CanViewPremiumLevel(_ string) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
func EffectiveDepositFreeQuotaCent(levelQuotaCent int64, manualQuotaCent int64) int64 {
|
||||
|
||||
@@ -136,11 +136,8 @@ func TestEffectiveLevelForUserHonorsManualOverride(t *testing.T) {
|
||||
if got := EffectiveLevelForUser(cfg, 5000, ""); got.Code != "peak" {
|
||||
t.Fatalf("自动等级 = %s, want peak", got.Code)
|
||||
}
|
||||
if !CanViewPremiumLevel("platinum") || !CanViewPremiumLevel("diamond") || !CanViewPremiumLevel("peak") {
|
||||
t.Fatal("铂金及以上等级应可查看极品专区")
|
||||
}
|
||||
if CanViewPremiumLevel(DefaultLevelCode) {
|
||||
t.Fatal("普通等级不应查看极品专区")
|
||||
if !CanViewPremiumLevel(DefaultLevelCode) {
|
||||
t.Fatal("普通等级也应允许查看和租用极品专区")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user