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.

186 lines
4.2 KiB

4 years ago
package activity
import (
"fmt"
"recook/internal/back"
"recook/internal/dbc"
"recook/internal/domain"
"recook/internal/model/activity"
"recook/internal/v2/model/rotation"
"recook/tools"
"strconv"
"time"
mysql2 "git.oa00.com/go/mysql"
4 years ago
"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"`
}
type activityReq struct {
IsSale bool `json:"is_sale"`
}
4 years ago
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 p activityReq
3 years ago
err := tools.ParseParams(&p, c)
if err != nil {
back.Fail(c, err.Error())
return
}
4 years ago
var list []viewTypeListRes
one := getTypeOne(1, p.IsSale)
4 years ago
list = append(list, one)
two := getTypeOne(2, p.IsSale)
4 years ago
list = append(list, two)
three := getTypeOne(3, p.IsSale)
4 years ago
list = append(list, three)
four := getTypeOne(4, p.IsSale)
4 years ago
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, isSale bool) viewTypeListRes {
4 years ago
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_sale=?", isSale).
Where("is_active=?", 1).
Where("type=?", tid).
Where("start_time<=?", time.Now()).
Where("end_time>=?", time.Now()).Find(&oneList)
4 years ago
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
}