修改了立减金额

This commit is contained in:
wucongxing8150 2024-09-09 11:08:44 +08:00
parent f5ccb4de2f
commit a0b6ffce91
5 changed files with 24 additions and 43 deletions

View File

@ -6,7 +6,6 @@ import (
"hepa-calc-api/api/dto" "hepa-calc-api/api/dto"
"hepa-calc-api/api/responses" "hepa-calc-api/api/responses"
"hepa-calc-api/api/service" "hepa-calc-api/api/service"
"math"
) )
type SystemMember struct{} type SystemMember struct{}
@ -29,7 +28,7 @@ func (b *SystemMember) GetSystemMember(c *gin.Context) {
isBuy := userService.CheckUserBuyMember(userId) isBuy := userService.CheckUserBuyMember(userId)
if isBuy == true { if isBuy == true {
for _, member := range systemMembers { 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 { for _, member := range systemMembers {
if member.FirstTimePrice == nil { if member.ReductionAmount == nil {
continue continue
} }
amount := member.Price - *member.FirstTimePrice
amount = math.Round(amount*100) / 100
if reductionAmount == nil { if reductionAmount == nil {
reductionAmount = &amount reductionAmount = member.ReductionAmount
continue continue
} }
if amount < *reductionAmount { if *member.ReductionAmount < *reductionAmount {
reductionAmount = &amount reductionAmount = member.ReductionAmount
} }
} }

View File

@ -3,7 +3,6 @@ package dto
import ( import (
"fmt" "fmt"
"hepa-calc-api/api/model" "hepa-calc-api/api/model"
"math"
) )
// SystemMemberDto 配置-会员配置 // SystemMemberDto 配置-会员配置
@ -13,7 +12,6 @@ type SystemMemberDto struct {
Price float64 `json:"price"` // 价格(原价) Price float64 `json:"price"` // 价格(原价)
DiscountPrice *float64 `json:"discount_price"` // 优惠价格 DiscountPrice *float64 `json:"discount_price"` // 优惠价格
DiscountEndTime *model.LocalTime `json:"discount_end_time"` // 优惠截止时间 DiscountEndTime *model.LocalTime `json:"discount_end_time"` // 优惠截止时间
FirstTimePrice *float64 `json:"first_time_price"` // 首次购买价格
ReductionAmount *float64 `json:"reduction_amount"` // 立减金额 ReductionAmount *float64 `json:"reduction_amount"` // 立减金额
CreatedAt model.LocalTime `json:"created_at"` // 创建时间 CreatedAt model.LocalTime `json:"created_at"` // 创建时间
UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间 UpdatedAt model.LocalTime `json:"updated_at"` // 更新时间
@ -32,7 +30,6 @@ func GetSystemMemberListDto(m []*model.SystemMember) []*SystemMemberDto {
Price: v.Price, Price: v.Price,
DiscountPrice: v.DiscountPrice, DiscountPrice: v.DiscountPrice,
DiscountEndTime: v.DiscountEndTime, DiscountEndTime: v.DiscountEndTime,
FirstTimePrice: v.FirstTimePrice,
CreatedAt: v.CreatedAt, CreatedAt: v.CreatedAt,
UpdatedAt: v.UpdatedAt, UpdatedAt: v.UpdatedAt,
} }
@ -56,7 +53,6 @@ func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto {
Price: m.Price, Price: m.Price,
DiscountPrice: m.DiscountPrice, DiscountPrice: m.DiscountPrice,
DiscountEndTime: m.DiscountEndTime, DiscountEndTime: m.DiscountEndTime,
FirstTimePrice: m.FirstTimePrice,
CreatedAt: m.CreatedAt, CreatedAt: m.CreatedAt,
UpdatedAt: m.UpdatedAt, UpdatedAt: m.UpdatedAt,
} }
@ -64,12 +60,7 @@ func GetSystemMemberDto(m *model.SystemMember) *SystemMemberDto {
// LoadReductionAmount 加载数据-立减金额 // LoadReductionAmount 加载数据-立减金额
func (r *SystemMemberDto) LoadReductionAmount(m *model.SystemMember) *SystemMemberDto { func (r *SystemMemberDto) LoadReductionAmount(m *model.SystemMember) *SystemMemberDto {
if m.FirstTimePrice != nil { r.ReductionAmount = m.ReductionAmount
reductionAmount := m.Price - *m.FirstTimePrice
reductionAmount = math.Round(reductionAmount*100) / 100
r.ReductionAmount = &reductionAmount
}
return r return r
} }

View File

@ -13,7 +13,7 @@ type SystemMember struct {
Price float64 `gorm:"column:price;type:decimal(10,2);default:0.00;comment:价格(原价)" json:"price"` 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"` 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"` 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 Model
} }

View File

@ -21,29 +21,23 @@ func (r *SystemMemberService) GetSystemMemberBuyPrice(m *model.SystemMember) (p
// GetUserBuyPrice 获取会员最终价格 // GetUserBuyPrice 获取会员最终价格
func (r *SystemMemberService) GetUserBuyPrice(userId int64, m *model.SystemMember) (p float64) { func (r *SystemMemberService) GetUserBuyPrice(userId int64, m *model.SystemMember) (p float64) {
// 检测用户是否购买过单项产品
var firstTimePrice *float64 // 优惠价格
userService := &UserService{} price := r.HandleSystemMemberDiscountPrice(m.DiscountPrice, m.DiscountEndTime)
isBuy := userService.CheckUserBuyMember(userId) if price == nil {
if isBuy == false { // 正常价格
// 未购买过 p = m.Price
if m.FirstTimePrice != nil { } else {
// 首次购买价格 p = *price
firstTimePrice = m.FirstTimePrice
}
} }
if firstTimePrice != nil { if m.ReductionAmount != nil {
// 首次购买价格 // 检测用户是否购买过单项产品
p = *firstTimePrice userService := &UserService{}
} else { isBuy := userService.CheckUserBuyMember(userId)
// 优惠价格 if isBuy == false {
price := r.HandleSystemMemberDiscountPrice(m.DiscountPrice, m.DiscountEndTime) // 未购买过
if price == nil { p = p - *m.ReductionAmount
// 正常价格
p = m.Price
} else {
p = *price
} }
} }

View File

@ -219,8 +219,8 @@ func (r *UserCouponService) GetUserUsableMemberCoupon(userId, systemMemberId int
return nil, errors.New("操作失败") return nil, errors.New("操作失败")
} }
if systemMember.FirstTimePrice != nil { if systemMember.ReductionAmount != nil {
// 存在首单优惠价格,不允许使用优惠卷 // 存在首单立减价格,不允许使用优惠卷
return nil, nil return nil, nil
} }
} }