3 Commits 7120c47746 ... 33c41d84ac

Author SHA1 Message Date
  Alvin 33c41d84ac update 新增查询总提现数量,总注册人数接口;完善提现记录过滤条件 8 months ago
  Alvin ecf5d2bff5 update 完善提现记录 8 months ago
  Alvin 97e6ef0ad1 update 添加假数据 8 months ago

+ 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的提现总值
+}

+ 1 - 1
game/game_cluster/nodes/webadmin/entity/user_withdrawal.go

@@ -25,8 +25,8 @@ type UserWithdrawalReq struct {
 	Page       int    `json:"page"`                         // 页码
 	Size       int    `json:"size"`                         // 每页数量
 	Withdrawal string `json:"withdrawal" bson:"withdrawal"` // 提现 1:提现成功 2:提现中 3:提现失败 4:拒绝提现
-	Address    string `json:"address" bson:"address"`       // 地址
 	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)

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

@@ -5,7 +5,6 @@ import (
 	"errors"
 	"log"
 	"math"
-	"os"
 	"sort"
 	"strconv"
 	"time"
@@ -123,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)
@@ -151,7 +194,7 @@ func (s *Synthesis) FindWithdrawal(req *entity.UserWithdrawalReq) ([]*entity.Use
 	if req.Withdrawal != "" {
 		withdrawal, err := strconv.Atoi(req.Withdrawal)
 		if err != nil {
-			return nil, 0, os.ErrInvalid
+			return nil, 0, err
 		}
 		filter["withdrawal"] = withdrawal
 	}
@@ -161,7 +204,11 @@ func (s *Synthesis) FindWithdrawal(req *entity.UserWithdrawalReq) ([]*entity.Use
 	}
 
 	if req.Status != "" {
-		filter["status"] = req.Status
+		status, err := strconv.Atoi(req.Status)
+		if err != nil {
+			return nil, 0, err
+		}
+		filter["status"] = status
 	}
 
 	// 设置分页选项