浏览代码

update 新增提现记录导出接口

Alvin 8 月之前
父节点
当前提交
f89e29202a

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

@@ -80,6 +80,23 @@ func (s *Synthesis) FindWithdrawal(ctx *gin.Context) {
 	common.PackOkResult(ctx, code.OK, resp)
 }
 
+// 导出提现记录
+func (s *Synthesis) WithdrawalExport(ctx *gin.Context) {
+	var req entity.UserWithdrawalExportReq
+	if err := ctx.ShouldBindJSON(&req); err != nil {
+		common.PackOkResult(ctx, code.ParamError)
+		return
+	}
+
+	resp, err := s.sev.WithdrawalExport(req)
+	if err != nil {
+		common.PackOkResult(ctx, err.Code)
+		return
+	}
+
+	common.PackOkResult(ctx, code.OK, resp)
+}
+
 // WithdrawalStatus 修改提现状态
 func (s *Synthesis) WithdrawalStatus(ctx *gin.Context) {
 	var req entity.UserWithdrawalStatus

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

@@ -38,6 +38,22 @@ type UserWithdrawalReq struct {
 	AfterAmountMax int    `json:"after_amount_max"`           // 提现后金额最大值
 }
 
+type UserWithdrawalExportReq struct {
+	ExportFormat   int    `json:"export_format"`              // 导出样式 0:返回需要导出的数据1:返回包含导出数据的csv文件url 该字段暂未使用
+	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"`                   // 结束时间
+	Address        string `json:"address"`                    // 地址
+	State          int    `json:"state"`                      // 服务器是否已经处理 0 未处理 1已处理
+	Withdrawal     int    `json:"withdrawal"`                 // 提现 0 :未体现 1:提现成功 2:提现中 3:提现失败 4:拒绝提现
+	AmountMin      int    `json:"amount_min"`                 // 提现金额最小值
+	AmountMax      int    `json:"amount_max"`                 // 提现金额最大值
+	AfterAmountMin int    `json:"after_amount_min"`           // 提现后金额最小值
+	AfterAmountMax int    `json:"after_amount_max"`           // 提现后金额最大值
+}
+
 type UserWithdrawalStatus struct {
 	UserName   string `json:"user_name" bson:"user_name" binding:"required"` // 用户ID
 	Status     int    `json:"status" bson:"status" `                         // 0:未审核 1:审核通过 2:审核失败

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

@@ -67,6 +67,7 @@ func (c *Controller) InitApiRouter(u *gin.RouterGroup) {
 
 	// 提现统计
 	u.POST("/user/withdrawal", controller.NewSynthesis().FindWithdrawal)
+	u.POST("/user/withdrawal/export", controller.NewSynthesis().WithdrawalExport)
 	u.POST("/user/withdrawal/status", controller.NewSynthesis().WithdrawalStatus)
 	u.POST("/user/withdrawal/status_batch", controller.NewSynthesis().WithdrawalStatusBatch)
 

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

@@ -215,6 +215,91 @@ func (s *Synthesis) FindWithdrawal(req entity.UserWithdrawalReq) (*entity.UserWi
 	}, nil
 }
 
+// 导出提现记录
+func (s *Synthesis) WithdrawalExport(req entity.UserWithdrawalExportReq) (*entity.UserWithdrawalResp, *code.Result) {
+	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
+	defer cancel()
+	collection := mdb.MDB.Collection(constant.CNameCashOutRecord)
+
+	// 构建过滤器
+	filter := bson.M{}
+	if req.UserName != "" {
+		filter["userName"] = req.UserName
+	}
+	if req.NickName != "" {
+		filter["nickName"] = req.NickName
+	}
+	if req.ID != "" {
+		filter["_id"], _ = primitive.ObjectIDFromHex(req.ID)
+	}
+	if req.Address != "" {
+		filter["address"] = req.Address
+	}
+	if req.State > 0 {
+		filter["state"] = req.State
+	}
+	if req.Withdrawal > 0 {
+		filter["withdrawal"] = req.Withdrawal
+	}
+	if req.StartTime > 0 && req.EndTime > 0 && req.StartTime <= req.EndTime {
+		filter["createAt"] = bson.M{
+			"$gte": req.StartTime,
+			"$lte": req.EndTime,
+		}
+	}
+	if req.AmountMin > 0 && req.AmountMax > 0 && req.AmountMin <= req.AmountMax {
+		filter["amount"] = bson.M{
+			"$gte": req.AmountMin,
+			"$lte": req.AmountMax,
+		}
+	}
+	if req.AfterAmountMin > 0 && req.AfterAmountMax > 0 && req.AfterAmountMin <= req.AfterAmountMax {
+		filter["after_amount"] = bson.M{
+			"$gte": req.AfterAmountMin,
+			"$lte": req.AfterAmountMax,
+		}
+	}
+
+	findOptions := options.Find()
+	findOptions.SetSort(bson.D{{"createAt", -1}})
+
+	// 获取总数total
+	count, err := collection.CountDocuments(ctx, filter)
+	if err != nil {
+		mhayaLogger.Warnf("WithdrawalExportData CountDocuments error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
+	// 查询数据
+	var results []*entity.UserWithdrawalDetail
+	cursor, err := collection.Find(ctx, filter, findOptions)
+	if err != nil {
+		mhayaLogger.Warnf("WithdrawalExportData Find error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
+	defer cursor.Close(ctx)
+	// 解析结果
+	for cursor.Next(ctx) {
+		var result entity.UserWithdrawalDetail
+		if err := cursor.Decode(&result); err != nil {
+			mhayaLogger.Warnf("WithdrawalExportData Decode error:%v", err)
+			return nil, common.NewResult(code.InternalError)
+		}
+		results = append(results, &result)
+	}
+
+	if err := cursor.Err(); err != nil {
+		mhayaLogger.Warnf("WithdrawalExportData cursor error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
+	return &entity.UserWithdrawalResp{
+		Details: results,
+		Total:   count,
+	}, nil
+}
+
 // WithdrawalStatus 更新提现状态
 func (s *Synthesis) WithdrawalStatus(req entity.UserWithdrawalStatus) *code.Result {
 	// ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)