蛋蛋星球 后台端

hdl_home_page.go 7.0 KiB

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