feat(subscription): validate price amount and migrate database column type

- Add validation to ensure subscription plan price amount is non-negative and does not exceed 9999.
- Migrate the price_amount column from float/double to decimal(10,6) in the database for improved precision.
- Update SubscriptionPlan model to reflect the new decimal type for price_amount.
This commit is contained in:
CaIon
2026-02-03 18:58:28 +08:00
parent 59c076978e
commit 6a9522ac5b
3 changed files with 75 additions and 1 deletions

View File

@@ -118,6 +118,14 @@ func AdminCreateSubscriptionPlan(c *gin.Context) {
common.ApiErrorMsg(c, "套餐标题不能为空")
return
}
if req.Plan.PriceAmount < 0 {
common.ApiErrorMsg(c, "价格不能为负数")
return
}
if req.Plan.PriceAmount > 9999 {
common.ApiErrorMsg(c, "价格不能超过9999")
return
}
if req.Plan.Currency == "" {
req.Plan.Currency = "USD"
}
@@ -172,6 +180,14 @@ func AdminUpdateSubscriptionPlan(c *gin.Context) {
common.ApiErrorMsg(c, "套餐标题不能为空")
return
}
if req.Plan.PriceAmount < 0 {
common.ApiErrorMsg(c, "价格不能为负数")
return
}
if req.Plan.PriceAmount > 9999 {
common.ApiErrorMsg(c, "价格不能超过9999")
return
}
req.Plan.Id = id
if req.Plan.Currency == "" {
req.Plan.Currency = "USD"