彻底优化数据库字段
This commit is contained in:
@@ -303,6 +303,10 @@ type arbitrationSettlement struct {
|
||||
|
||||
func buildArbitrationSettlement(order model.RentalOrder, req ArbitrateRequest) (arbitrationSettlement, error) {
|
||||
total := order.RentAmount + order.DepositAmount
|
||||
ownerRentAmount := order.OwnerRentAmount
|
||||
if ownerRentAmount <= 0 || ownerRentAmount > order.RentAmount {
|
||||
ownerRentAmount = order.RentAmount
|
||||
}
|
||||
settlement := arbitrationSettlement{}
|
||||
orderID := order.ID
|
||||
if total > 0 {
|
||||
@@ -359,9 +363,9 @@ func buildArbitrationSettlement(order model.RentalOrder, req ArbitrateRequest) (
|
||||
return settlement, ErrInvalidDispute
|
||||
}
|
||||
addRenterRefund(req.Amount, "仲裁部分退款")
|
||||
addOwnerIncome(total-req.Amount, "仲裁剩余金额结算给号主")
|
||||
addOwnerIncome(minMoney(total-req.Amount, ownerRentAmount+order.DepositAmount), "仲裁剩余金额结算给号主")
|
||||
case "release_deposit":
|
||||
addOwnerIncome(order.RentAmount, "仲裁确认订单金额结算给号主")
|
||||
addOwnerIncome(ownerRentAmount, "仲裁确认订单金额结算给号主")
|
||||
addRenterRefund(order.DepositAmount, "仲裁释放押金给租客")
|
||||
case "deduct_deposit", "compensate_owner":
|
||||
deductAmount := req.Amount
|
||||
@@ -372,7 +376,7 @@ func buildArbitrationSettlement(order model.RentalOrder, req ArbitrateRequest) (
|
||||
return settlement, ErrInvalidDispute
|
||||
}
|
||||
settlement.DepositDeductAmount = deductAmount
|
||||
addOwnerIncome(order.RentAmount+deductAmount, "仲裁订单金额及押金赔付结算给号主")
|
||||
addOwnerIncome(ownerRentAmount+deductAmount, "仲裁订单金额及押金赔付结算给号主")
|
||||
addRenterRefund(order.DepositAmount-deductAmount, "仲裁退回剩余押金给租客")
|
||||
case "order_close":
|
||||
// Only release frozen funds. No available-balance settlement happens in development mode.
|
||||
@@ -384,6 +388,13 @@ func buildArbitrationSettlement(order model.RentalOrder, req ArbitrateRequest) (
|
||||
return settlement, nil
|
||||
}
|
||||
|
||||
func minMoney(a float64, b float64) float64 {
|
||||
if a < b {
|
||||
return a
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (r *Repository) baseQuery() *gorm.DB {
|
||||
return r.db.Table("disputes AS d").
|
||||
Select("d.*, o.order_no, a.title").
|
||||
|
||||
Reference in New Issue
Block a user