蛋蛋星球-客户端
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.
 
 
 
 
 

74 Zeilen
2.1 KiB

  1. package svc
  2. import (
  3. "applet/app/db"
  4. "applet/app/utils"
  5. "applet/app/utils/cache"
  6. "applet/app/utils/logx"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  8. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  9. "strings"
  10. "time"
  11. )
  12. // 简单的recover
  13. func Rev() {
  14. if err := recover(); err != nil {
  15. _ = logx.Error(err)
  16. }
  17. }
  18. func UserImg(user *model.User) *model.User {
  19. if user.Avatar == "" {
  20. user.Avatar = GetSysCfgStr("default_avatar")
  21. }
  22. return user
  23. }
  24. func GetOssUrl(img string) string {
  25. redisConn := cache.GetPool().Get()
  26. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  27. sysCfg := sysCfgDb.SysCfgFindWithDb("oss_domain")
  28. if strings.Contains(img, "http") == false && img != "" {
  29. http := ""
  30. if strings.Contains(sysCfg["oss_domain"], "http") == false {
  31. http = "http://"
  32. }
  33. img = http + sysCfg["oss_domain"] + img
  34. }
  35. return img
  36. }
  37. func NumFormat(num int) string {
  38. str := utils.IntToStr(num)
  39. if num >= 10000 {
  40. str = utils.Float64ToStrPrec1(float64(int(float64(num)/10000*10))/10) + "w"
  41. }
  42. return str
  43. }
  44. func GetSysCfgStr(key string) string {
  45. redisConn := cache.GetPool().Get()
  46. sysCfgDb := implement.NewSysCfgDb(db.Db, redisConn)
  47. return sysCfgDb.SysCfgGetWithDb(key)
  48. }
  49. // GetYearsAndWeekStr 获取年份和周数
  50. func GetYearsAndWeekStr(esIndexName string) (string, string) {
  51. parts := strings.Split(esIndexName, "_")
  52. return parts[len(parts)-1][:4], parts[len(parts)-1][4:]
  53. }
  54. // GetWeekInfo 获取周数、开始时间、结束时间
  55. func GetWeekInfo(dateStr string) (string, string, string, string) {
  56. date := utils.TimeParseStd(dateStr)
  57. year, week := date.ISOWeek()
  58. location, _ := time.LoadLocation("Asia/Shanghai")
  59. // 计算给定年份1月1日是星期几
  60. startOfYear := time.Date(year, time.January, 1, 0, 0, 0, 0, location)
  61. daysOffset := int(startOfYear.Weekday()) - int(time.Monday) + 1
  62. // 计算给定年份的第一周的开始日期
  63. firstWeekStart := startOfYear.AddDate(0, 0, -daysOffset+1)
  64. // 计算给定周的开始日期
  65. weekStart := firstWeekStart.AddDate(0, 0, (week-1)*7)
  66. weekEnd := weekStart.AddDate(0, 0, 6)
  67. return utils.IntToStr(year), utils.IntToStr(week), weekStart.Format("2006-01-02"), weekEnd.Format("2006-01-02")
  68. }