删掉租期相关错误东西
This commit is contained in:
@@ -1,3 +1,3 @@
|
||||
# Order Module
|
||||
|
||||
订单状态机、账号交接、租期归还、超时处理。
|
||||
订单状态机、账号交接、归还、超时处理。
|
||||
|
||||
@@ -20,7 +20,6 @@ type OrderDTO struct {
|
||||
LoginPlatform string `json:"login_platform"`
|
||||
RentStartAt *time.Time `json:"rent_start_at"`
|
||||
RentEndAt *time.Time `json:"rent_end_at"`
|
||||
RentHours int `json:"rent_hours"`
|
||||
RentAmount float64 `json:"rent_amount"`
|
||||
DepositAmount float64 `json:"deposit_amount"`
|
||||
PlatformFee float64 `json:"platform_fee"`
|
||||
@@ -34,7 +33,6 @@ type OrderDTO struct {
|
||||
|
||||
type CreateRequest struct {
|
||||
ListingID uint64 `json:"listing_id" binding:"required"`
|
||||
RentHours int `json:"rent_hours" binding:"required"`
|
||||
}
|
||||
|
||||
type SubmitHandoffRequest struct {
|
||||
|
||||
@@ -282,7 +282,7 @@ func writeOrderError(c *gin.Context, err error) {
|
||||
case errors.Is(err, ErrDependencyUnavailable):
|
||||
response.ServiceUnavailable(c, "数据库未连接")
|
||||
case errors.Is(err, ErrInvalidRentHours):
|
||||
response.BadRequest(c, "租期不符合规则")
|
||||
response.BadRequest(c, "订单信息不符合规则")
|
||||
case errors.Is(err, ErrListingUnavailable):
|
||||
response.Error(c, http.StatusConflict, "listing_unavailable", "该账号暂不可租")
|
||||
case errors.Is(err, ErrCannotRentOwnListing):
|
||||
|
||||
@@ -38,9 +38,6 @@ func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, erro
|
||||
if listing.OwnerID == renterID {
|
||||
return ErrCannotRentOwnListing
|
||||
}
|
||||
if req.RentHours < listing.MinRentHours || req.RentHours > listing.MaxRentHours {
|
||||
return ErrInvalidRentHours
|
||||
}
|
||||
|
||||
var account model.GameAccount
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&account, listing.AccountID).Error; err != nil {
|
||||
@@ -55,7 +52,8 @@ func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, erro
|
||||
return err
|
||||
}
|
||||
now := time.Now()
|
||||
rentEnd := now.Add(time.Duration(req.RentHours) * time.Hour)
|
||||
rentHours := internalOrderHours
|
||||
rentEnd := now.Add(time.Duration(rentHours) * time.Hour)
|
||||
order := model.RentalOrder{
|
||||
OrderNo: orderNo,
|
||||
ListingID: listing.ID,
|
||||
@@ -64,8 +62,8 @@ func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, erro
|
||||
RenterID: renterID,
|
||||
RentStartAt: &now,
|
||||
RentEndAt: &rentEnd,
|
||||
RentHours: req.RentHours,
|
||||
RentAmount: listing.PriceHourly * float64(req.RentHours),
|
||||
RentHours: rentHours,
|
||||
RentAmount: listing.PriceHourly * float64(rentHours),
|
||||
DepositAmount: listing.DepositAmount,
|
||||
PlatformFee: 0,
|
||||
AccountSnapshot: snapshot,
|
||||
@@ -86,7 +84,7 @@ func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, erro
|
||||
BalanceType: "frozen",
|
||||
BizType: "order_lock",
|
||||
BizNo: order.OrderNo,
|
||||
Remark: "开发态模拟冻结租金和押金",
|
||||
Remark: "开发态模拟冻结订单金额和押金",
|
||||
},
|
||||
); err != nil {
|
||||
return err
|
||||
@@ -272,7 +270,7 @@ func (r *Repository) ConfirmReceive(userID uint64, orderID uint64) error {
|
||||
UserID: order.OwnerID,
|
||||
Type: "handoff",
|
||||
Title: "租客已确认收号",
|
||||
Content: "订单已进入租赁中。",
|
||||
Content: "订单已进入使用中。",
|
||||
BizType: "order",
|
||||
BizID: &orderID,
|
||||
}); err != nil {
|
||||
@@ -399,7 +397,7 @@ func (r *Repository) ConfirmReturn(userID uint64, orderID uint64) error {
|
||||
BalanceType: "available",
|
||||
BizType: "owner_income",
|
||||
BizNo: order.OrderNo,
|
||||
Remark: "订单完成模拟结算租金",
|
||||
Remark: "订单完成模拟结算订单金额",
|
||||
},
|
||||
wallet.Entry{
|
||||
UserID: order.RenterID,
|
||||
@@ -427,7 +425,7 @@ func (r *Repository) ConfirmReturn(userID uint64, orderID uint64) error {
|
||||
UserID: order.OwnerID,
|
||||
Type: "settlement",
|
||||
Title: "订单已完成",
|
||||
Content: "订单已完成,模拟租金已入账。",
|
||||
Content: "订单已完成,模拟订单金额已入账。",
|
||||
BizType: "order",
|
||||
BizID: &orderID,
|
||||
},
|
||||
@@ -727,7 +725,6 @@ func (row orderRow) toDTO() OrderDTO {
|
||||
LoginPlatform: row.LoginPlatform,
|
||||
RentStartAt: row.RentStartAt,
|
||||
RentEndAt: row.RentEndAt,
|
||||
RentHours: row.RentHours,
|
||||
RentAmount: row.RentAmount,
|
||||
DepositAmount: row.DepositAmount,
|
||||
PlatformFee: row.PlatformFee,
|
||||
|
||||
@@ -15,6 +15,8 @@ var (
|
||||
ErrPermissionDenied = errors.New("permission denied")
|
||||
)
|
||||
|
||||
const internalOrderHours = 24
|
||||
|
||||
type Service struct {
|
||||
repo *Repository
|
||||
}
|
||||
@@ -27,7 +29,7 @@ func (s *Service) Create(userID uint64, req CreateRequest) (*OrderDTO, error) {
|
||||
if s.repo == nil {
|
||||
return nil, ErrDependencyUnavailable
|
||||
}
|
||||
if req.ListingID == 0 || req.RentHours <= 0 {
|
||||
if req.ListingID == 0 {
|
||||
return nil, ErrInvalidRentHours
|
||||
}
|
||||
return s.repo.Create(userID, req)
|
||||
|
||||
Reference in New Issue
Block a user