65 lines
1.0 KiB
Go
65 lines
1.0 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/player/model"
|
|
"time"
|
|
|
|
"github.com/gogf/gf/v2/os/gtime"
|
|
)
|
|
|
|
// 获取任务信息
|
|
func (s *TaskService) Exec(id uint32, t func(*model.TaskEX) bool) {
|
|
var gg model.TaskEX
|
|
|
|
m1 := s.PModel(s.Model).Where("task_id", id)
|
|
m1.Scan(&gg)
|
|
tre := t(&gg)
|
|
|
|
if !tre { //不需要更新
|
|
return
|
|
}
|
|
if cool.Config.ServerInfo.IsVip != 0 {
|
|
|
|
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()},
|
|
},
|
|
}
|
|
|
|
}
|