feat:精品特推添加is_sale

master
howell 3 years ago
parent f55f1e4e92
commit 2c523cffe5

@ -20,6 +20,7 @@ type createPromotionParam struct {
StartDate string `json:"startDate" validate:"required" time_format:"2006-01-02"`
EndDate string `json:"endDate" validate:"required" time_format:"2006-01-02"`
TimeItems []timeItem `json:"timeItems" validate:"required"`
IsSale bool `json:"is_sale"`
}
type timeItem struct {
@ -62,8 +63,6 @@ func CreatePromotion(c *gin.Context) {
back.Fail(c, "日期无法解析")
return
}
startTime := time.Date(startDate.Year(), startDate.Month(), startDate.Day(), 0, 0, 0, 0, time.Local)
endDate, err := time.Parse("2006-01-02", p.EndDate)
if err != nil {
back.Fail(c, "日期无法解析")
@ -84,29 +83,29 @@ func CreatePromotion(c *gin.Context) {
}
endTime := time.Date(endDate.Year(), endDate.Month(), endDate.Day(), 23, 59, 59, 0, time.Local)
// 先检测
{
var promotionGoodsList []promotion.Goods
dbc.DB.Select("id, goods_id").Find(&promotionGoodsList, "start_time < ? AND end_time > ?", endTime, startTime)
// // 先检测
// {
// var promotionGoodsList []promotion.Goods
// dbc.DB.Select("id, goods_id").Find(&promotionGoodsList, "start_time < ? AND end_time > ?", endTime, startTime)
ids := map[uint]uint{}
for _, v := range promotionGoodsList {
ids[v.GoodsID] = 1
}
// ids := map[uint]uint{}
// for _, v := range promotionGoodsList {
// ids[v.GoodsID] = 1
// }
for _, v := range p.TimeItems {
for _, v2 := range v.GoodsList {
if _, ok := ids[v2.GoodsID]; ok {
back.Fail(c, "商品活动冲突")
return
}
}
// for _, v := range p.TimeItems {
// for _, v2 := range v.GoodsList {
// if _, ok := ids[v2.GoodsID]; ok {
// back.Fail(c, "商品活动冲突")
// return
// }
// }
if len(v.ActivitiesList) < 1 {
continue
}
}
}
// if len(v.ActivitiesList) < 1 {
// continue
// }
// }
// }
//for _, v := range p.TimeItems {
// for _, g := range v.GoodsList {
@ -136,6 +135,7 @@ func CreatePromotion(c *gin.Context) {
Name: p.Name,
StartDate: formatime.NewDateFrom(startDate),
EndDate: formatime.NewDateFrom(endDate),
IsSale: p.IsSale,
}
if err := tx.Create(&info).Error; err != nil {
back.Err(c, err.Error())

@ -16,24 +16,46 @@ import (
type goodsListParam struct {
Date string `json:"date" validate:"required" time_format:"2006-01-02"`
IsSale bool `json:"is_sale"`
}
type PromotionReq struct {
IsSale bool `json:"is_sale"`
}
func QueryWaitingList(c *gin.Context) {
var p PromotionReq
err := tools.Params(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
var l []promotion.Information
dbc.DB.Find(&l, "start_date > ? ", time.Now().Format("2006-01-02"))
dbc.DB.Where("is_sale = ?", p.IsSale).Find(&l, "start_date > ? ", time.Now().Format("2006-01-02"))
back.Suc(c, "操作成功", l)
}
func QueryActiveList(c *gin.Context) {
var p PromotionReq
err := tools.Params(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
var l []promotion.Information
format := time.Now().Format("2006-01-02")
dbc.DB.Find(&l, "start_date <= ? AND end_date >= ?", format, format)
dbc.DB.Where("is_sale = ?", p.IsSale).Find(&l, "start_date <= ? AND end_date >= ?", format, format)
back.Suc(c, "操作成功", l)
}
func QueryExpiredList(c *gin.Context) {
var p PromotionReq
err := tools.Params(&p, c)
if err != nil {
back.Fail(c, err.Error())
}
var l []promotion.Information
dbc.DB.Find(&l, "end_date < ?", time.Now().Format("2006-01-02"))
dbc.DB.Where("is_sale = ?", p.IsSale).Find(&l, "end_date < ?", time.Now().Format("2006-01-02"))
back.Suc(c, "操作成功", l)
}
@ -52,7 +74,8 @@ func QueryCheckPromotionDate(c *gin.Context) {
}
var count uint
dbc.DB.Table((&promotion.Information{}).TableName()).Where("start_date = ?", startDate.Format("2006-01-02")).Count(&count)
dbc.DB.Table((&promotion.Information{}).TableName()).Where("is_sale = ?", p.IsSale).
Where("start_date = ?", startDate.Format("2006-01-02")).Count(&count)
if count > 0 {
back.Fail(c, "该日期已创建过活动,请更改日期")
return

@ -10,6 +10,7 @@ type Information struct {
StartDate formatime.Date `gorm:"column:start_date" json:"startDate"`
EndDate formatime.Date `gorm:"column:end_date" json:"endDate"`
CreatedAt formatime.Second `gorm:"column:created_at" json:"-"`
IsSale bool `json:"-" gorm:"column:is_sale"`
}
// TableName sets the insert table name for this struct type

Loading…
Cancel
Save