Files
bl/modules/blazing/service/task.go

77 lines
1.4 KiB
Go
Raw Normal View History

2025-08-27 20:52:15 +00:00
package service
import (
"blazing/cool"
"blazing/modules/blazing/model"
2025-08-28 17:13:54 +00:00
"time"
2025-08-27 20:52:15 +00:00
)
// 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使用反射获取
// // 获取反射值对象
2025-08-27 20:52:15 +00:00
// ttt := player
2025-08-28 14:38:13 +00:00
// //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)
// }
2025-08-28 14:38:13 +00:00
// ttt.SetData(string(tmep))
// m1.Save(player)
// return false
// }
// 获取任务信息
2025-11-16 20:30:17 +00:00
func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
var gg model.TaskEX
m1 := s.GModel(s.Model).Where("task_id", id)
2025-11-16 20:30:17 +00:00
m1.Scan(&gg)
tre := t(&gg)
if !tre { //不需要更新
return
}
gg.PlayerID = uint64(s.userid)
gg.TaskID = id
2025-11-16 20:30:17 +00:00
m1.Save(gg)
}
2025-08-28 17:13:54 +00:00
// IsToday 判断给定时间是否是今天
func IsToday(t time.Time) bool {
// 获取当前时间
now := time.Now()
// 比较年、月、日是否相同
return t.Year() == now.Year() &&
t.Month() == now.Month() &&
t.Day() == now.Day()
}
2025-11-16 20:30:17 +00:00
type TaskService struct {
BaseService
}
func NewTaskService(id uint32) *TaskService {
return &TaskService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewTask()},
},
}
}