Files
bl/modules/blazing/service/task.go
昔念 ecd9cb704c ```
refactor(logic): 优化任务完成逻辑并提高可读性

- 将 `QuitSelf` 中的硬编码延时改为 `5 * time.Second`,提高可读性
- 使用 `switch` 语句重构任务奖励逻辑,替代多个 `if` 判断
- 统一处理任务 85、86、87、88 的奖励发放逻辑
- 添加默认分支处理未定义的任务 ID 和状态
- 修复函数签名中的空格格式问题
- 在任务服务中补充玩家 ID 和任务 ID 的赋值逻辑
```
2025-10-10 01:10:13 +08:00

69 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
"encoding/json"
"time"
)
func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool {
//todo待测试
var player T
m1 := cool.DBM(s.Model).Where("player_id", userid)
m1.Scan(&player)
// 方法2使用反射获取
// 获取反射值对象
ttt := player
//fmt.Println(dataField.Interface().(string))
var tt F
err := json.Unmarshal([]byte(ttt.GetData()), &tt)
if err != nil {
panic(err)
}
tt1 := processFunc(tt)
tmep, err := json.Marshal(tt1)
if err != nil {
panic(err)
}
ttt.SetData(string(tmep))
m1.Save(player)
return false
}
// 获取任务信息
func (s *UserService) Task(id uint32, t func(*model.TaskEX) bool) {
var gg model.TaskEX
m1 := cool.DBM(s.task.Model).
Where("player_id", s.userid).
Where("task_id", id)
err := m1.Scan(&gg)
tre := t(&gg)
if !tre { //不需要更新
return
}
gg.PlayerID = uint64(s.userid)
gg.TaskID = id
if err != nil {
m1.Insert(gg)
} else {
m1.Update(gg)
}
}
// IsToday 判断给定时间是否是今天
func IsToday(t time.Time) bool {
// 获取当前时间
now := time.Now()
// 比较年、月、日是否相同
return t.Year() == now.Year() &&
t.Month() == now.Month() &&
t.Day() == now.Day()
}