更新 `common/cool/service.go` 中 `QueryOp` 结构体字段的注释,明确 `FieldEQ` 和 `KeyWordField` 的用途。 同时修改玩家物品添加逻辑中的错误码,从 `ErrBaseItemTypeLimit` 改为 `ErrSystemError200007`。 在 `modules/blazing/service/item.go` 中为分页查询添加 `KeyWordField` 配置,支持按 `player_id` 搜索。 注释掉 `modules/blazing/service/pet_fusion
78 lines
1.6 KiB
Go
78 lines
1.6 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/blazing/model"
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func (s *ItemService) Get(min, max uint32) []model.Item {
|
|
|
|
//todo待测试
|
|
var ttt []model.Item
|
|
s.GModel(s.Model).Where(g.Map{
|
|
"item_id <=": max,
|
|
"item_id >=": min,
|
|
}).Scan(&ttt)
|
|
|
|
return ttt
|
|
|
|
}
|
|
func (s *ItemService) AddItem(id, count uint32) {
|
|
if t, _ := s.GModel(s.Model).Where("item_id", id).Count(); t != 0 {
|
|
_, err := s.GModel(s.Model).Where("item_id", id).Increment("item_cnt", count)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
s.GModel(s.Model).Data(g.Map{
|
|
"player_id": s.userid,
|
|
"item_id": id,
|
|
"item_cnt": count,
|
|
}).Insert()
|
|
}
|
|
|
|
}
|
|
func (s *ItemService) SubItem(id, count uint32) {
|
|
|
|
s.GModel(s.Model).Where("item_id", id).Decrement("item_cnt", count)
|
|
|
|
}
|
|
func (s *ItemService) CheakItem(id uint32) uint32 {
|
|
var ttt model.Item
|
|
s.GModel(s.Model).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},
|
|
}
|
|
},
|
|
}},
|
|
},
|
|
}
|
|
|
|
}
|