Jelajahi Sumber

update 完善接口

Alvin 8 bulan lalu
induk
melakukan
f66e88ae70

+ 11 - 8
game/game_cluster/internal/mdb/eventmodels/userWithdrawEvent.go

@@ -6,14 +6,17 @@ import "github.com/mhaya/game/game_cluster/internal/constant"
 type UserWithdrawEventContent struct {
 	UserBasic
 	EventBasic
-	Currency      constant.CurrencyTypeStr `json:"currency"`       // 货币类型
-	Ip            string                   `json:"ip"`             // IP
-	Platform      string                   `json:"platform"`       // 平台
-	Channel       string                   `json:"channel"`        // 渠道
-	Address       string                   `json:"address"`        // 提现地址
-	BeforeBalance int64                    `json:"before_balance"` // 提现前余额
-	Amount        int64                    `json:"amount"`         // 提现金额
-	AfterBalance  int64                    `json:"after_balance"`  // 提现后余额
+	WithdrawId      string                   `json:"withdraw_id"`      // 提现记录id
+	Currency        constant.CurrencyTypeStr `json:"currency"`         // 货币类型
+	Ip              string                   `json:"ip"`               // IP
+	Platform        string                   `json:"platform"`         // 平台
+	Channel         string                   `json:"channel"`          // 渠道
+	Address         string                   `json:"address"`          // 提现地址
+	BeforeBalance   int64                    `json:"before_balance"`   // 提现前余额
+	Amount          int64                    `json:"amount"`           // 提现金额
+	AfterBalance    int64                    `json:"after_balance"`    // 提现后余额
+	State           int                      `json:"state"`            // 服务器是否已经处理 0 未处理 1已处理
+	WithdrawalState int                      `json:"withdrawal_state"` // 提现 0 :未体现 1:提现成功 2:提现中 3:提现失败 4:拒绝提现
 }
 
 func (e *UserWithdrawEventContent) EventName() string {

+ 45 - 73
game/game_cluster/nodes/webadmin/service/synthesis.go

@@ -255,89 +255,64 @@ func (s *Synthesis) FindMDBUserLogDaily(req entity.UserLogDailyReq) (*entity.Use
 func (s *Synthesis) FindWithdrawal(req entity.UserWithdrawalReq) (*entity.UserWithdrawalResp, *code.Result) {
 	page, pageSize := checkPageParam(req.Page, req.Size)
 
-	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
-	defer cancel()
-	collection := mdb.MDB.Collection(constant.CNameCashOutRecord)
+	var records []*eventmodels.UserWithdrawEventContent
 
-	// 构建过滤器
-	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
+	where := &eventmodels.UserWithdrawEventContent{
+		UserBasic: eventmodels.UserBasic{
+			UserId:   req.UserName,
+			UserName: req.NickName,
+		},
+		EventBasic: eventmodels.EventBasic{
+			ServerId: s.nodeId,
+		},
+		WithdrawId:      req.ID,
+		Currency:        constant.UsdtCurrency,
+		Address:         req.Address,
+		State:           req.State,
+		WithdrawalState: req.Withdrawal,
 	}
+	db := mdb.LogstashDB.Model(&eventmodels.UserWithdrawEventContent{}).Where(where).Order("create_at")
+
 	if req.StartTime > 0 && req.EndTime > 0 && req.StartTime <= req.EndTime {
-		filter["createAt"] = bson.M{
-			"$gte": req.StartTime,
-			"$lte": req.EndTime,
-		}
+		db = db.Where("create_at >= ? and create_at <= ?", req.StartTime, req.EndTime)
 	}
 	if req.AmountMin > 0 && req.AmountMax > 0 && req.AmountMin <= req.AmountMax {
-		filter["amount"] = bson.M{
-			"$gte": req.AmountMin,
-			"$lte": req.AmountMax,
-		}
+		db = db.Where("amount >= ? and amount <= ?", req.AmountMin, req.AmountMax)
 	}
 	if req.AfterAmountMin > 0 && req.AfterAmountMax > 0 && req.AfterAmountMin <= req.AfterAmountMax {
-		filter["after_amount"] = bson.M{
-			"$gte": req.AfterAmountMin,
-			"$lte": req.AfterAmountMax,
-		}
+		db = db.Where("after_balance >= ? and after_balance <= ?", req.AfterAmountMin, req.AfterAmountMax)
 	}
 
-	// 设置分页选项
-	findOptions := options.Find()
-	findOptions.SetSkip(int64((page - 1) * pageSize))
-	findOptions.SetLimit(int64(pageSize))
-	findOptions.SetSort(bson.D{{"createAt", -1}})
-
-	// 获取总数total
-	count, err := collection.CountDocuments(ctx, filter)
-	if err != nil {
-		mhayaLogger.Warnf("FindWithdrawal CountDocuments error:%v", err)
-		return nil, common.NewResult(code.InternalError)
-	}
-
-	// 查询数据
-	var results []*entity.UserWithdrawalDetail
-	cursor, err := collection.Find(ctx, filter, findOptions)
-	if err != nil {
+	pages := Paginate(db, page, pageSize)
+	err := db.Scopes(pages.Limit).Find(&records).Error
+	if err != nil && err != gorm.ErrRecordNotFound {
 		mhayaLogger.Warnf("FindWithdrawal 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("FindWithdrawal Decode error:%v", err)
-			return nil, common.NewResult(code.InternalError)
-		}
-		results = append(results, &result)
-	}
-
-	if err := cursor.Err(); err != nil {
-		mhayaLogger.Warnf("FindWithdrawal cursor error:%v", err)
-		return nil, common.NewResult(code.InternalError)
+	var results []*entity.UserWithdrawalDetail
+	for _, v := range records {
+		results = append(results, &entity.UserWithdrawalDetail{
+			// TODO
+			// Id:          v.WithdrawId,
+			// UserName:    v.UserId,
+			// NickName:    v.UserName,
+			// OpenId:      v.TgId,
+			// Status:      v.State,
+			// Reason:      "",
+			// Withdrawal:  0,
+			// Amount:      0,
+			// AfterAmount: 0,
+			// Type:        nil,
+			// Address:     "",
+			// CreateAt:    nil,
+			// UpdateAt:    nil,
+		})
 	}
 
 	return &entity.UserWithdrawalResp{
 		Details: results,
-		Total:   count,
+		Total:   pages.Count,
 	}, nil
 }
 
@@ -727,13 +702,10 @@ func (s *Synthesis) RecordList(req entity.RecordListReq) (*entity.RecordListResp
 		EventBasic: eventmodels.EventBasic{
 			ServerId: s.nodeId,
 		},
-		RoleId:       req.RoleId,
-		Path:         req.Path,
-		Method:       "",
-		StatusCode:   req.StatusCode,
-		Dur:          0,
-		ClientIP:     req.ClientIP,
-		ErrorMessage: "",
+		RoleId:     req.RoleId,
+		Path:       req.Path,
+		StatusCode: req.StatusCode,
+		ClientIP:   req.ClientIP,
 	}
 	db := mdb.LogstashDB.Model(&eventmodels.BackendOperationEventContent{}).Where(where).Order("create_at")