From a0b6ffce91e64bd020510f3a3c54843a0741839f Mon Sep 17 00:00:00 2001 From: wucongxing8150 <815046773@qq.com> Date: Mon, 9 Sep 2024 11:08:44 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E7=AB=8B=E5=87=8F?= =?UTF-8?q?=E9=87=91=E9=A2=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/controller/SystemMember.go | 14 +++++-------- api/dto/SystemMember.go | 11 +---------- api/model/SystemMember.go | 2 +- api/service/SystemMember.go | 36 ++++++++++++++-------------------- api/service/UserCoupon.go | 4 ++-- 5 files changed, 24 insertions(+), 43 deletions(-) diff --git a/api/controller/SystemMember.go b/api/controller/SystemMember.go index bec8608..666d785 100644 --- a/api/controller/SystemMember.go +++ b/api/controller/SystemMember.go @@ -6,7 +6,6 @@ import ( "hepa-calc-api/api/dto" "hepa-calc-api/api/responses" "hepa-calc-api/api/service" - "math" ) type SystemMember struct{} @@ -29,7 +28,7 @@ func (b *SystemMember) GetSystemMember(c *gin.Context) { isBuy := userService.CheckUserBuyMember(userId) if isBuy == true { for _, member := range systemMembers { - member.FirstTimePrice = nil + member.ReductionAmount = nil } } @@ -64,20 +63,17 @@ func (b *SystemMember) GetSystemMemberLeast(c *gin.Context) { } for _, member := range systemMembers { - if member.FirstTimePrice == nil { + if member.ReductionAmount == nil { continue } - amount := member.Price - *member.FirstTimePrice - amount = math.Round(amount*100) / 100 - if reductionAmount == nil { - reductionAmount = &amount + reductionAmount = member.ReductionAmount continue } - if amount < *reductionAmount { - reductionAmount = &amount + if *member.ReductionAmount < *reductionAmount { + reductionAmount = member.ReductionAmount } } diff --git a/api/dto/SystemMember.go b/api/dto/SystemMember.go index afb4333..6d4f7a1 100644 --- a/api/dto/SystemMember.go +++ b/api/dto/SystemMember.go @@ -3,7 +3,6 @@ package dto import ( "fmt" "hepa-calc-api/api/model" - "math" ) // SystemMemberDto 配置-会员配置 @@ -13,7 +12,6 @@ type SystemMemberDto struct { Price float64 `json:"price"` // 价格(原价) DiscountPrice *float64 `json:"discount_price"` // 优惠价格 DiscountEndTime *model.LocalTime `json:"discount_end_time"` // 优惠截止时间 - FirstTimePrice *float64 `json:"first_time_price"` // 首次购买价格 ReductionAmount *float64 `json:"reduction_amount"` // 立减金额 CreatedAt model.LocalTime `json:"created_at"` // 创建时间 UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 @@ -32,7 +30,6 @@ func GetSystemMemberListDto(m []*model.SystemMember) []*SystemMemberDto { Price: v.Price, DiscountPrice: v.DiscountPrice, DiscountEndTime: v.DiscountEndTime, - FirstTimePrice: v.FirstTimePrice, CreatedAt: v.CreatedAt, UpdatedAt: v.UpdatedAt, } @@ -56,7 +53,6 @@ func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto { Price: m.Price, DiscountPrice: m.DiscountPrice, DiscountEndTime: m.DiscountEndTime, - FirstTimePrice: m.FirstTimePrice, CreatedAt: m.CreatedAt, UpdatedAt: m.UpdatedAt, } @@ -64,12 +60,7 @@ func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto { // LoadReductionAmount 加载数据-立减金额 func (r *SystemMemberDto) LoadReductionAmount(m *model.SystemMember) *SystemMemberDto { - if m.FirstTimePrice != nil { - reductionAmount := m.Price - *m.FirstTimePrice - reductionAmount = math.Round(reductionAmount*100) / 100 - - r.ReductionAmount = &reductionAmount - } + r.ReductionAmount = m.ReductionAmount return r } diff --git a/api/model/SystemMember.go b/api/model/SystemMember.go index 49f6154..384f86a 100644 --- a/api/model/SystemMember.go +++ b/api/model/SystemMember.go @@ -13,7 +13,7 @@ type SystemMember struct { Price float64 `gorm:"column:price;type:decimal(10,2);default:0.00;comment:价格(原价)" json:"price"` DiscountPrice *float64 `gorm:"column:discount_price;type:decimal(10,2);comment:优惠价格" json:"discount_price"` DiscountEndTime *LocalTime `gorm:"column:discount_end_time;type:datetime;comment:优惠截止时间" json:"discount_end_time"` - FirstTimePrice *float64 `gorm:"column:first_time_price;type:decimal(10,2);comment:首次购买价格" json:"first_time_price"` + ReductionAmount *float64 `gorm:"column:reduction_amount;type:decimal(10,2);comment:首单立减金额" json:"reduction_amount"` Model } diff --git a/api/service/SystemMember.go b/api/service/SystemMember.go index 3004048..ffc4302 100644 --- a/api/service/SystemMember.go +++ b/api/service/SystemMember.go @@ -21,29 +21,23 @@ func (r *SystemMemberService) GetSystemMemberBuyPrice(m *model.SystemMember) (p // GetUserBuyPrice 获取会员最终价格 func (r *SystemMemberService) GetUserBuyPrice(userId int64, m *model.SystemMember) (p float64) { - // 检测用户是否购买过单项产品 - var firstTimePrice *float64 - userService := &UserService{} - isBuy := userService.CheckUserBuyMember(userId) - if isBuy == false { - // 未购买过 - if m.FirstTimePrice != nil { - // 首次购买价格 - firstTimePrice = m.FirstTimePrice - } + + // 优惠价格 + price := r.HandleSystemMemberDiscountPrice(m.DiscountPrice, m.DiscountEndTime) + if price == nil { + // 正常价格 + p = m.Price + } else { + p = *price } - if firstTimePrice != nil { - // 首次购买价格 - p = *firstTimePrice - } else { - // 优惠价格 - price := r.HandleSystemMemberDiscountPrice(m.DiscountPrice, m.DiscountEndTime) - if price == nil { - // 正常价格 - p = m.Price - } else { - p = *price + if m.ReductionAmount != nil { + // 检测用户是否购买过单项产品 + userService := &UserService{} + isBuy := userService.CheckUserBuyMember(userId) + if isBuy == false { + // 未购买过 + p = p - *m.ReductionAmount } } diff --git a/api/service/UserCoupon.go b/api/service/UserCoupon.go index 27ad5dc..617029e 100644 --- a/api/service/UserCoupon.go +++ b/api/service/UserCoupon.go @@ -219,8 +219,8 @@ func (r *UserCouponService) GetUserUsableMemberCoupon(userId, systemMemberId int return nil, errors.New("操作失败") } - if systemMember.FirstTimePrice != nil { - // 存在首单优惠价格,不允许使用优惠卷 + if systemMember.ReductionAmount != nil { + // 存在首单立减价格,不允许使用优惠卷 return nil, nil } }