Documentation
¶
Index ¶
- Constants
- func ExpirePendingOrders(ctx context.Context)
- func GetBoolByKey(ctx context.Context, key string) (bool, error)
- func GetDecimalByKey(ctx context.Context, key string, precision int32) (decimal.Decimal, error)
- func GetIntByKey(ctx context.Context, key string) (int, error)
- type Dispute
- type DisputeStatus
- type LeaderboardResponse
- type LeaderboardUser
- type MerchantAPIKey
- type MerchantPaymentLink
- type OAuthUserInfo
- type Order
- type OrderStatus
- type OrderType
- type PayLevel
- type RedEnvelope
- type RedEnvelopeClaim
- type RedEnvelopeStatus
- type RedEnvelopeType
- type SystemConfig
- type TrustLevel
- type User
- func (u *User) CheckActive() error
- func (u *User) CreateWithInitialCredit(ctx context.Context, oauthInfo *OAuthUserInfo) error
- func (u *User) EnqueueBadgeScoreTask(ctx context.Context, delay time.Duration) error
- func (u *User) GetByID(tx *gorm.DB, id uint64) error
- func (u *User) GetUserGamificationScore(ctx context.Context) (*UserGamificationScoreResponse, error)
- func (u *User) UpdateFromOAuthInfo(oauthInfo *OAuthUserInfo)
- func (u *User) VerifyPayKey(inputPayKey string) bool
- type UserGamificationScoreResponse
- type UserPayConfig
Constants ¶
const ( ConfigKeyMerchantOrderExpireMinutes = "merchant_order_expire_minutes" // 商家订单过期时间(分钟) ConfigKeyWebsiteOrderExpireMinutes = "website_order_expire_minutes" // 网站订单过期时间(分钟) ConfigKeyDisputeTimeWindowHours = "dispute_time_window_hours" // 商家争议时间窗口(小时) ConfigKeyNewUserInitialCredit = "new_user_initial_credit" // 新用户注册初始积分 ConfigKeyNewUserProtectionDays = "new_user_protection_days" // 新用户保护期天数(期内不扣分) ConfigKeyLeaderboardCacheTTLSeconds = "leaderboard_cache_ttl_seconds" // 排行榜缓存过期时间(秒) ConfigKeyRedEnvelopeEnabled = "red_envelope_enabled" // 红包功能是否启用(1启用,0禁用) ConfigKeyRedEnvelopeMaxAmount = "red_envelope_max_amount" // 单个红包的最大积分上限 ConfigKeyRedEnvelopeDailyLimit = "red_envelope_daily_limit" // 每日发红包的个数限制 ConfigKeyRedEnvelopeFeeRate = "red_envelope_fee_rate" // 红包手续费率(0-1之间的小数,0表示不收费) ConfigKeyRedEnvelopeMaxRecipients = "red_envelope_max_recipients" // 每个红包的最大可领取人数上限 ConfigKeyUserBalanceStatsCacheTTL = "user_balance_stats_cache_ttl" // 用户余额统计缓存过期时间(秒) )
配置键常量 - 所有系统配置的 key 定义
const (
// SystemConfigRedisHashKey Redis Hash key,存储所有系统配置
SystemConfigRedisHashKey = "system:system_configs"
)
Variables ¶
This section is empty.
Functions ¶
func ExpirePendingOrders ¶
ExpirePendingOrders 将已过期且 pending 状态的订单设置为 expired
func GetBoolByKey ¶
GetBoolByKey 通过 key 查询配置并转换为 bool 类型
func GetDecimalByKey ¶
GetDecimalByKey 通过 key 查询配置并转换为 decimal.Decimal 类型 precision 指定保留的小数位数,多余的小数会被裁剪
Types ¶
type Dispute ¶
type Dispute struct {
ID uint64 `json:"id,string" gorm:"primaryKey"`
OrderID uint64 `json:"order_id,string" gorm:"uniqueIndex:idx_dispute_order;index:idx_dispute_order_status,priority:1;not null"`
InitiatorUserID uint64 `json:"initiator_user_id" gorm:"not null;index:idx_initiator_status_created,priority:1"`
Reason string `json:"reason" gorm:"size:500;not null"`
Status DisputeStatus `` /* 160-byte string literal not displayed */
HandlerUserID *uint64 `json:"handler_user_id" gorm:"index"`
InitiatorUsername string `json:"initiator_username" gorm:"-:migration;->"`
HandlerUsername string `json:"handler_username" gorm:"-:migration;->"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index:idx_initiator_status_created,priority:3"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
type DisputeStatus ¶
type DisputeStatus string
const ( DisputeStatusDisputing DisputeStatus = "disputing" DisputeStatusRefund DisputeStatus = "refund" DisputeStatusClosed DisputeStatus = "closed" )
type LeaderboardResponse ¶
type LeaderboardResponse struct {
Users []LeaderboardUser `json:"users"`
}
LeaderboardResponse 排行榜 API 响应
func GetLeaderboard ¶
func GetLeaderboard(ctx context.Context, page int) (*LeaderboardResponse, error)
GetLeaderboard 获取排行榜数据
type LeaderboardUser ¶
type LeaderboardUser struct {
ID uint64 `json:"id"`
Username string `json:"username"`
TotalScore int64 `json:"total_score"`
}
LeaderboardUser 排行榜用户信息
type MerchantAPIKey ¶
type MerchantAPIKey struct {
ID uint64 `json:"id,string" gorm:"primaryKey"`
UserID uint64 `json:"user_id" gorm:"not null;index:idx_merchant_api_keys_user_created,priority:1"`
ClientID string `json:"client_id" gorm:"size:64;uniqueIndex;index:idx_client_credentials,priority:2;not null"`
ClientSecret string `json:"client_secret" gorm:"size:64;index:idx_client_credentials,priority:1;not null"`
AppName string `json:"app_name" gorm:"size:20;not null"`
AppHomepageURL string `json:"app_homepage_url" gorm:"size:100;not null"`
AppDescription string `json:"app_description" gorm:"size:100"`
RedirectURI string `json:"redirect_uri" gorm:"size:100"`
NotifyURL string `json:"notify_url" gorm:"size:100;not null"`
TestMode bool `json:"test_mode" gorm:"default:false"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index:idx_merchant_api_keys_user_created,priority:2"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}
func (*MerchantAPIKey) BeforeCreate ¶
func (m *MerchantAPIKey) BeforeCreate(*gorm.DB) error
func (*MerchantAPIKey) GetByClientID ¶
func (m *MerchantAPIKey) GetByClientID(tx *gorm.DB, clientID string) error
GetByClientID 通过 ClientID 查询商户 API Key
type MerchantPaymentLink ¶
type MerchantPaymentLink struct {
ID uint64 `json:"id,string" gorm:"primaryKey"`
MerchantAPIKeyID uint64 `json:"merchant_api_key_id,string" gorm:"not null;index"`
Token string `json:"token" gorm:"size:64;uniqueIndex;not null"`
Amount decimal.Decimal `json:"amount" gorm:"type:numeric(20,2);not null"`
ProductName string `json:"product_name" gorm:"size:30;not null"`
Remark string `json:"remark" gorm:"size:100"`
TotalLimit *uint `json:"total_limit" gorm:"default:null"`
UserLimit *uint `json:"user_limit" gorm:"default:null"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}
func (*MerchantPaymentLink) BeforeCreate ¶
func (m *MerchantPaymentLink) BeforeCreate(*gorm.DB) error
func (*MerchantPaymentLink) GetByToken ¶
func (m *MerchantPaymentLink) GetByToken(tx *gorm.DB, token string) error
GetByToken 通过 Token 查询支付链接
type OAuthUserInfo ¶
type OAuthUserInfo struct {
Id uint64 `json:"id"`
Sub string `json:"sub"`
Username string `json:"username"`
Name string `json:"name"`
Active bool `json:"active"`
AvatarUrl string `json:"avatar_url"`
TrustLevel TrustLevel `json:"trust_level"`
}
OAuthUserInfo 用户信息结构(同时支持 OIDC ID Token claims 和 UserEndpoint 响应)
type Order ¶
type Order struct {
ID uint64 `json:"id,string" gorm:"primaryKey"`
OrderNo string `json:"order_no" gorm:"-"`
OrderName string `json:"order_name" gorm:"size:64;not null;index"`
MerchantOrderNo *string `json:"merchant_order_no" gorm:"size:64;uniqueIndex:idx_orders_client_merchant_order,priority:2"`
ClientID string `` /* 219-byte string literal not displayed */
PayerUserID uint64 `` /* 174-byte string literal not displayed */
PayeeUserID uint64 `json:"payee_user_id" gorm:"index:idx_orders_payee_status_type_created,priority:1;index:idx_orders_client_payee,priority:2"`
PayerUsername string `json:"payer_username" gorm:"-:migration;->"`
PayeeUsername string `json:"payee_username" gorm:"-:migration;->"`
Amount decimal.Decimal `json:"amount" gorm:"type:numeric(20,2);not null;index"`
Status OrderStatus `` /* 304-byte string literal not displayed */
Type OrderType `` /* 204-byte string literal not displayed */
Remark string `json:"remark" gorm:"size:255"`
PaymentType string `json:"payment_type" gorm:"size:20"`
PaymentLinkID *uint64 `json:"payment_link_id,string" gorm:"index:idx_orders_payment_link_status,priority:1"`
TradeTime time.Time `json:"trade_time" gorm:"index:idx_orders_payer_status_type_trade,priority:4"`
ExpiresAt time.Time `json:"expires_at" gorm:"not null"`
CreatedAt time.Time `` /* 197-byte string literal not displayed */
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;index"`
}
type OrderStatus ¶
type OrderStatus string
const ( OrderStatusSuccess OrderStatus = "success" OrderStatusFailed OrderStatus = "failed" OrderStatusPending OrderStatus = "pending" OrderStatusExpired OrderStatus = "expired" OrderStatusDisputing OrderStatus = "disputing" OrderStatusRefund OrderStatus = "refund" OrderStatusRefused OrderStatus = "refused" )
type OrderType ¶
type OrderType string
const ( OrderTypeReceive OrderType = "receive" OrderTypePayment OrderType = "payment" OrderTypeTransfer OrderType = "transfer" OrderTypeCommunity OrderType = "community" OrderTypeOnline OrderType = "online" OrderTypeTest OrderType = "test" OrderTypeDistribute OrderType = "distribute" OrderTypeRedEnvelopeSend OrderType = "red_envelope_send" OrderTypeRedEnvelopeReceive OrderType = "red_envelope_receive" OrderTypeRedEnvelopeRefund OrderType = "red_envelope_refund" )
type RedEnvelope ¶
type RedEnvelope struct {
ID uint64 `json:"id,string" gorm:"primaryKey"`
CreatorID uint64 `json:"creator_id,string" gorm:"index;not null"`
CreatorUsername string `json:"creator_username" gorm:"-:migration;->"`
CreatorAvatarURL string `json:"creator_avatar_url" gorm:"-:migration;->"`
Type RedEnvelopeType `json:"type" gorm:"type:varchar(20);not null"`
TotalAmount decimal.Decimal `json:"total_amount" gorm:"type:numeric(20,2);not null"`
RemainingAmount decimal.Decimal `json:"remaining_amount" gorm:"type:numeric(20,2);not null"`
TotalCount int `json:"total_count" gorm:"not null"`
RemainingCount int `json:"remaining_count" gorm:"not null"`
Greeting string `json:"greeting" gorm:"size:100"`
Status RedEnvelopeStatus `json:"status" gorm:"type:varchar(20);not null"`
ExpiresAt time.Time `json:"expires_at" gorm:"not null;index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
RedEnvelope 红包
type RedEnvelopeClaim ¶
type RedEnvelopeClaim struct {
ID uint64 `json:"id,string" gorm:"primaryKey"`
RedEnvelopeID uint64 `json:"red_envelope_id,string" gorm:"uniqueIndex:idx_red_envelope_user,priority:2;not null"`
UserID uint64 `json:"user_id,string" gorm:"uniqueIndex:idx_red_envelope_user,priority:1;not null"`
Username string `json:"username" gorm:"-:migration;->"`
AvatarURL string `json:"avatar_url" gorm:"-:migration;->"`
Amount decimal.Decimal `json:"amount" gorm:"type:numeric(20,2);not null"`
ClaimedAt time.Time `json:"claimed_at" gorm:"autoCreateTime"`
}
RedEnvelopeClaim 红包领取记录
type RedEnvelopeStatus ¶
type RedEnvelopeStatus string
const ( RedEnvelopeStatusActive RedEnvelopeStatus = "active" RedEnvelopeStatusFinished RedEnvelopeStatus = "finished" RedEnvelopeStatusExpired RedEnvelopeStatus = "expired" )
type RedEnvelopeType ¶
type RedEnvelopeType string
const ( RedEnvelopeTypeFixed RedEnvelopeType = "fixed" RedEnvelopeTypeRandom RedEnvelopeType = "random" )
type SystemConfig ¶
type SystemConfig struct {
Key string `json:"key" gorm:"primaryKey;size:64;not null"`
Value string `json:"value" gorm:"size:255;not null"`
Description string `json:"description" gorm:"size:255"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
}
type TrustLevel ¶
type TrustLevel uint8
const ( TrustLevelNewUser TrustLevel = iota TrustLevelBasicUser TrustLevelUser TrustLevelActiveUser TrustLevelLeader )
type User ¶
type User struct {
ID uint64 `json:"id" gorm:"primaryKey;index:idx_users_avail_bal_id,priority:2"`
Username string `json:"username" gorm:"size:64;uniqueIndex"`
Nickname string `json:"nickname" gorm:"size:100"`
AvatarUrl string `json:"avatar_url" gorm:"size:100"`
TrustLevel TrustLevel `json:"trust_level" gorm:"index"`
PayScore int64 `json:"pay_score" gorm:"default:0;index"`
PayKey string `json:"pay_key" gorm:"size:128"`
SignKey string `json:"sign_key" gorm:"size:64;uniqueIndex;not null"`
TotalReceive decimal.Decimal `json:"total_receive" gorm:"type:numeric(20,2);default:0"`
TotalPayment decimal.Decimal `json:"total_payment" gorm:"type:numeric(20,2);default:0"`
TotalTransfer decimal.Decimal `json:"total_transfer" gorm:"type:numeric(20,2);default:0"`
TotalCommunity decimal.Decimal `json:"total_community" gorm:"type:numeric(20,2);default:0"`
CommunityBalance decimal.Decimal `json:"community_balance" gorm:"type:numeric(20,2);default:0"`
AvailableBalance decimal.Decimal `json:"available_balance" gorm:"type:numeric(20,2);default:0;index:idx_users_avail_bal_id,priority:1"`
IsActive bool `json:"is_active" gorm:"default:true"`
IsAdmin bool `json:"is_admin" gorm:"default:false"`
LastLoginAt time.Time `json:"last_login_at" gorm:"index"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime;index"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime;index"`
}
func (*User) CreateWithInitialCredit ¶
func (u *User) CreateWithInitialCredit(ctx context.Context, oauthInfo *OAuthUserInfo) error
CreateWithInitialCredit 创建新用户并初始化积分、订单 如果u不为空(u.ID != 0),会先将当前用户标记为已注销,然后创建新用户
func (*User) EnqueueBadgeScoreTask ¶
EnqueueBadgeScoreTask 为用户下发积分计算任务
func (*User) GetUserGamificationScore ¶
func (u *User) GetUserGamificationScore(ctx context.Context) (*UserGamificationScoreResponse, error)
func (*User) UpdateFromOAuthInfo ¶
func (u *User) UpdateFromOAuthInfo(oauthInfo *OAuthUserInfo)
UpdateFromOAuthInfo 根据 OAuth 信息更新用户数据
func (*User) VerifyPayKey ¶
VerifyPayKey 验证用户支付密码 使用用户的 SignKey 解密存储的加密密码,然后与输入的明文密码比较
type UserGamificationScoreResponse ¶
type UserGamificationScoreResponse struct {
User struct {
GamificationScore int64 `json:"gamification_score"`
} `json:"user"`
}
UserGamificationScoreResponse API响应
type UserPayConfig ¶
type UserPayConfig struct {
ID uint64 `json:"id,string" gorm:"primaryKey;autoIncrement"`
Level PayLevel `json:"level" gorm:"uniqueIndex;not null"`
MinScore int64 `json:"min_score" gorm:"not null;index:idx_score_range,priority:1"`
MaxScore *int64 `json:"max_score" gorm:"index:idx_score_range,priority:2"`
DailyLimit *int64 `json:"daily_limit"`
FeeRate decimal.Decimal `json:"fee_rate" gorm:"type:numeric(3,2);default:0;check:fee_rate >= 0 AND fee_rate <= 1"`
ScoreRate decimal.Decimal `json:"score_rate" gorm:"type:numeric(3,2);default:0;check:score_rate >= 0 AND score_rate <= 1"`
DistributeRate decimal.Decimal `json:"distribute_rate" gorm:"type:numeric(3,2);default:0;check:distribute_rate >= 0 AND distribute_rate <= 1"`
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime"`
UpdatedAt time.Time `json:"updated_at" gorm:"autoUpdateTime"`
}
func (*UserPayConfig) GetByID ¶
func (upc *UserPayConfig) GetByID(tx *gorm.DB, id uint64) error
GetByID 通过 ID 查询支付配置
func (*UserPayConfig) GetByPayScore ¶
func (upc *UserPayConfig) GetByPayScore(tx *gorm.DB, payScore int64) error
GetByPayScore 通过 pay_score 查询对应的支付配置