119 lines
3.5 KiB
Go
119 lines
3.5 KiB
Go
package dashboard
|
|
|
|
import (
|
|
"context"
|
|
"strings"
|
|
|
|
"github.com/shopspring/decimal"
|
|
)
|
|
|
|
var walletGameEvents = map[string]struct{}{
|
|
"GAME_SLOT_MACHINE": {}, "GAME_BARBECUE": {}, "TURNTABLE_GAME": {}, "LUDO_GAME": {},
|
|
"GAME_BURST_CRYSTAL": {}, "EGG": {}, "FRUIT_GAME": {}, "DOUBLE_LAYER_FRUIT": {},
|
|
"DOUBLE_LAYER_BARBECUE": {}, "GAME_FRUIT_BET": {}, "GAME_FRUIT_AWARD": {}, "GAME_BACK": {},
|
|
"GAME_WINNING": {}, "LUDO_VICTORY": {}, "LUDO_REFUND": {}, "GAME_LUDO_REFUND": {},
|
|
"USD_GAME_WIN": {}, "USD_GAME_REFUND": {}, "USD_GAME_REFUND_DRAW": {}, "TEEN_PATTI": {},
|
|
"BET_TEEN_PATTI": {}, "LOTTERY_NUMBER_BET": {}, "LOTTERY_REWARD": {},
|
|
}
|
|
|
|
func (m *Mapper) mapWalletGame(ctx context.Context, schema string, table string, action string, row Row) ([]Contribution, error) {
|
|
eventType := row.String("event_type")
|
|
if isWalletGiftConsumeEvent(eventType) {
|
|
return nil, nil
|
|
}
|
|
if !isWalletGameEvent(eventType) {
|
|
return nil, nil
|
|
}
|
|
sysOrigin := row.String("sys_origin")
|
|
if !m.allowed(sysOrigin) {
|
|
return nil, nil
|
|
}
|
|
user, ok, err := m.user(ctx, row.Int64("user_id"))
|
|
if err != nil || !ok || user.IsDeleted {
|
|
return nil, err
|
|
}
|
|
if user.SysOrigin != sysOrigin {
|
|
return nil, nil
|
|
}
|
|
|
|
provider, gameID, gameName, err := m.store.ResolveWalletGame(ctx, sysOrigin, eventType, row.String("event_id"))
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
amount := row.Decimal("penny_amount").Div(decimal.NewFromInt(100))
|
|
consume := decimal.Zero
|
|
payout := decimal.Zero
|
|
if row.Int64("type") == 1 {
|
|
consume = amount
|
|
} else if row.Int64("type") == 0 {
|
|
payout = amount
|
|
}
|
|
|
|
c := m.base(schema, table, action, row, user, row.MillisTime("create_time"))
|
|
c.GameTotalFlow = consume
|
|
c.GamePayout = payout
|
|
c.GameUser = true
|
|
c.GameProvider = provider
|
|
c.GameID = gameID
|
|
c.GameName = gameName
|
|
c.GameConsume = consume
|
|
c.GamePayoutBy = payout
|
|
c.GameProfit = consume.Sub(payout)
|
|
c.GameOrder = 1
|
|
return []Contribution{c}, nil
|
|
}
|
|
|
|
func (m *Mapper) mapWalletGift(ctx context.Context, schema string, table string, action string, row Row) ([]Contribution, error) {
|
|
sysOrigin := row.String("sys_origin")
|
|
if !m.allowed(sysOrigin) {
|
|
return nil, nil
|
|
}
|
|
user, ok, err := m.user(ctx, row.Int64("user_id"))
|
|
if err != nil || !ok || user.IsDeleted {
|
|
return nil, err
|
|
}
|
|
if user.SysOrigin != sysOrigin {
|
|
return nil, nil
|
|
}
|
|
|
|
amount := row.Decimal("penny_amount").Div(decimal.NewFromInt(100))
|
|
if amount.IsZero() {
|
|
return nil, nil
|
|
}
|
|
eventType := row.String("event_type")
|
|
recordType := row.Int64("type")
|
|
c := m.base(schema, table, action, row, user, row.MillisTime("create_time"))
|
|
if action != "delete" {
|
|
c.EventKey = WalletMetricEventKey(schema, table, rowPK(row))
|
|
}
|
|
switch {
|
|
case isWalletGiftConsumeEvent(eventType) && recordType == 1:
|
|
c.GiftConsume = amount
|
|
default:
|
|
return nil, nil
|
|
}
|
|
return []Contribution{c}, nil
|
|
}
|
|
|
|
func isWalletGiftConsumeEvent(eventType string) bool {
|
|
return strings.HasPrefix(eventType, "GIVE_GIFT") && !strings.Contains(eventType, "LUCKY_GIFT")
|
|
}
|
|
|
|
func isWalletGameEvent(eventType string) bool {
|
|
if _, ok := walletGameEvents[eventType]; ok {
|
|
return true
|
|
}
|
|
if eventType == "LUCKY_GIFT" || eventType == "LUCKY_GIFT_GOLD_REWARD" ||
|
|
eventType == "LUCKY_BOX_GAME" || eventType == "NEW_LUCKY_BOX_GAME" || eventType == "GAME_RAKE" {
|
|
return false
|
|
}
|
|
if strings.HasPrefix(eventType, "GIVE_GIFT") || strings.HasPrefix(eventType, "ACCEPT_GIFT") {
|
|
return false
|
|
}
|
|
return strings.HasPrefix(eventType, "BAISHUN_GAME") ||
|
|
strings.HasPrefix(eventType, "GAME_OPEN_") ||
|
|
strings.HasPrefix(eventType, "YOMI_GAME") ||
|
|
strings.HasPrefix(eventType, "HKYS_GAME") ||
|
|
strings.HasPrefix(eventType, "HOT_GAME")
|
|
}
|