feat: 徽章api

This commit is contained in:
Blizzard
2026-02-12 14:34:31 +08:00
parent 01e13e736c
commit 0405968597
22 changed files with 1150 additions and 62 deletions
+30
View File
@@ -0,0 +1,30 @@
package request
type CreateBadge struct {
Name string `json:"name"`
Description string `json:"description"`
IconId string `json:"iconId"`
Dimension string `json:"dimension"` // 维度: EXPERTISE(专家), PERSISTENCE(勤勉), JOURNAL(记录)
GroupId string `json:"groupId"` // 组ID: 用于前端聚合显示 (e.g. "fertilizerMaster")
Tier int `json:"tier"` // 等级: 1=铜, 2=银, 3=金
TargetAction string `json:"targetAction"` // 触发动作: ACT_FERTILIZE, ACT_WATER...
Threshold int64 `json:"threshold"`
Comparator string `json:"comparator"`
RewardSunlight int64 `json:"rewardSunlight"`
Sort int `json:"sort"`
}
type UpdateBadge struct {
Id string `json:"id" binding:"required"`
Name string `json:"name"`
Description string `json:"description"`
IconId string `json:"iconId"`
Dimension string `json:"dimension"` // 维度: EXPERTISE(专家), PERSISTENCE(勤勉), JOURNAL(记录)
GroupId string `json:"groupId"` // 组Id: 用于前端聚合显示 (e.g. "fertilizerMaster")
Tier int `json:"tier"` // 等级: 1=铜, 2=银, 3=金
TargetAction string `json:"targetAction"` // 触发动作: ACT_FERTILIZE, ACT_WATER...
Threshold int64 `json:"threshold"`
Comparator string `json:"comparator"`
RewardSunlight int64 `json:"rewardSunlight"`
Sort int `json:"sort"`
}
+15 -4
View File
@@ -1,6 +1,17 @@
package response
//type BadgeGroup struct {
// CategoryName string `json:"categoryName" comment:"分类名称"`
// BadgeList []plant.Badge `json:"badgeList"`
//}
import "sundynix-go/model/plant"
// BadgeDimensionNode 1. 最外层:维度节点 (例如: "专家成就")
type BadgeDimensionNode struct {
Dimension string `json:"dimension"` // 维度 Key (e.g., "EXPERTISE")
Label string `json:"label"` // 维度显示名 (前端映射或后端返回)
Groups []BadgeGroupNode `json:"groups"` // 该维度下的徽章组
}
// BadgeGroupNode 2. 中间层:组节点 (例如: "炼金术士系列")
type BadgeGroupNode struct {
GroupId string `json:"groupId"` // 组 ID (e.g., "fertilizer_master")
GroupLabel string `json:"groupLabel"` // 中文显示名 (新增)
Badges []plant.BadgeConfig `json:"badges"` // 该组下的具体徽章 (铜/银/金)
}
+25 -8
View File
@@ -1,18 +1,35 @@
package plant
import (
"sundynix-go/config"
"sundynix-go/global"
"sundynix-go/model/system"
)
// BadgeConfig 徽章配置
type BadgeConfig struct {
global.BaseModel
GroupId string `json:"group_id"` // 徽章组 (用于系列徽章,如浇水铜/银/金)
Name string `json:"name"` // 徽章名称
Description string `json:"description"` // 描述
Tier config.BadgeTier `json:"tier"` // 稀有度
TargetAction config.ActionType `json:"target_action"` // 关联的行为
TargetCount int `json:"target_count"` // 需要完成该行为的次数
IconURL string `json:"icon_url"` // 徽章图标地址
Name string `gorm:"type:varchar(64);not null;comment:徽章名称" json:"name"`
Description string `gorm:"type:varchar(255);comment:徽章描述" json:"description"`
IconId string `gorm:"type:varchar(50);comment:图标资源id" json:"iconId"`
// --- 核心维度与分组 ---
// 维度: EXPERTISE(专家), PERSISTENCE(勤勉), JOURNAL(记录)
Dimension string `gorm:"type:varchar(32);index;not null;column:dimension;comment:维度分类" json:"dimension"`
// 组ID: 用于前端聚合显示 (e.g. "fertilizerMaster")
GroupId string `gorm:"type:varchar(64);index;not null;column:group_id;comment:系列组Id" json:"groupId"`
// 等级: 1=铜, 2=银, 3=金
Tier int `gorm:"type:tinyint;default:1;column:tier;comment:等级权重" json:"tier"`
// --- 触发条件逻辑 ---
// 触发动作: ACT_FERTILIZE, ACT_WATER...
TargetAction string `gorm:"type:varchar(32);index;not null;column:target_action;comment:触发动作代码" json:"targetAction"`
// 目标阈值
Threshold int64 `gorm:"not null;column:threshold;comment:所需次数或数值" json:"threshold"`
// 比较操作符: ">=", "="
Comparator string `gorm:"type:varchar(10);default:'>=';column:comparator;comment:比较条件" json:"comparator"`
// --- 奖励 ---
RewardSunlight int64 `gorm:"not null;column:reward_sunlight;comment:奖励阳光值" json:"rewardSunlight"`
// --- 显示控制 ---
Sort int `gorm:"default:1;column:sort;comment:排序优先级" json:"sort"`
IsHidden bool `gorm:"-" json:"isHidden"`
//图标
Icon *system.Oss `json:"icon" gorm:"foreignKey:IconId"`
}
+13
View File
@@ -0,0 +1,13 @@
package plant
import (
"sundynix-go/global"
"time"
)
type UserBadge struct {
global.BaseModel
UserId string `gorm:"type:varchar(50);index;not null;column:user_id;comment:用户id" json:"userId"`
BadgeId uint `gorm:"index:idx_user_badge,unique;not null;column:badge_id;comment:徽章配置ID" json:"badgeId"`
AcquiredAt time.Time `gorm:"autoCreateTime;column:acquired_at;comment:获得时间" json:"acquiredAt"`
}