package diamond_show import ( mysql2 "git.oa00.com/go/mysql" "github.com/gin-gonic/gin" "github.com/golangkit/formatime" "recook/internal/back" "recook/internal/domain" "recook/internal/v2/model/rotation" "strconv" "time" ) // 返回的数据中多了个 活动链接 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"` } func QueryDiamondShow(c *gin.Context) { //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=?", 1).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) }