Files
bl/modules/config/service/item.go
昔念 ff739c430e
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful
```
fix(config): 修复物品获取逻辑错误

在GetEgg方法中修正了物品数量计算的位置,将数据添加操作移至条件判断内部,
确保只有当ItemMaxCount不为0时才将物品信息添加到结果数组中。
```
2026-02-21 00:41:49 +08:00

71 lines
1.4 KiB
Go

package service
import (
"blazing/common/data"
"blazing/common/utils"
"blazing/cool"
"blazing/modules/config/model"
"github.com/gogf/gf/v2/util/grand"
)
type ItemService struct {
*cool.Service
}
// 实现物品数量的获取
func (s *ItemService) GetItem(id uint32) *model.ItemGift {
var item *model.ItemGift
dbm_notenable(s.Model).Where("id", id).Scan(&item)
return item
}
func (s *ItemService) GetItemCount(id uint32) data.ItemInfo {
var item model.ItemGift
var res data.ItemInfo
dbm_notenable(s.Model).Where("id", id).Scan(&item)
if item.ItemID == 0 {
return res
}
res.ItemId = item.ItemID
res.ItemCnt = item.ItemMinCount
if item.ItemMaxCount != 0 {
res.ItemCnt = int64(grand.N(int(item.ItemMinCount), int(item.ItemMaxCount)))
}
return res
}
func (s *ItemService) GetEgg(count int64) []data.ItemInfo {
var item []model.ItemGift
dbm_notenable(s.Model).Where("is_egg", 1).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 = int64(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(),
PageQueryOp: &cool.QueryOp{
KeyWordField: []string{"remark"},
FieldEQ: []string{"is_egg"},
},
},
}
}