蛋蛋星球 后台端
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

292 строки
9.4 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. "code.fnuoos.com/EggPlanet/egg_system_rules.git/enum"
  11. "fmt"
  12. "github.com/gin-gonic/gin"
  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. //TODO 暂时都展示全部的
  49. startAt := "2024-12-01"
  50. endAt := time.Now().Format("2006-01-02")
  51. //year := req.Year
  52. //month := req.Month
  53. //startAt := fmt.Sprintf("%s-%s-01", year, month)
  54. //dateStd := utils.TimeParseDateStd(startAt)
  55. //endAt := dateStd.AddDate(0, 1, 0).Format("2006-01-02")
  56. userDb := implement.NewUserDb(db.Db)
  57. userCount, err := userDb.UserCountByDate(startAt, endAt)
  58. if err != nil {
  59. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  60. return
  61. }
  62. certificateDb := implement.NewUserCertificateDb(db.Db)
  63. certificateCount, err := certificateDb.UserCertificateCountByDate(startAt, endAt)
  64. if err != nil {
  65. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  66. return
  67. }
  68. // 签到人数
  69. activityDb := implement.NewEggEnergyUserActivityDb(db.Db)
  70. signInCount, err := activityDb.EggEnergyUserActivityCountByDate(startAt, endAt)
  71. if err != nil {
  72. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  73. return
  74. }
  75. // 已提现累计金额
  76. flowDb := implement.NewUserWalletFlowDb(db.Db)
  77. sum, err := flowDb.UserWalletFlowGetSum(startAt, endAt, int(enum.UserWithdrawApply))
  78. if err != nil {
  79. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  80. return
  81. }
  82. resp := TotalDataResp{
  83. TotalUserCount: int(userCount),
  84. VerifiedUserCount: int(certificateCount),
  85. NoSignInUserCount: int(userCount - signInCount),
  86. TotalWithdrawAmount: utils.Float64ToStr(sum),
  87. Year: req.Year,
  88. Month: req.Month,
  89. }
  90. e.OutSuc(c, resp, nil)
  91. }
  92. type GetActiveDataResp struct {
  93. Today *model.PlatformActiveData `json:"today"` // 今日数据
  94. Yesterday *model.PlatformActiveData `json:"yesterday"` // 昨日数据
  95. }
  96. // GetActiveData
  97. // @Summary 首页-首页-活跃数据
  98. // @Tags 首页
  99. // @Description 活跃数据
  100. // @Accept json
  101. // @Produce json
  102. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  103. // @Success 200 {object} GetActiveDataResp "具体数据"
  104. // @Failure 400 {object} md.Response "具体错误"
  105. // @Router /api/homePage/activeData [GET]
  106. func GetActiveData(c *gin.Context) {
  107. nowStr := time.Now().Format("2006-01-02")
  108. todayStartAt := fmt.Sprintf("%s 00:00:00", nowStr)
  109. todayEndAt := fmt.Sprintf("%s 23:59:59", nowStr)
  110. yesterdayStr := time.Now().AddDate(0, 0, -1).Format("2006-01-02")
  111. yesterdayStartAt := fmt.Sprintf("%s 00:00:00", yesterdayStr)
  112. yesterdayEndAt := fmt.Sprintf("%s 23:59:59", yesterdayStr)
  113. userDb := implement.NewUserDb(db.Db)
  114. todayNewUserCount, err := userDb.UserCountByDate(todayStartAt, todayEndAt)
  115. if err != nil {
  116. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  117. return
  118. }
  119. yesterdayNewUserCount, err := userDb.UserCountByDate(yesterdayStartAt, yesterdayEndAt)
  120. if err != nil {
  121. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  122. return
  123. }
  124. activityDb := implement.NewEggEnergyUserActivityDb(db.Db)
  125. todayActivityCount, err := activityDb.EggEnergyUserActivityCountByDate(nowStr, nowStr)
  126. if err != nil {
  127. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  128. return
  129. }
  130. yesterdayActivityCount, err := activityDb.EggEnergyUserActivityCountByDate(yesterdayStr, yesterdayStr)
  131. if err != nil {
  132. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  133. return
  134. }
  135. flowDb := implement.NewUserWalletFlowDb(db.Db)
  136. todayWithdrawAmount, err := flowDb.UserWalletFlowGetSum(todayStartAt, todayEndAt, int(enum.UserWithdrawApply))
  137. if err != nil {
  138. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  139. return
  140. }
  141. yesterdayWithdrawAmount, err := flowDb.UserWalletFlowGetSum(yesterdayStartAt, yesterdayEndAt, int(enum.UserWithdrawApply))
  142. if err != nil {
  143. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  144. return
  145. }
  146. todayWithdrawUserCount, err := flowDb.UserWalletFlowUserCount(todayStartAt, todayEndAt, int(enum.UserWithdrawApply))
  147. if err != nil {
  148. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  149. return
  150. }
  151. yesterdayWithdrawUserCount, err := flowDb.UserWalletFlowUserCount(yesterdayStartAt, yesterdayEndAt, int(enum.UserWithdrawApply))
  152. if err != nil {
  153. e.OutErr(c, e.ERR_DB_ORM, err.Error())
  154. return
  155. }
  156. today := model.PlatformActiveData{
  157. NewUserCount: int(todayNewUserCount),
  158. UserSignInCount: int(todayActivityCount),
  159. WithdrawAmountCount: utils.Float64ToStr(todayWithdrawAmount),
  160. WithdrawUserCount: int(todayWithdrawUserCount),
  161. Date: nowStr,
  162. }
  163. yesterday := model.PlatformActiveData{
  164. NewUserCount: int(yesterdayNewUserCount),
  165. UserSignInCount: int(yesterdayActivityCount),
  166. WithdrawAmountCount: utils.Float64ToStr(yesterdayWithdrawAmount),
  167. WithdrawUserCount: int(yesterdayWithdrawUserCount),
  168. Date: yesterdayStr,
  169. }
  170. resp := GetActiveDataResp{
  171. Today: &today,
  172. Yesterday: &yesterday,
  173. }
  174. e.OutSuc(c, resp, nil)
  175. }
  176. type GetGrowDataReq struct {
  177. Kind string `form:"kind" binding:"required"`
  178. }
  179. // GetGrowData
  180. // @Summary 首页-首页-用户增长曲线
  181. // @Tags 首页
  182. // @Description 用户增长曲线
  183. // @Accept json
  184. // @Produce json
  185. // @param Authorization header string true "验证参数Bearer和token空格拼接"
  186. // @Param kind query string false "1:按天 2:按周 3:按小时"
  187. // @Success 200 {object} md.GetPriceCurveResp "具体数据"
  188. // @Failure 400 {object} md.Response "具体错误"
  189. // @Router /api/homePage/growData [GET]
  190. func GetGrowData(c *gin.Context) {
  191. var req GetGrowDataReq
  192. err := c.ShouldBindQuery(&req)
  193. if err != nil {
  194. err = svc.HandleValidateErr(err)
  195. err1 := err.(e.E)
  196. e.OutErr(c, err1.Code, err1.Error())
  197. return
  198. }
  199. kind := req.Kind
  200. var yData []interface{}
  201. var xData []interface{}
  202. now := time.Now()
  203. dataDb := implement.NewPlatformGrowDataDb(db.Db)
  204. m, has, err := dataDb.PlatformGrowDataGetLastOne()
  205. if err != nil || !has {
  206. resp := md.GetPriceCurveResp{
  207. XData: xData,
  208. YData: yData,
  209. }
  210. e.OutSuc(c, resp, nil)
  211. return
  212. }
  213. switch kind {
  214. case "1":
  215. // 日
  216. var date = now.AddDate(0, 0, -30).Format("2006-01-02")
  217. 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"))
  218. results, _ := db.Db.QueryString(sql)
  219. for _, v := range results {
  220. tmpDate := utils.TimeParseDateStd(v["date"])
  221. yData = append(yData, v["user_grow_count"])
  222. xData = append(xData, tmpDate.Format("2006-01-02"))
  223. }
  224. yData = append(yData, utils.IntToStr(m.UserGrowCount))
  225. tmpDate := utils.TimeParseDateStd(m.Date)
  226. xData = append(xData, tmpDate.Format("2006-01-02"))
  227. break
  228. case "2":
  229. // 周
  230. var nums = 29
  231. for i := nums; i >= 1; i-- {
  232. var date = now.AddDate(0, 0, -7*i).Format("2006-01-02")
  233. var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" "
  234. sql = fmt.Sprintf(sql, date)
  235. results, _ := db.Db.QueryString(sql)
  236. if results != nil {
  237. year, week, _, _ := utils.GetWeekInfoByDate(results[0]["date"])
  238. yData = append(yData, results[0]["user_grow_count"])
  239. xData = append(xData, fmt.Sprintf("%s年%s周", year, week))
  240. }
  241. }
  242. yData = append(yData, utils.IntToStr(m.UserGrowCount))
  243. year, week, _, _ := utils.GetWeekInfoByDate(m.Date)
  244. xData = append(xData, fmt.Sprintf("%s年%s周", year, week))
  245. break
  246. case "3":
  247. // 月
  248. var nums = 29
  249. for i := nums; i >= 1; i-- {
  250. var date = now.AddDate(0, -i, 0).Format("2006-01-02")
  251. var sql = "SELECT user_grow_count,date FROM `platform_grow_data` WHERE DATE = \"%s\" "
  252. sql = fmt.Sprintf(sql, date)
  253. results, _ := db.Db.QueryString(sql)
  254. if results != nil {
  255. tmpDate := utils.TimeParseDateStd(results[0]["date"])
  256. yData = append(yData, results[0]["user_grow_count"])
  257. xData = append(xData, tmpDate.Format("2006-01"))
  258. }
  259. }
  260. yData = append(yData, utils.IntToStr(m.UserGrowCount))
  261. tmpDate := utils.TimeParseDateStd(m.Date)
  262. xData = append(xData, tmpDate.Format("2006-01"))
  263. break
  264. }
  265. resp := md.GetPriceCurveResp{
  266. XData: xData,
  267. YData: yData,
  268. }
  269. e.OutSuc(c, resp, nil)
  270. }