package biz import ( "context" "fmt" "time" "sandc/pkg/utils" "github.com/google/wire" "gorm.io/gorm" ) // ProviderSet is biz providers. var ProviderSet = wire.NewSet(NewEonlineUsecase) type Cache interface { GetValue(ctx context.Context, key string) (string, error) DelValue(ctx context.Context, keys ...string) error WriteValue(ctx context.Context, key string, value interface{}, timeout int32) error Remember(ctx context.Context, key string, secone int32, fn func(ctx context.Context) (interface{}, error)) ([]byte, error) RedisLock(ctx context.Context, key string, value interface{}, timeout int32) (bool, error) RedisUnLock(ctx context.Context, key string) (bool, error) IncrValue(ctx context.Context, key string) error } type Transaction interface { InTx(context.Context, func(ctx context.Context) error) error DB(ctx context.Context) *gorm.DB } var SignFixedParameters = []string{ "Platform", "Deviceid", "Version", "Ip", "Ts", } // PayoutItem 账号状态 type PayoutItemId int const ( PayoutItemId1 PayoutItemId = iota + 1 // 提现0.1 PayoutItemId2 // 提现金币大额1 PayoutItemId3 // 提现绿钞大额1 PayoutItemId4 // 5.0美金,身份文件提交奖励 ) var PayoutItemIdAmountes = []float64{ PayoutItemId1: 5, PayoutItemId2: 0.1, PayoutItemId3: 0.1, } func (d PayoutItemId) Float64() float64 { n := int(d) if n < len(PayoutItemIdAmountes) && n > 0 { return PayoutItemIdAmountes[n] } return 0 } // PayoutItemStatus item状态类型 type PayoutItemStatus uint const ( // 可提现 PayoutItemStatusAvailable PayoutItemStatus = iota + 1 // 条件未达成 PayoutItemStatusUnfinished // 已提现 PayoutItemStatusPayouted // 禁止提现 PayoutItemStatusForbidden // 提现中 PayoutItemStatusPayouting ) var PayoutItemStatusNames = []string{ PayoutItemStatusAvailable: "available", PayoutItemStatusUnfinished: "unfinished", PayoutItemStatusPayouted: "payouted", PayoutItemStatusForbidden: "forbidden", } func (d PayoutItemStatus) String() string { n := int(d) if n < len(PayoutItemStatusNames) && n > 0 { return PayoutItemStatusNames[n] } return "" } // PayoutStatus type PayoutStatus uint const ( // 提现中 PayoutStatusPayouting PayoutStatus = iota + 1 // 提现成功 PayoutStatusPayouted // 提现失败 PayoutStatusPayoutFailed ) var PayoutStatusNames = []string{ PayoutStatusPayouting: "payouting", PayoutStatusPayouted: "payouted", PayoutStatusPayoutFailed: "payout_failed", } func (d PayoutStatus) String() string { n := int(d) if n < len(PayoutStatusNames) && n > 0 { return PayoutStatusNames[n] } return "" } // PayoutRecordLimit1 提现次数总限制 const PayoutRecordLimit1 = 1 const PayoutRecordLimit2 = 0 const PayoutRecordLimit3 = 0 const PayoutRecordLimit4 = 0 // PayoutAmountLimit 提现金额限制 const PayoutAmountLimit = 5 // GenPayoutUuid 生成payout_uuid func GenPayoutUuid(deviceId string) string { str := fmt.Sprintf("%s-tk0630", deviceId) str = utils.MD5Any(str) return str } // GetUuidPayoutRedisKey 获取uuid redis key,当日提现记录 func GetUuidPayoutRedisKey(uuid string, date string, itemId uint32) string { if date == "" { date = time.Now().Format("20060102") } // uuidRedisKey := fmt.Sprintf("pt_%s_%s", uuid, date) uuidRedisKey := fmt.Sprintf("pt:%s_%s_%d", uuid, date, itemId) return uuidRedisKey } // GetUuidLockRedisKey 获取uuid redis lock key,提现操作加锁,防止并发 func GetUuidLockRedisKey(uuid string, date string) string { if date == "" { date = time.Now().Format("20060102") } uuidRedisKey := fmt.Sprintf("ptlock_%s_%s", uuid, date) return uuidRedisKey } // GetPayoutNotifyRedisKey 获取提现通知redis key func GetPayoutNotifyRedisKey(payoutId string, date string) string { if date == "" { date = time.Now().Format("20060102") } uuidRedisKey := fmt.Sprintf("pt_notify_%s_%s", payoutId, date) return uuidRedisKey } // GetUserLoginRedisKey 获取用户登录redis key,当日登录记录 func GetUserLoginRedisKey(userId string, date string) string { if date == "" { date = time.Now().Format("20060102") } uuidRedisKey := fmt.Sprintf("pt_login_%s_%s", userId, date) return uuidRedisKey } // GetPayoutOrderIdRedisKey 获取提现订单对应的 提现reids记录 GetUuidPayoutRedisKey生成的 redis key, func GetPayoutOrderIdRedisKey(orderId string) string { uuidRedisKey := fmt.Sprintf("ts:%s", orderId) return uuidRedisKey } // 用户的paypal账号,生成审核结果的 redis key func GetCheckResultRedisKey(account string) string { return fmt.Sprintf("pt_result:%s", account) } // 用户的paypal账号,生成审核没通过的原因描述的 redis key func GetCheckResultFailRedisKey(account string) string { return fmt.Sprintf("pt_fail:%s", account) } // 用户的paypal账号,生成提交审核的 redis key 存储的数据结构[paypal, uuid] func GetCheckSubmitRedisKey(account string) string { return fmt.Sprintf("pt_submit:%s", account) } // 用户的paypal账号,生成提交审核的 redis key 存储的数据结构[uuid, paypal] func GetUuid2PaypalRedisKey(uuid string) string { return fmt.Sprintf("pt_uuid:%s", uuid) } // 提交审核计数的 redis key func GetCheckSubmitNumRedisKey() string { return fmt.Sprintf("svr_submitNum") } // 返回true,表示t1,t2是同一天 func isSameDay(t1, t2 time.Time) bool { y1 := t1.Year() y2 := t2.Year() if y1 != y2 { return false } d1 := t1.YearDay() d2 := t2.YearDay() if d1 != d2 { return false } return true }