印度包网
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

263 lines
9.9 KiB

1 year ago
package common
import (
"fmt"
"reflect"
"strconv"
"strings"
"gorm.io/gorm"
)
// 货币类型
type CurrencyType int
const (
CurrencyTypeZero CurrencyType = iota
CurrencyINR
1 year ago
CurrencyUSDT
CurrencyAll
)
type CurrencyRes int
// 货币来源(会影响所需下注量)
const (
2 months ago
CurrencyResourceZero CurrencyRes = iota
CurrencyResourceRecharge // 一般充值
CurrencyResourceBonus // 额外赠送
CurrencyResourceRechargeBonus // bonus充值
CurrencyResourceFirstRecharge // 首充
CurrencyResourceWeekCard // 周卡
CurrencyResourceShare // 分享
CurrencyResourceSecondRecharge // 第二次充
CurrencyResourceThirdRecharge // 第三次充
CurrencyResourceVipBonus // vip奖励
CurrencyResourceRechargeWithBonus // 一般充值(有bonus)
1 year ago
CurrencyResourceAll
)
const (
USDTKindZero = iota
USDTKindTRC20
USDTKindAll
)
func (t CurrencyType) IsValid() bool {
return t > CurrencyTypeZero && t < CurrencyAll
}
func (t CurrencyType) GetCurrencyName() string {
return strings.ToLower(reflect.TypeOf(PlayerCurrency{}).Field(int(t + 1)).Name)
}
func (t CurrencyType) GetRechargeInfoTable() string {
return fmt.Sprintf("recharge_info_%s", t.GetCurrencyName())
}
func GetCurrencyID(currency string) CurrencyType {
str := strings.ToUpper(currency)
ref := reflect.ValueOf(PlayerCurrency{})
reft := reflect.TypeOf(PlayerCurrency{})
for i := 2; i < ref.NumField(); i++ {
if reft.Field(i).Name == str {
return CurrencyType(i - 1)
}
}
return 0
}
type CurrencyEvent int
const (
CurrencyEventZero CurrencyEvent = iota // 无意义
CurrencyEventNewPlayer // 新注册赠送
CurrencyEventGameSettle // 游戏场结算
CurrencyEventGameBet // 游戏场牌局模式下注
CurrencyEventGameCancelBet // 取消下注
CurrencyEventReCharge // 充值
CurrencyEventWithDraw // 退出
CurrencyEventWithDrawBack // 退出失败退回
CurrencyEventMailDraw // 邮件领取
CurrencyEventGameVoidSettle // 游戏取消结算
CurrencyEventGameActivity // 游戏场活动赠与
CurrencyEventGameReSettle // 游戏场调整结算
CurrencyEventGameAdjustment // 游戏场调整余额
CurrencyEventBindPhone // 绑定手机奖励
CurrencyEventVIPBonus // 领取vip等级奖励
CurrencyEventVIPCashback // 领取vip返利
CurrencyEventActivityAppSpin // 下载app转盘奖励
CurrencyEventShareWithdraw // 分享奖励领取
CurrencyEventActivityPdd // pdd分享奖励领取
CurrencyEventGameAdjustBet // 投注额调整
CurrencyEventGameBonus // 游戏场bonus
CurrencyEventGameJackpot // 游戏场jackpot
CurrencyEventGameBuyIn // 游戏场扣钱操作
CurrencyEventGameBuyOut // 游戏场加钱操作
CurrencyEventTask // 任务奖励
CurrencyEventActivityFreeSpin // 免费旋转
CurrencyEventActivityFirstRechargeBack // 首日充值返还
CurrencyEventActivityLuckyCode // 兑换码活动
CurrencyEventActivitySign // 签到活动
CurrencyEventActivityBreakGift // 破产礼包活动
CurrencyEventActivityWeekCard // 周卡
CurrencyEventActivitySlots // slots奖池
CurrencyEventActivitySuper // 超级1+2
1 year ago
CurrencyEventActivityBetDraw // 下注抽奖
1 year ago
CurrencyEventActivityShareBind // 分享绑定
CurrencyEventActivityShareRank // 分享排行榜
3 months ago
CurrencyEventDrawMail // 领取邮箱奖励
CurrencyEventLuckyWheel // 充值转盘
CurrencyEventVIPWeekBonus // 领取vip周奖励
2 months ago
CurrencyEventShare
2 months ago
CurrencyEventShareBeInvite // 分享被邀请
CurrencyEventRankAward // 打码排行榜奖励
CurrencyEventShareRankAward // 分享排行榜奖励
1 year ago
CurrencyEventAll
CurrencyEventGM = 1000 // 后台修改货币
CurrencyEventGMRecharge = 1001 // 后台模拟充值
)
func GetCurrencyTypeName(ct CurrencyEvent) string {
switch ct {
case CurrencyEventNewPlayer:
return "新增注册赠送"
case CurrencyEventGameSettle:
return "游戏场结算"
case CurrencyEventGameBet:
return "游戏场下注"
case CurrencyEventGameCancelBet:
return "游戏场取消下注"
case CurrencyEventReCharge:
return "充值"
case CurrencyEventWithDraw:
return "退出"
case CurrencyEventWithDrawBack:
return "退出失败返回"
case CurrencyEventMailDraw:
return "邮件领取"
case CurrencyEventGameVoidSettle:
return "游戏场取消结算"
case CurrencyEventGameActivity:
return "游戏场活动赠与"
case CurrencyEventGameReSettle:
return "游戏场调整结算"
case CurrencyEventGameAdjustment:
return "游戏场调整余额"
case CurrencyEventBindPhone:
return "绑定手机奖励"
case CurrencyEventVIPBonus:
return "领取vip等级奖励"
case CurrencyEventVIPCashback:
return "领取输钱返利"
case CurrencyEventActivityAppSpin:
return "下载转盘奖励"
case CurrencyEventShareWithdraw:
return "分享奖励领取"
case CurrencyEventActivityPdd:
return "拼多多奖励领取"
case CurrencyEventGameAdjustBet:
return "调整投注"
case CurrencyEventGameBonus:
return "游戏场bonus奖励"
case CurrencyEventGameJackpot:
return "游戏场jackpot奖励"
case CurrencyEventGameBuyIn:
return "游戏场扣钱操作"
case CurrencyEventGameBuyOut:
return "游戏场加钱操作"
case CurrencyEventGM:
return "后台修改货币"
case CurrencyEventGMRecharge:
return "后台模拟充值"
case CurrencyEventTask:
return "领取任务奖励"
case CurrencyEventActivityFreeSpin:
return "免费转盘"
case CurrencyEventActivityFirstRechargeBack:
return "首充返还"
case CurrencyEventActivityLuckyCode:
return "幸运码活动"
case CurrencyEventActivitySign:
return "签到"
case CurrencyEventActivityBreakGift:
return "破产礼包活动"
case CurrencyEventActivityWeekCard:
return "周卡活动"
case CurrencyEventActivitySlots:
return "slots奖池活动"
case CurrencyEventActivitySuper:
return "超级1+2活动"
}
return strconv.Itoa(int(ct))
}
func GetGameEvents() []interface{} {
return []interface{}{CurrencyEventGameSettle, CurrencyEventGameBet, CurrencyEventGameCancelBet, CurrencyEventGameVoidSettle,
CurrencyEventGameActivity, CurrencyEventGameReSettle, CurrencyEventGameAdjustment, CurrencyEventGameAdjustBet,
CurrencyEventGameBonus, CurrencyEventGameJackpot, CurrencyEventGameBuyIn, CurrencyEventGameBuyOut}
}
// 游戏投入
func GetGameInEvents() []interface{} {
return []interface{}{CurrencyEventGameBet, CurrencyEventGameCancelBet, CurrencyEventGameAdjustBet, CurrencyEventGameBuyIn}
}
// 游戏产出
func GetGameOutEvents() []interface{} {
return []interface{}{CurrencyEventGameSettle, CurrencyEventGameVoidSettle,
CurrencyEventGameActivity, CurrencyEventGameReSettle, CurrencyEventGameAdjustment,
CurrencyEventGameBonus, CurrencyEventGameJackpot, CurrencyEventGameBuyOut}
}
// RoundCurrency 去除法币的无意义小数位数
func RoundCurrency(t CurrencyType, amount int64) int64 {
switch t {
case CurrencyINR:
1 year ago
return amount
1 year ago
case CurrencyUSDT:
return amount / 100 * 100
default:
return amount
}
}
type UpdateCurrency struct {
NotNotify bool // 为true时不通知客户端
Tx *gorm.DB
*CurrencyBalance
}
3 months ago
type CurrencyPair struct {
Type CurrencyType
Value int64
}
1 year ago
// Time 时间
// Value 变化的值
// Event 事件
// Type 货币类型
type CurrencyBalance struct {
Id int `gorm:"primary_key;AUTO_INCREMENT;column:id" json:"id" redis:"id"`
UID int `gorm:"column:uid" json:"uid"`
Time int64 `gorm:"column:time" json:"time"`
Value int64 `gorm:"column:value" json:"value"`
Balance int64 `gorm:"column:balance;type:bigint(20);default:0" json:"balance"`
Event CurrencyEvent `gorm:"column:event" json:"event"`
Type CurrencyType `gorm:"column:type" json:"type"`
ChannelID int `gorm:"column:channel_id;type:bigint(20);default:1;comment:渠道id" json:"channel_id"`
NeedBet int64 `gorm:"column:resource;type:bigint(20);default:0;comment:本次流水增加的打码量" json:"need_bet"`
Exi1 int `gorm:"column:exi1;type:bigint(20);default:0;comment:额外int字段1" json:"exi1"`
Exi2 int `gorm:"column:exi2;type:bigint(20);default:0;comment:额外int字段2" json:"exi2"`
Exi3 int `gorm:"column:exi3;type:bigint(11);default:0;comment:额外int字段3" json:"exi3"`
Exs1 string `gorm:"column:exs1;type:varchar(64);comment:额外string字段1" json:"exs1"`
Exs2 string `gorm:"column:exs2;type:varchar(64);comment:额外string字段2" json:"exs2"`
Exs3 string `gorm:"column:exs3;type:varchar(64);comment:额外string字段3" json:"exs3"`
}
func (c *CurrencyBalance) TableName() string {
return fmt.Sprintf("currency_balance_%02d", c.UID%100)
}