```
feat(cache): 添加复合键缓存操作支持 添加了基于 uint32+string 组合键的缓存操作方法,包括 GetByCompoundKey、SetByCompoundKey、DelByCompoundKey 和 ContainsByCompoundKey 方法,用于处理用户ID和会话ID的组合缓存场景 fix(vscode): 添加 cSpell 配置支持 struc 词汇 refactor(session): 移除过时的会话管理方法 移除了基于单一字符串键的会话管理方法,因为已迁移到使用 复合键的缓存操作方式 ```
This commit is contained in:
85
modules/player/service/item.go
Normal file
85
modules/player/service/item.go
Normal file
@@ -0,0 +1,85 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/player/model"
|
||||
"context"
|
||||
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
)
|
||||
|
||||
func (s *ItemService) Get(min, max uint32) []model.Item {
|
||||
m := s.TestModel(s.Model).Where(g.Map{
|
||||
"item_id <=": max,
|
||||
"item_id >=": min,
|
||||
})
|
||||
|
||||
var ttt []model.Item
|
||||
m.Scan(&ttt)
|
||||
|
||||
return ttt
|
||||
|
||||
}
|
||||
func (s *ItemService) UPDATE(id uint32, count int) {
|
||||
if cool.Config.ServerInfo.IsVip != 0 && count < 0 {
|
||||
cool.Logger.Info(context.TODO(), "测试服不消耗物品玩家数据", s.userid)
|
||||
return
|
||||
}
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
if t, _ := m.Where("item_id", id).Exist(); t {
|
||||
_, err := s.TestModel(s.Model).Where("item_id", id).Increment("item_cnt", count)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
} else {
|
||||
m := s.TestModel(s.Model)
|
||||
data := g.Map{
|
||||
"player_id": s.userid,
|
||||
"item_id": id,
|
||||
"item_cnt": count,
|
||||
"is_vip": cool.Config.ServerInfo.IsVip,
|
||||
}
|
||||
|
||||
m.Data(data).Insert()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (s *ItemService) CheakItem(id uint32) uint32 {
|
||||
var ttt model.Item
|
||||
m := s.TestModel(s.Model)
|
||||
|
||||
m.Where("item_id", id).Scan(&ttt)
|
||||
return ttt.ItemCnt
|
||||
}
|
||||
|
||||
// /添加进来的物品一定是保证存在的
|
||||
type ItemService struct {
|
||||
BaseService
|
||||
}
|
||||
|
||||
func NewItemService(id uint32) *ItemService {
|
||||
return &ItemService{
|
||||
|
||||
BaseService: BaseService{userid: id,
|
||||
|
||||
Service: &cool.Service{Model: model.NewPlayerBag(), UniqueKey: map[string]string{
|
||||
"player_id": "角色名称不能重复",
|
||||
}, PageQueryOp: &cool.QueryOp{
|
||||
KeyWordField: []string{"player_id"},
|
||||
Where: func(ctx context.Context) [][]interface{} {
|
||||
var (
|
||||
//admin = cool.GetAdmin(ctx)
|
||||
//userId = admin.UserId
|
||||
)
|
||||
return [][]interface{}{
|
||||
// {"player_id", userId, true},
|
||||
// {"free", 0, true},
|
||||
}
|
||||
},
|
||||
}},
|
||||
},
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user