master
howell 4 years ago
parent aaadf3ab58
commit e90bfade27

@ -30,7 +30,7 @@ type promotionTimeItemResp struct {
ShowName string `json:"showName"`
}
// 获取首页活动列表
// QueryPromotionTimeItems 获取首页活动列表
func QueryPromotionTimeItems(c *gin.Context) {
list := make([]promotionTimeItemResp, 0, 0)
@ -158,8 +158,25 @@ type picture struct {
Height uint `gorm:"column:height" json:"height,omitempty"`
}
//获取昨日的活动列表
// QueryPromotionGoodsListYesterday 获取昨日的活动列表
func QueryPromotionGoodsListYesterday(c *gin.Context) {
var p queryPromotionGoodsParam
err := tools.ParseParams(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
var u user2.RecookUserInfoModel
dbc.DB.First(&u, "id = ?", p.UserID)
rate := decimal.Zero
{
switch u.Level {
case 1:
rate = decimal.NewFromFloat(0.4)
case 2:
rate = decimal.NewFromFloat(0.7)
}
}
nTime := time.Now()
yesTime := nTime.AddDate(0, 0, -1)
logDay := yesTime.Format("2006-01-02")
@ -185,7 +202,7 @@ func QueryPromotionGoodsListYesterday(c *gin.Context) {
var promotionSku promotion.Sku
var sku goods.Sku
dbc.DB.First(&sku, "promotion_goods_id = ?", v.ID)
dbc.DB.Select("SUM(sales_volume) AS sales_volume, SUM(inventory) AS inventory, MIN(discount_price) AS discount_price, MIN(commission) AS commission").First(&promotionSku, "promotion_goods_id = ?", v.ID)
dbc.DB.Select("SUM(sales_volume) AS sales_volume, SUM(inventory) AS inventory, MIN(discount_price) AS discount_price, MIN(purchase_price) AS purchase_price, MIN(commission) AS commission").Find(&promotionSku, "promotion_goods_id = ?", v.ID)
salesVolume := 0
if sku.SalesVolume > 0 {
salesVolume = int(sku.SalesVolume)
@ -197,9 +214,9 @@ func QueryPromotionGoodsListYesterday(c *gin.Context) {
salesVolumeDesc = ""
}
percentage := decimal.NewFromInt(int64(salesVolume)).Div(decimal.NewFromInt(int64(v.TotalInventory))).Round(2)
percentageDesc := percentage.Mul(decimal.NewFromInt(100)).String() + "%"
//percentage := decimal.NewFromInt(int64(salesVolume)).Div(decimal.NewFromInt(int64(v.TotalInventory))).Round(2)
//
//percentageDesc := percentage.Mul(decimal.NewFromInt(100)).String() + "%"
inventoryDesc := "库存" + fmt.Sprintf("%d", sku.Inventory)
if sku.Inventory == 0 {
@ -210,6 +227,7 @@ func QueryPromotionGoodsListYesterday(c *gin.Context) {
var goodsSku goods.Sku
dbc.DB.Where("goods_id = ?", v.GoodsID).Find(&goodsSku)
cm := goodsSku.DiscountPrice.Sub(goodsSku.PurchasePrice).Mul(rate)
gList = append(gList, promotionGoods{
GoodsID: gi.ID,
GoodsName: gi.GoodsName,
@ -220,8 +238,8 @@ func QueryPromotionGoodsListYesterday(c *gin.Context) {
Price: goodsSku.DiscountPrice,
PrimePrice: goodsSku.OriginalPrice,
PriceDesc: goodsSku.DiscountPrice.String(),
Commission: promotionSku.Commission,
CommissionDesc: "赚" + promotionSku.Commission.String(),
Commission: cm,
CommissionDesc: "赚" + cm.String(),
Picture: pic,
Inventory: sku.Inventory,
InventoryDesc: inventoryDesc,
@ -231,8 +249,8 @@ func QueryPromotionGoodsListYesterday(c *gin.Context) {
SalesVolumeDesc: salesVolumeDesc,
StartTime: v.StartTime,
EndTime: v.EndTime,
Percentage: percentage,
PercentageDesc: percentageDesc,
Percentage: decimal.Zero,
PercentageDesc: "",
Coupon: sku.Coupon,
IsImport: gi.IsImport,
Storehouse: gi.Storehouse,
@ -250,7 +268,7 @@ func QueryPromotionGoodsListYesterday(c *gin.Context) {
}
//精品推荐 添加直播标记
// QueryPromotionGoodsList 精品推荐
func QueryPromotionGoodsList(c *gin.Context) {
var p queryPromotionGoodsParam
err := tools.ParseParams(&p, c)
@ -351,6 +369,7 @@ func QueryPromotionGoodsList(c *gin.Context) {
//存着有秒杀商品
one = GetSecKillDetail(v.GoodsID)
}
cm := goodsSku.DiscountPrice.Sub(goodsSku.PurchasePrice).Mul(rate)
gList = append(gList, promotionGoods{
GoodsID: gi.ID,
@ -362,8 +381,8 @@ func QueryPromotionGoodsList(c *gin.Context) {
Price: goodsSku.DiscountPrice, //打折
PrimePrice: goodsSku.OriginalPrice, //卷后
PriceDesc: goodsSku.DiscountPrice.String(),
Commission: goodsSku.DiscountPrice.Sub(goodsSku.PurchasePrice).Mul(rate),
CommissionDesc: "赚" + goodsSku.Commission.String(),
Commission: cm,
CommissionDesc: "赚" + cm.String(),
Picture: pic,
Inventory: inventory,
InventoryDesc: inventoryDesc,

Loading…
Cancel
Save