refactor: 重构物品更新逻辑并添加ID为0的检查
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
This commit is contained in:
@@ -32,30 +32,27 @@ func (s *ItemService) UPDATE(id uint32, count int) {
|
||||
|
||||
return
|
||||
}
|
||||
if id == 0 {
|
||||
return
|
||||
}
|
||||
m := s.dbm(s.Model)
|
||||
|
||||
var ttt model.Item
|
||||
s.dbm(s.Model).Scan(&ttt)
|
||||
ttt.PlayerID = uint64(s.userid)
|
||||
ttt.ItemId = id
|
||||
ttt.IsVip = cool.Config.ServerInfo.IsVip
|
||||
ttt.ItemCnt += int64(count)
|
||||
s.dbm(s.Model).Save(ttt)
|
||||
// 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,
|
||||
// }
|
||||
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()
|
||||
// }
|
||||
m.Data(data).Insert()
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user