Files
bl/modules/player/service/item.go
昔念 07d25b3e96 ```
feat(friend): 添加好友系统功能实现

完善好友管理功能,包括添加好友、回复好友请求、删除好友等操作,
同时优化了相关数据结构和接口定义。

BREAKING CHANGE: 调整了黑名单数据结构,将BlackInfo从结构体改为uint32数组
```
2026-01-20 06:15:55 +08:00

85 lines
1.7 KiB
Go

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 {
var ttt []model.Item
s.TestModel(s.Model).Where(g.Map{
"item_id <=": max,
"item_id >=": min,
}).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},
}
},
}},
},
}
}