msg.go 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. package tag
  2. import (
  3. "fmt"
  4. "jy/src/jfw/config"
  5. "strconv"
  6. "strings"
  7. "time"
  8. util "app.yhyue.com/moapp/jybase/common"
  9. )
  10. // 从json配置文件中读取值
  11. func Export() map[string]interface{} {
  12. return config.ExportConfig
  13. }
  14. // 从json配置文件中读取值
  15. func Msg(mtype, key string) string {
  16. return readproperty(mtype, key)
  17. }
  18. func DateTip(date2 int64) (timedate string) {
  19. timedate = "30秒前"
  20. date1 := time.Now().Unix()
  21. td := date1 - date2
  22. //天数
  23. var days = td / (24 * 3600)
  24. //小时
  25. var leave1 = td % (24 * 3600)
  26. var hours = leave1 / 3600
  27. //分钟
  28. var leave2 = leave1 % 3600
  29. var minutes = leave2 / 60
  30. if days > 0 {
  31. if days > 10 {
  32. var date1fm = time.Unix(date1, 0).Format("2006-01-02")
  33. var date2fm = time.Unix(date2, 0).Format("2006-01-02")
  34. date1fmyear := strings.Split(date1fm, "-")[0]
  35. date2fmyear := strings.Split(date2fm, "-")[0]
  36. if date1fmyear > date2fmyear {
  37. timedate = date2fm
  38. } else {
  39. timedate = time.Unix(date2, 0).Format("01-02")
  40. }
  41. } else {
  42. timedate = strconv.FormatInt(days, 10) + "天"
  43. }
  44. } else if hours > 0 {
  45. timedate = strconv.FormatInt(hours, 10) + "小时"
  46. } else if minutes > 0 {
  47. timedate = strconv.FormatInt(minutes, 10) + "分钟"
  48. }
  49. return
  50. }
  51. func readproperty(mtype, key string) string {
  52. switch mtype {
  53. case "seo":
  54. if key == "version" && config.Seoconfig_Version != "" {
  55. return config.Seoconfig_Version
  56. }
  57. if strings.HasSuffix(key, "_v") {
  58. avk := applyVersion[key]
  59. if avk != "" {
  60. return avk
  61. }
  62. return config.Seoconfig_Version
  63. }
  64. tmp := util.GetPropertie(key, config.Seoconfig)
  65. if tmp == nil {
  66. return ""
  67. } else {
  68. ret, _ := tmp.(string)
  69. return ret
  70. }
  71. case "date":
  72. fmt.Println(key, "--------")
  73. timedate := "30秒前"
  74. if len(key) > 0 {
  75. var date1 int64
  76. var date2 int64
  77. date1 = time.Now().Unix()
  78. date2, _ = strconv.ParseInt(key, 10, 0)
  79. td := date1 - date2
  80. //天数
  81. var days = td / (24 * 3600)
  82. //小时
  83. var leave1 = td % (24 * 3600)
  84. var hours = leave1 / 3600
  85. //分钟
  86. var leave2 = leave1 % 3600
  87. var minutes = leave2 / 60
  88. if days > 0 {
  89. if days > 10 {
  90. var date1fm = time.Unix(date1, 0).Format("2006-01-02")
  91. var date2fm = time.Unix(date2, 0).Format("2006-01-02")
  92. date1fmyear := strings.Split(date1fm, "-")[0]
  93. date2fmyear := strings.Split(date2fm, "-")[0]
  94. if date1fmyear > date2fmyear {
  95. timedate = date2fm
  96. } else {
  97. timedate = time.Unix(date2, 0).Format("01-02")
  98. }
  99. } else {
  100. timedate = strconv.FormatInt(days, 10) + "天"
  101. }
  102. } else if hours > 0 {
  103. timedate = strconv.FormatInt(hours, 10) + "小时"
  104. } else if minutes > 0 {
  105. timedate = strconv.FormatInt(minutes, 10) + "分钟"
  106. }
  107. }
  108. return timedate
  109. default:
  110. return ""
  111. }
  112. }