修改了立减金额
This commit is contained in:
parent
f5ccb4de2f
commit
a0b6ffce91
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user