Files
bl/modules/config/service/item.go
昔念 562bf380eb 根据提供的code differences信息,由于没有具体的代码变更内容,我将生成一个通用的commit message模板:
```
docs(changelog): 更新版本更新日志

- 添加新功能说明
- 修复已知问题记录
- 更新相关文档内容
```
2026-01-20 02:25:02 +08:00

67 lines
1.3 KiB
Go

package service
import (
"blazing/common/data"
"blazing/common/utils"
"blazing/cool"
"blazing/modules/config/model"
"github.com/gogf/gf/v2/database/gdb"
"github.com/gogf/gf/v2/util/grand"
)
type ItemService struct {
*cool.Service
}
//实现物品数量的获取
func (s *ItemService) GetItemCount(id uint32) data.ItemInfo {
var item model.ItemGift
var res data.ItemInfo
dbm(s.Model).Where("id", id).Where("is_enabled", 1).Scan(&item)
if item.ItemID == 0 {
return res
}
res.ItemId = item.ItemID
res.ItemCnt = item.ItemMinCount
if item.ItemMaxCount != 0 {
res.ItemCnt = uint32(grand.N(int(item.ItemMinCount), int(item.ItemMaxCount)))
}
return res
}
func (s *ItemService) GetEgg(count int32) []data.ItemInfo {
var item []model.ItemGift
cool.DBM(s.Model).Where("is_egg", 1).Where("is_enabled", 1).Cache(gdb.CacheOption{
// Duration: time.Hour,
Force: false,
}).Scan(&item)
rr := utils.RandomSlice(item, int(count))
var res = make([]data.ItemInfo, len(rr))
for _, v := range rr {
if v.ItemMaxCount != 0 {
v.ItemMinCount = uint32(grand.N(int(v.ItemMinCount), int(v.ItemMaxCount)))
}
res = append(res, data.ItemInfo{ItemId: v.ItemID, ItemCnt: v.ItemMinCount})
}
return res
}
func NewItemService() *ItemService {
return &ItemService{
&cool.Service{
Model: model.NewItemGift(),
},
}
}