按实际纯币金额计算租客优惠与积分
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/adminnotification"
|
||||
"hfb_sys/backend/internal/modules/notification"
|
||||
ordermodule "hfb_sys/backend/internal/modules/order"
|
||||
"hfb_sys/backend/internal/modules/rentergrowth"
|
||||
"hfb_sys/backend/internal/modules/wallet"
|
||||
"hfb_sys/backend/pkg/money"
|
||||
@@ -112,7 +113,23 @@ func (r *Repository) Arbitrate(ctx context.Context, adminID uint64, id uint64, r
|
||||
return err
|
||||
}
|
||||
if order.Status == "completed" {
|
||||
if err := rentergrowth.AwardOrderCompleted(tx, &order, arbitrationActualRentCent(order, settlement), rentergrowth.SourceOrderCompleted); err != nil {
|
||||
coinConsumedM, linkedCheckout, err := arbitrationCoinConsumedM(tx, row, req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
pureCoin := ordermodule.CalculateActualPureCoinAmounts(order, coinConsumedM)
|
||||
order.ActualCoinConsumedM = pureCoin.ConsumedM
|
||||
order.ActualPureCoinAmountCent = pureCoin.AmountCent
|
||||
order.ActualPureCoinDiscountCent = pureCoin.DiscountCent
|
||||
if linkedCheckout != nil {
|
||||
linkedCheckout.PureCoinAmountCent = pureCoin.AmountCent
|
||||
linkedCheckout.PureCoinDiscountCent = pureCoin.DiscountCent
|
||||
linkedCheckout.PureCoinPayableCent = pureCoin.PayableCent
|
||||
if err := tx.Save(linkedCheckout).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if err := rentergrowth.AwardOrderCompleted(tx, &order, pureCoin.AmountCent, rentergrowth.SourceOrderCompleted); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
@@ -146,6 +163,8 @@ func (r *Repository) Arbitrate(ctx context.Context, adminID uint64, id uint64, r
|
||||
"renter_refund_amount_cent": settlement.RenterRefundAmountCent,
|
||||
"owner_income_amount_cent": settlement.OwnerIncomeAmountCent,
|
||||
"deposit_deduct_amount_cent": settlement.DepositDeductAmountCent,
|
||||
"actual_coin_consumed_m": order.ActualCoinConsumedM,
|
||||
"actual_pure_coin_cent": order.ActualPureCoinAmountCent,
|
||||
"before_order_status": beforeOrderStatus,
|
||||
"after_order_status": order.Status,
|
||||
"before_handoff_status": beforeHandoffStatus,
|
||||
@@ -200,19 +219,22 @@ func (r *Repository) Arbitrate(ctx context.Context, adminID uint64, id uint64, r
|
||||
return &dto, nil
|
||||
}
|
||||
|
||||
func arbitrationActualRentCent(order model.RentalOrder, settlement arbitrationSettlement) int64 {
|
||||
rentRefundCent := settlement.RenterRefundAmountCent - settlement.RenterDepositRefundCent
|
||||
if rentRefundCent < 0 {
|
||||
rentRefundCent = 0
|
||||
func arbitrationCoinConsumedM(tx *gorm.DB, row model.Dispute, req ArbitrateRequest) (float64, *model.OrderCheckout, error) {
|
||||
var checkout *model.OrderCheckout
|
||||
if row.CheckoutID != nil && *row.CheckoutID > 0 {
|
||||
var saved model.OrderCheckout
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&saved, *row.CheckoutID).Error; err != nil {
|
||||
return 0, nil, err
|
||||
}
|
||||
checkout = &saved
|
||||
}
|
||||
if rentRefundCent > order.RentAmountCent {
|
||||
rentRefundCent = order.RentAmountCent
|
||||
if req.ActualCoinConsumedM != nil {
|
||||
return *req.ActualCoinConsumedM, checkout, nil
|
||||
}
|
||||
actualRentCent := order.RentAmountCent - rentRefundCent
|
||||
if actualRentCent < 0 {
|
||||
return 0
|
||||
if checkout != nil {
|
||||
return checkout.CoinConsumedM, checkout, nil
|
||||
}
|
||||
return actualRentCent
|
||||
return 0, nil, ErrInvalidDispute
|
||||
}
|
||||
|
||||
func isPlatformManagedOrder(order model.RentalOrder) bool {
|
||||
|
||||
Reference in New Issue
Block a user