59 lines
1.3 KiB
Go
59 lines
1.3 KiB
Go
package service
|
|
|
|
import (
|
|
"91porn-server/common"
|
|
"91porn-server/common/constant/redisconst"
|
|
"91porn-server/common/log"
|
|
"91porn-server/models/v/usermod"
|
|
"91porn-server/skd/skdg"
|
|
)
|
|
|
|
// 填充推广码
|
|
func MakePromotionCode() {
|
|
redisKey := redisconst.PromotionCodeKey()
|
|
var low int64 = 5000
|
|
total, err := skdg.Redis.SCard(redisKey)
|
|
if err != nil {
|
|
log.Warn("service MakePromotionCode SCard error", log.E(err), log.Any("total", total))
|
|
return
|
|
}
|
|
if total < low {
|
|
savePromotionCode(total)
|
|
}
|
|
}
|
|
|
|
func savePromotionCode(total int64) {
|
|
var max int64 = 9999
|
|
size := 100
|
|
redisKey := redisconst.PromotionCodeKey()
|
|
if total < max {
|
|
promotionCodeCollection := make([]string, size)
|
|
for i := 0; i < size; i++ {
|
|
p, err := getPromotionCode()
|
|
if err != nil {
|
|
break
|
|
}
|
|
promotionCodeCollection[i] = p
|
|
}
|
|
count, err := skdg.Redis.SAdd(redisKey, promotionCodeCollection)
|
|
if err != nil {
|
|
log.Warn("service savePromotionCode SAdd error", log.E(err), log.Any("total", total))
|
|
return
|
|
}
|
|
savePromotionCode(total + count)
|
|
}
|
|
}
|
|
|
|
// 获取不重复的推广码
|
|
func getPromotionCode() (string, error) {
|
|
promotionCode := common.InvitePromotionCodeGenera()
|
|
u, err := usermod.FindUserPromotionCode(promotionCode)
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
if u == nil {
|
|
return promotionCode, nil
|
|
}
|
|
return getPromotionCode()
|
|
}
|