修复退款审核详情关联与空值展示
This commit is contained in:
@@ -45,6 +45,15 @@ func MockData(database *gorm.DB) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// 财务退款属于平台审核业务,Mock 审核人必须引用平台账号而不是气站账号。
|
||||
if err := ensureMockRoot(tx, string(passwordHash)); err != nil {
|
||||
return err
|
||||
}
|
||||
var rootAccount models.PlatformAccount
|
||||
if err := tx.Where("username = ?", "root").First(&rootAccount).Error; err != nil {
|
||||
return fmt.Errorf("find root platform account for mock refund: %w", err)
|
||||
}
|
||||
|
||||
delivery := models.DeliveryBasic{
|
||||
Entity: entity(3, common.StatusEnable), DeliveryCode: "MOCK-DELIVERY-001",
|
||||
GasBasicID: gas.ID, Name: "和气示例配送点", Principal: "李主管",
|
||||
@@ -394,11 +403,14 @@ func MockData(database *gorm.DB) error {
|
||||
Entity: entity(37, common.StatusEnable), RefundStatus: 20, WalletBasicID: wallet.ID,
|
||||
PaymentOrderID: walletPayment.ID, RefundNo: "MOCK-REFUND-001", RequestNo: "MOCK-REQ-REFUND-001",
|
||||
BusinessType: "gasorder", BusinessIdentity: gasOrder.Identity, UserIdentity: user.Identity,
|
||||
Amount: 1000, Reason: "模拟部分退款", ReviewerIdentity: gasAccount.Identity, ReviewedAt: &refundCompletedAt, CompletedAt: &refundCompletedAt,
|
||||
Amount: 1000, Reason: "模拟部分退款", ReviewerIdentity: rootAccount.Identity, ReviewedAt: &refundCompletedAt, CompletedAt: &refundCompletedAt,
|
||||
}
|
||||
if err := put(tx, &refund); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := repairMockRefundReviewer(tx, refund.Identity, rootAccount.Identity); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
applyCash := models.WalletApplyCash{
|
||||
Entity: entity(38, common.StatusEnable), ApplyStatus: common.StatusApproved, WalletBasicID: wallet.ID, WalletBankID: bank.ID,
|
||||
@@ -539,9 +551,6 @@ func MockData(database *gorm.DB) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := ensureMockRoot(tx, string(passwordHash)); err != nil {
|
||||
return err
|
||||
}
|
||||
var rootRole models.PlatformRole
|
||||
if err := tx.Where("role_code = ?", "root").First(&rootRole).Error; err != nil {
|
||||
return fmt.Errorf("find root role for mock menu: %w", err)
|
||||
@@ -1005,6 +1014,35 @@ func ensureMockRoot(database *gorm.DB, passwordHash string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// repairMockRefundReviewer 幂等修复历史 Mock 退款误关联气站账号的问题。
|
||||
func repairMockRefundReviewer(database *gorm.DB, refundIdentity string, reviewerIdentity string) error {
|
||||
if refundIdentity == "" || reviewerIdentity == "" {
|
||||
return errors.New("mock refund reviewer identity is missing")
|
||||
}
|
||||
result := database.Model(&models.PaymentRefund{}).
|
||||
Where("identity = ?", refundIdentity).
|
||||
Update("reviewer_identity", reviewerIdentity)
|
||||
if result.Error != nil {
|
||||
return fmt.Errorf("repair mock refund reviewer: %w", result.Error)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// RepairMockRefundReviewer 仅修复固定 Mock 退款,不触发其他模拟资源写入。
|
||||
func RepairMockRefundReviewer(database *gorm.DB) (int64, error) {
|
||||
var rootAccount models.PlatformAccount
|
||||
if err := database.Where("username = ?", "root").First(&rootAccount).Error; err != nil {
|
||||
return 0, fmt.Errorf("find root platform account for mock refund: %w", err)
|
||||
}
|
||||
result := database.Model(&models.PaymentRefund{}).
|
||||
Where("identity = ? AND refund_no = ?", entity(37, common.StatusEnable).Identity, "MOCK-REFUND-001").
|
||||
Update("reviewer_identity", rootAccount.Identity)
|
||||
if result.Error != nil {
|
||||
return 0, fmt.Errorf("repair mock refund reviewer: %w", result.Error)
|
||||
}
|
||||
return result.RowsAffected, nil
|
||||
}
|
||||
|
||||
func entity(sequence int, status int) models.Entity {
|
||||
return models.Entity{
|
||||
Identity: fmt.Sprintf("%s%012d", mockIdentityPrefix, sequence),
|
||||
|
||||
Reference in New Issue
Block a user