feat(wish-tree): 许愿树页面微调七项
1. 背景图 aspectFill 撑满全屏,挂载点坐标按裁剪比例重算,便签不再落在图外 2. 写下心愿按钮单行不换行,缩小尺寸 3. 移除页面内许愿树标题/数量/最近心愿,点击便签弹出便签式详情卡 4. 默认请求100条:最新50条挂树,其余以弹幕形式缓缓飘过 5. MAKE A WISH 下方增加顶级位置轮播(购买后24小时内展示),点击弹出金色便签详情,与普通便签区分 6. 多棵树分屏轮播(swiper),背景图从服务器获取,带指示点 7. 后端:WishTree新增image字段,Wish新增isTop运行时标记,图片用go:embed内嵌随二进制部署,/images路由提供访问
This commit is contained in:
@@ -56,6 +56,13 @@ func autoMigrate() error {
|
||||
|
||||
// seedDefaultData 初始化默认数据
|
||||
func seedDefaultData() error {
|
||||
// 补充已有许愿树的背景图(新增字段后老数据为空)
|
||||
if err := DB.Model(&model.WishTree{}).
|
||||
Where("image = '' OR image IS NULL").
|
||||
Update("image", "/images/trees/tree-1.jpg").Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// 检查是否已有许愿树数据
|
||||
var count int64
|
||||
DB.Model(&model.WishTree{}).Count(&count)
|
||||
@@ -65,9 +72,9 @@ func seedDefaultData() error {
|
||||
|
||||
// 插入默认许愿树
|
||||
trees := []model.WishTree{
|
||||
{Name: "祈福树", Description: "许下美好愿望,祈福平安顺遂", Type: "pine", MaxWishes: 100, Sort: 0, Status: 1},
|
||||
{Name: "姻缘树", Description: "祈求姻缘美满,爱情甜蜜", Type: "sakura", MaxWishes: 50, Sort: 1, Status: 1},
|
||||
{Name: "事业树", Description: "祈愿事业顺利,步步高升", Type: "bamboo", MaxWishes: 80, Sort: 2, Status: 1},
|
||||
{Name: "祈福树", Description: "许下美好愿望,祈福平安顺遂", Type: "pine", Image: "/images/trees/tree-1.jpg", MaxWishes: 100, Sort: 0, Status: 1},
|
||||
{Name: "姻缘树", Description: "祈求姻缘美满,爱情甜蜜", Type: "sakura", Image: "/images/trees/tree-1.jpg", MaxWishes: 50, Sort: 1, Status: 1},
|
||||
{Name: "事业树", Description: "祈愿事业顺利,步步高升", Type: "bamboo", Image: "/images/trees/tree-1.jpg", MaxWishes: 80, Sort: 2, Status: 1},
|
||||
}
|
||||
if err := DB.Create(&trees).Error; err != nil {
|
||||
return err
|
||||
|
||||
@@ -14,6 +14,7 @@ type Wish struct {
|
||||
Position int `gorm:"default:0" json:"position"` // 位置(用于排序/覆盖)
|
||||
Status int `gorm:"default:1" json:"status"` // 1:正常 0:隐藏/删除
|
||||
IsRobot bool `gorm:"default:false" json:"isRobot"` // 是否机器人发布
|
||||
IsTop bool `gorm:"-" json:"isTop"` // 是否顶级位置(运行时计算)
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
@@ -24,6 +25,7 @@ type WishTree struct {
|
||||
Name string `gorm:"size:50" json:"name"`
|
||||
Description string `gorm:"size:255" json:"description"`
|
||||
Type string `gorm:"size:20;default:'pine'" json:"type"` // pine:松树 sakura:樱花 bamboo:竹子
|
||||
Image string `gorm:"size:255" json:"image"` // 背景图地址
|
||||
MaxWishes int `gorm:"default:100" json:"maxWishes"` // 最大许愿条数
|
||||
Sort int `gorm:"default:0" json:"sort"` // 排序
|
||||
Status int `gorm:"default:1" json:"status"`
|
||||
|
||||
@@ -97,15 +97,21 @@ func (s *WishService) CreateWish(wish *model.Wish) error {
|
||||
return s.db.Create(wish).Error
|
||||
}
|
||||
|
||||
// GetTreeWishes 获取指定树的许愿列表
|
||||
// GetTreeWishes 获取指定树的许愿列表(最新100条,标记顶级位置)
|
||||
func (s *WishService) GetTreeWishes(treeID uint) ([]*model.Wish, error) {
|
||||
var wishes []*model.Wish
|
||||
if err := s.db.Where("tree_id = ? AND status = 1", treeID).
|
||||
Order("position DESC, created_at DESC").
|
||||
Order("created_at DESC").
|
||||
Limit(100).
|
||||
Find(&wishes).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// 计算顶级位置:高位置付费许愿且购买后24小时内
|
||||
for _, w := range wishes {
|
||||
w.IsTop = w.Position >= 100 && time.Since(w.CreatedAt) <= 24*time.Hour
|
||||
}
|
||||
|
||||
return wishes, nil
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user