From f5ccb4de2fb407765240ecbe43c967847dae2826 Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 9 Sep 2024 09:00:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E4=BA=86=E7=AB=8B=E5=87=8F?= =?UTF-8?q?=E9=87=91=E9=A2=9D2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/SystemMember.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/api/controller/SystemMember.go b/api/controller/SystemMember.go index 1c9fd3d..bec8608 100644 --- a/api/controller/SystemMember.go +++ b/api/controller/SystemMember.go @@ -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) }