Game Callback (~15 games)
new BetTransactionModel(...)
// or
BetTransactionModel.updateOne({ ref1: ... }) (2 times per round)
Report Winlose/Account (/spa/report/wl_account_2)
BetTransactionModel.aggregate([
{
"$match":{
"$and":[
{
"gameDate":{
"$gte":"2021-03-09T07:00:00.000Z",
"$lt":"2021-03-09T11:00:00.000Z"
}
},
{
"commission.superAdmin.group":"5a3"
},
{
"commission.company.parentGroup":"2f2"
},
{
"status":{
"$in":[
"DONE",
"REJECTED",
"CANCELLED"
]
}
}
]
}
},
{
"$group":{
"_id":{
"groupId":"$commission.company.group"
},
"stackCount":{
"$sum":1
},
"amount":{
"$sum":"$amount"
},
"validAmount":{
"$sum":"$validAmount"
},
"grossComm":{
"$sum":{
"$multiply":[
"$validAmount",
{
"$divide":[
"$commission.superAdmin.commission",
100
]
}
]
}
},
"memberWinLose":{
"$sum":{
"$toDecimal":"$commission.member.winLose"
}
},
"memberWinLoseCom":{
"$sum":{
"$toDecimal":"$commission.member.winLoseCom"
}
},
"agentWinLose":{
"$sum":{
"$toDecimal":"$commission.agent.winLose"
}
},
"agentWinLoseCom":{
"$sum":{
"$toDecimal":"$commission.agent.winLoseCom"
}
},
"masterAgentWinLose":{
"$sum":{
"$toDecimal":"$commission.masterAgent.winLose"
}
},
"masterAgentWinLoseCom":{
"$sum":{
"$toDecimal":"$commission.masterAgent.winLoseCom"
}
},
"seniorWinLose":{
"$sum":{
"$toDecimal":"$commission.senior.winLose"
}
},
"seniorWinLoseCom":{
"$sum":{
"$toDecimal":"$commission.senior.winLoseCom"
}
},
"shareHolderWinLose":{
"$sum":{
"$toDecimal":"$commission.shareHolder.winLose"
}
},
"shareHolderWinLoseCom":{
"$sum":{
"$toDecimal":"$commission.shareHolder.winLoseCom"
}
},
"companyWinLose":{
"$sum":{
"$toDecimal":"$commission.company.winLose"
}
},
"companyWinLoseCom":{
"$sum":{
"$toDecimal":"$commission.company.winLoseCom"
}
},
"superAdminWinLose":{
"$sum":{
"$toDecimal":"$commission.superAdmin.winLose"
}
},
"superAdminWinLoseCom":{
"$sum":{
"$toDecimal":"$commission.superAdmin.winLoseCom"
}
}
}
},
{
"$project":{
"_id":1,
"type":"A_GROUP",
"group":"$_id.groupId",
"currency":"THB",
"stackCount":"$stackCount",
"grossComm":"$grossComm",
"amount":"$amount",
"validAmount":"$validAmount",
"memberWinLose":{
"$toDouble":"$memberWinLose"
},
"memberWinLoseCom":{
"$toDouble":"$memberWinLoseCom"
},
"memberTotalWinLoseCom":{
"$toDouble":{
"$add":[
"$memberWinLose",
"$memberWinLoseCom"
]
}
},
"agentWinLose":{
"$toDouble":"$agentWinLose"
},
"agentWinLoseCom":{
"$toDouble":"$agentWinLoseCom"
},
"agentTotalWinLoseCom":{
"$toDouble":{
"$add":[
"$agentWinLose",
"$agentWinLoseCom"
]
}
},
"masterAgentWinLose":{
"$toDouble":"$masterAgentWinLose"
},
"masterAgentWinLoseCom":{
"$toDouble":"$masterAgentWinLoseCom"
},
"masterAgentTotalWinLoseCom":{
"$toDouble":{
"$add":[
"$masterAgentWinLose",
"$masterAgentWinLoseCom"
]
}
},
"seniorWinLose":{
"$toDouble":"$seniorWinLose"
},
"seniorWinLoseCom":{
"$toDouble":"$seniorWinLoseCom"
},
"seniorTotalWinLoseCom":{
"$toDouble":{
"$add":[
"$seniorWinLose",
"$seniorWinLoseCom"
]
}
},
"shareHolderWinLose":{
"$toDouble":"$shareHolderWinLose"
},
"shareHolderWinLoseCom":{
"$toDouble":"$shareHolderWinLoseCom"
},
"shareHolderTotalWinLoseCom":{
"$toDouble":{
"$add":[
"$shareHolderWinLose",
"$shareHolderWinLoseCom"
]
}
},
"companyWinLose":{
"$toDouble":"$companyWinLose"
},
"companyWinLoseCom":{
"$toDouble":"$companyWinLoseCom"
},
"companyTotalWinLoseCom":{
"$toDouble":{
"$add":[
"$companyWinLose",
"$companyWinLoseCom"
]
}
},
"superAdminWinLose":{
"$toDouble":"$superAdminWinLose"
},
"superAdminWinLoseCom":{
"$toDouble":"$superAdminWinLoseCom"
},
"superAdminTotalWinLoseCom":{
"$toDouble":{
"$add":[
"$superAdminWinLose",
"$superAdminWinLoseCom"
]
}
}
}
}
])
.read('secondaryPreferred')
.option({ maxTimeMS: 200000 })
Report match detail (/spa/report/wl_match_detail)
BetTransactionModel.aggregate([
{
"$match":{
"gameDate":{
"$gte":"2021-03-08T11:00:00.000Z",
"$lt":"2021-03-09T11:00:00.000Z"
},
"commission.superAdmin.group":"5a3",
"status":{
"$in":[
"DONE",
"REJECTED",
"CANCELLED"
]
}
}
},
{
"$group":{
"_id":{
"game":"$game",
"source":"$source",
"leagueId":"$hdp.leagueId",
"leagueName":"$hdp.leagueName",
"matchName":"$hdp.matchName",
"matchId":"$hdp.matchId",
"oddType":"$hdp.oddType",
"parlay":"$parlay",
"gameType":"$gameType"
},
"stackCount":{
"$sum":1
},
"amount":{
"$sum":"$amount"
},
"grossComm":{
"$sum":{
"$multiply":[
"$amount",
{
"$divide":[
"$commission.superAdmin.commission",
100
]
}
]
}
},
"memberWinLose":{
"$sum":"$commission.member.winLose"
},
"memberWinLoseCom":{
"$sum":"$commission.member.winLoseCom"
},
"memberTotalWinLoseCom":{
"$sum":"$commission.member.totalWinLoseCom"
},
"agentWinLose":{
"$sum":"$commission.agent.winLose"
},
"agentWinLoseCom":{
"$sum":"$commission.agent.winLoseCom"
},
"agentTotalWinLoseCom":{
"$sum":"$commission.agent.totalWinLoseCom"
},
"masterAgentWinLose":{
"$sum":"$commission.masterAgent.winLose"
},
"masterAgentWinLoseCom":{
"$sum":"$commission.masterAgent.winLoseCom"
},
"masterAgentTotalWinLoseCom":{
"$sum":"$commission.masterAgent.totalWinLoseCom"
},
"seniorWinLose":{
"$sum":"$commission.senior.winLose"
},
"seniorWinLoseCom":{
"$sum":"$commission.senior.winLoseCom"
},
"seniorTotalWinLoseCom":{
"$sum":"$commission.senior.totalWinLoseCom"
},
"shareHolderWinLose":{
"$sum":"$commission.shareHolder.winLose"
},
"shareHolderWinLoseCom":{
"$sum":"$commission.shareHolder.winLoseCom"
},
"shareHolderTotalWinLoseCom":{
"$sum":"$commission.shareHolder.totalWinLoseCom"
},
"companyWinLose":{
"$sum":"$commission.company.winLose"
},
"companyWinLoseCom":{
"$sum":"$commission.company.winLoseCom"
},
"companyTotalWinLoseCom":{
"$sum":"$commission.company.totalWinLoseCom"
},
"superAdminWinLose":{
"$sum":"$commission.superAdmin.winLose"
},
"superAdminWinLoseCom":{
"$sum":"$commission.superAdmin.winLoseCom"
},
"superAdminTotalWinLoseCom":{
"$sum":"$commission.superAdmin.totalWinLoseCom"
}
}
},
{
"$project":{
"_id":0,
"key":"$_id",
"source":"$source",
"parlay":"$_id.parlay",
"member":"$_id.member",
"group":"$_id.commission",
"stackCount":"$stackCount",
"grossComm":"$grossComm",
"amount":"$amount",
"memberWinLose":"$memberWinLose",
"memberWinLoseCom":"$memberWinLoseCom",
"memberTotalWinLoseCom":"$memberTotalWinLoseCom",
"agentWinLose":"$agentWinLose",
"agentWinLoseCom":"$agentWinLoseCom",
"agentTotalWinLoseCom":"$agentTotalWinLoseCom",
"masterAgentWinLose":"$masterAgentWinLose",
"masterAgentWinLoseCom":"$masterAgentWinLoseCom",
"masterAgentTotalWinLoseCom":"$masterAgentTotalWinLoseCom",
"seniorWinLose":"$seniorWinLose",
"seniorWinLoseCom":"$seniorWinLoseCom",
"seniorTotalWinLoseCom":"$seniorTotalWinLoseCom",
"shareHolderWinLose":"$shareHolderWinLose",
"shareHolderWinLoseCom":"$shareHolderWinLoseCom",
"shareHolderTotalWinLoseCom":"$shareHolderTotalWinLoseCom",
"companyWinLose":"$companyWinLose",
"companyWinLoseCom":"$companyWinLoseCom",
"companyTotalWinLoseCom":"$companyTotalWinLoseCom",
"superAdminWinLose":"$superAdminWinLose",
"superAdminWinLoseCom":"$superAdminWinLoseCom",
"superAdminTotalWinLoseCom":"$superAdminTotalWinLoseCom"
}
}
])
.read('secondaryPreferred')
Update member balance (2 times per round)
new UpdateBalanceHistoryModel(body)
MemberModel.findOneAndUpdate(
{username_lower: username.toLowerCase()},
{$inc: {balance: amount},lastUpdateBalance:Utils.Date.currentDate()},
{new: true }
)
Login (/member/login)
MemberModel.findOne(condition)
.select({
_id: 1,
contact: 1,
username: 1,
username_lower: 1,
group: 1,
currency: 1,
limitSetting: 1,
commissionSetting: 1,
configuration: 1,
balance: 1,
termAndCondition: 1,
forceChangePassword: 1,
forceChangePasswordDate: 1,
lock: 1,
suspend: 1,
isAutoTopUp: 1,
})
// There is Redis to cache this one. (TTL.120sec)
AgentGroupModel.findById(mongoose.Types.ObjectId(agentGroupId))
.select('_id lock suspend parentId limitSetting name_lower')
.populate({
path: 'parentId',
select: '_id lock suspend parentId limitSetting name_lower',
populate: {
path: 'parentId',
select: '_id lock suspend parentId limitSetting name_lower',
populate: {
path: 'parentId',
select: '_id lock suspend parentId limitSetting name_lower',
populate: {
path: 'parentId',
select: '_id lock suspend parentId limitSetting name_lower',
populate: {
path: 'parentId',
select: '_id lock suspend parentId limitSetting name_lower',
}
}
}
}
})
MemberModel.update({_id: user._id}, {
$set: {
ipAddress: clientIp,
lastLogin: DateUtils.getCurrentDate()
}
})
TokenModel.update({username: user.username}, {
username: user.username,
uniqueId: user.uid,
type:'MEMBER',
createdAt: DateUtils.getCurrentDate()
})
Checking agent inactive status (A one off login into the game)
// There is Redis to cache this one. (TTL.120sec)
AgentGroupModel.findById(memberParentId)
.select("_id lock suspend active parentId limitSetting name_lower")
.populate({
path: "parentId",
select: "_id lock suspend active parentId limitSetting name_lower",
populate: {
path: "parentId",
select: "_id lock suspend active parentId limitSetting name_lower",
populate: {
path: "parentId",
select: "_id lock suspend active parentId limitSetting name_lower",
populate: {
path: "parentId",
select: "_id lock suspend active parentId limitSetting name_lower",
populate: {
path: "parentId",
select: "_id lock suspend active parentId limitSetting name_lower",
},
},
},
},
})
Alternative way of lookup