Browse Source

Merge branch 'refs/heads/dev_origin'

zhengtao 8 months ago
parent
commit
329386e8f9

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

@@ -42,6 +42,23 @@ func (s *Synthesis) FindUserLogDaily(ctx *gin.Context) {
 	})
 }
 
+// FindUserLogTotal 查询总提现数量,总注册人数,
+func (s *Synthesis) FindUserLogTotal(ctx *gin.Context) {
+	resp, err := s.sev.FindMDBUserLogTotal()
+	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,
+	})
+}
+
 // FindUserRetention 查询用户留存
 func (s *Synthesis) FindUserRetention(ctx *gin.Context) {
 	req := &entity.UserRetentionReq{}

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

@@ -26,3 +26,8 @@ type UserLogDailyReq struct {
 	Size      int    `json:"size"`
 	Total     int64  `json:"total"`
 }
+
+type UserLogTotalResp struct {
+	Registered int     `bson:"registered" json:"registered"` // registered: 总注册人数
+	UCashout   float64 `bson:"u_cashout" json:"u_cashout"`   // u_cashout: 全服U的提现总值
+}

+ 10 - 7
game/game_cluster/nodes/webadmin/entity/user_withdrawal.go

@@ -17,13 +17,16 @@ type UserWithdrawalResp struct {
 }
 
 type UserWithdrawalReq struct {
-	UserName  string `json:"user_name" bson:"user_name"` // 用户ID
-	NickName  string `json:"nick_name" bson:"nick_name"` // 昵称
-	ID        string `json:"id" bson:"id"`               // ID
-	StartTime int64  `json:"start_time"`                 // 开始时间
-	EndTime   int64  `json:"end_time"`                   // 结束时间
-	Page      int    `json:"page"`                       // 页码
-	Size      int    `json:"size"`                       // 每页数量
+	UserName   string `json:"user_name" bson:"user_name"`   // 用户ID
+	NickName   string `json:"nick_name" bson:"nick_name"`   // 昵称
+	ID         string `json:"id" bson:"id"`                 // ID
+	StartTime  int64  `json:"start_time"`                   // 开始时间
+	EndTime    int64  `json:"end_time"`                     // 结束时间
+	Page       int    `json:"page"`                         // 页码
+	Size       int    `json:"size"`                         // 每页数量
+	Withdrawal string `json:"withdrawal" bson:"withdrawal"` // 提现 1:提现成功 2:提现中 3:提现失败 4:拒绝提现
+	Status     string `json:"status" bson:"status"`         // 0:未审核 1:审核通过 2:审核失败
+	Address    string `json:"address" bson:"address"`       // 地址
 }
 
 type UserWithdrawalStatus struct {

+ 120 - 0
game/game_cluster/nodes/webadmin/fakedata/main.go

@@ -0,0 +1,120 @@
+package main
+
+import (
+	"context"
+	"fmt"
+	"math/rand"
+	"strconv"
+	"time"
+
+	mhayaTime "github.com/mhaya/extend/time"
+	"github.com/mhaya/game/game_cluster/internal/constant"
+	"github.com/mhaya/game/game_cluster/internal/mdb/models"
+	"go.mongodb.org/mongo-driver/mongo"
+	"go.mongodb.org/mongo-driver/mongo/options"
+	"go.mongodb.org/mongo-driver/mongo/readpref"
+)
+
+type NameData struct {
+	User_name string
+	Nick_name string
+	Balance   int
+}
+
+func main() {
+	uri := "mongodb://127.0.0.1:27017"
+	dbName := "db_mhaya"
+
+	o := options.Client().ApplyURI(uri)
+	if err := o.Validate(); err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
+	defer cancel()
+
+	client, err := mongo.Connect(ctx, o)
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	err = client.Ping(context.Background(), readpref.Primary())
+	if err != nil {
+		fmt.Println(err)
+		return
+	}
+
+	db := client.Database(dbName)
+
+	// 写入提现假数据
+	addresss := make([]string, 0, 8)
+	for i := 0; i < 5; i++ {
+		addresss = append(addresss, "address"+strconv.Itoa(i+1))
+	}
+
+	nameDatas := make([]*NameData, 0, 8)
+	for i := 0; i < 5; i++ {
+		nameDatas = append(nameDatas, &NameData{
+			User_name: "test" + strconv.Itoa(i),
+			Nick_name: "test" + strconv.Itoa(i),
+			Balance:   1000000,
+		})
+	}
+
+	for i := 0; i < 100; i++ {
+		index := rand.Intn(len(nameDatas))
+		nameDataObj := nameDatas[index]
+
+		amount := rand.Int63n(500)
+		nameDataObj.Balance -= int(amount)
+
+		_, err = db.Collection(constant.CNameCashOutRecord).InsertOne(context.Background(), &models.CashOutRecord{
+			UserName: nameDataObj.User_name,
+			NickName: nameDataObj.Nick_name,
+			Status: func() int {
+				if rand.Int63n(3) == 1 {
+					return 1
+				}
+
+				if rand.Int63n(3) == 2 {
+					return 2
+				}
+
+				return 0
+			}(), // 0:未审核 1:审核通过 2:审核失败
+			Type:        1,
+			AfterAmount: nameDataObj.Balance,
+			Amount:      int(amount),
+			Address: func() string {
+				index := rand.Intn(len(addresss))
+				return addresss[index]
+			}(),
+			Withdrawal: func() int {
+				if rand.Int63n(5) == 1 {
+					return 1
+				}
+
+				if rand.Int63n(5) == 2 {
+					return 2
+				}
+
+				if rand.Int63n(5) == 3 {
+					return 3
+				}
+
+				if rand.Int63n(5) == 4 {
+					return 4
+				}
+
+				return 0
+			}(), // 提现 0 :未体现 1:提现成功 2:提现中 3:提现失败 4:拒绝提现
+			CreateAt: mhayaTime.Now().Unix(),
+		})
+		if err != nil {
+			fmt.Println(err)
+			return
+		}
+	}
+}

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

@@ -38,6 +38,7 @@ func (c *Controller) SetRouter() {
 
 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/retention", controller.NewSynthesis().FindUserRetention)
 	u.POST("/user/country", controller.NewSynthesis().FindUserCountryCount)

+ 74 - 3
game/game_cluster/nodes/webadmin/service/synthesis.go

@@ -5,6 +5,8 @@ import (
 	"errors"
 	"log"
 	"math"
+	"sort"
+	"strconv"
 	"time"
 
 	"github.com/mhaya/game/game_cluster/internal/constant"
@@ -120,6 +122,50 @@ func (s *Synthesis) FindMDBUserLogDaily(req *entity.UserLogDailyReq) ([]entity.U
 	return results, nil
 }
 
+// FindUserLogTotal 查询总提现数量,总注册人数,
+func (s *Synthesis) FindMDBUserLogTotal() (*entity.UserLogTotalResp, 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": 0,
+	}
+
+	cursor, err := collection.Find(ctx, filter, nil)
+	if err != nil {
+		return nil, err
+	}
+	defer cursor.Close(ctx)
+
+	// 解析查询结果
+	var results []entity.UserLogDailyResp
+
+	for cursor.Next(ctx) {
+		var result entity.UserLogDailyResp
+		err := cursor.Decode(&result)
+		if err != nil {
+			return nil, err
+		}
+		results = append(results, result)
+	}
+
+	registerCount := 0
+	var uCashoutCount float64
+
+	for _, v := range results {
+		registerCount += v.Registered
+		uCashoutCount += v.UCashout
+	}
+
+	return &entity.UserLogTotalResp{
+		Registered: registerCount,
+		UCashout:   uCashoutCount,
+	}, nil
+}
+
 // FindWithdrawal 根据请求查询提现记录
 func (s *Synthesis) FindWithdrawal(req *entity.UserWithdrawalReq) ([]*entity.UserWithdrawalResp, int64, error) {
 	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
@@ -145,6 +191,26 @@ func (s *Synthesis) FindWithdrawal(req *entity.UserWithdrawalReq) ([]*entity.Use
 		}
 	}
 
+	if req.Withdrawal != "" {
+		withdrawal, err := strconv.Atoi(req.Withdrawal)
+		if err != nil {
+			return nil, 0, err
+		}
+		filter["withdrawal"] = withdrawal
+	}
+
+	if req.Address != "" {
+		filter["address"] = req.Address
+	}
+
+	if req.Status != "" {
+		status, err := strconv.Atoi(req.Status)
+		if err != nil {
+			return nil, 0, err
+		}
+		filter["status"] = status
+	}
+
 	// 设置分页选项
 	findOptions := options.Find()
 	findOptions.SetSkip(int64((req.Page - 1) * req.Size))
@@ -411,10 +477,15 @@ func (s *Synthesis) FindUserLevel() ([]*entity.UserLevelCountResp, error) {
 			dataMap[key] += v1
 		}
 	}
-	for k, v := range dataMap {
+	keys := make([]string, 0, len(dataMap))
+	for k := range dataMap {
+		keys = append(keys, k)
+	}
+	sort.Strings(keys)
+	for _, v := range keys {
 		results = append(results, &entity.UserLevelCountResp{
-			Level:     cast.ToInt(k),
-			UserCount: v,
+			Level:     cast.ToInt(v),
+			UserCount: dataMap[v],
 		})
 	}