新增了立减金额2

This commit is contained in:
wucongxing8150 2024-09-09 09:00:00 +08:00
parent 83c0362ff7
commit f5ccb4de2f

View File

@ -6,6 +6,7 @@ import (
"hepa-calc-api/api/dto"
"hepa-calc-api/api/responses"
"hepa-calc-api/api/service"
"math"
)
type SystemMember struct{}
@ -40,7 +41,7 @@ func (b *SystemMember) GetSystemMember(c *gin.Context) {
// GetSystemMemberLeast 获取会员配置数据-最少立减金额
func (b *SystemMember) GetSystemMemberLeast(c *gin.Context) {
var firstTimePrice *float64
var reductionAmount *float64
// 检测用户是否购买过会员
userId := c.GetInt64("UserId")
@ -48,7 +49,7 @@ func (b *SystemMember) GetSystemMemberLeast(c *gin.Context) {
userService := service.UserService{}
isBuy := userService.CheckUserBuyMember(userId)
if isBuy == true {
responses.OkWithData(firstTimePrice, c)
responses.OkWithData(reductionAmount, c)
return
}
}
@ -67,15 +68,18 @@ func (b *SystemMember) GetSystemMemberLeast(c *gin.Context) {
continue
}
if firstTimePrice == nil {
firstTimePrice = member.FirstTimePrice
amount := member.Price - *member.FirstTimePrice
amount = math.Round(amount*100) / 100
if reductionAmount == nil {
reductionAmount = &amount
continue
}
if *firstTimePrice > *member.FirstTimePrice {
firstTimePrice = member.FirstTimePrice
if amount < *reductionAmount {
reductionAmount = &amount
}
}
responses.OkWithData(firstTimePrice, c)
responses.OkWithData(reductionAmount, c)
}