feat: 精品特推

master
howell 3 years ago
parent 601c3ec83d
commit 1d94c0456a

@ -31,17 +31,28 @@ type promotionTimeItemResp struct {
ShowName string `json:"showName"`
}
type promotionReq struct {
IsSale bool `json:"is_sale"`
}
// QueryPromotionTimeItems 获取首页活动列表
func QueryPromotionTimeItems(c *gin.Context) {
list := make([]promotionTimeItemResp, 0, 0)
var p promotionReq
err := tools.Params(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
list := make([]promotionTimeItemResp, 0)
var yesterdayPromInfo promotion.Information // 昨天的
today := time.Now()
d, _ := time.ParseDuration("-24h")
yesterday := today.Add(d)
dbc.DB.Select("id").First(&yesterdayPromInfo, "start_date = ?", yesterday.Format("2006-01-02"))
dbc.DB.Select("id").First(&yesterdayPromInfo, "is_sale = ? AND start_date = ?", p.IsSale, yesterday.Format("2006-01-02"))
{
yesterdayTimeItems := make([]promotion.TimeItem, 0, 0)
yesterdayTimeItems := make([]promotion.TimeItem, 0)
dbc.DB.Order("start_time asc").Find(&yesterdayTimeItems, "promotion_id = ?", yesterdayPromInfo.ID)
for i, _ := range yesterdayTimeItems {
showName := "昨日精选"
@ -54,9 +65,9 @@ func QueryPromotionTimeItems(c *gin.Context) {
var todayPromInfo promotion.Information // 今天的
fmt.Println(time.Now().Format("2006-01-02 15:04:06"))
dbc.DB.Select("id").First(&todayPromInfo, "start_date = ?", time.Now().Format("2006-01-02"))
dbc.DB.Select("id").First(&todayPromInfo, "is_sale=? AND start_date = ?", p.IsSale, time.Now().Format("2006-01-02"))
{
todayTimeItems := make([]promotion.TimeItem, 0, 0)
todayTimeItems := make([]promotion.TimeItem, 0)
dbc.DB.Order("start_time asc").Find(&todayTimeItems, "promotion_id = ?", todayPromInfo.ID)
length := len(todayTimeItems)
@ -91,9 +102,9 @@ func QueryPromotionTimeItems(c *gin.Context) {
today = time.Now()
d, _ = time.ParseDuration("24h")
tomorrow := today.Add(d)
dbc.DB.Select("id").First(&tomorrowPromInfo, "start_date = ?", tomorrow.Format("2006-01-02"))
dbc.DB.Select("id").First(&tomorrowPromInfo, "is_sale=? AND start_date = ?", p.IsSale, tomorrow.Format("2006-01-02"))
{
tomorrowTimeItems := make([]promotion.TimeItem, 0, 0)
tomorrowTimeItems := make([]promotion.TimeItem, 0)
dbc.DB.Order("start_time asc").Find(&tomorrowTimeItems, "promotion_id = ?", tomorrowPromInfo.ID)
for i, _ := range tomorrowTimeItems {
showName := "明日优选"

Loading…
Cancel
Save