All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
fix(item): 修复物品数量判断逻辑 - 将物品数量判断从 `!= 0` 改为 `> 0`,确保只有正数才添加到列表中 - 将物品检查逻辑从 `< 1` 改为 `<= 0`,确保正确处理边界情况 - 在物品更新方法中增加ID为0的防护,避免无效操作 ```
97 lines
1.8 KiB
Go
97 lines
1.8 KiB
Go
package service
|
|
|
|
import (
|
|
"blazing/cool"
|
|
"blazing/modules/player/model"
|
|
"context"
|
|
|
|
"github.com/gogf/gf/v2/frame/g"
|
|
)
|
|
|
|
func (s *ItemService) Exist(itemid uint32) bool {
|
|
|
|
var ttt *model.Item
|
|
s.dbm(s.Model).Where("item_id", itemid).Scan(&ttt)
|
|
|
|
return ttt != nil
|
|
|
|
}
|
|
func (s *ItemService) Get(min, max uint32) []model.Item {
|
|
|
|
var ttt []model.Item
|
|
s.dbm(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
|
|
}
|
|
if id == 0 {
|
|
return
|
|
}
|
|
m := s.dbm(s.Model)
|
|
|
|
if t, _ := m.Where("item_id", id).Exist(); t {
|
|
_, err := s.dbm(s.Model).Where("item_id", id).Increment("item_cnt", count)
|
|
if err != nil {
|
|
panic(err)
|
|
}
|
|
} else {
|
|
m := s.dbm(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) int64 {
|
|
var ttt model.Item
|
|
m := s.dbm(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"},
|
|
FieldEQ: []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},
|
|
}
|
|
},
|
|
}},
|
|
},
|
|
}
|
|
|
|
}
|