refactor(task): 重构任务奖励系统,优化任务奖励处理逻辑

移除废弃的任务相关代码文件,包括task/list.go和task/list_daily.go,
以及相关的模型定义config_task表和PetReward服务。

修改任务奖励获取方式,从原有的TaskResultMap改为通过数据库配置获取,
新增TaskService.Get方法用于获取任务配置信息。

---
feat(boss): 优化
This commit is contained in:
2025-12-31 21:00:29 +08:00
parent c082eb3e91
commit 3efbba3883
12 changed files with 117 additions and 433 deletions

View File

@@ -14,7 +14,10 @@ type TaskConfig struct {
*cool.Model
// 核心字段
TaskId uint32 `gorm:"not null;uniqueIndex;comment:'任务唯一ID'" json:"task_id" description:"任务唯一ID"`
TaskId uint32 `gorm:"not null;comment:'任务唯一ID'" json:"task_id" description:"任务唯一ID"`
OutState uint32 `gorm:"not null;default:0;comment:'任务分支'" json:"out_state" description:"任务分支"`
//父级任务
ParentTaskId uint32 `gorm:"not null;default:0;comment:'父级任务ID'" json:"parent_task_id" description:"父级任务ID"`
// 奖励配置
ItemRewardIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定奖励物品ID数组关联item_gift表主键'" json:"item_reward_ids" description:"奖励物品数组"`

View File

@@ -3,6 +3,8 @@ package service
import (
"blazing/cool"
"blazing/modules/config/model"
"github.com/gogf/gf/v2/database/gdb"
)
type PetRewardService struct {
@@ -23,3 +25,18 @@ func (s *PetRewardService) GetEgg() model.PetReward {
return item
}
func (s *PetRewardService) Get(id uint32) *model.PetReward {
if id == 0 {
return nil
}
var item *model.PetReward
cool.DBM(s.Model).Where("id", 1).
Cache(gdb.CacheOption{
// Duration: time.Hour,
Force: false,
}).Scan(&item)
return item
}

View File

@@ -48,7 +48,10 @@ func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
var ret []model.ColorfulSkin
// 执行 Raw SQL 并扫描返回值
cool.DBM(s.Model).Wheref(`bind_elf_ids @> ?::jsonb`, id).Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Cache(gdb.CacheOption{
cool.DBM(s.Model).
Wheref(`bind_elf_ids @> ?::jsonb`, id).
Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").
Where("is_enabled", 1).Cache(gdb.CacheOption{
// Duration: time.Hour,
Force: false,
@@ -78,11 +81,15 @@ func (s *ShinyService) FixShiny(id uint32) *data.GlowFilter {
var ret []model.ColorfulSkin
// 执行 Raw SQL 并扫描返回值
cool.DBM(s.Model).Wheref(`bind_elf_ids @> ?::jsonb`, id).Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Cache(gdb.CacheOption{
// Duration: time.Hour,
cool.DBM(s.Model).
Wheref(`bind_elf_ids @> ?::jsonb`, id).
Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").
Where("is_enabled", 1).
Cache(gdb.CacheOption{
// Duration: time.Hour,
Force: false,
}).Scan(&ret)
Force: false,
}).Scan(&ret)
rets := utils.ToMap(ret, func(t model.ColorfulSkin) uint32 {
return uint32(t.ID)
@@ -98,7 +105,7 @@ func (s *ShinyService) FixShiny(id uint32) *data.GlowFilter {
r := json.Unmarshal([]byte(v.Color), &t)
if r == nil {
m := cool.DBM(s.Model).Where("id", id)
m.Increment("refresh_count", 1)
m.Increment("usage_count", 1)
return &t
}

View File

@@ -3,6 +3,8 @@ package service
import (
"blazing/cool"
"blazing/modules/config/model"
"github.com/gogf/gf/v2/database/gdb"
)
type TaskService struct {
@@ -16,3 +18,15 @@ func NewTaskService() *TaskService {
},
}
}
func (s *TaskService) Get(id, os uint32) *model.TaskConfig {
var item *model.TaskConfig
cool.DBM(s.Model).Where("task_id", id).Where("out_state", os).
Cache(gdb.CacheOption{
// Duration: time.Hour,
Force: false,
}).Scan(&item)
return item
}