12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- package assist
- import (
- "fmt"
- "git.bvbej.com/bvbej/base-golang/pkg/time_parse"
- "math"
- "math/rand"
- "strconv"
- "time"
- "unicode"
- )
- func GetOrderNumber() string {
- parse, _ := time.Parse(time_parse.CSTLayout, "2021-06-01 00:00:00")
- hours := time.Now().Sub(parse).Hours()
- day := math.Floor(hours / 24)
- prefix := fmt.Sprintf("%05d", int64(day))
- format := time.Now().Format("") + "%0" + strconv.Itoa(10) + "d"
- n := math.Pow10(10)
- return prefix + fmt.Sprintf(format, rand.New(rand.NewSource(time.Now().UnixNano())).Int63n(int64(n)))
- }
- func StringInArray(str string, strArray []string) bool {
- for _, s := range strArray {
- if str == s {
- return true
- }
- }
- return false
- }
- func Uint64InArray(str uint64, uint64Array []uint64) bool {
- for _, s := range uint64Array {
- if str == s {
- return true
- }
- }
- return false
- }
- func CurrencyDecimal(value float64) float64 {
- value, _ = strconv.ParseFloat(fmt.Sprintf("%.8f", value), 64)
- return value
- }
- func IsChinese(str string) bool {
- var count int
- for _, v := range str {
- if unicode.Is(unicode.Han, v) {
- count++
- break
- }
- }
- return count > 0
- }
- func RandInt(max int) int {
- rand.Seed(time.Now().UnixNano())
- <-time.After(time.Nanosecond)
- return rand.Intn(max)
- }
|