You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.5 KiB
83 lines
2.5 KiB
package diamond_show
|
|
|
|
import (
|
|
"recook/internal/back"
|
|
"recook/internal/domain"
|
|
"recook/internal/v2/model/rotation"
|
|
"recook/tools"
|
|
"strconv"
|
|
"time"
|
|
|
|
mysql2 "git.oa00.com/go/mysql"
|
|
"github.com/gin-gonic/gin"
|
|
"github.com/golangkit/formatime"
|
|
)
|
|
|
|
// 返回的数据中多了个 活动链接
|
|
type diamondResp struct {
|
|
ID uint `gorm:"column:id;primary_key" json:"id"`
|
|
GoodsID uint `gorm:"column:goods_id" json:"goodsId"`
|
|
URL string `gorm:"column:url" json:"url"`
|
|
CreatedAt formatime.Second `gorm:"column:created_at" json:"createdAt"`
|
|
ActiveID uint `gorm:"column:activity_id" json:"activityId"`
|
|
Color string `gorm:"column:color" json:"color"`
|
|
ActivityUrl string `json:"activityUrl"`
|
|
SortId uint `json:"sort_id"`
|
|
BackgroundColor string `json:"background_color"`
|
|
}
|
|
|
|
type diamondReq struct {
|
|
IsSale bool `json:"is_sale"`
|
|
}
|
|
|
|
func QueryDiamondShow(c *gin.Context) {
|
|
|
|
var args diamondReq
|
|
err := tools.ParseParams(&args, c)
|
|
if err != nil {
|
|
back.Fail(c, err.Error())
|
|
return
|
|
}
|
|
//var di []diamond_show.Information
|
|
//dbc.DB.Where("is_active=?", 1).Find(&di)
|
|
//var cdn = domain.GetCDN() + "/website/www/activity/t.html?id="
|
|
//var list = make([]diamondResp, len(di))
|
|
//for idx, val := range di {
|
|
// list[idx].ID = val.ID
|
|
// list[idx].GoodsID = val.GoodsID
|
|
// list[idx].URL = val.URL
|
|
// list[idx].CreatedAt = val.CreatedAt
|
|
// list[idx].ActiveID = val.ID
|
|
// list[idx].Color = val.Color
|
|
//
|
|
// if val.ActiveID > 0 {
|
|
// // 活动id 大于0 为活动, 拼接id字符串
|
|
// list[idx].ActivityUrl = cdn + strconv.Itoa(int(val.ActiveID))
|
|
// }
|
|
//}
|
|
//back.Suc(c, "", &list)
|
|
var p []rotation.RecookRotationModel
|
|
mysql2.Db.Table((&rotation.RecookRotationModel{}).TableName()).
|
|
Where("is_active=? AND is_sale=?", 1, args.IsSale).
|
|
Where("start_time<=?", time.Now()).Where("end_time>=?", time.Now()).Order("sort_id").Find(&p)
|
|
|
|
var cdn = domain.GetCDN() + "/website/www/activity/t.html?id="
|
|
var list = make([]diamondResp, len(p))
|
|
for idx, val := range p {
|
|
list[idx].ID = val.ID
|
|
list[idx].GoodsID = val.GoodsID
|
|
list[idx].URL = val.URL
|
|
list[idx].CreatedAt = val.CreatedAt
|
|
list[idx].ActiveID = val.ActiveID
|
|
list[idx].Color = val.Color
|
|
list[idx].SortId = val.SortId
|
|
list[idx].BackgroundColor = val.BackgroundColor
|
|
|
|
if val.ActiveID > 0 {
|
|
// 活动id 大于0 为活动, 拼接id字符串
|
|
list[idx].ActivityUrl = cdn + strconv.Itoa(int(val.ActiveID))
|
|
}
|
|
}
|
|
back.Suc(c, "", list)
|
|
}
|