兼容接入商品固定价格字段
This commit is contained in:
@@ -28,6 +28,21 @@ func NewRepository(db *gorm.DB) *Repository {
|
||||
return &Repository{db: db}
|
||||
}
|
||||
|
||||
func listingOrderPrice(listing model.RentalListing) float64 {
|
||||
switch {
|
||||
case listing.Price > 0:
|
||||
return listing.Price
|
||||
case listing.PriceDaily > 0:
|
||||
return listing.PriceDaily
|
||||
case listing.PriceHourly > 0:
|
||||
return listing.PriceHourly * float64(internalOrderHours)
|
||||
case listing.PriceWeekly > 0:
|
||||
return listing.PriceWeekly / 7
|
||||
default:
|
||||
return 0
|
||||
}
|
||||
}
|
||||
|
||||
func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, error) {
|
||||
var createdID uint64
|
||||
err := r.db.Transaction(func(tx *gorm.DB) error {
|
||||
@@ -62,7 +77,7 @@ func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, erro
|
||||
OwnerID: listing.OwnerID,
|
||||
RenterID: renterID,
|
||||
RentHours: rentHours,
|
||||
RentAmount: listing.PriceHourly * float64(rentHours),
|
||||
RentAmount: listingOrderPrice(listing),
|
||||
DepositAmount: listing.DepositAmount,
|
||||
PlatformFee: 0,
|
||||
AccountSnapshot: snapshot,
|
||||
|
||||
Reference in New Issue
Block a user