蛋蛋星球 后台端
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 
 

221 righe
6.9 KiB

  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 || !has {
  145. resp := md.GetPriceCurveResp{
  146. XData: xData,
  147. YData: yData,
  148. }
  149. e.OutSuc(c, resp, nil)
  150. return
  151. }
  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. }