43 lines
715 B
Go
43 lines
715 B
Go
package service
|
|
|
|
import (
|
|
"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) uint32 {
|
|
var item model.ItemGift
|
|
cool.DBM(s.Model).Where("id", id).Cache(gdb.CacheOption{
|
|
// Duration: time.Hour,
|
|
|
|
Force: false,
|
|
}).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(),
|
|
},
|
|
}
|
|
}
|