蛋蛋星球 后台端
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

hdl_home_page.go 9.3 KiB

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