You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
111 lines
3.6 KiB
111 lines
3.6 KiB
package goods
|
|
|
|
import (
|
|
"recook/internal/back"
|
|
"recook/internal/dbc"
|
|
"recook/internal/model/goods"
|
|
"recook/tools"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/jinzhu/gorm"
|
|
)
|
|
|
|
type queryFavoriteListParam struct {
|
|
UserID uint `json:"userID" validate:"required"`
|
|
}
|
|
|
|
type favoriteResp struct {
|
|
FavoriteID uint `json:"favoriteId"`
|
|
Goods QueryCategoryGoodsListResp `json:"goods"`
|
|
}
|
|
|
|
func QueryFavoriteGoodsList(c *gin.Context) {
|
|
var p queryFavoriteListParam
|
|
if err := tools.ParseParams(&p, c); err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
|
|
var fs []goods.Favorites
|
|
if err := dbc.DB.Select("id, goods_id").Order("id desc").Find(&fs, "user_id = ?", p.UserID).Error; err != nil && gorm.IsRecordNotFoundError(err) == false {
|
|
back.Err(c, err.Error())
|
|
return
|
|
}
|
|
|
|
list := make([]favoriteResp, 0, 0)
|
|
for _, v := range fs {
|
|
var goodsInfo goods.Information
|
|
dbc.DB.Select("id, goods_name, description,brand_id").First(&goodsInfo, v.GoodsID)
|
|
list = append(list, favoriteResp{
|
|
FavoriteID: v.ID,
|
|
Goods: getFavoritesGoodsRespByInfo(goodsInfo),
|
|
})
|
|
}
|
|
|
|
back.Suc(c, "", list)
|
|
}
|
|
|
|
func getFavoritesGoodsRespByInfo(goodsInfo goods.Information) QueryCategoryGoodsListResp {
|
|
var mainPhoto goods.MainPhoto
|
|
dbc.DB.Select("url").First(&mainPhoto, "goods_id = ? AND is_master = 1", goodsInfo.ID)
|
|
var gb goods.Brand
|
|
dbc.DB.First(&gb, "id = ?", goodsInfo.BrandID)
|
|
|
|
var sku goods.Sku
|
|
dbc.DB.Select("SUM(inventory) AS inventory, "+
|
|
"SUM(sales_volume) AS sales_volume, "+
|
|
"MIN(original_price) AS original_price, "+
|
|
"MIN(discount_price) AS discount_price, "+
|
|
"MIN(commission) AS commission").
|
|
First(&sku, "goods_id = ?", goodsInfo.ID)
|
|
|
|
/*
|
|
商品价格展示规则:
|
|
1.当前正在参加活动,则显示活动价格
|
|
2.今天的活动还没开始, 则显示活动价格
|
|
3.是明天参加活动,则显示活动价格
|
|
|
|
用23点做判断
|
|
*/
|
|
inventory := sku.Inventory
|
|
salesVolume := sku.SalesVolume
|
|
// now := time.Now()
|
|
// today := tools.GetToday23Clock()
|
|
// tomorrow := tools.GetTomorrow23Clock()
|
|
// var promotionGoods promotion.Goods
|
|
// dbc.DB.Select("id, promotion_name, start_time, end_time").First(&promotionGoods, "goods_id = ? AND start_time <= ? AND end_time >= ?", goodsInfo.ID, today, today)
|
|
// if promotionGoods.ID > 0 {
|
|
// if now.Unix() > promotionGoods.StartTime.Time.Unix() { // 活动如果已经开始了。则要去统计活动sku
|
|
// var promotionSku promotion.Sku
|
|
// dbc.DB.Select("SUM(inventory) AS inventory, SUM(sales_volume) AS sales_volume").First(&promotionSku, "promotion_goods_id = ?", promotionGoods.ID)
|
|
// inventory = promotionSku.Inventory
|
|
// salesVolume = promotionSku.SalesVolume
|
|
// }
|
|
// } else { // 再判断商品明天会不会参加活动
|
|
// dbc.DB.Select("id, promotion_name").First(&promotionGoods, "goods_id = ? AND start_time <= ? AND end_time >= ?", goodsInfo.ID, tomorrow, tomorrow)
|
|
// }
|
|
|
|
// discountPrice := sku.DiscountPrice
|
|
// if promotionGoods.ID > 0 {
|
|
// var promotionSku promotion.Sku
|
|
// dbc.DB.Select("MIN(discount_price) AS discount_price").Find(&promotionSku, "promotion_goods_id = ?", promotionGoods.ID)
|
|
// discountPrice = promotionSku.DiscountPrice
|
|
// }
|
|
|
|
return QueryCategoryGoodsListResp{
|
|
ID: goodsInfo.ID,
|
|
GoodsName: goodsInfo.GoodsName,
|
|
BrandName: gb.Name + "品牌馆",
|
|
BrandImg: gb.LogoURL,
|
|
BrandId: gb.ID,
|
|
Description: goodsInfo.Description,
|
|
Inventory: inventory,
|
|
SalesVolume: salesVolume,
|
|
MainPhotoURL: mainPhoto.URL,
|
|
PromotionName: goodsInfo.GoodsName,
|
|
OriginalPrice: sku.OriginalPrice,
|
|
DiscountPrice: sku.DiscountPrice,
|
|
Commission: sku.Commission,
|
|
}
|
|
}
|