|
|
|
@ -7,7 +7,6 @@ import (
|
|
|
|
|
"recook/internal/model/attention"
|
|
|
|
|
"recook/internal/model/coupon"
|
|
|
|
|
"recook/internal/model/goods"
|
|
|
|
|
"recook/internal/model/order"
|
|
|
|
|
"recook/internal/model/promotion"
|
|
|
|
|
"recook/internal/model/shopping_trolley"
|
|
|
|
|
goods2 "recook/internal/v2/model/recook/goods"
|
|
|
|
@ -64,52 +63,6 @@ type priceSub struct {
|
|
|
|
|
Limit uint `json:"limit"`
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type allPrice struct {
|
|
|
|
|
OriginalPrice decimal.Decimal `gorm:"column:original_price" json:"originalPrice"` // 重新计算折扣价
|
|
|
|
|
DiscountPrice decimal.Decimal `gorm:"column:discount_price" json:"discountPrice"`
|
|
|
|
|
Commission decimal.Decimal `gorm:"column:commission" json:"commission"`
|
|
|
|
|
PurchasePrice decimal.Decimal `gorm:"column:purchase_price" json:"purchasePrice"`
|
|
|
|
|
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 o.SalePurchasePrice.IsZero() {
|
|
|
|
|
return decimal.Zero
|
|
|
|
|
}
|
|
|
|
|
if level == 10 {
|
|
|
|
|
return o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2)
|
|
|
|
|
}
|
|
|
|
|
s1 := o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03)).Round(2).Mul(decimal.NewFromFloat(1.2)).Round(2)
|
|
|
|
|
// s1 = s1.Add(o.DiscountPrice.Sub(o.SalePurchasePrice.Mul(decimal.NewFromFloat(1.03))).Mul(decimal.NewFromFloat(0.2)).Round(2))
|
|
|
|
|
return s1.Round(2)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r allPrice) GetSelfProfit(level int) decimal.Decimal {
|
|
|
|
|
base := r.Commission
|
|
|
|
|
switch level {
|
|
|
|
|
case 0:
|
|
|
|
|
return decimal.Zero
|
|
|
|
|
case 1:
|
|
|
|
|
self := base.Mul(order.Self.GetProfit()).Round(2)
|
|
|
|
|
brand := base.Mul(order.Brand.GetProfit()).Round(2)
|
|
|
|
|
return self.Add(brand)
|
|
|
|
|
case 2:
|
|
|
|
|
// 店铺买
|
|
|
|
|
self := base.Mul(order.Self.GetProfit()).Round(2)
|
|
|
|
|
brand := base.Mul(order.Brand.GetProfit()).Round(2)
|
|
|
|
|
shop := base.Mul(order.Shop.GetProfit()).Round(2)
|
|
|
|
|
return self.Add(brand).Add(shop)
|
|
|
|
|
case 10:
|
|
|
|
|
// 子公司 100%自购
|
|
|
|
|
return base.Mul(order.All.GetProfit())
|
|
|
|
|
default:
|
|
|
|
|
return decimal.Zero
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
type recommend struct {
|
|
|
|
|
GoodsName string `json:"goodsName,omitempty"`
|
|
|
|
|
GoodsId uint `json:"goodsId,omitempty"`
|
|
|
|
@ -194,7 +147,7 @@ func fetchRecommends(goodsId int64, brandId uint) []recommend {
|
|
|
|
|
var mainPhoto goods.MainPhoto
|
|
|
|
|
dbc.DB.First(&mainPhoto, "goods_id = ? AND is_master = 1", v.ID)
|
|
|
|
|
|
|
|
|
|
var minAllPrice allPrice
|
|
|
|
|
var minAllPrice goods.AllPrice
|
|
|
|
|
selectMinPriceStr := "MIN(discount_price) AS discount_price"
|
|
|
|
|
dbc.DB.Table((&goods.Sku{}).TableName()).Select(selectMinPriceStr).First(&minAllPrice, "goods_id = ?", v.ID)
|
|
|
|
|
|
|
|
|
@ -350,7 +303,7 @@ func QueryGoodsDetailNew(c *gin.Context) {
|
|
|
|
|
summary.Inventory = sv.Inventory
|
|
|
|
|
summary.SaleInventory = sv.SaleInventory
|
|
|
|
|
|
|
|
|
|
var minAllPrice allPrice
|
|
|
|
|
var minAllPrice goods.AllPrice
|
|
|
|
|
selectMinPriceStr := "MIN(original_price) AS original_price, " +
|
|
|
|
|
"MIN(discount_price) AS discount_price, " +
|
|
|
|
|
"MIN(ROUND(discount_price-purchase_price*1.03, 2)) AS commission, " +
|
|
|
|
@ -361,7 +314,7 @@ func QueryGoodsDetailNew(c *gin.Context) {
|
|
|
|
|
dbc.DB.Table((&goods.Sku{}).TableName()).Select(selectMinPriceStr).First(&minAllPrice, "goods_id = ?", p.GoodsID)
|
|
|
|
|
minAllPrice.SalePrice = minAllPrice.GetSalePrice(u1.Level)
|
|
|
|
|
|
|
|
|
|
var maxAllPrice allPrice
|
|
|
|
|
var maxAllPrice goods.AllPrice
|
|
|
|
|
selectMaxPriceStr := "MAX(original_price) AS original_price, " +
|
|
|
|
|
"MAX(discount_price) AS discount_price, " +
|
|
|
|
|
"MAX(ROUND(discount_price-purchase_price*1.03, 2)) AS commission, " +
|
|
|
|
|