2025-12-22 19:04:16 +08:00
|
|
|
package service
|
|
|
|
|
|
|
|
|
|
import (
|
2025-12-26 20:38:08 +08:00
|
|
|
"blazing/common/data"
|
|
|
|
|
"blazing/common/utils"
|
2025-12-22 19:04:16 +08:00
|
|
|
"blazing/cool"
|
|
|
|
|
"blazing/modules/config/model"
|
|
|
|
|
|
|
|
|
|
"github.com/gogf/gf/v2/util/grand"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
type ItemService struct {
|
|
|
|
|
*cool.Service
|
|
|
|
|
}
|
|
|
|
|
|
2026-02-14 04:27:57 +08:00
|
|
|
// 实现物品数量的获取
|
|
|
|
|
func (s *ItemService) GetItem(id uint32) *model.ItemGift {
|
|
|
|
|
var item *model.ItemGift
|
2025-12-22 19:04:16 +08:00
|
|
|
|
2026-02-14 23:14:43 +08:00
|
|
|
dbm_notenable(s.Model).Where("id", id).Scan(&item)
|
2026-02-14 04:27:57 +08:00
|
|
|
|
|
|
|
|
return item
|
|
|
|
|
}
|
2025-12-26 20:38:08 +08:00
|
|
|
func (s *ItemService) GetItemCount(id uint32) data.ItemInfo {
|
2025-12-22 19:04:16 +08:00
|
|
|
var item model.ItemGift
|
2025-12-26 20:38:08 +08:00
|
|
|
var res data.ItemInfo
|
2026-02-14 23:14:43 +08:00
|
|
|
dbm_notenable(s.Model).Where("id", id).Scan(&item)
|
2025-12-22 19:04:16 +08:00
|
|
|
|
|
|
|
|
if item.ItemID == 0 {
|
2025-12-26 20:38:08 +08:00
|
|
|
|
|
|
|
|
return res
|
2025-12-22 19:04:16 +08:00
|
|
|
}
|
2025-12-26 20:38:08 +08:00
|
|
|
res.ItemId = item.ItemID
|
|
|
|
|
res.ItemCnt = item.ItemMinCount
|
2025-12-22 19:04:16 +08:00
|
|
|
|
|
|
|
|
if item.ItemMaxCount != 0 {
|
2026-02-12 04:28:20 +08:00
|
|
|
res.ItemCnt = int64(grand.N(int(item.ItemMinCount), int(item.ItemMaxCount)))
|
2025-12-26 20:38:08 +08:00
|
|
|
|
2025-12-22 19:04:16 +08:00
|
|
|
}
|
2025-12-26 20:38:08 +08:00
|
|
|
return res
|
2025-12-22 19:04:16 +08:00
|
|
|
}
|
2026-02-12 04:28:20 +08:00
|
|
|
func (s *ItemService) GetEgg(count int64) []data.ItemInfo {
|
2025-12-26 20:38:08 +08:00
|
|
|
var item []model.ItemGift
|
2026-02-14 23:14:43 +08:00
|
|
|
dbm_notenable(s.Model).Where("is_egg", 1).Scan(&item)
|
2025-12-22 19:04:16 +08:00
|
|
|
|
2025-12-26 20:38:08 +08:00
|
|
|
rr := utils.RandomSlice(item, int(count))
|
|
|
|
|
var res = make([]data.ItemInfo, len(rr))
|
|
|
|
|
for _, v := range rr {
|
|
|
|
|
if v.ItemMaxCount != 0 {
|
2026-02-12 04:28:20 +08:00
|
|
|
v.ItemMinCount = int64(grand.N(int(v.ItemMinCount), int(v.ItemMaxCount)))
|
2026-02-21 00:41:49 +08:00
|
|
|
res = append(res, data.ItemInfo{ItemId: v.ItemID, ItemCnt: v.ItemMinCount})
|
2025-12-26 20:38:08 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res
|
|
|
|
|
|
|
|
|
|
}
|
2025-12-22 19:04:16 +08:00
|
|
|
func NewItemService() *ItemService {
|
|
|
|
|
return &ItemService{
|
|
|
|
|
&cool.Service{
|
|
|
|
|
|
|
|
|
|
Model: model.NewItemGift(),
|
2026-03-06 23:49:20 +08:00
|
|
|
ListQueryOp: &cool.QueryOp{
|
|
|
|
|
FieldEQ: []string{"is_egg", "is_light"},
|
|
|
|
|
},
|
2026-02-05 19:59:20 +08:00
|
|
|
PageQueryOp: &cool.QueryOp{
|
|
|
|
|
KeyWordField: []string{"remark"},
|
2026-02-14 03:05:51 +08:00
|
|
|
FieldEQ: []string{"is_egg"},
|
2026-02-05 19:59:20 +08:00
|
|
|
},
|
2025-12-22 19:04:16 +08:00
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|