Quellcode durchsuchen

update 新增接口:近30天每天的U提现 新注册用户数

Alvin vor 8 Monaten
Ursprung
Commit
20dbfec70b

+ 25 - 0
game/game_cluster/nodes/webadmin/controller/synthesis.go

@@ -42,6 +42,31 @@ func (s *Synthesis) FindUserLogDaily(ctx *gin.Context) {
 	})
 }
 
+// FindUserLogHistory 近30天每天的U提现 新注册用户数
+func (s *Synthesis) FindUserLogHistory(ctx *gin.Context) {
+	req := &entity.UserLogDailyReq{}
+	if err := ctx.ShouldBindJSON(req); err != nil {
+		ctx.JSON(200, gin.H{
+			"code": 400,
+			"msg":  err.Error(),
+		})
+		return
+	}
+	resp, err := s.sev.FindUserLogHistory()
+	if err != nil {
+		ctx.JSON(200, gin.H{
+			"code": 400,
+			"msg":  err.Error(),
+		})
+		return
+	}
+	ctx.JSON(200, gin.H{
+		"code": 200,
+		"msg":  "success",
+		"data": resp,
+	})
+}
+
 // FindUserLogTotal 查询总提现数量,总注册人数,
 func (s *Synthesis) FindUserLogTotal(ctx *gin.Context) {
 	resp, err := s.sev.FindMDBUserLogTotal()

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

@@ -31,3 +31,9 @@ type UserLogTotalResp struct {
 	Registered int     `bson:"registered" json:"registered"` // registered: 总注册人数
 	UCashout   float64 `bson:"u_cashout" json:"u_cashout"`   // u_cashout: 全服U的提现总值
 }
+
+type UserLogHistoryResp struct {
+	Timestamp  int64   `bson:"daily" json:"timestamp"`       // timestamp: 数据记录的时间戳
+	Registered int     `bson:"registered" json:"registered"` // registered: 新用户注册的数量
+	UCashout   float64 `bson:"u_cashout" json:"u_cashout"`   // u_cashout: 全服U的提现总值
+}

+ 1 - 0
game/game_cluster/nodes/webadmin/router/router.go

@@ -40,6 +40,7 @@ func (c *Controller) InitApiRouter(u *gin.RouterGroup) {
 	u.Use(Auth())
 	u.POST("/user/log/total", controller.NewSynthesis().FindUserLogTotal)
 	u.POST("/user/log/daily", controller.NewSynthesis().FindUserLogDaily)
+	u.POST("/user/log/history", controller.NewSynthesis().FindUserLogHistory)
 	u.POST("/user/retention", controller.NewSynthesis().FindUserRetention)
 	u.POST("/user/country", controller.NewSynthesis().FindUserCountryCount)
 	u.POST("/user/withdrawal", controller.NewSynthesis().FindWithdrawal)

+ 60 - 0
game/game_cluster/nodes/webadmin/service/synthesis.go

@@ -9,6 +9,7 @@ import (
 	"strconv"
 	"time"
 
+	mhayaTime "github.com/mhaya/extend/time"
 	"github.com/mhaya/game/game_cluster/internal/constant"
 	"github.com/mhaya/game/game_cluster/internal/mdb"
 	"github.com/mhaya/game/game_cluster/internal/mdb/models"
@@ -166,6 +167,65 @@ func (s *Synthesis) FindMDBUserLogTotal() (*entity.UserLogTotalResp, error) {
 	}, nil
 }
 
+// FindUserLogHistory 近30天每天的U提现 新注册用户数
+func (s *Synthesis) FindUserLogHistory() ([]*entity.UserLogHistoryResp, error) {
+	collection := mdb.MDB.Collection("playerDailyRecord")
+
+	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
+	defer cancel()
+
+	filter := bson.M{}
+	filter["daily"] = bson.M{
+		"$gte": mhayaTime.Now().StartOfDay().Add(-30 * 24 * time.Hour).Unix(),
+		"$lte": mhayaTime.Now().Unix(),
+	}
+
+	cursor, err := collection.Find(ctx, filter, nil)
+	if err != nil {
+		return nil, err
+	}
+	defer cursor.Close(ctx)
+
+	// 解析查询结果
+	var results []*entity.UserLogHistoryResp
+
+	for cursor.Next(ctx) {
+		var result *entity.UserLogHistoryResp
+		err := cursor.Decode(&result)
+		if err != nil {
+			return nil, err
+		}
+		results = append(results, result)
+	}
+
+	// 合并每日的数据
+	allPlatformRecordMap := make(map[int64]*entity.UserLogHistoryResp)
+	for _, result := range results {
+		item, exist := allPlatformRecordMap[result.Timestamp]
+		if !exist {
+			allPlatformRecordMap[result.Timestamp] = &entity.UserLogHistoryResp{
+				Timestamp:  result.Timestamp,
+				Registered: result.Registered,
+				UCashout:   result.UCashout,
+			}
+
+			continue
+		}
+
+		item.Registered += result.Registered
+		item.UCashout += result.UCashout
+		allPlatformRecordMap[result.Timestamp] = item
+	}
+
+	results = make([]*entity.UserLogHistoryResp, 0, len(allPlatformRecordMap))
+
+	for _, v := range allPlatformRecordMap {
+		results = append(results, v)
+	}
+
+	return results, nil
+}
+
 // FindWithdrawal 根据请求查询提现记录
 func (s *Synthesis) FindWithdrawal(req *entity.UserWithdrawalReq) ([]*entity.UserWithdrawalResp, int64, error) {
 	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)