rubbishclass-srv/admin/user-handler.go

41 lines
860 B
Go

package admin
import (
"net/http"
"github.com/gin-gonic/gin"
"yyjishu.com/rubbish-class/user"
)
//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,
})
}