fix(item): 修复物品数量判断逻辑 - 将物品数量判断从 `!= 0` 改为 `> 0`,确保只有正数才添加到列表中 - 将物品检查逻辑从 `< 1` 改为 `<= 0`,确保正确处理边界情况 - 在物品更新方法中增加ID为0的防护,避免无效操作 ```
This commit is contained in:
16
help/查询多余物品.sql
Normal file
16
help/查询多余物品.sql
Normal file
@@ -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";
|
||||
4
help/约束类.sql
Normal file
4
help/约束类.sql
Normal file
@@ -0,0 +1,4 @@
|
||||
-- 玩家+物品+VIP状态 联合唯一
|
||||
ALTER TABLE player_item
|
||||
ADD CONSTRAINT uk_player_item_player_item_vip
|
||||
UNIQUE (player_id, item_id, is_vip);
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user