Explorar o código

update 完善综合统计接口

Alvin hai 9 meses
pai
achega
714cf1ca88

+ 20 - 19
game/game_cluster/nodes/webadmin/entity/synthesis.go

@@ -12,23 +12,23 @@ type OverviewResp struct {
 }
 
 type OverviewDetail struct {
-	UserName                   string `json:"userName" bson:"userName"`             // 用户名 用户ID
-	OpenId                     string `json:"openId" bson:"openId"`                 // 对应tgid
-	FirstLoginDate             int64  `json:"firstLoginDate"`                       // 用户首次登录日期
-	CreateTime                 int64  `json:"createTime" bson:"createTime"`         // 用户注册时间
-	LastLoginTime              int64  `json:"lastLoginTime" bson:"loginTime"`       // 用户最后一次登录日期
-	MaxSuccessions             int    `json:"maxSuccessions" bson:"maxSuccessions"` // 用户累计登录天数
-	DieRoll                    int64  `json:"dieRoll"`                              // 用户骰子投掷次数
-	CurrentIntegral            int64  `json:"currentIntegral"`                      // 用户当前积分
-	SuccessfulInvitations      int64  `json:"successfulInvitations"`                // 用户邀请成功人数
-	Withdrawals                int64  `json:"withdrawals"`                          // 用户提现次数(USDT)
-	CumulativeWithdrawalAmount int64  `json:"cumulativeWithdrawalAmount"`           // 用户累计提现金额(USDT)
-	TurntableRuns              int64  `json:"turntableRuns"`                        // 用户转盘实际抽奖次数
-	PointsRanking              int64  `json:"pointsRanking"`                        // 用户积分排名
-	RankingOfDiceRolls         int64  `json:"rankingOfDiceRolls"`                   // 用户骰子投掷次数排名
-	InvitesRanking             int64  `json:"invitesRanking"`                       // 用户邀请人数排名
-	TonValue                   int64  `json:"tonValue"`                             // 用户账户Ton值
-	UsdtValue                  int64  `json:"usdtValue"`                            // 用户账户USDT值
+	UserName                   string  `json:"userName" bson:"userName"`             // 用户名 用户ID
+	OpenId                     string  `json:"openId" bson:"openId"`                 // 对应tgid
+	FirstLoginDate             int64   `json:"firstLoginDate"`                       // 用户首次登录日期
+	CreateTime                 int64   `json:"createTime" bson:"createTime"`         // 用户注册时间
+	LastLoginTime              int64   `json:"lastLoginTime" bson:"loginTime"`       // 用户最后一次登录日期
+	MaxSuccessions             int     `json:"maxSuccessions" bson:"maxSuccessions"` // 用户累计登录天数
+	DieRoll                    int64   `json:"dieRoll"`                              // 用户骰子投掷次数
+	CurrentIntegral            int64   `json:"currentIntegral"`                      // 用户当前积分
+	SuccessfulInvitations      int64   `json:"successfulInvitations"`                // 用户邀请成功人数
+	Withdrawals                int64   `json:"withdrawals"`                          // 用户提现次数(USDT)
+	CumulativeWithdrawalAmount int64   `json:"cumulativeWithdrawalAmount"`           // 用户累计提现金额(USDT)
+	TurntableRuns              int64   `json:"turntableRuns"`                        // 用户转盘实际抽奖次数
+	PointsRanking              int64   `json:"pointsRanking"`                        // 用户积分排名
+	RankingOfDiceRolls         int64   `json:"rankingOfDiceRolls"`                   // 用户骰子投掷次数排名
+	InvitesRanking             int64   `json:"invitesRanking"`                       // 用户邀请人数排名
+	TonValue                   float64 `json:"tonValue"`                             // 用户账户Ton值
+	UsdtValue                  float64 `json:"usdtValue"`                            // 用户账户USDT值
 }
 
 type UserListReq struct {
@@ -89,6 +89,7 @@ type AssetsDetail struct {
 	UserName        string  `json:"userName" bson:"userName"` // 用户名 用户ID
 	TonValue        float64 `json:"tonValue"`                 // 用户账户Ton值
 	UsdtValue       float64 `json:"usdtValue"`                // 用户账户USDT值
+	PointsValue     int64   `json:"PointsValue"`              // 用户账户积分值
 	StatisticalDate int64   `json:"statisticalDate"`          // 统计日期
 }
 
@@ -156,8 +157,8 @@ type ActiveDetail struct {
 	LastLoginTime              int64  `json:"lastLoginTime" bson:"loginTime"`       // 用户最后一次登录日期
 	MaxSuccessions             int    `json:"maxSuccessions" bson:"maxSuccessions"` // 用户累计登录天数
 	SuccessfulInvitations      int64  `json:"successfulInvitations"`                // 用户邀请成功人数
-	Withdrawals                int64  `json:"withdrawals"`                          // 用户提现次数
-	CumulativeWithdrawalAmount int64  `json:"cumulativeWithdrawalAmount"`           // 用户累计提现金额
+	Withdrawals                int64  `json:"withdrawals"`                          // 用户提现次数(USDT)
+	CumulativeWithdrawalAmount int64  `json:"cumulativeWithdrawalAmount"`           // 用户累计提现金额(USDT)
 	TurntableRuns              int64  `json:"turntableRuns"`                        // 用户转盘实际抽奖次数
 }
 

+ 19 - 0
game/game_cluster/nodes/webadmin/service/playerMange.go

@@ -432,6 +432,25 @@ func (a *PlayerManage) GetFollowRecord(userName, channelName string) (*eventmode
 	return followRecord, nil
 }
 
+// 获取最新的用户骰子投掷记录
+func (a *PlayerManage) GetPlayerLastestDiceRecord(userName string) (*eventmodels.DiceEventContent, *code.Result) {
+	var diceRecord *eventmodels.DiceEventContent
+	where := &eventmodels.DiceEventContent{
+		UserBasic: eventmodels.UserBasic{UserId: userName},
+	}
+	err := mdb.LogstashDB.Model(&eventmodels.DiceEventContent{}).Where(where).Order("create_at desc").First(&diceRecord).Error
+	if err != nil && err != gorm.ErrRecordNotFound {
+		mhayaLogger.Warnf("GetPlayerLastestDiceRecord First diceRecord error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
+	if err == gorm.ErrRecordNotFound {
+		return nil, nil
+	}
+
+	return diceRecord, nil
+}
+
 // 获取玩家详情
 func (a *PlayerManage) PlayerInfo(ctx context.Context, req entity.PlayerInfoReq) (*entity.PlayerInfoResp, *code.Result) {
 	updateRecord, codeResult := a.GetPlayerLastestUpdateRecord(req.UserName)

+ 110 - 36
game/game_cluster/nodes/webadmin/service/synthesis.go

@@ -41,59 +41,124 @@ func NewSynthesis(nodeId string) *Synthesis {
 func (s *Synthesis) Overview(req entity.OverviewReq) (*entity.OverviewResp, *code.Result) {
 	page, pageSize := checkPageParam(req.Page, req.Size)
 
-	// 构建查询条件
-	filter := bson.M{}
+	playerMgr := NewPlayerManage()
+	// 根据条件查询
 	if req.UserName != "" {
-		filter["userName"] = req.UserName
-	}
+		detail, codeResult := s.getOverviewDetail(req.UserName)
+		if codeResult != nil {
+			mhayaLogger.Warnf("Overview getOverviewDetail error:%v", codeResult)
+			return nil, codeResult
+		}
 
-	// 设置分页选项
-	findOptions := options.Find()
-	findOptions.SetSkip(int64((page - 1) * pageSize))
-	findOptions.SetLimit(int64(pageSize))
-	findOptions.SetSort(bson.D{{"createTime", -1}})
+		if detail == nil {
+			return nil, nil
+		}
 
-	ctx, cancel := context.WithTimeout(context.Background(), 100*time.Second)
-	defer cancel()
+		var results []*entity.OverviewDetail
+		results = append(results, detail)
 
-	collection := mdb.MDB.Collection(constant.CNamePlayer)
+		return &entity.OverviewResp{
+			Details: results,
+			Total:   1,
+		}, nil
+	}
 
-	// 查询数据
-	var results []*entity.OverviewDetail
-	cursor, err := collection.Find(ctx, filter, findOptions)
-	if err != nil {
-		mhayaLogger.Warnf("Overview Find error:%v", err)
-		return nil, common.NewResult(code.InternalError)
+	// 查询列表
+	listResp, codeResult := playerMgr.List(context.Background(), entity.PlayerListReq{
+		Page: page,
+		Size: pageSize,
+	})
+	if codeResult != nil {
+		mhayaLogger.Warnf("Overview List error:%v", codeResult)
+		return nil, codeResult
 	}
 
-	defer cursor.Close(ctx)
-	// 解析结果
-	for cursor.Next(ctx) {
-		var result entity.OverviewDetail
-		if err := cursor.Decode(&result); err != nil {
-			mhayaLogger.Warnf("Overview Decode error:%v", err)
-			return nil, common.NewResult(code.InternalError)
+	var results []*entity.OverviewDetail
+	for _, detail := range listResp.Details {
+		detail, codeResult := s.getOverviewDetail(detail.UserName)
+		if codeResult != nil {
+			mhayaLogger.Warnf("Overview getOverviewDetail error:%v", codeResult)
+			return nil, codeResult
 		}
 
-		results = append(results, &result)
+		if detail != nil {
+			results = append(results, detail)
+		}
 	}
 
-	if err := cursor.Err(); err != nil {
-		mhayaLogger.Warnf("Overview cursor error:%v", err)
-		return nil, common.NewResult(code.InternalError)
+	count, codeResult := playerMgr.GetPlayerTotalCount()
+	if codeResult != nil {
+		mhayaLogger.Warnf("Overview GetPlayerTotalCount codeResult:%v", codeResult)
+		return nil, codeResult
 	}
 
-	// TODO 综合统计相关信息
-
-	// TODO 获取总数total
-	var count int64
-
 	return &entity.OverviewResp{
 		Details: results,
 		Total:   count,
 	}, nil
 }
 
+func (s *Synthesis) getOverviewDetail(userName string) (*entity.OverviewDetail, *code.Result) {
+	userDetail, codeResult := s.getUserDetail(userName)
+	if codeResult != nil {
+		mhayaLogger.Warnf("getOverviewDetail getUserDetail error:%v", codeResult)
+		return nil, codeResult
+	}
+
+	activeDetail, codeResult := s.getActive(userName)
+	if codeResult != nil {
+		mhayaLogger.Warnf("getOverviewDetail getActive error:%v", codeResult)
+		return nil, codeResult
+	}
+
+	assetDetail, codeResult := s.getAsset(userName)
+	if codeResult != nil {
+		mhayaLogger.Warnf("getOverviewDetail getAsset error:%v", codeResult)
+		return nil, codeResult
+	}
+
+	playerMgr := NewPlayerManage()
+
+	// 获取最新的用户骰子投掷记录
+	diceRecord, codeResult := playerMgr.GetPlayerLastestDiceRecord(userName)
+	if codeResult != nil {
+		mhayaLogger.Warnf("getOverviewDetail GetPlayerLastestDiceRecord error:%v", codeResult)
+		return nil, codeResult
+	}
+
+	// 获取最新的用户登录记录
+	loginRecord, codeResult := playerMgr.GetPlayerLastestLoginRecord(userName)
+	if codeResult != nil {
+		mhayaLogger.Warnf("getOverviewDetail GetPlayerLastestLoginRecord error:%v", codeResult)
+		return nil, codeResult
+	}
+
+	if loginRecord == nil {
+		mhayaLogger.Warnf("getOverviewDetail loginRecord:%v", loginRecord)
+		return nil, nil
+	}
+
+	return &entity.OverviewDetail{
+		UserName:                   userName,
+		OpenId:                     userDetail.OpenId,
+		FirstLoginDate:             userDetail.FirstLoginDate,
+		CreateTime:                 userDetail.CreateTime,
+		LastLoginTime:              userDetail.LastLoginTime,
+		MaxSuccessions:             activeDetail.MaxSuccessions,
+		DieRoll:                    int64(diceRecord.Count),
+		CurrentIntegral:            assetDetail.PointsValue,
+		SuccessfulInvitations:      activeDetail.SuccessfulInvitations,
+		Withdrawals:                activeDetail.Withdrawals,
+		CumulativeWithdrawalAmount: activeDetail.CumulativeWithdrawalAmount,
+		TurntableRuns:              activeDetail.TurntableRuns,
+		PointsRanking:              loginRecord.PointsRankSeq,
+		RankingOfDiceRolls:         loginRecord.ThrowDiceRankSeq,
+		InvitesRanking:             loginRecord.InviteUserRankSeq,
+		TonValue:                   assetDetail.TonValue,
+		UsdtValue:                  assetDetail.UsdtValue,
+	}, nil
+}
+
 // 统计用户相关信息
 func (s *Synthesis) UserList(req entity.UserListReq) (*entity.UserListResp, *code.Result) {
 	page, pageSize := checkPageParam(req.Page, req.Size)
@@ -917,7 +982,6 @@ func (s *Synthesis) Assets(req entity.AssetsReq) (*entity.AssetsResp, *code.Resu
 
 func (s *Synthesis) getAsset(userName string) (*entity.AssetsDetail, *code.Result) {
 	var totalUsdtAmount int64
-	var totalTonAmount int64
 	where := &eventmodels.AssetsEventContent{
 		UserBasic: eventmodels.UserBasic{
 			UserId: userName,
@@ -933,6 +997,7 @@ func (s *Synthesis) getAsset(userName string) (*entity.AssetsDetail, *code.Resul
 		return nil, common.NewResult(code.InternalError)
 	}
 
+	var totalTonAmount int64
 	where.Currency = string(constant.TonCurrency)
 	err = mdb.LogstashDB.Model(&eventmodels.AssetsEventContent{}).Where(where).Pluck("SUM(amount) as total_amount", &totalTonAmount).Error
 	if err != nil {
@@ -940,10 +1005,19 @@ func (s *Synthesis) getAsset(userName string) (*entity.AssetsDetail, *code.Resul
 		return nil, common.NewResult(code.InternalError)
 	}
 
+	var totalPointsAmount int64
+	where.Currency = string(constant.PointsCurrency)
+	err = mdb.LogstashDB.Model(&eventmodels.AssetsEventContent{}).Where(where).Pluck("SUM(amount) as total_amount", &totalPointsAmount).Error
+	if err != nil {
+		mhayaLogger.Warnf("getAsset Pluck PointsCurrency error:%v", err)
+		return nil, common.NewResult(code.InternalError)
+	}
+
 	return &entity.AssetsDetail{
 		UserName:        userName,
 		TonValue:        cutils.QuoInt64ByRatioToFloat64(totalTonAmount, constant.MoneyRatio),
 		UsdtValue:       cutils.QuoInt64ByRatioToFloat64(totalUsdtAmount, constant.MoneyRatio),
+		PointsValue:     totalPointsAmount,
 		StatisticalDate: mhayaTime.Now().Unix(),
 	}, nil
 }
@@ -1298,7 +1372,7 @@ func (s *Synthesis) getTaskCompletionDetail(userName string) (*entity.TaskComple
 
 	return &entity.TaskCompletionDetail{
 		UserName:   userName,
-		DicePerDay: 0, // TODO
+		DicePerDay: 0, // TODO 每日骰子数量
 		IsJoinTgChannel: func() bool {
 			return joinTgRecord != nil
 		}(),