fix(distribution): 分站挂牌的号主收入记入对应分站钱包
结账和仲裁不再把分销站号主收入写入主站钱包,用户列表也只展示主站余额。 Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -33,7 +33,7 @@ func (r *Repository) finalizeCheckout(tx *gorm.DB, order *model.RentalOrder, che
|
||||
if settlement.ShortfallCent > 0 {
|
||||
return nil, ErrCheckoutDepositShortfall
|
||||
}
|
||||
if err := appendCheckoutOwnerIncome(tx, order, settlement); err != nil {
|
||||
if err := appendCheckoutOwnerIncome(tx, order, listing, settlement); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
refund, err := r.prepareCheckoutRefund(order, settlement)
|
||||
@@ -65,7 +65,14 @@ func (r *Repository) finalizeCheckout(tx *gorm.DB, order *model.RentalOrder, che
|
||||
return refund, nil
|
||||
}
|
||||
|
||||
func appendCheckoutOwnerIncome(tx *gorm.DB, order *model.RentalOrder, settlement checkoutSettlement) error {
|
||||
func ownerWalletSiteID(listing *model.RentalListing) uint64 {
|
||||
if listing != nil && listing.DistributionSiteID != nil {
|
||||
return *listing.DistributionSiteID
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
func appendCheckoutOwnerIncome(tx *gorm.DB, order *model.RentalOrder, listing *model.RentalListing, settlement checkoutSettlement) error {
|
||||
if isPlatformSettlementOrder(*order) {
|
||||
amountCent := settlement.OwnerRentIncomeCent + settlement.DepositCompensationCent
|
||||
order.OfflineSettlementAmountCent = amountCent
|
||||
@@ -77,11 +84,12 @@ func appendCheckoutOwnerIncome(tx *gorm.DB, order *model.RentalOrder, settlement
|
||||
return nil
|
||||
}
|
||||
orderID := order.ID
|
||||
siteID := ownerWalletSiteID(listing)
|
||||
var ownerEntries []wallet.Entry
|
||||
if settlement.OwnerRentIncomeCent > 0 {
|
||||
ownerEntries = append(ownerEntries, wallet.Entry{
|
||||
UserID: order.OwnerID,
|
||||
DistributionSiteID: 0,
|
||||
DistributionSiteID: siteID,
|
||||
OrderID: &orderID,
|
||||
Direction: "in",
|
||||
AmountCent: settlement.OwnerRentIncomeCent,
|
||||
@@ -94,7 +102,7 @@ func appendCheckoutOwnerIncome(tx *gorm.DB, order *model.RentalOrder, settlement
|
||||
if settlement.DepositCompensationCent > 0 {
|
||||
ownerEntries = append(ownerEntries, wallet.Entry{
|
||||
UserID: order.OwnerID,
|
||||
DistributionSiteID: 0,
|
||||
DistributionSiteID: siteID,
|
||||
OrderID: &orderID,
|
||||
Direction: "in",
|
||||
AmountCent: settlement.DepositCompensationCent,
|
||||
|
||||
@@ -694,3 +694,16 @@ func TestApplyCheckoutPriceView_RoleIsolationAndPlatformFeeHidden(t *testing.T)
|
||||
t.Fatalf("租客视角必须展示 RenterRefundAmountCent, 实际为: %v", renterDTO.RenterRefundAmountCent)
|
||||
}
|
||||
}
|
||||
|
||||
func TestOwnerWalletSiteIDFollowsListingSite(t *testing.T) {
|
||||
if got := ownerWalletSiteID(nil); got != 0 {
|
||||
t.Fatalf("空挂牌站点 = %d, want 0", got)
|
||||
}
|
||||
if got := ownerWalletSiteID(&model.RentalListing{}); got != 0 {
|
||||
t.Fatalf("主站挂牌站点 = %d, want 0", got)
|
||||
}
|
||||
siteID := uint64(3)
|
||||
if got := ownerWalletSiteID(&model.RentalListing{DistributionSiteID: &siteID}); got != 3 {
|
||||
t.Fatalf("分站挂牌站点 = %d, want 3", got)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user