兼容接入商品固定价格字段

This commit is contained in:
yml
2026-05-24 18:13:20 +08:00
parent 14aafcf728
commit e69d08ca9f
15 changed files with 153 additions and 32 deletions
+16 -1
View File
@@ -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,