Files
bl/modules/blazing/service/task.go
昔念 294cb2e3fd feat(login): 重构登录逻辑并迁移每日重置功能到 Personself 方法
将原本在 Controller.Login 中处理的每日重置逻辑(如电池、任务等)迁移到
service.Info.Personself 方法中,并移除对 gtime.Now().Time 的旧引用。同时更新了
相关的时间判断函数 IsToday,使其支持 *gtime.Time 类型。

此外,清理无用导入包,优化日志打印方式,并修复部分结构体字段定义与使用问题。
2025-12-07 19:23:44 +08:00

87 lines
1.6 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"
"github.com/gogf/gf/v2/os/gtime"
)
// 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
_, err := m1.Save(gg)
if err != nil {
panic(err)
}
}
// IsToday 判断给定时间是否是今天
func IsToday(t1 *gtime.Time) bool {
if t1 == nil {
return false
}
t := t1.Time
// 获取当前时间
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()},
},
}
}