Files
bl/modules/player/service/item.go
xinian cdb7cec4ad
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
refactor: 移除冗余日志输出并优化日志处理
2026-02-02 18:32:41 +08:00

85 lines
1.6 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 {
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},
}
},
}},
},
}
}