feat(tenant): 按租户隔离支付退款与商户配置
This commit is contained in:
@@ -5,6 +5,7 @@ import (
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/tenancy"
|
||||
|
||||
"go.uber.org/zap"
|
||||
"gorm.io/gorm"
|
||||
@@ -114,6 +115,7 @@ func (r *Repository) StartMohong(ctx context.Context, userID uint64, orderID uin
|
||||
func (r *Repository) prepareMohongPayment(ctx context.Context, userID uint64, orderID uint64, req StartPaymentRequest, runtimeConfig runtimePaymentConfig) (*model.PaymentOrder, *model.MohongOrder, error) {
|
||||
var paymentID uint64
|
||||
var orderRow model.MohongOrder
|
||||
tenantID := tenancy.IDFromContext(ctx)
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var row model.MohongOrder
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).
|
||||
@@ -137,6 +139,7 @@ func (r *Repository) prepareMohongPayment(ctx context.Context, userID uint64, or
|
||||
existing.PayWay = firstNonEmpty(req.PayWay, existing.PayWay, runtimeConfig.PayWay, "ZFBZF")
|
||||
existing.JSPayFlag = firstNonEmpty(req.JSPayFlag, existing.JSPayFlag, runtimeConfig.JSPayFlag, "2")
|
||||
existing.AmountCent = row.AmountCent
|
||||
existing.TenantID = firstNonZero(existing.TenantID, tenantID)
|
||||
existing.PaymentConfigID = firstNonZero(existing.PaymentConfigID, runtimeConfig.ID)
|
||||
existing.Provider = firstNonEmpty(existing.Provider, runtimeConfig.Provider)
|
||||
existing.MerchantID = firstNonEmpty(existing.MerchantID, runtimeConfig.MerchantID)
|
||||
@@ -153,7 +156,7 @@ func (r *Repository) prepareMohongPayment(ctx context.Context, userID uint64, or
|
||||
} else if err != gorm.ErrRecordNotFound {
|
||||
return err
|
||||
}
|
||||
payment, err := newMohongPayment(row, req, runtimeConfig)
|
||||
payment, err := newMohongPayment(row, req, runtimeConfig, tenantID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -174,12 +177,13 @@ func (r *Repository) prepareMohongPayment(ctx context.Context, userID uint64, or
|
||||
return payment, &orderRow, nil
|
||||
}
|
||||
|
||||
func newMohongPayment(row model.MohongOrder, req StartPaymentRequest, runtimeConfig runtimePaymentConfig) (model.PaymentOrder, error) {
|
||||
func newMohongPayment(row model.MohongOrder, req StartPaymentRequest, runtimeConfig runtimePaymentConfig, tenantID uint64) (model.PaymentOrder, error) {
|
||||
paymentNo, err := newPaymentNo()
|
||||
if err != nil {
|
||||
return model.PaymentOrder{}, err
|
||||
}
|
||||
payment := model.PaymentOrder{
|
||||
TenantID: tenantID,
|
||||
PaymentNo: paymentNo,
|
||||
OrderID: row.ID,
|
||||
OrderNo: row.OrderNo,
|
||||
@@ -205,8 +209,12 @@ func newMohongPayment(row model.MohongOrder, req StartPaymentRequest, runtimeCon
|
||||
// QueryMohong 查询撞车订单支付状态。
|
||||
func (r *Repository) QueryMohong(ctx context.Context, userID uint64, orderID uint64) (*PaymentDTO, error) {
|
||||
var payment model.PaymentOrder
|
||||
if err := r.db.WithContext(ctx).
|
||||
Where("order_id = ? AND user_id = ? AND biz_type = ?", orderID, userID, bizTypeMohongPay).
|
||||
query := r.db.WithContext(ctx).
|
||||
Where("order_id = ? AND user_id = ? AND biz_type = ?", orderID, userID, bizTypeMohongPay)
|
||||
if tenantID := tenancy.IDFromContext(ctx); tenantID > 0 {
|
||||
query = query.Where("tenant_id = ?", tenantID)
|
||||
}
|
||||
if err := query.
|
||||
Order("id DESC").
|
||||
First(&payment).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
|
||||
Reference in New Issue
Block a user