2 次代码提交 02d2bf6bcc ... 02d80575e5

作者 SHA1 备注 提交日期
  Alvin 02d80575e5 update 完善获取转盘中奖记录 8 月之前
  Alvin c9357e26d7 update 完善获取转盘中奖记录 8 月之前

+ 64 - 0
game/game_cluster/internal/mdb/models/reward.go

@@ -1,7 +1,10 @@
 package models
 
 import (
+	cutils "github.com/mhaya/extend/utils"
+	"github.com/mhaya/game/game_cluster/internal/constant"
 	"github.com/mhaya/game/game_cluster/internal/data"
+	"go.mongodb.org/mongo-driver/bson"
 )
 
 const (
@@ -34,3 +37,64 @@ type PlayerReward map[int]*PlayerRewardBase
 func NewPlayerReward() map[int]*PlayerRewardBase {
 	return make(map[int]*PlayerRewardBase)
 }
+
+type ToPlayerRewardBase struct {
+	UserName   string          `json:"userName" bson:"userName"`
+	AddReward  []*ToItemReward `json:"AddReward" bson:"addReward"`
+	Desc       interface{}     `json:"desc" bson:"desc"`
+	CreateTime int64           `json:"createTime" bson:"createTime"`
+}
+
+type ToItemReward struct {
+	ItemID   int     // itemID:道具ID
+	Amount   float64 // amount:数量
+	ItemName string  // itemName:道具名称
+}
+
+type ToDesc struct {
+	ID    int `json:"id" bson:"id"`
+	CurID int `json:"cur_id" bson:"curid"`
+}
+
+func (uw *PlayerRewardBase) To() *ToPlayerRewardBase {
+	return &ToPlayerRewardBase{
+		UserName: uw.UserName,
+		AddReward: func() []*ToItemReward {
+			ret := make([]*ToItemReward, 0, 8)
+			for _, v := range uw.AddReward {
+				itemName := ""
+				cfg, exist := data.ItemConfig.Get(v.ItemID)
+				if exist {
+					itemName = cfg.ItemKey
+				}
+
+				ret = append(ret, &ToItemReward{
+					ItemID: v.ItemID,
+					Amount: func() float64 {
+						if itemName == "u" || itemName == "ton" {
+							return cutils.QuoInt64ByRatioToFloat64(int64(v.Amount), constant.MoneyRatio)
+						}
+
+						return float64(v.Amount)
+					}(),
+					ItemName: itemName,
+				})
+			}
+
+			return ret
+		}(),
+		Desc: func() *ToDesc {
+			if uw.Desc == nil {
+				return nil
+			}
+
+			drawMap := uw.Desc.(bson.D).Map()
+			return &ToDesc{
+				ID:    int(drawMap["id"].(int32)),
+				CurID: int(drawMap["curid"].(int32)),
+			}
+		}(),
+		// Desc:       uw.Desc,
+		CreateTime: uw.CreateTime,
+	}
+}

+ 6 - 0
game/game_cluster/nodes/webadmin/entity/admin.go

@@ -136,9 +136,15 @@ type RewardListReq struct {
 type RewardListResp struct {
 	UserName   string        `json:"userName" bson:"userName"` // 用户名
 	AddReward  []*ItemReward `json:"AddReward" bson:"addReward"`
+	Desc       *Desc         `json:"desc" bson:"desc"`
 	CreateTime int64         `json:"createTime" bson:"createTime"`
 }
 
+type Desc struct {
+	ID    int `json:"id"`     // 中奖位置
+	CurID int `json:"cur_id"` // 规则id
+}
+
 type ItemReward struct {
 	ItemID   int    // itemID:道具ID
 	Amount   int    // amount:数量

+ 5 - 14
game/game_cluster/nodes/webadmin/service/playerMange.go

@@ -7,7 +7,6 @@ import (
 
 	mhayaTime "github.com/mhaya/extend/time"
 	"github.com/mhaya/game/game_cluster/internal/constant"
-	"github.com/mhaya/game/game_cluster/internal/data"
 	"github.com/mhaya/game/game_cluster/internal/mdb"
 	"github.com/mhaya/game/game_cluster/internal/mdb/models"
 	"github.com/mhaya/game/game_cluster/nodes/webadmin/entity"
@@ -162,7 +161,7 @@ func (a *PlayerManage) PlayerInfo(ctx context.Context, req entity.PlayerInfoReq)
 }
 
 // 获取玩家中奖记录(默认查询最近三天)
-func (a *PlayerManage) RewardList(ctx context.Context, req entity.RewardListReq) ([]*entity.RewardListResp, int64, error) {
+func (a *PlayerManage) RewardList(ctx context.Context, req entity.RewardListReq) ([]*models.ToPlayerRewardBase, int64, error) {
 	page := req.Page
 	// 验证参数
 	if page <= 0 {
@@ -178,6 +177,7 @@ func (a *PlayerManage) RewardList(ctx context.Context, req entity.RewardListReq)
 	if req.UserName != "" {
 		filter["userName"] = bson.M{"$regex": escapeRegex(req.UserName), "$options": "i"}
 	}
+	filter["source"] = models.SourceDraw
 
 	startTime := mhayaTime.Now().Add(-3 * 24 * time.Hour).Unix()
 	endTime := mhayaTime.Now().Unix()
@@ -222,26 +222,17 @@ func (a *PlayerManage) RewardList(ctx context.Context, req entity.RewardListReq)
 	}()
 
 	// 解析结果
-	results := make([]*entity.RewardListResp, 0)
+	results := make([]*models.ToPlayerRewardBase, 0)
 	for cursor.Next(ctx) {
-		var result entity.RewardListResp
+		var result models.PlayerRewardBase
 		if err := cursor.Decode(&result); err != nil {
 			return nil, 0, err
 		}
-		results = append(results, &result)
+		results = append(results, result.To())
 	}
 	if err := cursor.Err(); err != nil {
 		return nil, 0, err
 	}
 
-	for _, result := range results {
-		for _, v := range result.AddReward {
-			cfg, exist := data.ItemConfig.Get(v.ItemID)
-			if exist {
-				v.ItemName = cfg.ItemKey
-			}
-		}
-	}
-
 	return results, count, nil
 }