tool.go 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package assist
  2. import (
  3. "fmt"
  4. "git.bvbej.com/bvbej/base-golang/pkg/time_parse"
  5. "math"
  6. "math/rand"
  7. "strconv"
  8. "time"
  9. "unicode"
  10. )
  11. func GetOrderNumber() string {
  12. parse, _ := time.Parse(time_parse.CSTLayout, "2021-06-01 00:00:00")
  13. hours := time.Now().Sub(parse).Hours()
  14. day := math.Floor(hours / 24)
  15. prefix := fmt.Sprintf("%05d", int64(day))
  16. format := time.Now().Format("") + "%0" + strconv.Itoa(10) + "d"
  17. n := math.Pow10(10)
  18. return prefix + fmt.Sprintf(format, rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(int64(n)))
  19. }
  20. func StringInArray(str string, strArray []string) bool {
  21. for _, s := range strArray {
  22. if str == s {
  23. return true
  24. }
  25. }
  26. return false
  27. }
  28. func Uint64InArray(str uint64, uint64Array []uint64) bool {
  29. for _, s := range uint64Array {
  30. if str == s {
  31. return true
  32. }
  33. }
  34. return false
  35. }
  36. func CurrencyDecimal(value float64) float64 {
  37. value, _ = strconv.ParseFloat(fmt.Sprintf("%.8f", value), 64)
  38. return value
  39. }
  40. func IsChinese(str string) bool {
  41. var count int
  42. for _, v := range str {
  43. if unicode.Is(unicode.Han, v) {
  44. count++
  45. break
  46. }
  47. }
  48. return count > 0
  49. }