Browse Source

fix:bug

master
黄梓健 5 years ago
parent
commit
ec3f41f2c6
  1. 4
      services/red_envelope/red_envelop.go
  2. 5
      utils/utils.go

4
services/red_envelope/red_envelop.go

@ -50,7 +50,7 @@ const (
) )
func GenRedPack(amount, num int) []int { func GenRedPack(amount, num int) []int {
r := rand.New(rand.NewSource(time.Now().UnixNano()))
r := rand.New(rand.NewSource(time.Now().Unix()))
sumMoney := 0 sumMoney := 0
redPacks := make([]int, 0) redPacks := make([]int, 0)
for i := 0; i < num; i++ { for i := 0; i < num; i++ {
@ -82,7 +82,7 @@ func GenRedPack(amount, num int) []int {
func GenRedEnvelope(aid int64, name string, rid int64, rule *models.ShakeRedEnvelopeRule) error { func GenRedEnvelope(aid int64, name string, rid int64, rule *models.ShakeRedEnvelopeRule) error {
// 判断红包是否存在 // 判断红包是否存在
// 根据算法提前生成红包 // 根据算法提前生成红包
r := rand.New(rand.NewSource(time.Now().UnixNano()))
r := rand.New(rand.NewSource(time.Now().Unix()))
if rule.Model == define.SHAKERB_RULE_RANDOM { // 随机红包 if rule.Model == define.SHAKERB_RULE_RANDOM { // 随机红包
// 检测红包是否存在 // 检测红包是否存在
randSum := int(rule.RandSum * 100) randSum := int(rule.RandSum * 100)

5
utils/utils.go

@ -114,8 +114,8 @@ func RandomStr(length int) string {
str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" str := "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
bytes := []byte(str) bytes := []byte(str)
var result []byte var result []byte
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < length; i++ { for i := 0; i < length; i++ {
r := rand.New(rand.NewSource(time.Now().UnixNano() + int64(i) + int64(time.Now().Nanosecond())))
result = append(result, bytes[r.Intn(len(bytes))]) result = append(result, bytes[r.Intn(len(bytes))])
} }
return string(result) return string(result)
@ -125,8 +125,9 @@ func RandomInt(length int) int {
str := "0123456789" str := "0123456789"
bytes := []byte(str) bytes := []byte(str)
var result []byte var result []byte
r := rand.New(rand.NewSource(time.Now().UnixNano()))
for i := 0; i < length; { for i := 0; i < length; {
r := rand.New(rand.NewSource(time.Now().UnixNano() + int64(i) + int64(time.Now().Nanosecond())))
b := bytes[r.Intn(len(bytes))] b := bytes[r.Intn(len(bytes))]
if i == 0 && b == '0' { if i == 0 && b == '0' {
continue continue

Loading…
Cancel
Save