|
@@ -7,6 +7,7 @@ import (
|
|
|
"time"
|
|
|
|
|
|
mhayaTime "github.com/mhaya/extend/time"
|
|
|
+ cutils "github.com/mhaya/extend/utils"
|
|
|
"github.com/mhaya/game/game_cluster/internal/code"
|
|
|
"github.com/mhaya/game/game_cluster/internal/constant"
|
|
|
"github.com/mhaya/game/game_cluster/internal/mdb"
|
|
@@ -250,11 +251,10 @@ 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)
|
|
|
|
|
|
- // TODO 是否需要校验货币类型
|
|
|
- // if !constant.CurrencyValid(req.Currency) {
|
|
|
- // mhayaLogger.Warnf("FindWithdrawal unknow currency:%v", req.Currency)
|
|
|
- // return nil, common.NewResult(code.ParamError)
|
|
|
- // }
|
|
|
+ if !constant.CurrencyValid(req.Currency) {
|
|
|
+ mhayaLogger.Warnf("FindWithdrawal unknow currency:%v", req.Currency)
|
|
|
+ return nil, common.NewResult(code.ParamError)
|
|
|
+ }
|
|
|
|
|
|
var records []*eventmodels.UserWithdrawEventContent
|
|
|
|
|
@@ -796,22 +796,17 @@ func (s *Synthesis) Turntable(req entity.TurntableReq) (*entity.TurntableResp, *
|
|
|
func (s *Synthesis) Assets(req entity.AssetsReq) (*entity.AssetsResp, *code.Result) {
|
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
|
|
|
|
+ playerMgr := NewPlayerManage()
|
|
|
// 根据条件查询
|
|
|
if req.UserName != "" {
|
|
|
- // 构建查询条件
|
|
|
- filter := bson.M{}
|
|
|
- if req.UserName != "" {
|
|
|
- filter["userName"] = req.UserName
|
|
|
- }
|
|
|
-
|
|
|
- var playerInfo *models.Player
|
|
|
- err := mdb.MDB.Collection(constant.CNamePlayer).FindOne(context.Background(), filter).Decode(&playerInfo)
|
|
|
- if err != nil && err != mongo.ErrNoDocuments {
|
|
|
- mhayaLogger.Warnf("Assets FindOne playerInfo error:%v", err)
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
+ registerRecord, codeResult := playerMgr.GetRegisterRecord(req.UserName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("Assets GetRegisterRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
|
|
|
- if playerInfo == nil {
|
|
|
+ if registerRecord == nil {
|
|
|
+ mhayaLogger.Warnf("Assets registerRecord:%v", registerRecord)
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
@@ -832,7 +827,6 @@ func (s *Synthesis) Assets(req entity.AssetsReq) (*entity.AssetsResp, *code.Resu
|
|
|
}
|
|
|
|
|
|
// 查询列表
|
|
|
- playerMgr := NewPlayerManage()
|
|
|
listResp, codeResult := playerMgr.List(context.Background(), entity.PlayerListReq{
|
|
|
Page: page,
|
|
|
Size: pageSize,
|
|
@@ -892,8 +886,8 @@ func (s *Synthesis) getAsset(userName string) (*entity.AssetsDetail, *code.Resul
|
|
|
|
|
|
return &entity.AssetsDetail{
|
|
|
UserName: userName,
|
|
|
- TonValue: totalTonAmount,
|
|
|
- UsdtValue: totalUsdtAmount,
|
|
|
+ TonValue: cutils.QuoInt64ByRatioToFloat64(totalTonAmount, constant.MoneyRatio),
|
|
|
+ UsdtValue: cutils.QuoInt64ByRatioToFloat64(totalUsdtAmount, constant.MoneyRatio),
|
|
|
StatisticalDate: mhayaTime.Now().Unix(),
|
|
|
}, nil
|
|
|
}
|
|
@@ -902,17 +896,15 @@ func (s *Synthesis) getAsset(userName string) (*entity.AssetsDetail, *code.Resul
|
|
|
func (s *Synthesis) AssetsRecord(req entity.AssetsRecordReq) (*entity.AssetsRecordResp, *code.Result) {
|
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
|
|
|
|
- // TODO 是否需要校验货币类型
|
|
|
- // if !constant.CurrencyValid(req.Currency) {
|
|
|
- // mhayaLogger.Warnf("AssetsRecord unknow currency:%v", req.Currency)
|
|
|
- // return nil, common.NewResult(code.ParamError)
|
|
|
- // }
|
|
|
+ if !constant.CurrencyValid(req.Currency) {
|
|
|
+ mhayaLogger.Warnf("AssetsRecord unknow currency:%v", req.Currency)
|
|
|
+ return nil, common.NewResult(code.ParamError)
|
|
|
+ }
|
|
|
|
|
|
- // TODO 是否需要校验资产变动的操作类型
|
|
|
- // if req.OperationType != string(constant.IncreaseOp) && req.OperationType != string(constant.DecreaseOp) {
|
|
|
- // mhayaLogger.Warnf("AssetsRecord unknow OperationType:%v", req.OperationType)
|
|
|
- // return nil, common.NewResult(code.ParamError)
|
|
|
- // }
|
|
|
+ if req.OperationType != string(constant.IncreaseOp) && req.OperationType != string(constant.DecreaseOp) {
|
|
|
+ mhayaLogger.Warnf("AssetsRecord unknow OperationType:%v", req.OperationType)
|
|
|
+ return nil, common.NewResult(code.ParamError)
|
|
|
+ }
|
|
|
|
|
|
var records []*eventmodels.AssetsEventContent
|
|
|
|
|
@@ -944,7 +936,6 @@ func (s *Synthesis) AssetsRecord(req entity.AssetsRecordReq) (*entity.AssetsReco
|
|
|
for _, v := range records {
|
|
|
results = append(results, &entity.AssetsRecordDetail{
|
|
|
UserName: v.UserName,
|
|
|
- OpenId: v.TgId,
|
|
|
AssetType: string(v.Currency),
|
|
|
AssetsGrowth: v.Amount,
|
|
|
AcquisitionTime: v.CreateAt,
|
|
@@ -1002,33 +993,20 @@ func (s *Synthesis) Invite(req entity.InviteReq) (*entity.InviteResp, *code.Resu
|
|
|
func (s *Synthesis) Active(req entity.ActiveReq) (*entity.ActiveResp, *code.Result) {
|
|
|
page, pageSize := checkPageParam(req.Page, req.Size)
|
|
|
|
|
|
+ playerMgr := NewPlayerManage()
|
|
|
// 根据条件查询
|
|
|
if req.UserName != "" {
|
|
|
- // 构建查询条件
|
|
|
- filter := bson.M{}
|
|
|
- if req.UserName != "" {
|
|
|
- filter["userName"] = req.UserName
|
|
|
- }
|
|
|
-
|
|
|
- var playerInfo *models.Player
|
|
|
- err := mdb.MDB.Collection(constant.CNamePlayer).FindOne(context.Background(), filter).Decode(&playerInfo)
|
|
|
- if err != nil && err != mongo.ErrNoDocuments {
|
|
|
- mhayaLogger.Warnf("Active FindOne playerInfo error:%v", err)
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
+ detail, codeResult := s.getActive(req.UserName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("Active getActive error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
|
|
|
- if playerInfo == nil {
|
|
|
+ if detail == nil {
|
|
|
return nil, nil
|
|
|
}
|
|
|
|
|
|
var results []*entity.ActiveDetail
|
|
|
-
|
|
|
- detail, codeResult := s.getActive(playerInfo)
|
|
|
- if codeResult != nil {
|
|
|
- mhayaLogger.Warnf("Active getActive error:%v", codeResult)
|
|
|
- return nil, codeResult
|
|
|
- }
|
|
|
-
|
|
|
results = append(results, detail)
|
|
|
|
|
|
return &entity.ActiveResp{
|
|
@@ -1038,7 +1016,6 @@ func (s *Synthesis) Active(req entity.ActiveReq) (*entity.ActiveResp, *code.Resu
|
|
|
}
|
|
|
|
|
|
// 查询列表
|
|
|
- playerMgr := NewPlayerManage()
|
|
|
listResp, codeResult := playerMgr.List(context.Background(), entity.PlayerListReq{
|
|
|
Page: page,
|
|
|
Size: pageSize,
|
|
@@ -1050,14 +1027,7 @@ func (s *Synthesis) Active(req entity.ActiveReq) (*entity.ActiveResp, *code.Resu
|
|
|
|
|
|
var results []*entity.ActiveDetail
|
|
|
for _, detail := range listResp.Details {
|
|
|
- var playerInfo *models.Player
|
|
|
- err := mdb.MDB.Collection(constant.CNamePlayer).FindOne(context.Background(), bson.M{"userName": detail.UserName}).Decode(&playerInfo)
|
|
|
- if err != nil && err != mongo.ErrNoDocuments {
|
|
|
- mhayaLogger.Warnf("Active FindOne playerInfo error:%v", err)
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
- }
|
|
|
-
|
|
|
- detail, codeResult := s.getActive(playerInfo)
|
|
|
+ detail, codeResult := s.getActive(detail.UserName)
|
|
|
if codeResult != nil {
|
|
|
mhayaLogger.Warnf("Active getActive error:%v", codeResult)
|
|
|
return nil, codeResult
|
|
@@ -1078,81 +1048,70 @@ func (s *Synthesis) Active(req entity.ActiveReq) (*entity.ActiveResp, *code.Resu
|
|
|
}, nil
|
|
|
}
|
|
|
|
|
|
-func (s *Synthesis) getActive(playerInfo *models.Player) (*entity.ActiveDetail, *code.Result) {
|
|
|
- // 累计登录次数
|
|
|
- loginWhere := &eventmodels.UserLoginEventContent{
|
|
|
- UserBasic: eventmodels.UserBasic{
|
|
|
- UserId: playerInfo.UserName,
|
|
|
- TgId: playerInfo.OpenId,
|
|
|
- },
|
|
|
+func (s *Synthesis) getActive(userName string) (*entity.ActiveDetail, *code.Result) {
|
|
|
+ playerMgr := NewPlayerManage()
|
|
|
+
|
|
|
+ // 获取注册记录
|
|
|
+ registerRecord, codeResult := playerMgr.GetRegisterRecord(userName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getActive GetRegisterRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ if registerRecord == nil {
|
|
|
+ mhayaLogger.Warnf("getActive registerRecord:%v", registerRecord)
|
|
|
+ return nil, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ // 获取最新的用户登录记录
|
|
|
+ loginRecord, codeResult := playerMgr.GetPlayerLastestLoginRecord(userName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getActive GetPlayerLastestLoginRecord error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
+ }
|
|
|
+
|
|
|
+ if loginRecord == nil {
|
|
|
+ mhayaLogger.Warnf("getActive loginRecord:%v", loginRecord)
|
|
|
+ return nil, nil
|
|
|
}
|
|
|
- loginDb := mdb.LogstashDB.Model(&eventmodels.UserLoginEventContent{}).Where(loginWhere).Order("create_at")
|
|
|
- var loginCount int64
|
|
|
- loginDb.Count(&loginCount)
|
|
|
|
|
|
// 邀请成功人数
|
|
|
- inviteWhere := &eventmodels.InviteEventContent{
|
|
|
- UserBasic: eventmodels.UserBasic{
|
|
|
- UserId: playerInfo.UserName,
|
|
|
- TgId: playerInfo.OpenId,
|
|
|
- },
|
|
|
+ inviteCount, codeResult := playerMgr.GetSuccessfulInvitations(userName, 0)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getActive GetSuccessfulInvitations error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
- inviteDb := mdb.LogstashDB.Model(&eventmodels.InviteEventContent{}).Where(inviteWhere).Order("create_at")
|
|
|
- var successfulInvitations int64
|
|
|
- inviteDb.Count(&successfulInvitations)
|
|
|
|
|
|
// 提现次数
|
|
|
- withdrawalWhere := &eventmodels.UserWithdrawEventContent{
|
|
|
- UserBasic: eventmodels.UserBasic{
|
|
|
- UserId: playerInfo.UserName,
|
|
|
- TgId: playerInfo.OpenId,
|
|
|
- },
|
|
|
- EventBasic: eventmodels.EventBasic{
|
|
|
- Status: 0,
|
|
|
- },
|
|
|
+ withdrawCount, codeResult := playerMgr.GetWithdrawalCount(userName, -1)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getActive GetWithdrawalCount error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
- withdrawalDb := mdb.LogstashDB.Model(&eventmodels.UserWithdrawEventContent{}).Where(withdrawalWhere).Order("create_at")
|
|
|
- var withdrawals int64
|
|
|
- withdrawalDb.Count(&withdrawals)
|
|
|
|
|
|
// 累计提现金额
|
|
|
- withdrawalAmountWhere := &eventmodels.UserWithdrawEventContent{
|
|
|
- UserBasic: eventmodels.UserBasic{
|
|
|
- UserId: playerInfo.UserName,
|
|
|
- TgId: playerInfo.OpenId,
|
|
|
- },
|
|
|
- EventBasic: eventmodels.EventBasic{
|
|
|
- Status: 0,
|
|
|
- },
|
|
|
- // Currency: string(constant.UsdtCurrency), // TODO 是否需要区分货币类型
|
|
|
- }
|
|
|
- var cumulativeWithdrawalAmount int64
|
|
|
- err := mdb.LogstashDB.Model(&eventmodels.UserWithdrawEventContent{}).Where(withdrawalAmountWhere).Pluck("SUM(amount) as total_amount", &cumulativeWithdrawalAmount).Error
|
|
|
- if err != nil {
|
|
|
- mhayaLogger.Warnf("getActive Pluck currency error:%v", err)
|
|
|
- return nil, common.NewResult(code.InternalError)
|
|
|
+ // TODO 暂定USDT
|
|
|
+ cumulativeWithdrawalAmount, codeResult := playerMgr.GetCumulativeWithdrawalAmount(userName, string(constant.UsdtCurrency), -1)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getActive GetCumulativeWithdrawalAmount error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
|
|
|
// 转盘实际抽奖次数
|
|
|
- turntableWhere := &eventmodels.TurntableEventContent{
|
|
|
- UserBasic: eventmodels.UserBasic{
|
|
|
- UserId: playerInfo.UserName,
|
|
|
- TgId: playerInfo.OpenId,
|
|
|
- },
|
|
|
+ turntableRuns, codeResult := playerMgr.GetTurntableRuns(userName)
|
|
|
+ if codeResult != nil {
|
|
|
+ mhayaLogger.Warnf("getActive GetTurntableRuns error:%v", codeResult)
|
|
|
+ return nil, codeResult
|
|
|
}
|
|
|
- turntableDb := mdb.LogstashDB.Model(&eventmodels.TurntableEventContent{}).Where(turntableWhere).Order("create_at")
|
|
|
- var turntableRuns int64
|
|
|
- turntableDb.Count(&turntableRuns)
|
|
|
|
|
|
return &entity.ActiveDetail{
|
|
|
- UserName: playerInfo.UserName,
|
|
|
- OpenId: playerInfo.OpenId,
|
|
|
- IfUserVip: false, // TODO 玩家信息需要添加该字段
|
|
|
- CreateTime: playerInfo.JoinTime,
|
|
|
- LastLoginTime: playerInfo.PrevTime,
|
|
|
- MaxSuccessions: int(loginCount),
|
|
|
- SuccessfulInvitations: successfulInvitations,
|
|
|
- Withdrawals: withdrawals,
|
|
|
+ UserName: userName,
|
|
|
+ IfUserVip: loginRecord.IfTgVip,
|
|
|
+ CreateTime: registerRecord.CreateAt,
|
|
|
+ LastLoginTime: loginRecord.CreateAt,
|
|
|
+ MaxSuccessions: loginRecord.ContinuousDaysMax,
|
|
|
+ SuccessfulInvitations: inviteCount,
|
|
|
+ Withdrawals: withdrawCount,
|
|
|
CumulativeWithdrawalAmount: cumulativeWithdrawalAmount,
|
|
|
TurntableRuns: turntableRuns,
|
|
|
}, nil
|