feat: 增加采集限购按日、周、月重置功能
Some checks failed
ci/woodpecker/push/my-first-workflow Pipeline failed

This commit is contained in:
xinian
2026-03-27 13:17:42 +08:00
committed by cnb
parent 40411ba84b
commit 99af9b6e01
6 changed files with 72 additions and 31 deletions

View File

@@ -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]) {

View File

@@ -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"`

View File

@@ -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 资源采集表名

View File

@@ -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() {

View File

@@ -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 //没在地图
}

View File

@@ -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
}