附近小店
Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

vor 3 Monaten
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. package utils
  2. import (
  3. "code.fnuoos.com/go_rely_warehouse/zyos_go_coupon.git/utils"
  4. "fmt"
  5. "github.com/gin-gonic/gin"
  6. "math"
  7. "strings"
  8. )
  9. func CouponFormat(c *gin.Context, data string) string {
  10. switch data {
  11. case "0.00", "0", "":
  12. return ""
  13. default:
  14. return GetPrec(c, data, "2")
  15. }
  16. }
  17. func GetPrec(c *gin.Context, sum, commPrec string) string {
  18. if sum == "" {
  19. sum = "0"
  20. }
  21. sum = StrToFormat(c, sum, utils.StrToInt(commPrec))
  22. ex := strings.Split(sum, ".")
  23. if len(ex) == 2 && c.GetString("is_show_point") != "1" {
  24. if utils.StrToFloat64(ex[1]) == 0 {
  25. sum = ex[0]
  26. } else {
  27. val := utils.Float64ToStrByPrec(utils.StrToFloat64(ex[1]), 0)
  28. keyMax := 0
  29. for i := 0; i < len(val); i++ {
  30. ch := string(val[i])
  31. fmt.Println(utils.StrToInt(ch))
  32. if utils.StrToInt(ch) > 0 {
  33. keyMax = i
  34. }
  35. }
  36. valNew := val[0 : keyMax+1]
  37. sum = ex[0] + "." + strings.ReplaceAll(ex[1], val, valNew)
  38. }
  39. }
  40. return sum
  41. }
  42. func CommissionFormat(data string) string {
  43. if StrToFloat64(data) > 0 {
  44. return data
  45. }
  46. return ""
  47. }
  48. func HideString(src string, hLen int) string {
  49. str := []rune(src)
  50. if hLen == 0 {
  51. hLen = 4
  52. }
  53. hideStr := ""
  54. for i := 0; i < hLen; i++ {
  55. hideStr += "*"
  56. }
  57. hideLen := len(str) / 2
  58. showLen := len(str) - hideLen
  59. if hideLen == 0 || showLen == 0 {
  60. return hideStr
  61. }
  62. subLen := showLen / 2
  63. if subLen == 0 {
  64. return string(str[:showLen]) + hideStr
  65. }
  66. s := string(str[:subLen])
  67. s += hideStr
  68. s += string(str[len(str)-subLen:])
  69. return s
  70. }
  71. // SaleCountFormat is 格式化销量
  72. func SaleCountFormat(s string) string {
  73. s = strings.ReplaceAll(s, "+", "")
  74. if strings.Contains(s, "万") {
  75. s = strings.ReplaceAll(s, "万", "")
  76. s = Float64ToStrByPrec(StrToFloat64(s)*10000, 0)
  77. }
  78. ex := strings.Split(s, ".")
  79. if len(ex) == 2 && StrToInt(ex[1]) == 0 {
  80. s = ex[0]
  81. }
  82. if utils.StrToInt(s) > 0 {
  83. s = Comm(s)
  84. return "已售" + s
  85. }
  86. return "已售0"
  87. }
  88. func SaleCountFormat2(s string) string {
  89. s = strings.ReplaceAll(s, "+", "")
  90. if strings.Contains(s, "万") {
  91. s = strings.ReplaceAll(s, "万", "")
  92. s = Float64ToStrByPrec(StrToFloat64(s)*10000, 0)
  93. }
  94. ex := strings.Split(s, ".")
  95. if len(ex) == 2 && StrToInt(ex[1]) == 0 {
  96. s = ex[0]
  97. }
  98. if utils.StrToInt(s) > 0 {
  99. s = Comm(s)
  100. return s
  101. }
  102. return "0"
  103. }
  104. func SaleCountFormat1(s string) string {
  105. s = strings.ReplaceAll(s, "+", "")
  106. if strings.Contains(s, "万") {
  107. s = strings.ReplaceAll(s, "万", "")
  108. s = Float64ToStrByPrec(StrToFloat64(s)*10000, 0)
  109. }
  110. ex := strings.Split(s, ".")
  111. if len(ex) == 2 && StrToInt(ex[1]) == 0 {
  112. s = ex[0]
  113. }
  114. if utils.StrToInt(s) > 0 {
  115. s = Comm(s)
  116. return s
  117. }
  118. return "0"
  119. }
  120. func Comm(s string) string {
  121. ex := strings.Split(s, ".")
  122. if len(ex) == 2 && StrToInt(ex[1]) == 0 {
  123. s = ex[0]
  124. }
  125. if utils.StrToInt(s) >= 10000 {
  126. num := FloatFormat(StrToFloat64(s)/10000, 2)
  127. numStr := Float64ToStr(num)
  128. ex := strings.Split(numStr, ".")
  129. if len(ex) == 2 {
  130. if utils.StrToFloat64(ex[1]) == 0 {
  131. numStr = ex[0]
  132. } else {
  133. val := utils.Float64ToStrByPrec(utils.StrToFloat64(ex[1]), 0)
  134. keyMax := 0
  135. for i := 0; i < len(val); i++ {
  136. ch := string(val[i])
  137. fmt.Println(utils.StrToInt(ch))
  138. if utils.StrToInt(ch) > 0 {
  139. keyMax = i
  140. }
  141. }
  142. valNew := val[0 : keyMax+1]
  143. numStr = ex[0] + "." + strings.ReplaceAll(ex[1], val, valNew)
  144. }
  145. }
  146. s = numStr + "万"
  147. }
  148. //if StrToInt(s) >= 10000000 {
  149. // num := FloatFormat(StrToFloat64(s)/10000000, 2)
  150. // numStr := Float64ToStr(num)
  151. // ex := strings.Split(numStr, ".")
  152. // if len(ex) == 2 {
  153. // if utils.StrToFloat64(ex[1]) == 0 {
  154. // numStr = ex[0]
  155. // } else {
  156. // val := utils.Float64ToStrByPrec(utils.StrToFloat64(ex[1]), 0)
  157. // keyMax := 0
  158. // for i := 0; i < len(val); i++ {
  159. // ch := string(val[i])
  160. // fmt.Println(utils.StrToInt(ch))
  161. // if utils.StrToInt(ch) > 0 {
  162. // keyMax = i
  163. // }
  164. // }
  165. // valNew := val[0 : keyMax+1]
  166. // numStr = ex[0] + "." + strings.ReplaceAll(ex[1], val, valNew)
  167. // }
  168. // }
  169. // s = numStr + "千万"
  170. //}
  171. return s
  172. }
  173. func CommissionFormat1(numStr string) string {
  174. split := strings.Split(numStr, ".")
  175. if len(split) == 2 {
  176. if split[1] == "00" {
  177. numStr = strings.ReplaceAll(numStr, ".00", "")
  178. }
  179. }
  180. return numStr
  181. }
  182. // 小数格式化
  183. func FloatFormat(f float64, i int) float64 {
  184. if i > 14 {
  185. return f
  186. }
  187. p := math.Pow10(i)
  188. return float64(int64((f+0.000000000000009)*p)) / p
  189. }