Files
bl/modules/blazing/service/item.go
昔念 038bd0ce0c ```text
build(go): 升级 gf/v2 框架至 v2.7.0

统一将 common、login 和 mysql driver 中的 github.com/gogf/gf/v2 依赖版本从 v2.6.3 更新到 v2.7.0。

feat(logic): 优化道具服务逻辑与数据结构

- 修改 Item 结构体,去除 Data 字段,新增 ItemId 和 ItemCnt 字段以提高可读性和查询效率。
- 调整 Item 相关方法实现,包括 Item(), AddItem(), SubItem() 和 CheakItem() 方法,支持直接按范围获取及增减物品
2025-11-02 18:56:16 +08:00

45 lines
963 B
Go

package service
import (
"blazing/modules/blazing/model"
"github.com/gogf/gf/v2/frame/g"
)
func (s *UserService) Item(min, max uint32) []model.Item {
//todo待测试
var ttt []model.Item
s.Model(s.item.Model).Where(g.Map{
"item_id <=": max,
"item_id >=": min,
}).Scan(&ttt)
return ttt
}
func (s *UserService) AddItem(id, count uint32) {
if t, _ := s.Model(s.item.Model).Where("item_id", id).Count(); t != 0 {
s.Model(s.item.Model).Where("item_id", id).Increment("item_cnt", count)
} else {
s.Model(s.item.Model).Data(g.Map{
"player_id": s.userid,
"item_id": id,
"item_cnt": count,
}).Insert()
}
}
func (s *UserService) SubItem(id, count uint32) {
s.Model(s.item.Model).Where("item_id", id).Decrement("item_cnt", count)
}
func (s *UserService) CheakItem(id uint32) uint32 {
var ttt model.Item
s.Model(s.item.Model).Where("item_id", id).Scan(&ttt)
return ttt.ItemCnt
}
// /添加进来的物品一定是保证存在的