package activity import ( "fmt" mysql2 "git.oa00.com/go/mysql" "recook/internal/back" "recook/internal/dbc" "recook/internal/domain" "recook/internal/model/activity" "recook/internal/v2/model/rotation" "recook/tools" "strconv" "time" "github.com/gin-gonic/gin" ) type queryParam struct { Area int64 `json:"area" validator:"required"` ActivityID int64 `json:"activityId"` } type queryActDetailResp struct { activity.Info GoodsList []activity.Goods `json:"goodsList"` } type customResp struct { LogoUrl string `json:"logoUrl"` Website string `json:"website"` SortId uint `json:"sort_id"` } func QueryActivityList(c *gin.Context) { //var A activity.Info //dbc.DB.Select("logo_url").Last(&A, "type=1") //var B activity.Info //dbc.DB.Select("logo_url").Last(&B, "type=2") //var CC activity.Info //dbc.DB.Select("logo_url").Last(&CC, "type=3") //var DD activity.Info //dbc.DB.Select("logo_url").Last(&DD, "type=4") // //back.Suc(c, "", gin.H{ // "a": customResp{ // LogoUrl: A.LogoUrl, // Website: domain.GetCDN() + "/website/www/activity/a.html", // }, // "b": customResp{ // LogoUrl: B.LogoUrl, // Website: domain.GetCDN() + "/website/www/activity/b.html", // }, // "c": customResp{ // LogoUrl: CC.LogoUrl, // Website: domain.GetCDN() + "/website/www/activity/c.html", // }, // "d": customResp{ // LogoUrl: DD.LogoUrl, // Website: domain.GetCDN() + "/website/www/activity/d.html", // }, //}) var list []viewTypeListRes one := getTypeOne(1) list = append(list, one) two := getTypeOne(2) list = append(list, two) three := getTypeOne(3) list = append(list, three) four := getTypeOne(4) list = append(list, four) back.Suc(c, "ok", gin.H{ "a": customResp{ LogoUrl: list[0].LogoUrl, Website: list[0].WebSite, SortId: list[0].SortId, }, "b": customResp{ LogoUrl: list[1].LogoUrl, Website: list[1].WebSite, SortId: list[1].SortId, }, "c": customResp{ LogoUrl: list[2].LogoUrl, Website: list[2].WebSite, SortId: list[2].SortId, }, "d": customResp{ LogoUrl: list[3].LogoUrl, Website: list[3].WebSite, SortId: list[3].SortId, }, }) } func QueryActivityDetail(c *gin.Context) { var p queryParam err := tools.Params(&p, c) if err != nil { back.Fail(c, err.Error()) return } if p.Area > 0 { var one activity.Info dbc.DB.Last(&one, "type=?", p.Area) list := make([]activity.Goods, 0, 0) dbc.DB.Find(&list, "activity_id = ?", one.ID) back.Suc(c, "", &queryActDetailResp{ one, list, }) } else { fmt.Println("in it ") if p.ActivityID <= 0 { back.Fail(c, "非法参数") return } var one activity.Info dbc.DB.Find(&one, p.ActivityID) fmt.Println(one.ID) list := make([]activity.Goods, 0, 0) dbc.DB.Find(&list, "activity_id = ?", one.ID) back.Suc(c, "", &queryActDetailResp{ one, list, }) } } type viewTypeListRes struct { LogoUrl string `json:"logo_url"` WebSite string `json:"web_site"` SortId uint `json:"sort_id"` } func getTypeOne(tid uint) viewTypeListRes { var cdn = domain.GetCDN() + "/website/www/activity/t.html?id=" var one rotation.RecookActivityTypeInfoModel var oneList []rotation.RecookActivityTypeInfoModel mysql2.Db.Table(one.TableName()).Where("is_active=?", 1).Where("type=?", tid).Where("start_time<=?", time.Now()).Where("end_time>=?", time.Now()).Find(&oneList) now := time.Now().Unix() var temp int64 var sid uint if len(oneList) > 0 { temp = now - oneList[0].StartTime.Time.Unix() sid = oneList[0].ID } fmt.Println("sid:", sid) for _, s := range oneList { num := now - s.StartTime.Time.Unix() if num < temp { temp = num sid = s.ID } } fmt.Println("sid:", sid) mysql2.Db.Table(one.TableName()).Where("id=?", sid).First(&one) var oneInfo rotation.RecookActivityInfoModel mysql2.Db.Table(oneInfo.TableName()).Where("id=?", one.ActiveID).First(&oneInfo) var rest = viewTypeListRes{ LogoUrl: one.URL, WebSite: cdn + strconv.Itoa(int(one.ActiveID)), SortId: tid, } return rest }