2025-08-27 20:52:15 +00:00
|
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
|
"blazing/cool"
|
|
|
|
|
|
"blazing/modules/blazing/model"
|
|
|
|
|
|
"encoding/json"
|
2025-08-28 17:13:54 +00:00
|
|
|
|
"time"
|
2025-08-27 20:52:15 +00:00
|
|
|
|
)
|
|
|
|
|
|
|
2025-08-30 21:59:52 +08:00
|
|
|
|
func Exec[T cool.UserModel, F any](userid uint32, s *cool.Service, processFunc func(F) F) bool {
|
2025-08-28 14:38:13 +00:00
|
|
|
|
//todo待测试
|
|
|
|
|
|
var player T
|
2025-08-30 21:59:52 +08:00
|
|
|
|
|
|
|
|
|
|
m1 := cool.DBM(s.Model).Where("player_id", userid)
|
|
|
|
|
|
m1.Scan(&player)
|
2025-08-28 14:38:13 +00:00
|
|
|
|
// 方法2:使用反射获取
|
|
|
|
|
|
// 获取反射值对象
|
2025-08-27 20:52:15 +00:00
|
|
|
|
|
2025-08-30 21:59:52 +08:00
|
|
|
|
ttt := player
|
2025-08-28 14:38:13 +00:00
|
|
|
|
|
2025-08-30 21:59:52 +08:00
|
|
|
|
//fmt.Println(dataField.Interface().(string))
|
2025-08-28 14:38:13 +00:00
|
|
|
|
var tt F
|
2025-08-30 21:59:52 +08:00
|
|
|
|
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
|
|
|
|
|
2025-08-30 21:59:52 +08:00
|
|
|
|
ttt.SetData(string(tmep))
|
2025-08-28 14:38:13 +00:00
|
|
|
|
m1.Save(player)
|
|
|
|
|
|
return false
|
2025-08-27 20:52:15 +00:00
|
|
|
|
}
|
2025-08-30 00:36:08 +08:00
|
|
|
|
|
2025-08-31 08:42:53 +00:00
|
|
|
|
// 获取任务信息
|
2025-09-23 15:01:52 +00:00
|
|
|
|
func (s *UserService) Task(id uint32, t func(*model.TaskEX) bool) {
|
|
|
|
|
|
var gg model.TaskEX
|
2025-09-04 02:00:57 +08:00
|
|
|
|
m1 := cool.DBM(s.task.Model).
|
|
|
|
|
|
Where("player_id", s.userid).
|
|
|
|
|
|
Where("task_id", id)
|
2025-09-23 15:01:52 +00:00
|
|
|
|
err := m1.Scan(&gg)
|
|
|
|
|
|
tre := t(&gg)
|
|
|
|
|
|
if !tre { //不需要更新
|
|
|
|
|
|
return
|
2025-08-30 21:59:52 +08:00
|
|
|
|
}
|
2025-09-04 02:00:57 +08:00
|
|
|
|
if err != nil {
|
2025-09-23 15:01:52 +00:00
|
|
|
|
m1.Insert(gg)
|
|
|
|
|
|
} else {
|
|
|
|
|
|
m1.Update(gg)
|
2025-09-04 02:00:57 +08:00
|
|
|
|
}
|
2025-08-30 21:59:52 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
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()
|
|
|
|
|
|
}
|