|
@@ -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,
|
|
|
+ }
|
|
|
+}
|