fix: promtion goods return

master
howell 3 years ago
parent 30aa0eaee1
commit 4d92285f9c

@ -76,7 +76,8 @@ func CreatePromotion(c *gin.Context) {
// 判断日期提前
var count uint
dbc.DB.Table((&promotion.Information{}).TableName()).Where("start_date = ?", startDate.Format("2006-01-02")).Count(&count)
dbc.DB.Table((&promotion.Information{}).TableName()).
Where("is_sale=?", p.IsSale).Where("start_date = ?", startDate.Format("2006-01-02")).Count(&count)
if count > 0 {
back.Fail(c, "该日期已创建过活动,请更改日期")
return
@ -168,7 +169,11 @@ func CreatePromotion(c *gin.Context) {
for _, g := range v.GoodsList {
totalInventory := 0
for _, sku := range g.SkuList {
totalInventory += int(sku.Inventory)
inventory := sku.Inventory
if p.IsSale {
inventory = 9999
}
totalInventory += int(inventory)
}
order, _ := strconv.Atoi(g.Order)
@ -200,15 +205,23 @@ func CreatePromotion(c *gin.Context) {
return
}
discount := decimal.NewFromFloat(sku.DiscountPrice).Truncate(2)
commission := decimal.NewFromFloat(sku.DiscountPrice).Mul(goodsSku.CommissionRate).Truncate(2)
i1 := sku.Inventory
if p.IsSale {
discount = goodsSku.SalePurchasePrice
commission = decimal.Zero
i1 = 9999
}
s := promotion.Sku{
PromotionGoodsID: promotionGoods.ID,
GoodsID: promotionGoods.GoodsID,
SkuID: sku.SkuID,
DiscountPrice: decimal.NewFromFloat(sku.DiscountPrice).Truncate(2),
Commission: decimal.NewFromFloat(sku.DiscountPrice).Mul(goodsSku.CommissionRate).Truncate(2),
DiscountPrice: discount,
Commission: commission,
SkuName: goodsSku.Name,
SkuCode: goodsSku.Code,
Inventory: sku.Inventory,
Inventory: i1,
}
if err = tx.Create(&s).Error; err != nil {
back.Err(c, "数据错误:"+err.Error())

@ -10,15 +10,16 @@ import (
"recook/internal/model/promotion"
goods2 "recook/internal/v2/model/recook/goods"
user2 "recook/internal/v2/model/recook/user"
"recook/internal/v2/model/special_sale"
"recook/tools"
"strconv"
"strings"
"time"
"git.oa00.com/go/mysql"
"github.com/gin-gonic/gin"
"github.com/golangkit/formatime"
"github.com/shopspring/decimal"
"gorm.io/gorm/clause"
)
type queryPromotionGoodsParam struct {
@ -162,6 +163,7 @@ type promotionGoods struct {
GysId uint `json:"gys_id"` //供应商id
CountryIcon string `json:"country_icon"`
SecKill SecKillDetail `json:"sec_kill"`
SalePrice decimal.Decimal `json:"sale_price"`
}
type picture struct {
@ -290,138 +292,25 @@ func QueryPromotionGoodsList(c *gin.Context) {
}
var u user2.RecookUserInfoModel
dbc.DB.First(&u, "id = ?", p.UserID)
//rate1 := decimal.NewFromFloat32(0.4)
//rate2 := decimal.NewFromFloat32(0.1)
//rate3 := decimal.Zero
//if u.Level == 2 {
// rate3 = decimal.NewFromFloat(0.2)
//}
//p.TimeItemID=1275
var promotionGoodsList []promotion.Goods
dbc.DB.Order("`order` asc").Find(&promotionGoodsList, "promotion_time_item_id = ?", p.TimeItemID)
if len(promotionGoodsList) == 0 {
back.Suc(c, "", nil)
return
}
var p1 promotion.Information
dbc.DB.First(&p1, "id = ?", promotionGoodsList[0].PromotionID)
gList := make([]promotionGoods, 0)
aList := make([]activityList, 0)
/*
*/
//获取当前时间段的秒杀goodsid
//gmp := GetSecKillGoods()
ids := make([]interface{}, 0)
place := make([]string, 0)
for _, v := range promotionGoodsList {
if v.GoodsID > 0 {
var gi goods.Information
dbc.DB.First(&gi, "id = ? AND publish_status = 1", v.GoodsID)
gb := goods.Brand{}
dbc.DB.First(&gb, "id = ?", gi.BrandID)
if gi.ID == 0 {
continue
}
var pic picture
dbc.DB.Table((&goods.MainPhoto{}).TableName()).First(&pic, "goods_id = ? AND is_master = 1", v.GoodsID)
var promotionSku promotion.Sku
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)
salesVolume := 0
if promotionSku.SalesVolume > 0 {
salesVolume = int(promotionSku.SalesVolume)
}
var goodsSkuVolume goods.Sku
dbc.DB.Select("SUM(sales_volume) AS sales_volume, SUM(sales_volume_inc) AS sales_volume_inc,SUM(inventory) AS inventory").
Find(&goodsSkuVolume, "goods_id = ?", v.GoodsID)
salesVolume1 := int(goodsSkuVolume.SalesVolume) + int(goodsSkuVolume.SalesVolumeInc)
fmt.Println(v.ID)
fmt.Println(goodsSkuVolume)
// salesVolumeDesc := "已抢" + fmt.Sprintf("%d", salesVolume) + "件"
salesVolumeDesc := "累计已售" + fmt.Sprintf("%d", salesVolume1) + "件"
if salesVolume == int(goodsSkuVolume.Inventory) {
//salesVolumeDesc = "已抢光"
salesVolumeDesc = ""
}
// todo已售未改成sku的已售仍然是活动的已售
//percentage := decimal.NewFromInt(int64(salesVolume)).Div(decimal.NewFromInt(int64(v.TotalInventory))).Round(2)
//
//percentageDesc := percentage.Mul(decimal.NewFromInt(100)).String() + "%"
inventoryDesc := "库存" + fmt.Sprintf("%d", goodsSkuVolume.Inventory)
if goodsSkuVolume.Inventory == 0 {
inventoryDesc = "已售罄"
}
var goodsSkus []goods.Sku
dbc.DB.Order("discount_price asc").Where("goods_id = ?", v.GoodsID).Find(&goodsSkus)
goodsSku := goods.Sku{}
if len(goodsSkus) > 0 {
goodsSku = goodsSkus[0]
}
inventory := uint(0)
for _, skus := range goodsSkus {
inventory += skus.Inventory
}
//后面把这个代码删除
//if c.Request.Header.Get("X-Recook-System") == "ios" {
// mytemp := goodsSku.DiscountPrice
// goodsSku.DiscountPrice = goodsSku.OriginalPrice
// goodsSku.OriginalPrice = mytemp
//}
var country goods2.RecookAbroadCountryModel
dbc.DB.Table(country.TableName()).First(&country, "id = ?", gi.Country)
var one SecKillDetail
//if _, ok := gmp[v.ID]; ok {
// //存着有秒杀商品
// one = GetSecKillDetail(v.GoodsID)
//}
//base := goodsSku.GetBase()
//commission1 := base.Mul(rate1).Round(2)
//commission2 := base.Mul(rate2).Round(2)
//commission3 := base.Mul(rate3).Round(2)
//cm := commission1.Add(commission2).Add(commission3)
//if u.Level == 10 {
// cm = goodsSku.DiscountPrice.Sub(goodsSku.PurchasePrice.Mul(decimal.NewFromFloat(1.03))).Mul(decimal.NewFromFloat(define.Coefficient)).Round(2)
//}
cm := goodsSku.GetSelfProfit(u.Level)
gList = append(gList, promotionGoods{
GoodsID: gi.ID,
GoodsName: strings.Join([]string{gi.GoodsName, strings.Replace(goodsSku.Name, "+", " ", -1)}, " "),
BrandName: gb.Name + "品牌馆",
BrandImg: gb.LogoURL,
BrandId: gb.ID,
Description: v.Subtitle,
Price: goodsSku.DiscountPrice, //打折
PrimePrice: goodsSku.OriginalPrice, //卷后
PriceDesc: goodsSku.DiscountPrice.String(),
Commission: cm,
CommissionDesc: "赚" + cm.String(),
Picture: pic,
Inventory: inventory,
InventoryDesc: inventoryDesc,
TotalInventory: v.TotalInventory,
TotalInventoryDesc: "限购" + fmt.Sprintf("%d", v.TotalInventory) + "件",
TotalSalesVolume: uint(salesVolume1),
SalesVolumeDesc: salesVolumeDesc,
StartTime: v.StartTime,
EndTime: v.EndTime,
Percentage: decimal.Zero,
PercentageDesc: "",
Coupon: goodsSku.Coupon,
IsImport: gi.IsImport,
Storehouse: gi.Storehouse,
IsFerme: gi.IsFerme,
GysId: gi.VendorID, //添加供应商id
CountryIcon: country.Icon,
SecKill: one,
})
ids = append(ids, v.GoodsID)
place = append(place, "?")
}
if v.ActivityID > 0 {
var activityInfo activity.Info
dbc.DB.First(&activityInfo, v.ActivityID)
@ -433,64 +322,45 @@ func QueryPromotionGoodsList(c *gin.Context) {
})
}
}
/*
gListgoodsId
*/
var goodsList []goods.Information
//for i, k := range gList {
// var vo live
// dbc.DB.Table("recook_live_live_item").Where("main_goods_id=?", k.GoodsID).Select("status").Order("id desc").First(&vo)
// if vo.Status == 1 {
// gList[i].Living.Status = 1
// gList[i].Living.RoomId = vo.RoomId
// }
//
//}
/*
*/
//var SIcon kingKongIcon.SpecialSaleIconModel
//dbc.DB.Table(SIcon.TableName()).First(&SIcon)
//for i, _ := range gList {
// if i < 5 {
// gList[i].SpecialSale = SIcon.SpecialSaleIcon
// } else {
// break
// }
//}
/*
*/
var sp special_sale.SpecialSaleModel
var spes special_sale.SpecialSaleAssociationModel
var spess []special_sale.SpecialSaleAssociationModel
var spc []special_sale.SpecialSaleModel
//获取全部的特卖活动
dbc.DB.Table(sp.TableName()).Find(&spc)
//获取活动规则,活动商品或供应商
for i, v := range gList {
var spList []string
for _, k := range spc {
if k.Type == 1 { //全部商品
if k.GysId == v.GysId {
if k.EndTime.Time.Unix() > time.Now().Unix() {
spList = append(spList, k.Url)
}
}
} else { //部分商品
dbc.DB.Table(spes.TableName()).Where("special_sale_id=?", k.Id).Find(&spess)
for _, j := range spess {
if v.GoodsID == j.GoodsId {
if k.EndTime.Time.Unix() > time.Now().Unix() {
spList = append(spList, k.Url)
}
}
}
}
}
fmt.Println("图标路由为:", spList)
gList[i].SpecialSale = spList
field := fmt.Sprintf("FIELD(id, %s)", strings.Join(place, ","))
mysql.Db.Where("id in (?)", ids).Clauses(clause.OrderBy{
Expression: clause.Expr{SQL: field, Vars: ids, WithoutParentheses: true},
}).Find(&goodsList)
res := GetGoodsRespByInfoList(goodsList, p.UserID, p1.IsSale)
for _, v := range res {
gList = append(gList, promotionGoods{
GoodsID: v.ID,
GoodsName: v.GoodsName,
BrandName: v.BrandName,
BrandImg: v.BrandImg,
BrandId: v.BrandId,
Description: v.Description,
Price: v.DiscountPrice,
PrimePrice: v.OriginalPrice,
PriceDesc: v.DiscountPrice.String(),
Commission: v.Commission,
CommissionDesc: "赚" + v.Commission.String(),
Picture: picture{
URL: v.MainPhotoURL,
Width: 0,
Height: 0,
},
Inventory: v.Inventory,
InventoryDesc: "",
TotalInventory: v.Inventory,
TotalInventoryDesc: "",
TotalSalesVolume: uint(v.SalesVolume),
SalesVolumeDesc: "",
StartTime: v.StartTime,
EndTime: v.EndTime,
Percentage: decimal.Zero,
PercentageDesc: "",
Coupon: v.Coupon,
SalePrice: v.SalePrice,
})
}
back.Suc(c, "", &promotionList{

Loading…
Cancel
Save