Files
bl/modules/blazing/service/task.go
昔念 a95e6b8491 ```
feat(common): 升级 gf 框架版本至 v2.8.0 并优化模型时间字段

- 将 `github.com/gogf/gf/contrib/drivers/pgsql/v2` 和 redis 依赖从 v2.6.3 升级到 v2.8.0
- 使用 `*gtime.Time` 替代标准库 `time.Time` 以支持更灵活的时间处理
- 移除 Model 结构体中 CreateTime、UpdateTime 等字段的默认初始化逻辑
- 注释掉已弃用的 GDBM 函数,推荐使用 DBM
- 在 DBM 中添加 OnConflict("id") 配置以增强写入安全性
- 调整部分代码结构与调用方式以适配新版框架行为
```
2025-11-17 12:59:46 +08:00

77 lines
1.4 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"
"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 *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
var gg model.TaskEX
m1 := s.GModel(s.Model).Where("task_id", id)
m1.Scan(&gg)
tre := t(&gg)
if !tre { //不需要更新
return
}
gg.PlayerID = uint64(s.userid)
gg.TaskID = id
m1.Save(gg)
}
// IsToday 判断给定时间是否是今天
func IsToday(t time.Time) bool {
// 获取当前时间
now := time.Now()
// 比较年、月、日是否相同
return t.Year() == now.Year() &&
t.Month() == now.Month() &&
t.Day() == now.Day()
}
type TaskService struct {
BaseService
}
func NewTaskService(id uint32) *TaskService {
return &TaskService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewTask()},
},
}
}