蛋蛋星球 后台端
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

hdl_home_page.go 6.0 KiB

1 week ago
6 days ago
1 week ago
6 days ago
1 week ago
6 days ago
1 week ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  1. package hdl
  2. import (
  3. "applet/app/db"
  4. "applet/app/e"
  5. "applet/app/utils"
  6. "code.fnuoos.com/EggPlanet/egg_models.git/src/implement"
  7. "code.fnuoos.com/EggPlanet/egg_models.git/src/model"
  8. "fmt"
  9. "github.com/gin-gonic/gin"
  10. "strings"
  11. "time"
  12. )
  13. type TotalDataResp struct {
  14. TotalUserCount int `json:"total_user_count"` // 平台总用户数
  15. VerifiedUserCount int `json:"verified_user_count"` // 已认证用户数
  16. NoSignInUserCount int `json:"no_sign_in_user_count"` // 未签到用户数
  17. TotalWithdrawAmount string `json:"total_withdraw_amount"` //已提现累计金额
  18. Year string `json:"year"` // 年份
  19. Month string `json:"month"` // 月份
  20. }
  21. // GetTotalData
  22. // @Summary 首页-首页-数据总览
  23. // @Tags 首页
  24. // @Description 数据总览
  25. // @Accept json
  26. // @Produce json
  27. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  28. // @Param year query string true "年"
  29. // @Param month query string true "月"
  30. // @Success 200 {object} TotalDataResp "具体数据"
  31. // @Failure 400 {object} md.Response "具体错误"
  32. // @Router /api/homePage/totalData [GET]
  33. func GetTotalData(c *gin.Context) {
  34. year := c.Query("year")
  35. month := c.Query("month")
  36. if year == "" || month == "" {
  37. nowStr := time.Now().Format("2006-01-02")
  38. year = strings.Split(nowStr, "-")[0]
  39. month = strings.Split(nowStr, "-")[1]
  40. }
  41. dataDb := implement.NewPlatformTotalDataDb(db.Db)
  42. data, err := dataDb.PlatformTotalDataGetOneByTime(year, month)
  43. if err != nil {
  44. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  45. return
  46. }
  47. resp := TotalDataResp{
  48. TotalUserCount: data.TotalUserCount,
  49. VerifiedUserCount: data.VerifiedUserCount,
  50. NoSignInUserCount: data.NoSignInUserCount,
  51. TotalWithdrawAmount: data.TotalWithdrawAmount,
  52. Year: data.Year,
  53. Month: data.Month,
  54. }
  55. e.OutSuc(c, resp, nil)
  56. }
  57. type GetActiveDataResp struct {
  58. Today *model.PlatformActiveData `json:"today"` // 今日数据
  59. Yesterday *model.PlatformActiveData `json:"yesterday"` // 昨日数据
  60. }
  61. // GetActiveData
  62. // @Summary 首页-首页-活跃数据
  63. // @Tags 首页
  64. // @Description 活跃数据
  65. // @Accept json
  66. // @Produce json
  67. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  68. // @Success 200 {object} GetActiveDataResp "具体数据"
  69. // @Failure 400 {object} md.Response "具体错误"
  70. // @Router /api/homePage/activeData [GET]
  71. func GetActiveData(c *gin.Context) {
  72. nowStr := time.Now().Format("2006-01-02")
  73. yesterdayStr := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  74. activityDb := implement.NewPlatformActiveDataDb(db.Db)
  75. today, err := activityDb.PlatformActiveDataGetOneByParams(map[string]interface{}{"key": "date", "value": nowStr})
  76. if err != nil {
  77. e.OutErr(c, e.ERR_DB_ORM, err)
  78. }
  79. yesterday, err := activityDb.PlatformActiveDataGetOneByParams(map[string]interface{}{"key": "date", "value": yesterdayStr})
  80. if err != nil {
  81. e.OutErr(c, e.ERR_DB_ORM, err)
  82. }
  83. resp := GetActiveDataResp{
  84. Today: today,
  85. Yesterday: yesterday,
  86. }
  87. e.OutSuc(c, resp, nil)
  88. }
  89. // GetGrowData
  90. // @Summary 首页-首页-用户增长曲线
  91. // @Tags 首页
  92. // @Description 用户增长曲线
  93. // @Accept json
  94. // @Produce json
  95. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  96. // @Param kind query string false "1:按天 2:按周 3:按小时"
  97. // @Success 200 {object} md.GetPriceCurveResp "具体数据"
  98. // @Failure 400 {object} md.Response "具体错误"
  99. // @Router /api/homePage/growData [GET]
  100. func GetGrowData(c *gin.Context) {
  101. kind := c.DefaultQuery("kind", "1")
  102. now := time.Now()
  103. dataDb := implement.NewPlatformGrowDataDb(db.Db)
  104. m, has, err := dataDb.PlatformGrowDataGetLastOne()
  105. if err != nil {
  106. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  107. return
  108. }
  109. if !has {
  110. e.OutErr(c, e.ERR_NO_DATA, "未查询到数据")
  111. return
  112. }
  113. var yData []interface{}
  114. var xData []interface{}
  115. switch kind {
  116. case "1":
  117. // 日
  118. var date = now.AddDate(0, 0, -30).Format("2006-01-02")
  119. 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"))
  120. results, _ := db.Db.QueryString(sql)
  121. for _, v := range results {
  122. tmpDate := utils.TimeParseStd(v["date"])
  123. yData = append(yData, v["user_grow_count"])
  124. xData = append(xData, tmpDate.Format("2006-01-02"))
  125. }
  126. yData = append(yData, m.UserGrowCount)
  127. tmpDate := utils.TimeParseStd(m.Date)
  128. xData = append(xData, tmpDate.Format("2006-01-02"))
  129. break
  130. case "2":
  131. // 周
  132. var nums = 29
  133. for i := nums; i >= 1; i-- {
  134. var date = now.AddDate(0, 0, -7*i).Format("2006-01-02")
  135. var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" "
  136. sql = fmt.Sprintf(sql, date)
  137. results, _ := db.Db.QueryString(sql)
  138. if results != nil {
  139. year, week, _, _ := utils.GetWeekInfo(results[0]["date"])
  140. yData = append(yData, results[0]["user_grow_count"])
  141. xData = append(xData, fmt.Sprintf("%s年%s周", year, week))
  142. }
  143. }
  144. yData = append(yData, m.UserGrowCount)
  145. year, week, _, _ := utils.GetWeekInfo(m.Date)
  146. xData = append(xData, fmt.Sprintf("%s年%s周", year, week))
  147. break
  148. case "3":
  149. // 月
  150. var nums = 29
  151. for i := nums; i >= 1; i-- {
  152. var date = now.AddDate(0, -i, 0).Format("2006-01-02")
  153. var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" "
  154. sql = fmt.Sprintf(sql, date)
  155. results, _ := db.Db.QueryString(sql)
  156. if results != nil {
  157. tmpDate := utils.TimeParseStd(results[0]["date"])
  158. yData = append(yData, results[0]["user_grow_count"])
  159. xData = append(xData, tmpDate.Format("2006-01"))
  160. }
  161. }
  162. yData = append(yData, m.UserGrowCount)
  163. tmpDate := utils.TimeParseStd(m.Date)
  164. xData = append(xData, tmpDate.Format("2006-01"))
  165. break
  166. }
  167. }