Browse Source

update 添加接口参数、返回值

Alvin 8 tháng trước cách đây
mục cha
commit
5e6dd83c66

+ 39 - 3
game/game_cluster/nodes/webadmin/controller/synthesis.go

@@ -171,17 +171,53 @@ func (s *Synthesis) Activity(ctx *gin.Context) {
 
 // 转盘统计
 func (s *Synthesis) Turntable(ctx *gin.Context) {
-	// TODO Turntable
+	var req entity.TurntableReq
+	if err := ctx.ShouldBindJSON(&req); err != nil {
+		common.PackOkResult(ctx, code.ParamError)
+		return
+	}
+
+	resp, err := s.sev.Turntable(req)
+	if err != nil {
+		common.PackOkResult(ctx, err.Code)
+		return
+	}
+
+	common.PackOkResult(ctx, code.OK, resp)
 }
 
 // 资产统计
 func (s *Synthesis) Assets(ctx *gin.Context) {
-	// TODO Assets
+	var req entity.AssetsReq
+	if err := ctx.ShouldBindJSON(&req); err != nil {
+		common.PackOkResult(ctx, code.ParamError)
+		return
+	}
+
+	resp, err := s.sev.Assets(req)
+	if err != nil {
+		common.PackOkResult(ctx, err.Code)
+		return
+	}
+
+	common.PackOkResult(ctx, code.OK, resp)
 }
 
 // 邀请统计
 func (s *Synthesis) Invite(ctx *gin.Context) {
-	// TODO Invite
+	var req entity.InviteReq
+	if err := ctx.ShouldBindJSON(&req); err != nil {
+		common.PackOkResult(ctx, code.ParamError)
+		return
+	}
+
+	resp, err := s.sev.Invite(req)
+	if err != nil {
+		common.PackOkResult(ctx, err.Code)
+		return
+	}
+
+	common.PackOkResult(ctx, code.OK, resp)
 }
 
 // 后台操作记录

+ 65 - 0
game/game_cluster/nodes/webadmin/entity/synthesis.go

@@ -0,0 +1,65 @@
+package entity
+
+type UserListReq struct {
+	Page     int    `json:"page"`
+	Size     int    `json:"size"`
+	UserName string `json:"user_name"` // 用户名
+	NickName string `json:"nick_name"` // 昵称
+}
+
+type UserListResp struct {
+	Details []*UserListDetail `json:"details"`
+	Total   int64             `json:"total"`
+}
+
+type UserListDetail struct {
+	// TODO UserListDetail 用户统计数据详情
+}
+
+type TurntableReq struct {
+	Page     int    `json:"page"`
+	Size     int    `json:"size"`
+	UserName string `json:"user_name"` // 用户名
+	NickName string `json:"nick_name"` // 昵称
+}
+
+type TurntableResp struct {
+	Details []*TurntableDetail `json:"details"`
+	Total   int64              `json:"total"`
+}
+
+type TurntableDetail struct {
+	// TODO TurntableDetail 转盘统计数据详情
+}
+
+type AssetsReq struct {
+	Page     int    `json:"page"`
+	Size     int    `json:"size"`
+	UserName string `json:"user_name"` // 用户名
+	NickName string `json:"nick_name"` // 昵称
+}
+
+type AssetsResp struct {
+	Details []*AssetsDetail `json:"details"`
+	Total   int64           `json:"total"`
+}
+
+type AssetsDetail struct {
+	// TODO AssetsDetail 资产统计数据详情
+}
+
+type InviteReq struct {
+	Page     int    `json:"page"`
+	Size     int    `json:"size"`
+	UserName string `json:"user_name"` // 用户名
+	NickName string `json:"nick_name"` // 昵称
+}
+
+type InviteResp struct {
+	Details []*InviteDetail `json:"details"`
+	Total   int64           `json:"total"`
+}
+
+type InviteDetail struct {
+	// TODO InviteDetail 邀请统计数据详情
+}

+ 0 - 16
game/game_cluster/nodes/webadmin/entity/user_log_daily.go

@@ -30,19 +30,3 @@ type UserLogDailyReq struct {
 	Page      int    `json:"page"`
 	Size      int    `json:"size"`
 }
-
-type UserListReq struct {
-	Page     int    `json:"page"`
-	Size     int    `json:"size"`
-	UserName string `json:"user_name"` // 用户名
-	NickName string `json:"nick_name"` // 昵称
-}
-
-type UserListResp struct {
-	Details []*UserListDetail `json:"details"`
-	Total   int64             `json:"total"`
-}
-
-type UserListDetail struct {
-	// TODO UserListDetail 用户统计数据详情
-}

+ 81 - 1
game/game_cluster/nodes/webadmin/service/synthesis.go

@@ -33,8 +33,70 @@ func NewSynthesis() *Synthesis {
 
 // 统计用户相关信息
 func (s *Synthesis) UserList(req entity.UserListReq) (*entity.UserListResp, *code.Result) {
+	// 验证参数
+	page := req.Page
+	if req.Page <= 0 {
+		page = 1
+	}
+	pageSize := req.Size
+	if req.Size <= 0 {
+		pageSize = 10
+	}
+
+	// 构建查询条件
+	filter := bson.M{}
+	if req.UserName != "" {
+		filter["userName"] = req.UserName
+	}
+	if req.NickName != "" {
+		filter["nickName"] = req.NickName
+	}
+
+	// 设置分页选项
+	findOptions := options.Find()
+	findOptions.SetSkip(int64((page - 1) * pageSize))
+	findOptions.SetLimit(int64(pageSize))
+	findOptions.SetSort(bson.D{{"createTime", -1}})
+
+	collection := mdb.MDB.Collection(constant.CNamePlayer)
+	// 获取总数total
+	count, err := collection.CountDocuments(ctx, filter)
+	if err != nil {
+		mhayaLogger.Warnf("UserList CountDocuments error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
 	// TODO UserList 统计用户相关信息
-	return nil, nil
+	// 查询数据
+	var results []*entity.UserListDetail
+	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
+	defer cancel()
+	cursor, err := collection.Find(ctx, filter, findOptions)
+	if err != nil {
+		mhayaLogger.Warnf("UserList Find error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
+	defer cursor.Close(ctx)
+	// 解析结果
+	for cursor.Next(ctx) {
+		var result entity.UserListDetail
+		if err := cursor.Decode(&result); err != nil {
+			mhayaLogger.Warnf("UserList Decode error:%v", err)
+			return nil, common.NewResult(code.InternalError)
+		}
+		results = append(results, &result)
+	}
+
+	if err := cursor.Err(); err != nil {
+		mhayaLogger.Warnf("UserList cursor error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
+	return &entity.UserListResp{
+		Details: results,
+		Total:   count,
+	}, nil
 }
 
 func (s *Synthesis) FindMDBUserLogDaily(req entity.UserLogDailyReq) (*entity.UserLogDailyResp, *code.Result) {
@@ -669,3 +731,21 @@ func (s *Synthesis) RecordList(req entity.RecordListReq) (*entity.RecordListResp
 		Total:   count,
 	}, nil
 }
+
+// 转盘统计
+func (s *Synthesis) Turntable(req entity.TurntableReq) (*entity.TurntableResp, *code.Result) {
+	// TODO Turntable 转盘统计
+	return nil, nil
+}
+
+// 资产统计
+func (s *Synthesis) Assets(req entity.AssetsReq) (*entity.AssetsResp, *code.Result) {
+	// TODO Assets 资产统计
+	return nil, nil
+}
+
+// 邀请统计
+func (s *Synthesis) Invite(req entity.InviteReq) (*entity.InviteResp, *code.Result) {
+	// TODO Invite 邀请统计
+	return nil, nil
+}