feat: publish sanitized custom.97 source
This commit is contained in:
1022 files changed
+69903
-19207
No files matched your search
+54
-53
@@ -43,12 +43,13 @@ const (
|
||||
)
|
||||
|
||||
var (
|
||||
ErrPaymentMethodMismatch = errors.New("payment method mismatch")
|
||||
ErrTopUpNotFound = errors.New("topup not found")
|
||||
ErrTopUpStatusInvalid = errors.New("topup status invalid")
|
||||
ErrInvalidTopUpQuota = errors.New("invalid top-up quota")
|
||||
ErrTopUpQuotaLimitExceeded = errors.New("top-up quota limit exceeded")
|
||||
ErrWalletQuotaLimitExceeded = errors.New("wallet quota limit exceeded")
|
||||
ErrPaymentMethodMismatch = errors.New("payment method mismatch")
|
||||
ErrTopUpNotFound = errors.New("topup not found")
|
||||
ErrTopUpStatusInvalid = errors.New("topup status invalid")
|
||||
// The quota errors reach the web console, so they carry message keys.
|
||||
ErrInvalidTopUpQuota error = common.NewMessage("Invalid top-up quota")
|
||||
ErrTopUpQuotaLimitExceeded error = common.NewMessage("Top-up quota limit exceeded")
|
||||
ErrWalletQuotaLimitExceeded error = common.NewMessage("Wallet quota limit exceeded")
|
||||
)
|
||||
|
||||
func (topUp *TopUp) Insert() error {
|
||||
@@ -144,7 +145,7 @@ func GetTopUpByTradeNo(tradeNo string) *TopUp {
|
||||
|
||||
func UpdatePendingTopUpStatus(tradeNo string, expectedPaymentProvider string, targetStatus string) error {
|
||||
if tradeNo == "" {
|
||||
return errors.New("未提供支付单号")
|
||||
return errors.New("payment order number not provided")
|
||||
}
|
||||
|
||||
refCol := "`trade_no`"
|
||||
@@ -175,7 +176,7 @@ func UpdatePendingTopUpStatus(tradeNo string, expectedPaymentProvider string, ta
|
||||
// 进程内的 LockOrder 只是优化,正确性由本函数的数据库行锁保证。
|
||||
func RechargeEpay(tradeNo string, actualPaymentMethod string, callerIp string) (alreadyDone bool, err error) {
|
||||
if tradeNo == "" {
|
||||
return false, errors.New("未提供支付单号")
|
||||
return false, errors.New("payment order number not provided")
|
||||
}
|
||||
|
||||
refCol := "`trade_no`"
|
||||
@@ -218,23 +219,23 @@ func RechargeEpay(tradeNo string, actualPaymentMethod string, callerIp string) (
|
||||
})
|
||||
if err != nil {
|
||||
if !errors.Is(err, ErrTopUpNotFound) && !errors.Is(err, ErrPaymentMethodMismatch) && !errors.Is(err, ErrTopUpStatusInvalid) {
|
||||
common.SysError("epay topup failed: " + err.Error())
|
||||
common.SysError(common.LogText("epay topup failed: %s", err.Error()))
|
||||
}
|
||||
return false, err
|
||||
}
|
||||
if alreadyDone {
|
||||
return true, nil
|
||||
}
|
||||
syncCreditUserQuotaCache(topUp.UserId, quotaToAdd, "epay topup")
|
||||
syncCreditUserQuotaCache(topUp.UserId, quotaToAdd, common.LogText("epay topup"))
|
||||
|
||||
common.SysLog(fmt.Sprintf("易支付充值成功 trade_no=%s user_id=%d quota_to_add=%d money=%.2f", topUp.TradeNo, topUp.UserId, quotaToAdd, topUp.Money))
|
||||
RecordTopupLog(topUp.UserId, fmt.Sprintf("使用在线充值成功,充值金额: %v,支付金额:%f", logger.LogQuota(quotaToAdd), topUp.Money), callerIp, topUp.PaymentMethod, PaymentProviderEpay)
|
||||
common.SysLog(common.LogText("Epay top-up succeeded trade_no=%s user_id=%d quota_to_add=%d money=%.2f", topUp.TradeNo, topUp.UserId, quotaToAdd, topUp.Money))
|
||||
RecordTopupLog(topUp.UserId, common.NewMessage("Online top-up succeeded, amount added: {{quota}}, payment amount: {{amount}}", map[string]any{"quota": logger.FormatQuota(quotaToAdd), "amount": fmt.Sprintf("%f", topUp.Money)}), callerIp, topUp.PaymentMethod, PaymentProviderEpay)
|
||||
return false, nil
|
||||
}
|
||||
|
||||
func Recharge(referenceId string, customerId string, callerIp string) (err error) {
|
||||
if referenceId == "" {
|
||||
return errors.New("未提供支付单号")
|
||||
return errors.New("payment order number not provided")
|
||||
}
|
||||
|
||||
var quota int
|
||||
@@ -248,7 +249,7 @@ func Recharge(referenceId string, customerId string, callerIp string) (err error
|
||||
err = DB.Transaction(func(tx *gorm.DB) error {
|
||||
err := lockForUpdate(tx).Where(refCol+" = ?", referenceId).First(topUp).Error
|
||||
if err != nil {
|
||||
return errors.New("充值订单不存在")
|
||||
return errors.New("top-up order not found")
|
||||
}
|
||||
|
||||
if topUp.PaymentProvider != PaymentProviderStripe {
|
||||
@@ -256,7 +257,7 @@ func Recharge(referenceId string, customerId string, callerIp string) (err error
|
||||
}
|
||||
|
||||
if topUp.Status != common.TopUpStatusPending {
|
||||
return errors.New("充值订单状态错误")
|
||||
return errors.New("invalid top-up order status")
|
||||
}
|
||||
|
||||
topUp.CompleteTime = common.GetTimestamp()
|
||||
@@ -278,12 +279,12 @@ func Recharge(referenceId string, customerId string, callerIp string) (err error
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
common.SysError("topup failed: " + err.Error())
|
||||
return errors.New("充值失败,请稍后重试")
|
||||
common.SysError(common.LogText("topup failed: %s", err.Error()))
|
||||
return errors.New("top-up failed")
|
||||
}
|
||||
syncCreditUserQuotaCache(topUp.UserId, quota, "stripe topup")
|
||||
syncCreditUserQuotaCache(topUp.UserId, quota, common.LogText("stripe topup"))
|
||||
|
||||
RecordTopupLog(topUp.UserId, fmt.Sprintf("使用在线充值成功,充值金额: %v,支付金额:%d", logger.FormatQuota(quota), topUp.Amount), callerIp, topUp.PaymentMethod, PaymentMethodStripe)
|
||||
RecordTopupLog(topUp.UserId, common.NewMessage("Online top-up succeeded, amount added: {{quota}}, payment amount: {{amount}}", map[string]any{"quota": logger.FormatQuota(quota), "amount": topUp.Amount}), callerIp, topUp.PaymentMethod, PaymentMethodStripe)
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -389,14 +390,14 @@ func SearchUserTopUps(userId int, keyword string, pageInfo *common.PageInfo) (to
|
||||
|
||||
if err = query.Limit(searchTopUpCountHardLimit).Count(&total).Error; err != nil {
|
||||
tx.Rollback()
|
||||
common.SysError("failed to count search topups: " + err.Error())
|
||||
return nil, 0, errors.New("搜索充值记录失败")
|
||||
common.SysError(common.LogText("failed to count search topups: %s", err.Error()))
|
||||
return nil, 0, common.NewMessage("Failed to search top-up records")
|
||||
}
|
||||
|
||||
if err = query.Order("id desc").Limit(pageInfo.GetPageSize()).Offset(pageInfo.GetStartIdx()).Find(&topups).Error; err != nil {
|
||||
tx.Rollback()
|
||||
common.SysError("failed to search topups: " + err.Error())
|
||||
return nil, 0, errors.New("搜索充值记录失败")
|
||||
common.SysError(common.LogText("failed to search topups: %s", err.Error()))
|
||||
return nil, 0, common.NewMessage("Failed to search top-up records")
|
||||
}
|
||||
|
||||
if err = tx.Commit().Error; err != nil {
|
||||
@@ -429,14 +430,14 @@ func SearchAllTopUps(keyword string, pageInfo *common.PageInfo) (topups []*TopUp
|
||||
|
||||
if err = query.Limit(searchTopUpCountHardLimit).Count(&total).Error; err != nil {
|
||||
tx.Rollback()
|
||||
common.SysError("failed to count search topups: " + err.Error())
|
||||
return nil, 0, errors.New("搜索充值记录失败")
|
||||
common.SysError(common.LogText("failed to count search topups: %s", err.Error()))
|
||||
return nil, 0, common.NewMessage("Failed to search top-up records")
|
||||
}
|
||||
|
||||
if err = query.Order("id desc").Limit(pageInfo.GetPageSize()).Offset(pageInfo.GetStartIdx()).Find(&topups).Error; err != nil {
|
||||
tx.Rollback()
|
||||
common.SysError("failed to search topups: " + err.Error())
|
||||
return nil, 0, errors.New("搜索充值记录失败")
|
||||
common.SysError(common.LogText("failed to search topups: %s", err.Error()))
|
||||
return nil, 0, common.NewMessage("Failed to search top-up records")
|
||||
}
|
||||
|
||||
if err = tx.Commit().Error; err != nil {
|
||||
@@ -448,7 +449,7 @@ func SearchAllTopUps(keyword string, pageInfo *common.PageInfo) (topups []*TopUp
|
||||
// ManualCompleteTopUp 管理员手动完成订单并给用户充值
|
||||
func ManualCompleteTopUp(tradeNo string, callerIp string) error {
|
||||
if tradeNo == "" {
|
||||
return errors.New("未提供订单号")
|
||||
return common.NewMessage("Order number not provided")
|
||||
}
|
||||
|
||||
refCol := "`trade_no`"
|
||||
@@ -465,7 +466,7 @@ func ManualCompleteTopUp(tradeNo string, callerIp string) error {
|
||||
topUp := &TopUp{}
|
||||
// 行级锁,避免并发补单
|
||||
if err := lockForUpdate(tx).Where(refCol+" = ?", tradeNo).First(topUp).Error; err != nil {
|
||||
return errors.New("充值订单不存在")
|
||||
return common.NewMessage("Top-up order does not exist")
|
||||
}
|
||||
|
||||
// 幂等处理:已成功直接返回
|
||||
@@ -474,7 +475,7 @@ func ManualCompleteTopUp(tradeNo string, callerIp string) error {
|
||||
}
|
||||
|
||||
if topUp.Status != common.TopUpStatusPending {
|
||||
return errors.New("订单状态不是待支付,无法补单")
|
||||
return common.NewMessage("Order is not pending payment and cannot be completed")
|
||||
}
|
||||
|
||||
// 计算应充值额度:
|
||||
@@ -517,13 +518,13 @@ func ManualCompleteTopUp(tradeNo string, callerIp string) error {
|
||||
}
|
||||
|
||||
// 事务外记录日志,避免阻塞
|
||||
syncCreditUserQuotaCache(userId, quotaToAdd, "manual topup")
|
||||
RecordTopupLog(userId, fmt.Sprintf("管理员补单成功,充值金额: %v,支付金额:%f", logger.FormatQuota(quotaToAdd), payMoney), callerIp, paymentMethod, "admin")
|
||||
syncCreditUserQuotaCache(userId, quotaToAdd, common.LogText("manual topup"))
|
||||
RecordTopupLog(userId, common.NewMessage("Administrator completed the order, amount added: {{quota}}, payment amount: {{amount}}", map[string]any{"quota": logger.FormatQuota(quotaToAdd), "amount": fmt.Sprintf("%f", payMoney)}), callerIp, paymentMethod, "admin")
|
||||
return nil
|
||||
}
|
||||
func RechargeCreem(referenceId string, customerEmail string, customerName string, callerIp string) (err error) {
|
||||
if referenceId == "" {
|
||||
return errors.New("未提供支付单号")
|
||||
return errors.New("payment order number not provided")
|
||||
}
|
||||
|
||||
var quota int
|
||||
@@ -537,7 +538,7 @@ func RechargeCreem(referenceId string, customerEmail string, customerName string
|
||||
err = DB.Transaction(func(tx *gorm.DB) error {
|
||||
err := lockForUpdate(tx).Where(refCol+" = ?", referenceId).First(topUp).Error
|
||||
if err != nil {
|
||||
return errors.New("充值订单不存在")
|
||||
return errors.New("top-up order not found")
|
||||
}
|
||||
|
||||
if topUp.PaymentProvider != PaymentProviderCreem {
|
||||
@@ -545,7 +546,7 @@ func RechargeCreem(referenceId string, customerEmail string, customerName string
|
||||
}
|
||||
|
||||
if topUp.Status != common.TopUpStatusPending {
|
||||
return errors.New("充值订单状态错误")
|
||||
return errors.New("invalid top-up order status")
|
||||
}
|
||||
|
||||
topUp.CompleteTime = common.GetTimestamp()
|
||||
@@ -583,19 +584,19 @@ func RechargeCreem(referenceId string, customerEmail string, customerName string
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
common.SysError("creem topup failed: " + err.Error())
|
||||
return errors.New("充值失败,请稍后重试")
|
||||
common.SysError(common.LogText("creem topup failed: %s", err.Error()))
|
||||
return errors.New("top-up failed")
|
||||
}
|
||||
syncCreditUserQuotaCache(topUp.UserId, quota, "creem topup")
|
||||
syncCreditUserQuotaCache(topUp.UserId, quota, common.LogText("creem topup"))
|
||||
|
||||
RecordTopupLog(topUp.UserId, fmt.Sprintf("使用Creem充值成功,充值额度: %v,支付金额:%.2f", quota, topUp.Money), callerIp, topUp.PaymentMethod, PaymentMethodCreem)
|
||||
RecordTopupLog(topUp.UserId, common.NewMessage("{{provider}} top-up succeeded, amount added: {{quota}}, payment amount: {{amount}}", map[string]any{"provider": "Creem", "quota": quota, "amount": fmt.Sprintf("%.2f", topUp.Money)}), callerIp, topUp.PaymentMethod, PaymentMethodCreem)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func RechargeWaffo(tradeNo string, callerIp string) (err error) {
|
||||
if tradeNo == "" {
|
||||
return errors.New("未提供支付单号")
|
||||
return errors.New("payment order number not provided")
|
||||
}
|
||||
|
||||
var quotaToAdd int
|
||||
@@ -609,7 +610,7 @@ func RechargeWaffo(tradeNo string, callerIp string) (err error) {
|
||||
err = DB.Transaction(func(tx *gorm.DB) error {
|
||||
err := lockForUpdate(tx).Where(refCol+" = ?", tradeNo).First(topUp).Error
|
||||
if err != nil {
|
||||
return errors.New("充值订单不存在")
|
||||
return errors.New("top-up order not found")
|
||||
}
|
||||
|
||||
if topUp.PaymentProvider != PaymentProviderWaffo {
|
||||
@@ -621,7 +622,7 @@ func RechargeWaffo(tradeNo string, callerIp string) (err error) {
|
||||
}
|
||||
|
||||
if topUp.Status != common.TopUpStatusPending {
|
||||
return errors.New("充值订单状态错误")
|
||||
return errors.New("invalid top-up order status")
|
||||
}
|
||||
|
||||
quotaToAdd, err = common.WalletQuotaFromDecimalStrict(
|
||||
@@ -641,13 +642,13 @@ func RechargeWaffo(tradeNo string, callerIp string) (err error) {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
common.SysError("waffo topup failed: " + err.Error())
|
||||
return errors.New("充值失败,请稍后重试")
|
||||
common.SysError(common.LogText("waffo topup failed: %s", err.Error()))
|
||||
return errors.New("top-up failed")
|
||||
}
|
||||
syncCreditUserQuotaCache(topUp.UserId, quotaToAdd, "waffo topup")
|
||||
syncCreditUserQuotaCache(topUp.UserId, quotaToAdd, common.LogText("waffo topup"))
|
||||
|
||||
if quotaToAdd > 0 {
|
||||
RecordTopupLog(topUp.UserId, fmt.Sprintf("Waffo充值成功,充值额度: %v,支付金额: %.2f", logger.FormatQuota(quotaToAdd), topUp.Money), callerIp, topUp.PaymentMethod, PaymentMethodWaffo)
|
||||
RecordTopupLog(topUp.UserId, common.NewMessage("{{provider}} top-up succeeded, amount added: {{quota}}, payment amount: {{amount}}", map[string]any{"provider": "Waffo", "quota": logger.FormatQuota(quotaToAdd), "amount": fmt.Sprintf("%.2f", topUp.Money)}), callerIp, topUp.PaymentMethod, PaymentMethodWaffo)
|
||||
}
|
||||
|
||||
return nil
|
||||
@@ -655,7 +656,7 @@ func RechargeWaffo(tradeNo string, callerIp string) (err error) {
|
||||
|
||||
func RechargeWaffoPancake(tradeNo string) (err error) {
|
||||
if tradeNo == "" {
|
||||
return errors.New("未提供支付单号")
|
||||
return errors.New("payment order number not provided")
|
||||
}
|
||||
|
||||
var quotaToAdd int
|
||||
@@ -669,7 +670,7 @@ func RechargeWaffoPancake(tradeNo string) (err error) {
|
||||
err = DB.Transaction(func(tx *gorm.DB) error {
|
||||
err := lockForUpdate(tx).Where(refCol+" = ?", tradeNo).First(topUp).Error
|
||||
if err != nil {
|
||||
return errors.New("充值订单不存在")
|
||||
return errors.New("top-up order not found")
|
||||
}
|
||||
|
||||
if topUp.PaymentProvider != PaymentProviderWaffoPancake {
|
||||
@@ -681,7 +682,7 @@ func RechargeWaffoPancake(tradeNo string) (err error) {
|
||||
}
|
||||
|
||||
if topUp.Status != common.TopUpStatusPending {
|
||||
return errors.New("充值订单状态错误")
|
||||
return errors.New("invalid top-up order status")
|
||||
}
|
||||
|
||||
quotaToAdd, err = common.WalletQuotaFromDecimalStrict(
|
||||
@@ -701,13 +702,13 @@ func RechargeWaffoPancake(tradeNo string) (err error) {
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
common.SysError("waffo pancake topup failed: " + err.Error())
|
||||
return errors.New("充值失败,请稍后重试")
|
||||
common.SysError(common.LogText("waffo pancake topup failed: %s", err.Error()))
|
||||
return errors.New("top-up failed")
|
||||
}
|
||||
syncCreditUserQuotaCache(topUp.UserId, quotaToAdd, "waffo pancake topup")
|
||||
syncCreditUserQuotaCache(topUp.UserId, quotaToAdd, common.LogText("waffo pancake topup"))
|
||||
|
||||
if quotaToAdd > 0 {
|
||||
RecordLog(topUp.UserId, LogTypeTopup, fmt.Sprintf("Waffo Pancake充值成功,充值额度: %v,支付金额: %.2f", logger.FormatQuota(quotaToAdd), topUp.Money))
|
||||
RecordLog(topUp.UserId, LogTypeTopup, common.NewMessage("{{provider}} top-up succeeded, amount added: {{quota}}, payment amount: {{amount}}", map[string]any{"provider": "Waffo Pancake", "quota": logger.FormatQuota(quotaToAdd), "amount": fmt.Sprintf("%.2f", topUp.Money)}))
|
||||
}
|
||||
|
||||
return nil
|
||||
|
||||
Reference in new issue
Block a user