uitls.go 627 B

1234567891011121314151617181920212223242526272829303132
  1. package utils
  2. import (
  3. "math/rand"
  4. )
  5. func OrderIdRange(OrderId int64) (int64, int64) {
  6. minOrderId := OrderId //后面有几个零
  7. var maxStep int64 = 1
  8. currValue := minOrderId
  9. for {
  10. if currValue%10 == 0 {
  11. currValue = currValue / 10
  12. maxStep = maxStep * 10
  13. } else {
  14. break
  15. }
  16. }
  17. maxOrderId := minOrderId + maxStep - 1
  18. return minOrderId, maxOrderId
  19. }
  20. // 长度为62
  21. var bytes []byte = []byte("ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890")
  22. func RandName(n int) string {
  23. result := make([]byte, n)
  24. for i := 0; i < n; i++ {
  25. result[i] = bytes[rand.Int31()%62]
  26. }
  27. return string(result)
  28. }