Files
bl/modules/player/service/talk.go
昔念 026689f3ed ```
feat(cache): 添加复合键缓存操作支持

添加了基于 uint32+string 组合键的缓存操作方法,包括
GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和
ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景

fix(vscode): 添加 cSpell 配置支持 struc 词汇

refactor(session): 移除过时的会话管理方法

移除了基于单一字符串键的会话管理方法,因为已迁移到使用
复合键的缓存操作方式
```
2026-01-19 18:51:56 +08:00

76 lines
1.7 KiB
Go

package service
import (
"blazing/cool"
config "blazing/modules/config/service"
"blazing/modules/player/model"
"context"
)
type TalkService struct {
BaseService
}
func NewTalkService(id uint32) *TalkService {
return &TalkService{
BaseService: BaseService{userid: id,
Service: &cool.Service{Model: model.NewTalk()},
},
}
}
//实现挖矿次数确认
func (s *TalkService) Cheak(mapid uint32, flag int) (int, bool) {
m1 := s.PModel(s.Model)
var talks *model.Talk
m1.Where("talk_id", flag).Scan(&talks)
if talks == nil {
talks = model.NewTalk()
talks.PlayerID = uint64(s.userid)
talks.TalkID = uint32(flag)
s.PModel(s.Model).Data(talks).FieldsEx("id").Insert()
return 0, true //如果表里没有记载数据,那么就可以直接挖矿
}
//因为这个是挖一次更新一次,而且是实时更新的,如果更新日期是今天,那么就可以确认不用再重置,否则就需要重置挖矿记录
if !IsToday(talks.UpdateTime) {
talks.Count = 0
m1.Save(talks)
return int(talks.Count), true
}
if uint32(mapid) != config.NewTalkConfigService().GetCache(flag).MapID {
return 0, false //没在地图
}
if talks.Count >= config.NewTalkConfigService().GetCache(flag).DailyCollectCount {
return 0, false
}
return int(talks.Count), true //int(config.MaxDailyCnt - talks.Count)
}
func (s *TalkService) Update(flag int) {
if cool.Config.ServerInfo.IsVip != 0 {
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
return
}
m1 := s.PModel(s.Model)
var talks model.Talk
m1.Where("talk_id", flag).Scan(&talks)
//talks.PlayerID = uint64(s.userid)
//talks.TalkID = uint32(flag)
talks.Count += 1
m1.Save(talks)
}