refactor(utils): 修复密码哈希比较逻辑错误 feat(user): 新增按状态筛选优惠券接口 docs: 添加虚拟发货与任务中心相关文档 fix(wechat): 修正Code2Session上下文传递问题 test: 补充订单折扣与积分转换测试用例 build: 更新配置文件与构建脚本 style: 清理多余的空行与注释
28 lines
735 B
Go
28 lines
735 B
Go
package order
|
|
|
|
import "bindbox-game/internal/repository/mysql/model"
|
|
|
|
func ApplyCouponDiscount(amount int64, c *model.SystemCoupons, minSpendOK bool) int64 {
|
|
if c == nil || amount <= 0 || !minSpendOK { return 0 }
|
|
switch c.DiscountType {
|
|
case 1:
|
|
return clamp(c.DiscountValue, 0, amount)
|
|
case 2:
|
|
return clamp(c.DiscountValue, 0, amount)
|
|
case 3:
|
|
rate := c.DiscountValue
|
|
if rate < 0 { rate = 0 }
|
|
if rate > 1000 { rate = 1000 }
|
|
newAmt := amount * rate / 1000
|
|
return clamp(amount - newAmt, 0, amount)
|
|
default:
|
|
return 0
|
|
}
|
|
}
|
|
|
|
func clamp(v int64, min int64, max int64) int64 {
|
|
if v < min { return min }
|
|
if v > max { return max }
|
|
return v
|
|
}
|