|
|
package activity
|
|
|
|
|
|
import (
|
|
|
"recook/internal/back"
|
|
|
"recook/internal/dbc"
|
|
|
"recook/internal/model/activity"
|
|
|
"recook/tools"
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
)
|
|
|
|
|
|
type queryParam struct {
|
|
|
Area int64 `json:"area" validator:"oneof=1 2 3 4"`
|
|
|
}
|
|
|
|
|
|
type queryActDetailResp struct {
|
|
|
activity.Info
|
|
|
GoodsList []activity.Goods `json:"goodsList"`
|
|
|
}
|
|
|
|
|
|
type customResp struct {
|
|
|
ID int64 `json:"id"`
|
|
|
LogoUrl string `json:"logoUrl"`
|
|
|
Website string `json:"website"`
|
|
|
}
|
|
|
|
|
|
type queryPageParam struct {
|
|
|
Page int64 `json:"page" validate:"numeric"`
|
|
|
IsSale bool `json:"is_sale"`
|
|
|
}
|
|
|
|
|
|
func QueryActivityList(c *gin.Context) {
|
|
|
var A activity.Info
|
|
|
dbc.DB.Last(&A, "type=1")
|
|
|
var B activity.Info
|
|
|
dbc.DB.Last(&B, "type=2")
|
|
|
var CC activity.Info
|
|
|
dbc.DB.Last(&CC, "type=3")
|
|
|
|
|
|
back.Suc(c, "", gin.H{
|
|
|
"a": customResp{
|
|
|
ID: A.ID,
|
|
|
LogoUrl: A.LogoUrl,
|
|
|
Website: "https://cdn.reecook.cn/website/activity/a.html",
|
|
|
},
|
|
|
"b": customResp{
|
|
|
ID: B.ID,
|
|
|
LogoUrl: B.LogoUrl,
|
|
|
Website: "https://cdn.reecook.cn/website/activity/b.html",
|
|
|
},
|
|
|
"c": customResp{
|
|
|
ID: CC.ID,
|
|
|
LogoUrl: CC.LogoUrl,
|
|
|
Website: "https://cdn.reecook.cn/website/activity/c.html",
|
|
|
},
|
|
|
})
|
|
|
}
|
|
|
|
|
|
func QueryActivityDetail(c *gin.Context) {
|
|
|
var p queryParam
|
|
|
err := tools.Params(&p, c)
|
|
|
if err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
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,
|
|
|
})
|
|
|
}
|
|
|
|
|
|
type queryActListResp struct {
|
|
|
List []activity.Info `json:"list"`
|
|
|
Total int64 `json:"total"`
|
|
|
}
|
|
|
|
|
|
//type actListInfo struct {
|
|
|
// ID int64 `gorm:"column:id" json:"id"`
|
|
|
// name string `gorm:"column:name" json:"name"`
|
|
|
// CreateAt formatime.Second `gorm:"column:created_at" json:"createAt"`
|
|
|
//}
|
|
|
|
|
|
// QueryNewActivityList 活动页的活动列表
|
|
|
func QueryNewActivityList(c *gin.Context) {
|
|
|
var limit int64 = 20
|
|
|
|
|
|
var isActive = 1
|
|
|
// 每页显示数据条数
|
|
|
var page queryPageParam
|
|
|
err := tools.Params(&page, c)
|
|
|
if err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
if page.Page < 0 {
|
|
|
page.Page = 1
|
|
|
}
|
|
|
|
|
|
var count int64
|
|
|
// 页面只显示 id, name, 创建时间
|
|
|
var activities = make([]activity.Info, 10)
|
|
|
|
|
|
dbc.DB.Table("recook_activity_info").
|
|
|
Limit(limit).Offset((page.Page-1)*limit).Where("is_sale = ?", page.IsSale).Where("is_active=?", isActive).Scan(&activities)
|
|
|
dbc.DB.Table("recook_activity_info").Where("is_sale = ?", page.IsSale).Where("is_active=?", 1).Count(&count)
|
|
|
|
|
|
back.Suc(c, "", &queryActListResp{
|
|
|
List: activities,
|
|
|
Total: count,
|
|
|
})
|
|
|
|
|
|
}
|
|
|
|
|
|
type queryOneActivityParam struct {
|
|
|
ActivityID int64 `json:"activityId"`
|
|
|
}
|
|
|
|
|
|
type oneActivityResp struct {
|
|
|
ActivityInfo activity.Info `json:"activityInfo"`
|
|
|
GoodsList []activity.Goods `json:"goodsList"`
|
|
|
}
|
|
|
|
|
|
// 查询单个 活动信息
|
|
|
func QueryOneActivityList(c *gin.Context) {
|
|
|
var p queryOneActivityParam
|
|
|
err := tools.Params(&p, c)
|
|
|
if err != nil {
|
|
|
back.Fail(c, err.Error())
|
|
|
return
|
|
|
}
|
|
|
|
|
|
var activityModel activity.Info
|
|
|
dbc.DB.Where("is_active=1 or is_active is null").Where("id=?", p.ActivityID).Find(&activityModel)
|
|
|
if activityModel.ID <= 0 {
|
|
|
back.Fail(c, "活动不存在")
|
|
|
return
|
|
|
}
|
|
|
var goodsList []activity.Goods
|
|
|
dbc.DB.Where("activity_id=?", p.ActivityID).Find(&goodsList)
|
|
|
|
|
|
back.Suc(c, "", &oneActivityResp{
|
|
|
ActivityInfo: activityModel,
|
|
|
GoodsList: goodsList,
|
|
|
})
|
|
|
return
|
|
|
}
|