3 Komitmen 1ae132ac6c ... 20dbfec70b

Pembuat SHA1 Pesan Tanggal
  Alvin 20dbfec70b update 新增接口:近30天每天的U提现 新注册用户数 8 bulan lalu
  Alvin 3fb90e7c16 update 删除导致程序启动慢的无效的数据库连接 8 bulan lalu
  Alvin 378be7a447 update 提现记录用户昵称支持模糊搜索 8 bulan lalu

+ 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)

+ 61 - 1
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)
@@ -178,7 +238,7 @@ func (s *Synthesis) FindWithdrawal(req *entity.UserWithdrawalReq) ([]*entity.Use
 		filter["userName"] = req.UserName
 	}
 	if req.NickName != "" {
-		filter["nickName"] = req.NickName
+		filter["nickName"] = bson.M{"$regex": escapeRegex(req.NickName), "$options": "i"}
 	}
 	if req.ID != "" {
 		filter["_id"], _ = primitive.ObjectIDFromHex(req.ID)

+ 0 - 2
game/game_cluster/nodes/webadmin/web/web.go

@@ -9,7 +9,6 @@ import (
 	checkCenter "github.com/mhaya/game/game_cluster/internal/component/check_center"
 	"github.com/mhaya/game/game_cluster/internal/data"
 	"github.com/mhaya/game/game_cluster/internal/mdb"
-	mdb2 "github.com/mhaya/game/game_cluster/nodes/webadmin/mdb"
 	"github.com/mhaya/game/game_cluster/nodes/webadmin/router"
 )
 
@@ -34,7 +33,6 @@ func main() {
 	app.AddActors(
 		&mdb.ActorDB{},
 	)
-	mdb2.InitializeMongoDB()
 	// 启动mhaya引擎
 	app.Startup()
 }