fix: 增加平台供货价

master
howell 3 years ago
parent d469ded996
commit d8d63c6f2e

@ -72,14 +72,15 @@ type allPrice struct {
Min uint `gorm:"column:min_num" json:"min"`
Limit uint `gorm:"column:limit_num" json:"limit"`
SalePrice decimal.Decimal `gorm:"column:sale_price" json:"sale_price"`
SalePurchasePrice decimal.Decimal `gorm:"column:sale_purchase_price" json:"-"`
}
func (o allPrice) GetSalePrice(level int) decimal.Decimal {
if level == 10 {
return o.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
return o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
}
s1 := o.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
s1 = s1.Add(o.DiscountPrice.Sub(o.PurchasePrice).Mul(decimal.NewFromFloat(0.2)).Round(2))
s1 := o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
s1 = s1.Add(o.DiscountPrice.Sub(o.SalePurchasePrice).Mul(decimal.NewFromFloat(0.2)).Round(2))
return s1.Round(2)
}
@ -328,7 +329,8 @@ func QueryGoodsDetailNew(c *gin.Context) {
"MIN(commission) AS commission, " +
"MIN(purchase_price) AS purchase_price, " +
"MIN(min_num) AS min_num, " +
"MIN(limit_num) AS limit_num "
"MIN(limit_num) AS limit_num, " +
"MIN(sale_purchase_price) as sale_purchase_price"
dbc.DB.Table((&goods.Sku{}).TableName()).Select(selectMinPriceStr).First(&minAllPrice, "goods_id = ?", p.GoodsID)
minAllPrice.SalePrice = minAllPrice.GetSalePrice(u1.Level)
@ -338,7 +340,8 @@ func QueryGoodsDetailNew(c *gin.Context) {
"MAX(commission) AS commission, " +
"MAX(purchase_price) AS purchase_price, " +
"MAX(min_num) AS min_num, " +
"MAX(limit_num) AS limit_num "
"MAX(limit_num) AS limit_num, " +
"MAX(sale_purchase_price) as sale_purchase_price"
dbc.DB.Table((&goods.Sku{}).TableName()).Select(selectMaxPriceStr).First(&maxAllPrice, "goods_id = ?", p.GoodsID)
maxAllPrice.SalePrice = maxAllPrice.GetSalePrice(u1.Level)

@ -32,6 +32,7 @@ type Sku struct {
SaleInventory uint `json:"sale_inventory" gorm:"column:sale_inventory"`
Limit uint `json:"limit" gorm:"column:limit_num"`
Min uint `json:"min" gorm:"column:min_num"`
SalePurchasePrice decimal.Decimal `json:"sale_purchase_price" gorm:"column:sale_purchase_price"` // 批发供货价
}
// TableName sets the insert table name for this struct type
@ -47,9 +48,9 @@ func (r *Sku) GetBase() decimal.Decimal {
func (o *Sku) GetSalePrice(level int) decimal.Decimal {
if level == 10 {
return o.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
return o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
}
s1 := o.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
s1 = s1.Add(o.DiscountPrice.Sub(o.PurchasePrice).Mul(decimal.NewFromFloat(0.2)).Round(2))
s1 := o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
s1 = s1.Add(o.DiscountPrice.Sub(o.SalePurchasePrice).Mul(decimal.NewFromFloat(0.2)).Round(2))
return s1.Round(2)
}

@ -270,6 +270,10 @@ func (o logic) OrderPreview(args OrderPreview) (err error, res OrderPreviewInfo)
sl := make([]ShopCartSku, 0)
for _, v := range skuList {
if v.SalePurchasePrice.IsZero() {
err = errors.New("价格异常")
return
}
qu := decimal.NewFromInt(int64(idMap[v.Id]))
goodsInfo := v.GoodsInfo
one := order_preview.GoodsDetail{
@ -293,7 +297,7 @@ func (o logic) OrderPreview(args OrderPreview) (err error, res OrderPreviewInfo)
PromotionGoodsId: 0,
PromotionName: "",
UnitPrice: v.GetSalePrice(u1.Level),
PurchasePrice: v.PurchasePrice,
PurchasePrice: v.SalePurchasePrice,
TotalCommission: decimal.Zero,
GoodsAmount: v.GetSalePrice(u1.Level).Mul(qu),
IsImport: goodsInfo.IsImport,

@ -51,14 +51,15 @@ type RecookGoodsSkuModel struct {
Min int `json:"min" gorm:"column:min_num"`
SaleInventory uint `json:"sale_inventory"`
GoodsInfo *RecookGoodsInfoModel `json:"-" gorm:"foreignKey:goods_id"`
SalePurchasePrice decimal.Decimal `json:"sale_purchase_price" gorm:"column:sale_purchase_price"`
}
func (r *RecookGoodsSkuModel) GetSalePrice(level int) decimal.Decimal {
if level == 10 {
return r.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
return r.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
}
s1 := r.PurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
s1 = s1.Add(r.DiscountPrice.Sub(r.PurchasePrice).Mul(decimal.NewFromFloat(0.2)).Round(2))
s1 := r.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
s1 = s1.Add(r.DiscountPrice.Sub(r.SalePurchasePrice).Mul(decimal.NewFromFloat(0.2)).Round(2))
return s1.Round(2)
}

Loading…
Cancel
Save