From 3e4b091724a13160af9be40652176a433536f58d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <12574910+72wo@users.noreply.github.com> Date: Sun, 22 Feb 2026 19:33:17 +0800 Subject: [PATCH] =?UTF-8?q?```=20fix(item):=20=E4=BF=AE=E5=A4=8D=E7=89=A9?= =?UTF-8?q?=E5=93=81=E6=95=B0=E9=87=8F=E5=88=A4=E6=96=AD=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将物品数量判断从 `!= 0` 改为 `> 0`,确保只有正数才添加到列表中 - 将物品检查逻辑从 `< 1` 改为 `<= 0`,确保正确处理边界情况 - 在物品更新方法中增加ID为0的防护,避免无效操作 ``` --- help/查询多余物品.sql | 16 ++++++++++++++++ help/约束类.sql | 4 ++++ logic/controller/item_use.go | 2 +- logic/service/fight/loop.go | 2 +- modules/player/service/item.go | 3 +++ 5 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 help/查询多余物品.sql create mode 100644 help/约束类.sql diff --git a/help/查询多余物品.sql b/help/查询多余物品.sql new file mode 100644 index 000000000..a0c19ad34 --- /dev/null +++ b/help/查询多余物品.sql @@ -0,0 +1,16 @@ +SELECT + t1.* +FROM player_item t1 +JOIN ( + SELECT + player_id, + item_id + FROM player_item + WHERE is_vip = 0 + GROUP BY player_id, item_id + HAVING COUNT(*) > 1 +) t2 +ON t1.player_id = t2.player_id +AND t1.item_id = t2.item_id +WHERE t1.is_vip = 0 +ORDER BY t1.player_id, t1.item_id, t1."createTime"; \ No newline at end of file diff --git a/help/约束类.sql b/help/约束类.sql new file mode 100644 index 000000000..f681fae3f --- /dev/null +++ b/help/约束类.sql @@ -0,0 +1,4 @@ +-- 玩家+物品+VIP状态 联合唯一 +ALTER TABLE player_item +ADD CONSTRAINT uk_player_item_player_item_vip +UNIQUE (player_id, item_id, is_vip); \ No newline at end of file diff --git a/logic/controller/item_use.go b/logic/controller/item_use.go index 435f00376..5c615a300 100644 --- a/logic/controller/item_use.go +++ b/logic/controller/item_use.go @@ -32,7 +32,7 @@ func (h Controller) GetUserItemList(data *item.ItemListInboundInfo, c *player.Pl ItemCnt: uint32(itemData.ItemCnt), LeftTime: ItemDefaultLeftTime, } - if itemInfo.ItemCnt != 0 { + if itemInfo.ItemCnt > 0 { result.ItemList = append(result.ItemList, itemInfo) } } diff --git a/logic/service/fight/loop.go b/logic/service/fight/loop.go index d34a57ef3..8e138755a 100644 --- a/logic/service/fight/loop.go +++ b/logic/service/fight/loop.go @@ -351,7 +351,7 @@ func (f *FightC) handleItemAction(a *action.UseItemAction) { return } r := f.GetInputByAction(a, false).Player.(*player.Player).Service.Item.CheakItem(uint32(a.ItemID)) - if r < 1 { + if r <= 0 { return } f.GetInputByAction(a, false).Player.(*player.Player).Service.Item.UPDATE(a.ItemID, -1) diff --git a/modules/player/service/item.go b/modules/player/service/item.go index 3d028af51..fd9c50e06 100644 --- a/modules/player/service/item.go +++ b/modules/player/service/item.go @@ -32,6 +32,9 @@ func (s *ItemService) UPDATE(id uint32, count int) { return } + if id == 0 { + return + } m := s.dbm(s.Model) if t, _ := m.Where("item_id", id).Exist(); t {