|
@ -49,10 +49,7 @@ const ( |
|
|
MaxRedPackAmount = 20000 // 200块钱
|
|
|
MaxRedPackAmount = 20000 // 200块钱
|
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
func GenRedPack(amount, num int) ([]int, error) { |
|
|
|
|
|
if amount/num <= 100 { |
|
|
|
|
|
return nil, errors.New("每个红包的平均金额必须在1.00元到200.00元之间") |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
func GenRedPack(amount, num int) []int { |
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano())) |
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano())) |
|
|
sumMoney := 0 |
|
|
sumMoney := 0 |
|
|
redPacks := make([]int, 0) |
|
|
redPacks := make([]int, 0) |
|
@ -78,7 +75,7 @@ func GenRedPack(amount, num int) ([]int, error) { |
|
|
sumMoney += money |
|
|
sumMoney += money |
|
|
redPacks = append(redPacks, money) |
|
|
redPacks = append(redPacks, money) |
|
|
} |
|
|
} |
|
|
return redPacks, nil |
|
|
|
|
|
|
|
|
return redPacks |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// 提前生成红包
|
|
|
// 提前生成红包
|
|
@ -88,9 +85,12 @@ func GenRedEnvelope(aid int64, name string, rid int64, rule *models.ShakeRedEnve |
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano())) |
|
|
r := rand.New(rand.NewSource(time.Now().UnixNano())) |
|
|
if rule.Model == define.SHAKERB_RULE_RANDOM { // 随机红包
|
|
|
if rule.Model == define.SHAKERB_RULE_RANDOM { // 随机红包
|
|
|
// 检测红包是否存在
|
|
|
// 检测红包是否存在
|
|
|
|
|
|
randSum := int(rule.RandSum * 100) |
|
|
|
|
|
sumMoney := 0 |
|
|
|
|
|
if randSum/rule.RedEnvelopeNum > MinRedPackAmount && randSum/rule.RedEnvelopeNum < MaxRedPackAmount { |
|
|
|
|
|
return errors.New("每个红包的平均金额必须在1.00元到200.00元之间") |
|
|
|
|
|
} |
|
|
for i := 0; i < rule.RedEnvelopeNum; i++ { |
|
|
for i := 0; i < rule.RedEnvelopeNum; i++ { |
|
|
randSum := int(rule.RandSum * 100) |
|
|
|
|
|
sumMoney := 0 |
|
|
|
|
|
money := r.Int() * 2 * (randSum - sumMoney) / (rule.RedEnvelopeNum - i) |
|
|
money := r.Int() * 2 * (randSum - sumMoney) / (rule.RedEnvelopeNum - i) |
|
|
if money <= MinRedPackAmount { // 随机的金额可能小于1块钱
|
|
|
if money <= MinRedPackAmount { // 随机的金额可能小于1块钱
|
|
|
money = MinRedPackAmount |
|
|
money = MinRedPackAmount |
|
|