@ -6,7 +6,6 @@ import (
"recook/internal/cache"
"recook/internal/dbc"
"recook/internal/model/goods"
"recook/internal/model/promotion"
"recook/internal/v2/lib/es"
"recook/internal/v2/model/flashsale"
"recook/internal/v2/model/keywords"
@ -181,7 +180,7 @@ func QueryGoodsListByDiscountPrice(c *gin.Context) {
"goods_id" ) . Order ( order ) . Group ( "goods_id" ) .
Find ( & skuList , "goods_id IN (?)" , goodsIdList )
back . Suc ( c , "" , GetGoodsRespBySkuList ( skuList ))
back . Suc ( c , "" , GetGoodsRespBySkuList ( skuList , p . UserId ))
}
// GetGoodsRespByInfoList ==============================================================
@ -224,10 +223,16 @@ func GetGoodsRespByInfoList(goodsList []goods.Information, userID uint) []QueryC
if isMember , _ := cache . IsMemberOfNewerTehui ( strconv . Itoa ( int ( v . ID ) ) ) ; isMember {
tags = append ( tags , "新人特惠" )
}
rate1 := decimal . NewFromFloat32 ( 0.4 )
rate2 := decimal . NewFromFloat32 ( 0.1 )
rate1 := decimal . Zero
rate2 := decimal . Zero
rate3 := decimal . Zero
if u . Level == 1 {
rate1 = decimal . NewFromFloat32 ( 0.4 )
rate2 = decimal . NewFromFloat32 ( 0.1 )
}
if u . Level == 2 {
rate1 = decimal . NewFromFloat32 ( 0.4 )
rate2 = decimal . NewFromFloat32 ( 0.1 )
rate3 = decimal . NewFromFloat ( 0.2 )
}
base := sku . GetBase ( )
@ -275,8 +280,24 @@ type live struct {
RoomId int ` json:"room_id" `
}
func GetGoodsRespBySkuList ( skuList [ ] goods . Sku ) [ ] QueryCategoryGoodsListResp {
func GetGoodsRespBySkuList ( skuList [ ] goods . Sku , uid uint ) [ ] QueryCategoryGoodsListResp {
list := make ( [ ] QueryCategoryGoodsListResp , 0 , 0 )
var u user . RecookUserInfoModel
mysql2 . Db . First ( & u , "id = ?" , uid )
rate1 := decimal . Zero
rate2 := decimal . Zero
rate3 := decimal . Zero
if u . Level == 1 {
rate1 = decimal . NewFromFloat32 ( 0.4 )
rate2 = decimal . NewFromFloat32 ( 0.1 )
}
if u . Level == 2 {
rate1 = decimal . NewFromFloat32 ( 0.4 )
rate2 = decimal . NewFromFloat32 ( 0.1 )
rate3 = decimal . NewFromFloat ( 0.2 )
}
for _ , v := range skuList {
var mainPhoto goods . MainPhoto
dbc . DB . Select ( "url" ) . First ( & mainPhoto , "goods_id = ? AND is_master = 1" , v . GoodsID )
@ -297,47 +318,11 @@ func GetGoodsRespBySkuList(skuList []goods.Sku) []QueryCategoryGoodsListResp {
commission := v . Commission
inventory = v . Inventory //sku库存
now := time . Now ( )
var promotionGoods promotion . Goods
dbc . DB . Select ( "id, promotion_name, start_time, end_time" ) .
First ( & promotionGoods , "goods_id = ? AND start_time <= ? AND end_time >= ?" , v . GoodsID , now , now )
if promotionGoods . ID > 0 {
var promotionSku promotion . Sku
dbc . DB . Select ( "SUM(inventory) AS inventory, SUM(sales_volume) AS sales_volume,min(discount_price) as discount_price,min(discount_price) as discount_price" ) .
First ( & promotionSku , "promotion_goods_id = ?" , promotionGoods . ID )
discountPrice = promotionSku . DiscountPrice //活动的价格
commission = promotionSku . Commission //活动的佣金
inventory = promotionSku . Inventory
salesVolume = promotionSku . SalesVolume
//计算%
//percent = uint(salesVolume / (inventory + salesVolume) * 100)
startTime = promotionGoods . StartTime
endTime = promotionGoods . EndTime
} else {
dbc . DB . Select ( "id, promotion_name" ) .
First ( & promotionGoods , "goods_id = ? AND start_time > ?" , v . GoodsID , now )
if promotionGoods . ID > 0 {
var promotionSku promotion . Sku
dbc . DB . Select ( "MIN(discount_price) AS discount_price, MIN(commission) AS commission" ) . Find ( & promotionSku , "promotion_goods_id = ?" , promotionGoods . ID )
startTime = promotionGoods . StartTime
endTime = promotionGoods . EndTime
}
}
//新增进口专区国家图标
//var iconList []goods2.RecookAbroadCountryModel
//dbc.DB.Table((&goods2.RecookAbroadCountryModel{}).TableName()).Find(&iconList)
//var countryMap = make(map[uint]string)
//countryMap[0] = ""
//for _, j := range iconList {
// countryMap[j.ID] = j.Icon
//}
//fmt.Println(len(countryMap))
//国家图标放入map结束
base := v . GetBase ( )
commission1 := base . Mul ( rate1 ) . Round ( 2 )
commission2 := base . Mul ( rate2 ) . Round ( 2 )
commission3 := base . Mul ( rate3 ) . Round ( 2 )
commission = commission1 . Add ( commission2 ) . Add ( commission3 )
recookGoodsInfoModel := & goods2 . RecookGoodsInfoModel { }
list = append ( list , QueryCategoryGoodsListResp {
@ -350,7 +335,7 @@ func GetGoodsRespBySkuList(skuList []goods.Sku) []QueryCategoryGoodsListResp {
Inventory : inventory ,
SalesVolume : salesVolume ,
MainPhotoURL : mainPhoto . URL ,
PromotionName : promotionGoods . PromotionName ,
PromotionName : "" ,
OriginalPrice : v . OriginalPrice ,
DiscountPrice : discountPrice ,
Commission : commission ,