Browse Source

#1249

Optimized the generation of serial numbers
tags/v1.22.9.2^2
chenyifan01 3 years ago
parent
commit
f03249a852
1 changed files with 5 additions and 1 deletions
  1. +5
    -1
      services/reward/serial.go

+ 5
- 1
services/reward/serial.go View File

@@ -11,7 +11,7 @@ import (

func GetSerialNoByRedis() (string, error) {
now := time.Now()
r := int64(rand.Intn(4)) + 1
r := int64(rand.Intn(3)) + 1
n, err := redis_client.IncrBy(redis_key.RewardSerialCounter(now), r)
if err != nil {
log.Error("GetSerialNoByRedis RewardSerialCounter error. %v", err)
@@ -20,5 +20,9 @@ func GetSerialNoByRedis() (string, error) {
if n == r {
redis_client.Expire(redis_key.RewardSerialCounter(now), 2*time.Minute)
}
//when the counter n exceeds 1000, the length of the serial number will become longer
if n > 1000 {
return now.Format("200601021504") + fmt.Sprintf("%d", n) + fmt.Sprint(rand.Intn(10)), nil
}
return now.Format("200601021504") + fmt.Sprintf("%03d", n) + fmt.Sprint(rand.Intn(10)), nil
}

Loading…
Cancel
Save