rubbishclass-srv/admin/user-handler.go

41 lines
860 B
Go
Raw Permalink Normal View History

2020-03-24 07:12:31 +00:00
package admin
2020-03-30 06:27:05 +00:00
import (
"net/http"
2020-03-24 07:12:31 +00:00
2020-03-30 06:27:05 +00:00
"github.com/gin-gonic/gin"
"yyjishu.com/rubbish-class/user"
)
2020-03-24 07:12:31 +00:00
2020-03-30 06:27:05 +00:00
//UserStatHandler 统计社区当天的活跃用户数据
func UserStatHandler(c *gin.Context) {
communityID := c.Param("commid")
service := user.NewService()
total, err := service.StatTotal(&communityID)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"err": err.Error(),
})
return
}
active, err := service.StatActive(&communityID)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"err": err.Error(),
})
return
}
newer, err := service.StatNewer(&communityID)
if err != nil {
c.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{
"err": err.Error(),
})
return
}
c.JSON(http.StatusOK, gin.H{
"total": total,
"active": active,
"newer": newer,
})
2020-03-24 07:12:31 +00:00
}