From 1d94c0456ac3ae2bc1cafd583d76416e9068fe79 Mon Sep 17 00:00:00 2001 From: howell <2827207845@qq.com> Date: Tue, 15 Mar 2022 16:08:21 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E7=B2=BE=E5=93=81=E7=89=B9=E6=8E=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- internal/api/mobile/goods/promotion_list.go | 25 +++++++++++++++------ 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/internal/api/mobile/goods/promotion_list.go b/internal/api/mobile/goods/promotion_list.go index 8161fdf..99df485 100755 --- a/internal/api/mobile/goods/promotion_list.go +++ b/internal/api/mobile/goods/promotion_list.go @@ -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 := "明日优选"