From 8ad0a1b3e1545f170c0e2a4f7b23674fec54b724 Mon Sep 17 00:00:00 2001 From: shenjiachi Date: Wed, 27 Nov 2024 21:09:06 +0800 Subject: [PATCH] add home page --- app/hdl/hdl_home_page.go | 158 ++++++++++++++++++++++++++++++ app/router/router.go | 6 ++ app/utils/time.go | 22 ++++- docs/docs.go | 204 +++++++++++++++++++++++++++++++++++++++ docs/swagger.json | 204 +++++++++++++++++++++++++++++++++++++++ docs/swagger.yaml | 132 +++++++++++++++++++++++++ go.mod | 2 +- 7 files changed, 724 insertions(+), 4 deletions(-) create mode 100644 app/hdl/hdl_home_page.go diff --git a/app/hdl/hdl_home_page.go b/app/hdl/hdl_home_page.go new file mode 100644 index 0000000..1da9f6f --- /dev/null +++ b/app/hdl/hdl_home_page.go @@ -0,0 +1,158 @@ +package hdl + +import ( + "applet/app/db" + "applet/app/e" + "applet/app/utils" + "code.fnuoos.com/EggPlanet/egg_models.git/src/implement" + "code.fnuoos.com/EggPlanet/egg_models.git/src/model" + "fmt" + "github.com/gin-gonic/gin" + "strings" + "time" +) + +// GetTotalData +// @Summary 首页-首页-数据总览 +// @Tags 首页 +// @Description 数据总览 +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Param year query string true "年" +// @Param month query string true "月" +// @Success 200 {object} model.PlatformTotalData "具体数据" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/homePage/totalData [GET] +func GetTotalData(c *gin.Context) { + year := c.Query("year") + month := c.Query("month") + if year == "" || month == "" { + nowStr := time.Now().Format("2006-01-02") + year = strings.Split(nowStr, "-")[0] + month = strings.Split(nowStr, "-")[1] + } + dataDb := implement.NewPlatformTotalDataDb(db.Db) + data, err := dataDb.PlatformTotalDataGetOneByTime(year, month) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + e.OutSuc(c, data, nil) +} + +type GetActiveDataResp struct { + Today *model.PlatformActiveData `json:"today"` // 今日数据 + Yesterday *model.PlatformActiveData `json:"yesterday"` // 昨日数据 +} + +// GetActiveData +// @Summary 首页-首页-活跃数据 +// @Tags 首页 +// @Description 活跃数据 +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Success 200 {object} GetActiveDataResp "具体数据" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/homePage/activeData [GET] +func GetActiveData(c *gin.Context) { + nowStr := time.Now().Format("2006-01-02") + yesterdayStr := time.Now().AddDate(0, 0, -1).Format("2006-01-02") + activityDb := implement.NewPlatformActiveDataDb(db.Db) + + today, err := activityDb.PlatformActiveDataGetOneByParams(map[string]interface{}{"key": "date", "value": nowStr}) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err) + } + yesterday, err := activityDb.PlatformActiveDataGetOneByParams(map[string]interface{}{"key": "date", "value": yesterdayStr}) + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err) + } + resp := GetActiveDataResp{ + Today: today, + Yesterday: yesterday, + } + e.OutSuc(c, resp, nil) +} + +// GetGrowData +// @Summary 首页-首页-用户增长曲线 +// @Tags 首页 +// @Description 用户增长曲线 +// @Accept json +// @Produce json +// @param Authorization header string true "验证参数Bearer和token空格拼接" +// @Param kind query string false "1:按天 2:按周 3:按小时" +// @Success 200 {object} md.GetPriceCurveResp "具体数据" +// @Failure 400 {object} md.Response "具体错误" +// @Router /api/homePage/growData [GET] +func GetGrowData(c *gin.Context) { + kind := c.DefaultQuery("kind", "1") + now := time.Now() + + dataDb := implement.NewPlatformGrowDataDb(db.Db) + m, has, err := dataDb.PlatformGrowDataGetLastOne() + if err != nil { + e.OutErr(c, e.ERR_DB_ORM, err.Error()) + return + } + if !has { + e.OutErr(c, e.ERR_NO_DATA, "未查询到数据") + return + } + var yData []interface{} + var xData []interface{} + switch kind { + 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")) + results, _ := db.Db.QueryString(sql) + for _, v := range results { + tmpDate := utils.TimeParseStd(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) + xData = append(xData, tmpDate.Format("2006-01-02")) + break + case "2": + // 周 + var nums = 29 + for i := nums; i >= 1; i-- { + var date = now.AddDate(0, 0, -7*i).Format("2006-01-02") + var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" " + sql = fmt.Sprintf(sql, date) + results, _ := db.Db.QueryString(sql) + if results != nil { + year, week, _, _ := utils.GetWeekInfo(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) + xData = append(xData, fmt.Sprintf("%s年%s周", year, week)) + break + case "3": + // 月 + var nums = 29 + for i := nums; i >= 1; i-- { + var date = now.AddDate(0, -i, 0).Format("2006-01-02") + var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" " + sql = fmt.Sprintf(sql, date) + results, _ := db.Db.QueryString(sql) + if results != nil { + tmpDate := utils.TimeParseStd(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) + xData = append(xData, tmpDate.Format("2006-01")) + break + } +} diff --git a/app/router/router.go b/app/router/router.go index 09c5536..c364eaf 100644 --- a/app/router/router.go +++ b/app/router/router.go @@ -76,6 +76,7 @@ func route(r *gin.RouterGroup) { rInstitutionalManagement(r.Group("/institutionalManagement")) rMarketingApplications(r.Group("/marketingApplications")) rMemberCenter(r.Group("/memberCenter")) + rHomePage(r.Group("/homePage")) rSettCenter(r.Group("/settCenter")) rFinancialCenter(r.Group("/financialCenter")) rAdvertising(r.Group("/advertising")) @@ -95,6 +96,11 @@ func rSettCenter(r *gin.RouterGroup) { //设置中心 } } } +func rHomePage(r *gin.RouterGroup) { + r.GET("/totalData", hdl.GetTotalData) + r.GET("/activeData", hdl.GetActiveData) + r.GET("/growData", hdl.GetGrowData) +} func rAdvertising(r *gin.RouterGroup) { r.GET("/getBasic", advertising.GetBasic) r.POST("/setBasic", advertising.SetBasic) diff --git a/app/utils/time.go b/app/utils/time.go index 6860a57..8f0d1aa 100644 --- a/app/utils/time.go +++ b/app/utils/time.go @@ -209,18 +209,34 @@ func GetDateTimeRangeStr(s string) (string, string) { return stime.Format("2006-01-02 15:04:05"), etime.Format("2006-01-02 15:04:05") } -//获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。 +// 获取传入的时间所在月份的第一天,即某月第一天的0点。如传入time.Now(), 返回当前月份的第一天0点时间。 func GetFirstDateOfMonth(d time.Time) time.Time { d = d.AddDate(0, 0, -d.Day()+1) return GetZeroTime(d) } -//获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。 +// 获取传入的时间所在月份的最后一天,即某月最后一天的0点。如传入time.Now(), 返回当前月份的最后一天0点时间。 func GetLastDateOfMonth(d time.Time) time.Time { return GetFirstDateOfMonth(d).AddDate(0, 1, -1) } -//获取某一天的0点时间 +// 获取某一天的0点时间 func GetZeroTime(d time.Time) time.Time { return time.Date(d.Year(), d.Month(), d.Day(), 0, 0, 0, 0, d.Location()) } + +// GetWeekInfo 获取周数、开始时间、结束时间 +func GetWeekInfo(dateStr string) (string, string, string, string) { + date := TimeParseStd(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") +} diff --git a/docs/docs.go b/docs/docs.go index d6dfbed..6b3b5f3 100644 --- a/docs/docs.go +++ b/docs/docs.go @@ -1503,6 +1503,140 @@ const docTemplate = `{ } } }, + "/api/homePage/activeData": { + "get": { + "description": "活跃数据", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "首页-首页-活跃数据", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/hdl.GetActiveDataResp" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, + "/api/homePage/growData": { + "get": { + "description": "用户增长曲线", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "首页-首页-用户增长曲线", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "1:按天 2:按周 3:按小时", + "name": "kind", + "in": "query" + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/md.GetPriceCurveResp" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, + "/api/homePage/totalData": { + "get": { + "description": "数据总览", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "首页-首页-数据总览", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "年", + "name": "year", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "月", + "name": "month", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/model.PlatformTotalData" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/im/addCustomerService": { "post": { "description": "客服(新增)", @@ -6637,6 +6771,27 @@ const docTemplate = `{ } } }, + "hdl.GetActiveDataResp": { + "type": "object", + "properties": { + "today": { + "description": "今日数据", + "allOf": [ + { + "$ref": "#/definitions/model.PlatformActiveData" + } + ] + }, + "yesterday": { + "description": "昨日数据", + "allOf": [ + { + "$ref": "#/definitions/model.PlatformActiveData" + } + ] + } + } + }, "md.ActivePointsWalletNode": { "type": "object", "properties": { @@ -12213,6 +12368,55 @@ const docTemplate = `{ } } }, + "model.PlatformActiveData": { + "type": "object", + "properties": { + "date": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "new_user_count": { + "type": "integer" + }, + "user_sign_in_count": { + "type": "integer" + }, + "withdraw_amount_count": { + "type": "string" + }, + "withdraw_user_count": { + "type": "integer" + } + } + }, + "model.PlatformTotalData": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "month": { + "type": "string" + }, + "no_sigin_in_user_count": { + "type": "integer" + }, + "total_user_count": { + "type": "integer" + }, + "total_withdraw_amount": { + "type": "string" + }, + "verified_user_count": { + "type": "integer" + }, + "year": { + "type": "string" + } + } + }, "model.UserLevelTask": { "type": "object", "properties": { diff --git a/docs/swagger.json b/docs/swagger.json index 8659767..dea23b3 100644 --- a/docs/swagger.json +++ b/docs/swagger.json @@ -1496,6 +1496,140 @@ } } }, + "/api/homePage/activeData": { + "get": { + "description": "活跃数据", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "首页-首页-活跃数据", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/hdl.GetActiveDataResp" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, + "/api/homePage/growData": { + "get": { + "description": "用户增长曲线", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "首页-首页-用户增长曲线", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "1:按天 2:按周 3:按小时", + "name": "kind", + "in": "query" + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/md.GetPriceCurveResp" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, + "/api/homePage/totalData": { + "get": { + "description": "数据总览", + "consumes": [ + "application/json" + ], + "produces": [ + "application/json" + ], + "tags": [ + "首页" + ], + "summary": "首页-首页-数据总览", + "parameters": [ + { + "type": "string", + "description": "验证参数Bearer和token空格拼接", + "name": "Authorization", + "in": "header", + "required": true + }, + { + "type": "string", + "description": "年", + "name": "year", + "in": "query", + "required": true + }, + { + "type": "string", + "description": "月", + "name": "month", + "in": "query", + "required": true + } + ], + "responses": { + "200": { + "description": "具体数据", + "schema": { + "$ref": "#/definitions/model.PlatformTotalData" + } + }, + "400": { + "description": "具体错误", + "schema": { + "$ref": "#/definitions/md.Response" + } + } + } + } + }, "/api/im/addCustomerService": { "post": { "description": "客服(新增)", @@ -6630,6 +6764,27 @@ } } }, + "hdl.GetActiveDataResp": { + "type": "object", + "properties": { + "today": { + "description": "今日数据", + "allOf": [ + { + "$ref": "#/definitions/model.PlatformActiveData" + } + ] + }, + "yesterday": { + "description": "昨日数据", + "allOf": [ + { + "$ref": "#/definitions/model.PlatformActiveData" + } + ] + } + } + }, "md.ActivePointsWalletNode": { "type": "object", "properties": { @@ -12206,6 +12361,55 @@ } } }, + "model.PlatformActiveData": { + "type": "object", + "properties": { + "date": { + "type": "string" + }, + "id": { + "type": "integer" + }, + "new_user_count": { + "type": "integer" + }, + "user_sign_in_count": { + "type": "integer" + }, + "withdraw_amount_count": { + "type": "string" + }, + "withdraw_user_count": { + "type": "integer" + } + } + }, + "model.PlatformTotalData": { + "type": "object", + "properties": { + "id": { + "type": "integer" + }, + "month": { + "type": "string" + }, + "no_sigin_in_user_count": { + "type": "integer" + }, + "total_user_count": { + "type": "integer" + }, + "total_withdraw_amount": { + "type": "string" + }, + "verified_user_count": { + "type": "integer" + }, + "year": { + "type": "string" + } + } + }, "model.UserLevelTask": { "type": "object", "properties": { diff --git a/docs/swagger.yaml b/docs/swagger.yaml index cedb6fe..db4fb58 100644 --- a/docs/swagger.yaml +++ b/docs/swagger.yaml @@ -206,6 +206,17 @@ definitions: - content_type - file_name type: object + hdl.GetActiveDataResp: + properties: + today: + allOf: + - $ref: '#/definitions/model.PlatformActiveData' + description: 今日数据 + yesterday: + allOf: + - $ref: '#/definitions/model.PlatformActiveData' + description: 昨日数据 + type: object md.ActivePointsWalletNode: properties: amount: @@ -4086,6 +4097,38 @@ definitions: violate_nums: type: string type: object + model.PlatformActiveData: + properties: + date: + type: string + id: + type: integer + new_user_count: + type: integer + user_sign_in_count: + type: integer + withdraw_amount_count: + type: string + withdraw_user_count: + type: integer + type: object + model.PlatformTotalData: + properties: + id: + type: integer + month: + type: string + no_sigin_in_user_count: + type: integer + total_user_count: + type: integer + total_withdraw_amount: + type: string + verified_user_count: + type: integer + year: + type: string + type: object model.UserLevelTask: properties: create_at: @@ -5096,6 +5139,95 @@ paths: summary: 财务中心-提现-基础设置(更新) tags: - 提现 + /api/homePage/activeData: + get: + consumes: + - application/json + description: 活跃数据 + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + produces: + - application/json + responses: + "200": + description: 具体数据 + schema: + $ref: '#/definitions/hdl.GetActiveDataResp' + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 首页-首页-活跃数据 + tags: + - 首页 + /api/homePage/growData: + get: + consumes: + - application/json + description: 用户增长曲线 + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + - description: 1:按天 2:按周 3:按小时 + in: query + name: kind + type: string + produces: + - application/json + responses: + "200": + description: 具体数据 + schema: + $ref: '#/definitions/md.GetPriceCurveResp' + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 首页-首页-用户增长曲线 + tags: + - 首页 + /api/homePage/totalData: + get: + consumes: + - application/json + description: 数据总览 + parameters: + - description: 验证参数Bearer和token空格拼接 + in: header + name: Authorization + required: true + type: string + - description: 年 + in: query + name: year + required: true + type: string + - description: 月 + in: query + name: month + required: true + type: string + produces: + - application/json + responses: + "200": + description: 具体数据 + schema: + $ref: '#/definitions/model.PlatformTotalData' + "400": + description: 具体错误 + schema: + $ref: '#/definitions/md.Response' + summary: 首页-首页-数据总览 + tags: + - 首页 /api/im/addCustomerService: post: consumes: diff --git a/go.mod b/go.mod index a2d097e..d775f24 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( ) require ( - code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241127101621-1959e539cc1f + code.fnuoos.com/EggPlanet/egg_models.git v0.2.1-0.20241127130035-a00c65a48d15 code.fnuoos.com/EggPlanet/egg_system_rules.git v0.0.4-0.20241127101803-8cd39f7b84b2 code.fnuoos.com/go_rely_warehouse/zyos_go_es.git v1.0.1-0.20241118083738-0f22da9ba0be code.fnuoos.com/go_rely_warehouse/zyos_go_mq.git v0.0.5