feat(user-talk): 优化聊天功能中的物品奖励逻辑

重构 Talk 方法中物品奖励的获取方式,使用新的配置服务以支持多物品 ID 奖励机制。
移除了对 github.com/gogf/gf/v2/util/grand 包的依赖,改为通过服务获取实际物品数量。

同时更新了相关模型定义:
- 修改 MineralCollectionConfig 中 ItemID 为数组形式以支持多个物品配置
- 调整 ItemGift 模型字段
This commit is contained in:
2025-12-22 19:04:16 +08:00
parent 8505bfd4e3
commit cf7736a3e7
10 changed files with 86 additions and 49 deletions

View File

@@ -0,0 +1,39 @@
package service
import (
"blazing/cool"
"blazing/modules/config/model"
"github.com/gogf/gf/v2/util/grand"
)
type ItemService struct {
*cool.Service
}
//实现物品数量的获取
func (s *ItemService) GetItemCount(id uint32) uint32 {
var item model.ItemGift
cool.DBM(s.Model).Where("id", id).Scan(&item)
if item.ItemID == 0 {
return 0
}
if item.ItemMaxCount != 0 {
return uint32(grand.N(int(item.ItemMinCount), int(item.ItemMaxCount)))
}
return item.ItemMinCount
}
func NewItemService() *ItemService {
return &ItemService{
&cool.Service{
Model: model.NewItemGift(),
},
}
}
var Items = NewItemService()

View File

@@ -11,8 +11,6 @@ type TalkConfigService struct {
*cool.Service
}
var TalkConfigServiceS = NewTalkConfigService()
func NewTalkConfigService() *TalkConfigService {
return &TalkConfigService{
@@ -22,9 +20,9 @@ func NewTalkConfigService() *TalkConfigService {
}
func (s *TalkConfigService) GetCache(flag int) []model.MineralCollectionConfig {
func (s *TalkConfigService) GetCache(flag int) model.MineralCollectionConfig {
var config []model.MineralCollectionConfig
var config model.MineralCollectionConfig
cool.DBM(s.Model).Where("type", flag).Cache(gdb.CacheOption{
// Duration: time.Hour,