diff --git a/internal/v2/controller/manage/activebit/activebitshow.go b/internal/v2/controller/manage/activebit/activebitshow.go index bafcd7a..765baf4 100644 --- a/internal/v2/controller/manage/activebit/activebitshow.go +++ b/internal/v2/controller/manage/activebit/activebitshow.go @@ -62,8 +62,17 @@ func (a ControllerActive) Del(c *gin.Context) { } +type ShowReq struct { + IsSale bool `json:"is_sale"` +} + func (a ControllerActive) ShowList(c *gin.Context) { - rest := activebit.LogicActiveBit.ShowList() + var p ShowReq + if err := tools.Params(&p, c); err != nil { + back.Fail(c, err.Error()) + return + } + rest := activebit.LogicActiveBit.ShowList(p.IsSale) back.Suc(c, "ok", rest) } diff --git a/internal/v2/logic/manage/activebit/logic.go b/internal/v2/logic/manage/activebit/logic.go index a62fb04..6ee9d5a 100644 --- a/internal/v2/logic/manage/activebit/logic.go +++ b/internal/v2/logic/manage/activebit/logic.go @@ -33,6 +33,7 @@ type CreatedReq struct { StartTime string `json:"start_time"` EndTime string `json:"end_time"` SortId uint `json:"sort_id"` + IsSale bool `json:"is_sale"` } //Add 新增轮播图 @@ -140,7 +141,7 @@ func (b logicActiveBit) Add(p CreatedReq) error { if activityOrGoods == "goods" && p.GoodsID > 0 { // 重复性检查 var show rotation.RecookRotationModel - dbc.DB.Where("is_active=1").First(&show, "good_id = ?", p.GoodsID) + dbc.DB.Where("is_active=1").Where("is_sale=?", p.IsSale).First(&show, "good_id = ?", p.GoodsID) if show.ID > 0 { return errors.New("该商品已在钻展中") } @@ -155,6 +156,7 @@ func (b logicActiveBit) Add(p CreatedReq) error { StartTime: formatime.NewSecondFrom(t1), EndTime: formatime.NewSecondFrom(t2), SortId: p.SortId, + IsSale: p.IsSale, } err := dbc.DB.Table(one.TableName()).Create(&one).Error if err != nil { @@ -186,6 +188,7 @@ func (b logicActiveBit) Add(p CreatedReq) error { StartTime: formatime.NewSecondFrom(t1), EndTime: formatime.NewSecondFrom(t2), SortId: p.SortId, + IsSale: p.IsSale, } if err := dbc.DB.Create(&one).Error; err != nil { return err @@ -206,10 +209,11 @@ type queryResp struct { Status uint `json:"status"` //1:待生效 2:生效中 3已失效 } -func (b logicActiveBit) ShowList() (list []queryResp) { +func (b logicActiveBit) ShowList(isSale bool) (list []queryResp) { var of []rotation.RecookRotationModel - mysql2.Db.Table((&rotation.RecookRotationModel{}).TableName()).Where("is_active=?", 1).Order("id desc").Find(&of) + mysql2.Db.Table((&rotation.RecookRotationModel{}).TableName()).Where("is_sale=?", isSale). + Where("is_active=?", 1).Order("id desc").Find(&of) fmt.Println(len(of)) for _, v := range of { diff --git a/internal/v2/model/rotation/rotation.go b/internal/v2/model/rotation/rotation.go index 13310af..b6bf3bd 100644 --- a/internal/v2/model/rotation/rotation.go +++ b/internal/v2/model/rotation/rotation.go @@ -14,6 +14,7 @@ type RecookRotationModel struct { StartTime formatime.Second `gorm:"column:start_time" json:"start_time"` EndTime formatime.Second `gorm:"column:end_time" json:"end_time"` SortId uint `gorm:"column:sort_id" json:"sort_id"` + IsSale bool `json:"is_sale" gorm:"column:is_sale"` } // TableName sets the insert table name for this struct type