diff --git a/app/hdl/hdl_home_page.go b/app/hdl/hdl_home_page.go index d577dea..7e928b5 100644 --- a/app/hdl/hdl_home_page.go +++ b/app/hdl/hdl_home_page.go @@ -3,6 +3,7 @@ package hdl import ( "applet/app/db" "applet/app/e" + md "applet/app/md/institutional_management/egg_energy" "applet/app/utils" "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" "code.fnuoos.com/EggPlanet/egg_models.git/src/model" @@ -47,6 +48,18 @@ func GetTotalData(c *gin.Context) { e.OutErr(c, e.ERR_DB_ORM, err.Error()) return } + if data == nil { + resp := TotalDataResp{ + TotalUserCount: 0, + VerifiedUserCount: 0, + NoSignInUserCount: 0, + TotalWithdrawAmount: "", + Year: "", + Month: "", + } + e.OutSuc(c, resp, nil) + return + } resp := TotalDataResp{ TotalUserCount: data.TotalUserCount, VerifiedUserCount: data.VerifiedUserCount, @@ -124,15 +137,15 @@ func GetGrowData(c *gin.Context) { case "1": // 日 var date = now.AddDate(0, 0, -30).Format("2006-01-02") - var sql = fmt.Sprintf("SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE >= \"%s\" AND DATE != \"%s\" ORDER BY DATE ASC ", date, now.Format("2006-01-02")) + var sql = fmt.Sprintf("SELECT user_grow_count, date FROM `platform_grow_data` WHERE DATE >= \"%s\" AND DATE != \"%s\" ORDER BY DATE ASC ", date, now.Format("2006-01-02")) results, _ := db.Db.QueryString(sql) for _, v := range results { - tmpDate := utils.TimeParseStd(v["date"]) + tmpDate := utils.TimeParseDateStd(v["date"]) yData = append(yData, v["user_grow_count"]) xData = append(xData, tmpDate.Format("2006-01-02")) } - yData = append(yData, m.UserGrowCount) - tmpDate := utils.TimeParseStd(m.Date) + yData = append(yData, utils.IntToStr(m.UserGrowCount)) + tmpDate := utils.TimeParseDateStd(m.Date) xData = append(xData, tmpDate.Format("2006-01-02")) break case "2": @@ -144,13 +157,13 @@ func GetGrowData(c *gin.Context) { sql = fmt.Sprintf(sql, date) results, _ := db.Db.QueryString(sql) if results != nil { - year, week, _, _ := utils.GetWeekInfo(results[0]["date"]) + year, week, _, _ := utils.GetWeekInfoByDate(results[0]["date"]) yData = append(yData, results[0]["user_grow_count"]) xData = append(xData, fmt.Sprintf("%s年%s周", year, week)) } } - yData = append(yData, m.UserGrowCount) - year, week, _, _ := utils.GetWeekInfo(m.Date) + yData = append(yData, utils.IntToStr(m.UserGrowCount)) + year, week, _, _ := utils.GetWeekInfoByDate(m.Date) xData = append(xData, fmt.Sprintf("%s年%s周", year, week)) break case "3": @@ -162,14 +175,19 @@ func GetGrowData(c *gin.Context) { sql = fmt.Sprintf(sql, date) results, _ := db.Db.QueryString(sql) if results != nil { - tmpDate := utils.TimeParseStd(results[0]["date"]) + tmpDate := utils.TimeParseDateStd(results[0]["date"]) yData = append(yData, results[0]["user_grow_count"]) xData = append(xData, tmpDate.Format("2006-01")) } } - yData = append(yData, m.UserGrowCount) - tmpDate := utils.TimeParseStd(m.Date) + yData = append(yData, utils.IntToStr(m.UserGrowCount)) + tmpDate := utils.TimeParseDateStd(m.Date) xData = append(xData, tmpDate.Format("2006-01")) break } + resp := md.GetPriceCurveResp{ + XData: xData, + YData: yData, + } + e.OutSuc(c, resp, nil) } diff --git a/app/utils/time.go b/app/utils/time.go index 50fbcf8..499ead7 100644 --- a/app/utils/time.go +++ b/app/utils/time.go @@ -72,6 +72,11 @@ func TimeParseStd(src string) time.Time { return t } +func TimeParseDateStd(src string) time.Time { + t, _ := TimeParse("2006-01-02", src) + return t +} + func TimeStdParseUnix(src string) int64 { t, err := TimeParse("2006-01-02 15:04:05", src) if err != nil { @@ -242,6 +247,22 @@ func GetWeekInfo(dateStr string) (string, string, string, string) { return IntToStr(year), IntToStr(week), weekStart.Format("2006-01-02"), weekEnd.Format("2006-01-02") } +// GetWeekInfoByDate 获取周数、开始时间、结束时间 +func GetWeekInfoByDate(dateStr string) (string, string, string, string) { + date := TimeParseDateStd(dateStr) + year, week := date.ISOWeek() + location, _ := time.LoadLocation("Asia/Shanghai") + // 计算给定年份1月1日是星期几 + startOfYear := time.Date(year, time.January, 1, 0, 0, 0, 0, location) + daysOffset := int(startOfYear.Weekday()) - int(time.Monday) + 1 + // 计算给定年份的第一周的开始日期 + firstWeekStart := startOfYear.AddDate(0, 0, -daysOffset+1) + // 计算给定周的开始日期 + weekStart := firstWeekStart.AddDate(0, 0, (week-1)*7) + weekEnd := weekStart.AddDate(0, 0, 6) + return IntToStr(year), IntToStr(week), weekStart.Format("2006-01-02"), weekEnd.Format("2006-01-02") +} + func IsTimeFormat(s string) bool { // 正则表达式匹配HH:MM格式 re := regexp.MustCompile(`^(\d{2}):(\d{2})$`)