43 lines
754 B
Go
43 lines
754 B
Go
package entity
|
||
|
||
import (
|
||
"admin/apps/game/model"
|
||
"admin/internal/consts"
|
||
"admin/lib/cdkey"
|
||
)
|
||
|
||
var MaxKeyNum = 100000 // 每个批次直接搞10w个,不然运营想补加码,算法又要一开始定好数量
|
||
|
||
type CDKey struct {
|
||
Po *model.CDKey
|
||
}
|
||
|
||
func NewCDKey(po *model.CDKey) *CDKey {
|
||
return &CDKey{
|
||
Po: po,
|
||
}
|
||
}
|
||
|
||
func (c *CDKey) GetName() string {
|
||
return c.Po.Name
|
||
}
|
||
|
||
func (c *CDKey) IsGlobalType() bool {
|
||
return c.Po.CodeType == consts.CDKeyType_Global
|
||
}
|
||
|
||
func (c *CDKey) GenerateKeys() []string {
|
||
if c.IsGlobalType() {
|
||
return []string{c.Po.Code}
|
||
}
|
||
return cdkey.GenerateAll(c.Po.ID, MaxKeyNum)[:c.Po.CodeNum]
|
||
}
|
||
|
||
func (c *CDKey) AddCount(delta int) {
|
||
c.Po.CodeNum += delta
|
||
}
|
||
|
||
func (c *CDKey) GetCount() int {
|
||
return c.Po.CodeNum
|
||
}
|