diff --git a/common/utils/help.go b/common/utils/help.go index 3f0ed8110..f4bca0945 100644 --- a/common/utils/help.go +++ b/common/utils/help.go @@ -27,6 +27,37 @@ func IsToday(t1 *gtime.Time) bool { t.Month() == now.Month() && t.Day() == now.Day() } + +func IsWEEK(t1 *gtime.Time) bool { + if t1 == nil { + return false + } + t := t1.Time + + // 获取当前时间 + now := time.Now() + _, nweek := now.ISOWeek() + _, tweek := now.ISOWeek() + // 比较年、月、日是否相同 + return t.Year() == now.Year() && + tweek == nweek + +} +func IsMon(t1 *gtime.Time) bool { + if t1 == nil { + return false + } + t := t1.Time + + // 获取当前时间 + now := time.Now() + nweek := now.Month() + tweek := now.Month() + // 比较年、月、日是否相同 + return t.Year() == now.Year() && + tweek == nweek + +} func FindWithIndex[T any](slice []T, predicate func(item T) bool) (int, *T, bool) { for i := range slice { if predicate(slice[i]) { diff --git a/modules/config/model/user_talk.go b/modules/config/model/user_talk.go index dcaaf1c64..e249be288 100644 --- a/modules/config/model/user_talk.go +++ b/modules/config/model/user_talk.go @@ -14,7 +14,8 @@ type MineralCollectionConfig struct { // MapID 矿产所在地图ID MapID uint32 `gorm:"column:map_id;not null;index:idx_mineral_collection_config_map_id;comment:矿产所在地图ID" json:"map_id"` - Type uint32 `gorm:"column:type;not null;index:idx_mineral_collection_config_type;comment:类型" json:"type"` + //uint32 `gorm:"not null;default:0;comment:'限购类型( 0-每日限购 1-每周限购 2-每月限购)'" json:"quota_type" description:"限购类型"` + Type uint32 `gorm:"column:type;not null;index:idx_mineral_collection_config_type;comment:类型" json:"type"` // DailyCollectCount 每日可采集次数 DailyCollectCount uint32 `gorm:"column:daily_collect_count;not null;comment:每日可采集次数" json:"daily_collect_count"` diff --git a/modules/player/model/talk.go b/modules/player/model/talk.go index b1a76eb50..e69e783e9 100644 --- a/modules/player/model/talk.go +++ b/modules/player/model/talk.go @@ -2,6 +2,8 @@ package model import ( "blazing/cool" + + "github.com/gogf/gf/v2/os/gtime" ) // 资源采集计数表名 @@ -16,10 +18,10 @@ func NewTalk() *Talk { // ResourceCollection 记录玩家每种资源的采集计数 type Talk struct { Base - PlayerID uint64 `gorm:"not null;index:idx_player_resource;comment:'所属玩家ID'" json:"player_id"` - Type - TalkID uint32 `gorm:"not null;comment:'资源ID'" json:"talk_id"` - Count uint32 `gorm:"not null;comment:'采集计数'" json:"count"` + PlayerID uint64 `gorm:"not null;index:idx_player_resource;comment:'所属玩家ID'" json:"player_id"` + LastResetTime *gtime.Time `struc:"skip" json:"last_reset_time"` // 重置时间,比如电池和每日任务 + TalkID uint32 `gorm:"not null;comment:'资源ID'" json:"talk_id"` + Count uint32 `gorm:"not null;comment:'采集计数'" json:"count"` } // TableName 资源采集表名 diff --git a/modules/player/service/info.go b/modules/player/service/info.go index 4e5131435..bcb616fd2 100644 --- a/modules/player/service/info.go +++ b/modules/player/service/info.go @@ -123,7 +123,7 @@ func (s *InfoService) GetLogin() *model.PlayerInfo { panic(err) } } - if !IsWEEK(tt.WeekLastResetTime) { + if !utils.IsWEEK(tt.WeekLastResetTime) { for _, v := range service.NewTaskService().GetWeek() { diff --git a/modules/player/service/talk.go b/modules/player/service/talk.go index 2cc634b0b..80ae4a22b 100644 --- a/modules/player/service/talk.go +++ b/modules/player/service/talk.go @@ -5,6 +5,8 @@ import ( "blazing/cool" config "blazing/modules/config/service" "blazing/modules/player/model" + + "github.com/gogf/gf/v2/os/gtime" ) type TalkService struct { @@ -21,6 +23,9 @@ func NewTalkService(id uint32) *TalkService { } } +func (s *TalkService) reset(flag int) { + s.dbm(s.Model).Where("talk_id", flag).Data("count", 0, "last_reset_time", gtime.Now()).Update() +} //实现挖矿次数确认 @@ -35,14 +40,34 @@ func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) { return 0, true //如果表里没有记载数据,那么就可以直接挖矿 } - //因为这个是挖一次更新一次,而且是实时更新的,如果更新日期是今天,那么就可以确认不用再重置,否则就需要重置挖矿记录 - if !utils.IsToday(talks.UpdateTime) { - - talks.Count = 0 - m1.Save(talks) - return int(talks.Count), true - } c := config.NewTalkConfigService().GetCache(flag) + + //因为这个是挖一次更新一次,而且是实时更新的,如果更新日期是今天,那么就可以确认不用再重置,否则就需要重置挖矿记录 + if c == nil { + return 0, false //没在地图 + } + switch c.Type { + case 0: + if !utils.IsToday(talks.LastResetTime) { + + s.reset(flag) + return int(0), true + } + + case 1: + if !utils.IsWEEK(talks.LastResetTime) { + + s.reset(flag) + return int(0), true + } + case 2: + if !utils.IsMon(talks.LastResetTime) { + + s.reset(flag) + return int(0), true + } + } + if uint32(mapid) != c.MapID { return 0, false //没在地图 } diff --git a/modules/player/service/task.go b/modules/player/service/task.go index 7bc8d224b..a5f6b6b9d 100644 --- a/modules/player/service/task.go +++ b/modules/player/service/task.go @@ -3,9 +3,7 @@ package service import ( "blazing/cool" "blazing/modules/player/model" - "time" - "github.com/gogf/gf/v2/os/gtime" "github.com/pointernil/bitset32" ) @@ -65,22 +63,6 @@ func (s *TaskService) Exec(id uint32, t func(*model.Task) bool) { } -func IsWEEK(t1 *gtime.Time) bool { - if t1 == nil { - return false - } - t := t1.Time - - // 获取当前时间 - now := time.Now() - _, nweek := now.ISOWeek() - _, tweek := now.ISOWeek() - // 比较年、月、日是否相同 - return t.Year() == now.Year() && - tweek == nweek - -} - type TaskService struct { BaseService }