feat(benefits): 增加权益中心
This commit is contained in:
@@ -17,12 +17,23 @@ var (
|
||||
)
|
||||
|
||||
type SummaryDTO struct {
|
||||
AvailablePoints int64 `json:"available_points"`
|
||||
LifetimePoints int64 `json:"lifetime_points"`
|
||||
LevelCode string `json:"level_code"`
|
||||
LevelName string `json:"level_name"`
|
||||
PointsPerYuan int64 `json:"points_per_yuan"`
|
||||
PointsMultiplierBps int `json:"points_multiplier_bps"`
|
||||
AvailablePoints int64 `json:"available_points"`
|
||||
LifetimePoints int64 `json:"lifetime_points"`
|
||||
LevelCode string `json:"level_code"`
|
||||
LevelName string `json:"level_name"`
|
||||
PointsPerYuan int64 `json:"points_per_yuan"`
|
||||
PointsMultiplierBps int `json:"points_multiplier_bps"`
|
||||
GrowthEnabled bool `json:"growth_enabled"`
|
||||
Levels []GrowthLevelDTO `json:"levels"`
|
||||
}
|
||||
|
||||
type GrowthLevelDTO struct {
|
||||
Code string `json:"code"`
|
||||
Name string `json:"name"`
|
||||
MinPoints int64 `json:"min_points"`
|
||||
PointsMultiplierBps int `json:"points_multiplier_bps"`
|
||||
DiscountBps int `json:"discount_bps"`
|
||||
DepositFreeQuotaCent int64 `json:"deposit_free_quota_cent"`
|
||||
}
|
||||
|
||||
type ProductDTO struct {
|
||||
|
||||
@@ -35,6 +35,17 @@ func (r *Repository) Summary(ctx context.Context, userID uint64) (*SummaryDTO, e
|
||||
return nil, err
|
||||
}
|
||||
level := rentergrowth.LevelForPoints(cfg, user.RenterGrowthPoints)
|
||||
levels := make([]GrowthLevelDTO, 0, len(cfg.Levels))
|
||||
for _, item := range cfg.Levels {
|
||||
levels = append(levels, GrowthLevelDTO{
|
||||
Code: item.Code,
|
||||
Name: item.Name,
|
||||
MinPoints: item.MinPoints,
|
||||
PointsMultiplierBps: item.PointsMultiplierBps,
|
||||
DiscountBps: item.DiscountBps,
|
||||
DepositFreeQuotaCent: item.DepositFreeQuotaCent,
|
||||
})
|
||||
}
|
||||
return &SummaryDTO{
|
||||
AvailablePoints: user.PointsAvailable,
|
||||
LifetimePoints: user.RenterGrowthPoints,
|
||||
@@ -42,6 +53,8 @@ func (r *Repository) Summary(ctx context.Context, userID uint64) (*SummaryDTO, e
|
||||
LevelName: level.Name,
|
||||
PointsPerYuan: cfg.PointsPerYuan,
|
||||
PointsMultiplierBps: level.PointsMultiplierBps,
|
||||
GrowthEnabled: cfg.Enabled,
|
||||
Levels: levels,
|
||||
}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -76,3 +76,33 @@ func TestRedeemDeductsAvailablePointsAndStock(t *testing.T) {
|
||||
t.Fatalf("redemption status = %s, want completed", completed.Status)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSummaryIncludesGrowthLevelRules(t *testing.T) {
|
||||
db := database.NewTestDB()
|
||||
user := model.User{
|
||||
Phone: "13900009602",
|
||||
RenterGrowthPoints: 1000,
|
||||
PointsAvailable: 432,
|
||||
}
|
||||
if err := db.Create(&user).Error; err != nil {
|
||||
t.Fatalf("create user failed: %v", err)
|
||||
}
|
||||
|
||||
summary, err := NewRepository(db).Summary(t.Context(), user.ID)
|
||||
if err != nil {
|
||||
t.Fatalf("summary failed: %v", err)
|
||||
}
|
||||
if !summary.GrowthEnabled || len(summary.Levels) != 4 {
|
||||
t.Fatalf("growth config = enabled %v levels %d", summary.GrowthEnabled, len(summary.Levels))
|
||||
}
|
||||
if summary.LevelCode != "diamond" || summary.PointsMultiplierBps != 15_000 {
|
||||
t.Fatalf(
|
||||
"current level = %s multiplier %d, want diamond/15000",
|
||||
summary.LevelCode,
|
||||
summary.PointsMultiplierBps,
|
||||
)
|
||||
}
|
||||
if summary.Levels[2].DiscountBps != 9800 || summary.Levels[2].DepositFreeQuotaCent != 100_000 {
|
||||
t.Fatalf("diamond rules = %+v", summary.Levels[2])
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user