蛋蛋星球 后台端
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hdl_home_page.go 7.0 KiB

2 周前
2 周前
2 周前
3 周前
3 周前
2 周前
2 周前
3 周前
2 周前
2 周前
1周前
2 周前
1周前
1周前
2 周前
2 周前
2 周前
2 周前
2 周前
2 周前
2 周前
2 周前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. var yData []interface{}
  140. var xData []interface{}
  141. now := time.Now()
  142. dataDb := implement.NewPlatformGrowDataDb(db.Db)
  143. m, has, err := dataDb.PlatformGrowDataGetLastOne()
  144. if err != nil {
  145. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  146. return
  147. }
  148. if !has {
  149. resp := md.GetPriceCurveResp{
  150. XData: xData,
  151. YData: yData,
  152. }
  153. e.OutSuc(c, resp, nil)
  154. return
  155. }
  156. switch kind {
  157. case "1":
  158. // 日
  159. var date = now.AddDate(0, 0, -30).Format("2006-01-02")
  160. 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"))
  161. results, _ := db.Db.QueryString(sql)
  162. for _, v := range results {
  163. tmpDate := utils.TimeParseDateStd(v["date"])
  164. yData = append(yData, v["user_grow_count"])
  165. xData = append(xData, tmpDate.Format("2006-01-02"))
  166. }
  167. yData = append(yData, utils.IntToStr(m.UserGrowCount))
  168. tmpDate := utils.TimeParseDateStd(m.Date)
  169. xData = append(xData, tmpDate.Format("2006-01-02"))
  170. break
  171. case "2":
  172. // 周
  173. var nums = 29
  174. for i := nums; i >= 1; i-- {
  175. var date = now.AddDate(0, 0, -7*i).Format("2006-01-02")
  176. var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" "
  177. sql = fmt.Sprintf(sql, date)
  178. results, _ := db.Db.QueryString(sql)
  179. if results != nil {
  180. year, week, _, _ := utils.GetWeekInfoByDate(results[0]["date"])
  181. yData = append(yData, results[0]["user_grow_count"])
  182. xData = append(xData, fmt.Sprintf("%s年%s周", year, week))
  183. }
  184. }
  185. yData = append(yData, utils.IntToStr(m.UserGrowCount))
  186. year, week, _, _ := utils.GetWeekInfoByDate(m.Date)
  187. xData = append(xData, fmt.Sprintf("%s年%s周", year, week))
  188. break
  189. case "3":
  190. // 月
  191. var nums = 29
  192. for i := nums; i >= 1; i-- {
  193. var date = now.AddDate(0, -i, 0).Format("2006-01-02")
  194. var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" "
  195. sql = fmt.Sprintf(sql, date)
  196. results, _ := db.Db.QueryString(sql)
  197. if results != nil {
  198. tmpDate := utils.TimeParseDateStd(results[0]["date"])
  199. yData = append(yData, results[0]["user_grow_count"])
  200. xData = append(xData, tmpDate.Format("2006-01"))
  201. }
  202. }
  203. yData = append(yData, utils.IntToStr(m.UserGrowCount))
  204. tmpDate := utils.TimeParseDateStd(m.Date)
  205. xData = append(xData, tmpDate.Format("2006-01"))
  206. break
  207. }
  208. resp := md.GetPriceCurveResp{
  209. XData: xData,
  210. YData: yData,
  211. }
  212. e.OutSuc(c, resp, nil)
  213. }