迁入,准备其它事情
This commit is contained in:
parent
9ec72a1980
commit
ec465919d3
|
|
@ -1,7 +1,40 @@
|
|||
package admin
|
||||
|
||||
import "github.com/gin-gonic/gin"
|
||||
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,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,25 +7,25 @@ import (
|
|||
"yyjishu.com/rubbish-class/rubbish"
|
||||
)
|
||||
|
||||
type CommunityModel struct {
|
||||
type Community struct {
|
||||
gorm.Model
|
||||
Name string `gorm:"type:varchar(20);"`
|
||||
}
|
||||
|
||||
var once sync.Once
|
||||
|
||||
type Community struct {
|
||||
type CommunityService struct {
|
||||
}
|
||||
|
||||
func NewService() *Community {
|
||||
c := &Community{}
|
||||
func NewService() *CommunityService {
|
||||
c := &CommunityService{}
|
||||
once.Do(c.Init)
|
||||
return c
|
||||
}
|
||||
|
||||
//Map 社区KV获取
|
||||
func (c *Community) Map() (*map[string]uint, error) {
|
||||
var cs []CommunityModel
|
||||
func (c *CommunityService) Map() (*map[string]uint, error) {
|
||||
var cs []Community
|
||||
if err := rubbish.DB.Find(&cs).Error; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
|
@ -37,7 +37,7 @@ func (c *Community) Map() (*map[string]uint, error) {
|
|||
}
|
||||
|
||||
//Create 创建社区信息
|
||||
func (c *Community) Create(model *CommunityModel) error {
|
||||
func (c *CommunityService) Create(model *Community) error {
|
||||
if err := rubbish.DB.Create(model).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -45,6 +45,6 @@ func (c *Community) Create(model *CommunityModel) error {
|
|||
}
|
||||
|
||||
//Init 社区表初始化
|
||||
func (c *Community) Init() {
|
||||
rubbish.DB.AutoMigrate(&CommunityModel{})
|
||||
func (c *CommunityService) Init() {
|
||||
rubbish.DB.AutoMigrate(&Community{})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,7 +22,7 @@ func CommunityListHandler(c *gin.Context) {
|
|||
|
||||
//CommunityCreateHandler 社区创建
|
||||
func CommunityCreateHandler(c *gin.Context) {
|
||||
var model community.CommunityModel
|
||||
var model community.Community
|
||||
if err := c.ShouldBindJSON(&model); err != nil {
|
||||
c.AbortWithStatusJSON(http.StatusBadRequest, nil)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ func main() {
|
|||
rbGroup := r.Group(`/rubbish`)
|
||||
{
|
||||
rbGroup.GET(`/community/list`, public.CommunityListHandler) //社区列表,OK
|
||||
rbGroup.POST(`/community/create`, public.CommunityCreateHandler) //社区列表,OK
|
||||
rbGroup.POST(`/community/create`, public.CommunityCreateHandler) //社区创建,测试维护使用,OK
|
||||
rbGroup.StaticFS(`/video`, http.Dir("./data"))
|
||||
|
||||
authorized := rbGroup.Group(`/admin`, gin.BasicAuth(gin.Accounts{
|
||||
|
|
@ -51,8 +51,8 @@ func main() {
|
|||
|
||||
userGroup := authorized.Group(`/user`)
|
||||
{
|
||||
userGroup.GET(`/stat/:commid`, admin.UserStatHandler)
|
||||
userGroup.GET(`/stat`, admin.UserStatHandler) //统计当天活跃用户、当天新增用户、历史用户
|
||||
userGroup.GET(`/stat/:commid`, admin.UserStatHandler) //统计社区当天的活跃用户数据
|
||||
userGroup.GET(`/stat`, admin.UserStatHandler) //统计当天活跃用户、当天新增用户、历史用户
|
||||
}
|
||||
integralGroup := authorized.Group(`/integral`) //积分
|
||||
{
|
||||
|
|
|
|||
10
service.rest
10
service.rest
|
|
@ -12,14 +12,20 @@ POST {{url}}/community/create HTTP/1.1
|
|||
Content-Type: application/json
|
||||
|
||||
{
|
||||
"name":"aaa小区"
|
||||
"name":"ddd小区"
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
|
||||
GET {{url}}/community/list HTTP/1.1
|
||||
|
||||
### 用户统计
|
||||
GET {{url}}/admin/user/stat HTTP/1.1
|
||||
Authorization: Basic YWRtaW46YWRtaW4=
|
||||
|
||||
### 社区用户统计
|
||||
GET {{url}}/admin/user/stat/11111 HTTP/1.1
|
||||
Authorization: Basic YWRtaW46YWRtaW4=
|
||||
|
||||
############################### 以下微信小程序 ########################################
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package user
|
||||
|
||||
import "github.com/jinzhu/gorm"
|
||||
|
||||
type User struct {
|
||||
gorm.Model
|
||||
Username string `gorm:"type:varchar(20);"`
|
||||
}
|
||||
|
|
@ -5,8 +5,44 @@ import (
|
|||
"mime/multipart"
|
||||
"os"
|
||||
"strings"
|
||||
"sync"
|
||||
|
||||
"yyjishu.com/rubbish-class/rubbish"
|
||||
)
|
||||
|
||||
var once sync.Once
|
||||
|
||||
type UserService struct {
|
||||
}
|
||||
|
||||
func NewService() *UserService {
|
||||
u := &UserService{}
|
||||
once.Do(u.Init)
|
||||
return u
|
||||
}
|
||||
|
||||
//StatTotal 人员总数统计服务
|
||||
func (u *UserService) StatTotal(communityid *string) (*int, error) {
|
||||
r := 1200
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
//StatNewer 统计当天新增
|
||||
func (u *UserService) StatNewer(communityid *string) (*int, error) {
|
||||
r := 12
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
//StatActive 统计当天活跃
|
||||
func (u *UserService) StatActive(communityid *string) (*int, error) {
|
||||
r := 385
|
||||
return &r, nil
|
||||
}
|
||||
|
||||
func (u *UserService) Init() {
|
||||
rubbish.DB.AutoMigrate(&User{})
|
||||
}
|
||||
|
||||
//SaveVideoFileService 文件上传服务
|
||||
func SaveVideoFileService(file *multipart.FileHeader, openid *string) (*string, error) {
|
||||
p := "./video/" + *openid
|
||||
|
|
|
|||
Loading…
Reference in New Issue