@ -2,7 +2,6 @@ package call
import (
import (
"context"
"context"
"encoding/json"
"fmt"
"fmt"
"github.com/liangdas/mqant/log"
"github.com/liangdas/mqant/log"
"gorm.io/gorm"
"gorm.io/gorm"
@ -85,11 +84,11 @@ func RankHandler() {
for rankCycle := range rank . RankCycleMap {
for rankCycle := range rank . RankCycleMap {
switch rankCycle {
switch rankCycle {
case "1" :
case "1" :
awardAt = util . GetZeroTime ( now . AddDate ( 0 , 0 , 1 ) ) . Add ( time . Hour )
awardAt = util . GetZeroTime ( now . AddDate ( 0 , 0 , 1 ) ) . Add ( 30 * time . Minute )
case "2" :
case "2" :
awardAt = util . GetWeekZeroTime ( now ) . AddDate ( 0 , 0 , 7 ) . Add ( 2 * time . Hour )
awardAt = util . GetWeekZeroTime ( now ) . AddDate ( 0 , 0 , 7 ) . Add ( 45 * time . Minute )
case "3" :
case "3" :
awardAt = util . GetFirstDateOfMonth ( now ) . AddDate ( 0 , 1 , 0 ) . Add ( 2 * time . Hour )
awardAt = util . GetFirstDateOfMonth ( now ) . AddDate ( 0 , 1 , 0 ) . Add ( 60 * time . Minute )
}
}
if awardAt . IsZero ( ) {
if awardAt . IsZero ( ) {
log . Error ( "get award time err, %+v, %s" , * rank , rankCycle )
log . Error ( "get award time err, %+v, %s" , * rank , rankCycle )
@ -194,10 +193,22 @@ func rankAward(ticker *rankTicker) {
if userAwardCount == 0 {
if userAwardCount == 0 {
continue
continue
}
}
awardData , _ := json . Marshal ( common . CurrencyPair {
if rankData . IsRobot == 1 {
Type : common . CurrencyINR ,
continue
Value : userAwardCount ,
}
_ , err = UpdateCurrencyPro ( & common . UpdateCurrency {
CurrencyBalance : & common . CurrencyBalance {
UID : rankData . UID ,
Type : common . CurrencyINR ,
Value : userAwardCount ,
Event : common . CurrencyEventRankAward ,
NeedBet : GetConfigCurrencyResourceNeedBet ( common . CurrencyResourceBonus , userAwardCount ) ,
} ,
} )
} )
if err != nil {
log . Error ( "rank award err, %s" , err . Error ( ) )
}
var rankCycle string
var rankCycle string
switch ticker . rankCycle {
switch ticker . rankCycle {
case "1" :
case "1" :
@ -215,7 +226,6 @@ func rankAward(ticker *rankTicker) {
Type : 1 ,
Type : 1 ,
Title : fmt . Sprintf ( "%s Rank Rankings settlement(%s)" , rankCycle , rankAt . Format ( "20060102" ) ) ,
Title : fmt . Sprintf ( "%s Rank Rankings settlement(%s)" , rankCycle , rankAt . Format ( "20060102" ) ) ,
Content : fmt . Sprintf ( "Nice work! You ranked %dth on the betting leaderboard and earned a reward. Go claim it now!" , rank ) ,
Content : fmt . Sprintf ( "Nice work! You ranked %dth on the betting leaderboard and earned a reward. Go claim it now!" , rank ) ,
Enc : string ( awardData ) ,
SendMethod : 1 ,
SendMethod : 1 ,
Status : common . MailStatusNew ,
Status : common . MailStatusNew ,
Time : now . Unix ( ) ,
Time : now . Unix ( ) ,
@ -228,10 +238,23 @@ func rankAward(ticker *rankTicker) {
// 重置上一期奖池数量
// 重置上一期奖池数量
preJackpotLessKey := jackpotKey + "|less"
preJackpotLessKey := jackpotKey + "|less"
log . Debug ( "rankAward, %s, %d, less jackpot:%d" , jackpotKey , jackpot , lessJackpot )
log . Debug ( "rankAward, %s, %d, less jackpot:%d" , jackpotKey , jackpot , lessJackpot )
err = db . Redis ( ) . GetRedis ( ) . Set ( context . Background ( ) , preJackpotLessKey , lessJackpot , time . Hour * 24 * 30 * 2 ) . Err ( )
if lessJackpot < 0 {
lessJackpot = 0
}
err = db . Redis ( ) . GetRedis ( ) . Set ( context . Background ( ) , preJackpotLessKey , lessJackpot , 0 ) . Err ( )
if err != nil {
if err != nil {
log . Error ( "share rankAward, %s set less-jackpot err, %s" , preJackpotLessKey , err . Error ( ) )
log . Error ( "share rankAward, %s set less-jackpot err, %s" , preJackpotLessKey , err . Error ( ) )
}
}
var expire int64
switch ticker . rankCycle {
case "1" :
expire = 24 * 60 * 60 * 2
case "2" :
expire = 24 * 60 * 60 * 7 * 2
case "3" :
expire = 24 * 60 * 60 * 30 * 2
}
db . Redis ( ) . Expire ( preJackpotLessKey , time . Duration ( expire ) * time . Second )
if lessJackpot > 0 {
if lessJackpot > 0 {
_ , _ , _ , jackpotKeyNow := getRankJackpotKey ( rankConfig . RankType , ticker . rankCycle )
_ , _ , _ , jackpotKeyNow := getRankJackpotKey ( rankConfig . RankType , ticker . rankCycle )
_ , err = db . Redis ( ) . Incr ( jackpotKeyNow , lessJackpot )
_ , err = db . Redis ( ) . Incr ( jackpotKeyNow , lessJackpot )
@ -263,11 +286,13 @@ func UpdateRankValue(mode int, uid int, updateValue int64, isRobot int) {
RankCycle : util . ToInt ( rankCycle ) ,
RankCycle : util . ToInt ( rankCycle ) ,
RankAt : rankAt . Unix ( ) ,
RankAt : rankAt . Unix ( ) ,
IsRobot : isRobot ,
IsRobot : isRobot ,
TotalBet : updateValue ,
RankValue : updateValueReal ,
RankValue : updateValueReal ,
UpdatedAt : now . Unix ( ) ,
UpdatedAt : now . Unix ( ) ,
}
}
updates := map [ string ] interface { } {
updates := map [ string ] interface { } {
"total_bet" : gorm . Expr ( fmt . Sprintf ( "total_bet + %d" , rankData . TotalBet ) ) ,
"rank_value" : gorm . Expr ( fmt . Sprintf ( "rank_value + %d" , rankData . RankValue ) ) ,
"rank_value" : gorm . Expr ( fmt . Sprintf ( "rank_value + %d" , rankData . RankValue ) ) ,
"updated_at" : rankData . UpdatedAt ,
"updated_at" : rankData . UpdatedAt ,
}
}
@ -455,6 +480,14 @@ func rankUsersGet(rankType int, rankCycle string, rankAt time.Time, page, pageSi
log . Error ( "get rank user with info err, %s" , err . Error ( ) )
log . Error ( "get rank user with info err, %s" , err . Error ( ) )
return
return
}
}
cfg := GetConfigRankByCycle ( rankType , rankCycle )
for _ , rankUser := range rankUsers {
if rankUser . TotalBet == 0 {
rankUser . RankValue = rankUser . RankValue * 10000 / int64 ( cfg . FreeRatesMap [ rankCycle ] )
} else {
rankUser . RankValue = rankUser . TotalBet
}
}
return
return
}
}