refactor(task): 重构任务奖励系统,优化任务奖励处理逻辑 移除废弃的任务相关代码文件,包括task/list.go和task/list_daily.go, 以及相关的模型定义config_task表和PetReward服务。 修改任务奖励获取方式,从原有的TaskResultMap改为通过数据库配置获取, 新增TaskService.Get方法用于获取任务配置信息。 --- feat(boss): 优化
116 lines
2.2 KiB
Go
116 lines
2.2 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/common/data"
|
|
"blazing/common/utils"
|
|
"blazing/cool"
|
|
"blazing/modules/config/model"
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"github.com/gogf/gf/v2/database/gdb"
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
"github.com/gogf/gf/v2/util/gconv"
|
|
"github.com/gogf/gf/v2/util/grand"
|
|
)
|
|
|
|
type ShinyService struct {
|
|
*cool.Service
|
|
}
|
|
|
|
func NewShinyService() *ShinyService {
|
|
return &ShinyService{
|
|
&cool.Service{
|
|
Model: model.NewColorfulSkin(),
|
|
InsertParam: func(ctx context.Context) g.MapStrAny {
|
|
admin := cool.GetAdmin(ctx)
|
|
userId := admin.UserId
|
|
return g.MapStrAny{
|
|
"author": userId,
|
|
}
|
|
},
|
|
},
|
|
}
|
|
}
|
|
func (s *ShinyService) ModifyBefore(ctx context.Context, method string, param g.MapStrAny) (err error) {
|
|
var t data.GlowFilter
|
|
|
|
if method == "Delete" {
|
|
return nil
|
|
}
|
|
r := json.Unmarshal([]byte(gconv.String(param["color"])), &t)
|
|
if r != nil {
|
|
return r
|
|
}
|
|
return nil
|
|
}
|
|
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").
|
|
Where("is_enabled", 1).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Scan(&ret)
|
|
|
|
for _, v := range ret {
|
|
//print(v.ID)
|
|
|
|
id := v.ID
|
|
|
|
if grand.Meet(int(v.ElfProbability), 1000) {
|
|
var t 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)
|
|
return &t
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
return nil
|
|
}
|
|
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").
|
|
Where("is_enabled", 1).
|
|
Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).Scan(&ret)
|
|
|
|
rets := utils.ToMap(ret, func(t model.ColorfulSkin) uint32 {
|
|
return uint32(t.ID)
|
|
})
|
|
|
|
for _, v := range rets {
|
|
//print(v.ID)
|
|
|
|
id := v.ID
|
|
|
|
var t data.GlowFilter
|
|
|
|
r := json.Unmarshal([]byte(v.Color), &t)
|
|
if r == nil {
|
|
m := cool.DBM(s.Model).Where("id", id)
|
|
m.Increment("usage_count", 1)
|
|
return &t
|
|
}
|
|
|
|
}
|
|
|
|
return nil
|
|
}
|