feat:轮播图添加is_sale

master
howell 3 years ago
parent ef9fa3bca3
commit 22da20a1e8

@ -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)
}

@ -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 {

@ -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

Loading…
Cancel
Save