集中订单状态常量
This commit is contained in:
@@ -18,7 +18,7 @@ func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, erro
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&listing, req.ListingID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if listing.Status != "published" || listing.ReviewStatus != "approved" || listing.InTransaction {
|
||||
if listing.Status != listingStatusPublished || listing.ReviewStatus != listingReviewStatusApproved || listing.InTransaction {
|
||||
return ErrListingUnavailable
|
||||
}
|
||||
if listing.OwnerID == renterID {
|
||||
@@ -58,9 +58,9 @@ func (r *Repository) Create(renterID uint64, req CreateRequest) (*OrderDTO, erro
|
||||
DepositWaivedAmountCent: waivedDepositAmountCent,
|
||||
PlatformFeeCent: pricing.PlatformFeeCent,
|
||||
AccountSnapshot: snapshot,
|
||||
Status: "pending_payment",
|
||||
HandoffStatus: "none",
|
||||
SettlementStatus: "unsettled",
|
||||
Status: orderStatusPendingPayment,
|
||||
HandoffStatus: handoffStatusNone,
|
||||
SettlementStatus: settlementStatusUnsettled,
|
||||
}
|
||||
if err := tx.Create(&order).Error; err != nil {
|
||||
return err
|
||||
@@ -112,7 +112,7 @@ func activeDepositFreeUsed(tx *gorm.DB, renterID uint64) (int64, error) {
|
||||
err := tx.Model(&model.RentalOrder{}).
|
||||
Where("renter_id = ? AND status NOT IN ?",
|
||||
renterID,
|
||||
[]string{"completed", "cancelled", "closed"},
|
||||
[]string{orderStatusCompleted, orderStatusCancelled, orderStatusClosed},
|
||||
).
|
||||
Select("COALESCE(SUM(deposit_waived_amount_cent), 0)").
|
||||
Scan(&used).Error
|
||||
@@ -139,10 +139,10 @@ func (r *Repository) ConfirmPaidFromChannel(orderID uint64, providerBizNo string
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&order, orderID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if order.Status == "pending_handoff" || order.Status == "renting" {
|
||||
if order.Status == orderStatusPendingHandoff || order.Status == orderStatusRenting {
|
||||
return nil
|
||||
}
|
||||
if order.Status != "pending_payment" {
|
||||
if order.Status != orderStatusPendingPayment {
|
||||
return ErrOrderCannotPay
|
||||
}
|
||||
|
||||
@@ -150,7 +150,7 @@ func (r *Repository) ConfirmPaidFromChannel(orderID uint64, providerBizNo string
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&listing, order.ListingID).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if listing.Status != "published" || listing.ReviewStatus != "approved" || !listing.InTransaction {
|
||||
if listing.Status != listingStatusPublished || listing.ReviewStatus != listingReviewStatusApproved || !listing.InTransaction {
|
||||
return ErrListingUnavailable
|
||||
}
|
||||
var account model.GameAccount
|
||||
@@ -160,10 +160,10 @@ func (r *Repository) ConfirmPaidFromChannel(orderID uint64, providerBizNo string
|
||||
|
||||
// 租客已通过外部渠道付款,这里不写租客钱包流水。
|
||||
orderID := order.ID
|
||||
order.Status = "pending_handoff"
|
||||
order.HandoffStatus = "pending_owner"
|
||||
listing.Status = "rented"
|
||||
account.Status = "rented"
|
||||
order.Status = orderStatusPendingHandoff
|
||||
order.HandoffStatus = handoffStatusPendingOwner
|
||||
listing.Status = listingStatusRented
|
||||
account.Status = accountStatusRented
|
||||
conv, err := chat.EnsureOrderConversation(tx, order)
|
||||
if err != nil {
|
||||
return err
|
||||
@@ -215,7 +215,7 @@ func (r *Repository) Cancel(userID uint64, orderID uint64) error {
|
||||
First(&order).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
if order.Status != "pending_payment" && order.Status != "pending_handoff" {
|
||||
if order.Status != orderStatusPendingPayment && order.Status != orderStatusPendingHandoff {
|
||||
return ErrOrderCannotCancel
|
||||
}
|
||||
var listing model.RentalListing
|
||||
@@ -228,12 +228,12 @@ func (r *Repository) Cancel(userID uint64, orderID uint64) error {
|
||||
}
|
||||
|
||||
beforeStatus := order.Status
|
||||
order.Status = "cancelled"
|
||||
order.HandoffStatus = "cancelled"
|
||||
order.Status = orderStatusCancelled
|
||||
order.HandoffStatus = handoffStatusCancelled
|
||||
orderID := order.ID
|
||||
if beforeStatus == "pending_handoff" {
|
||||
if beforeStatus == orderStatusPendingHandoff {
|
||||
totalCent := order.RentAmountCent + order.DepositAmountCent
|
||||
action, err := r.prepareRefund(&order, totalCent, "cancel_refund", "取消订单原路退款")
|
||||
action, err := r.prepareRefund(&order, totalCent, refundBizCancel, "取消订单原路退款")
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -259,9 +259,9 @@ func (r *Repository) Cancel(userID uint64, orderID uint64) error {
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
listing.Status = "published"
|
||||
listing.Status = listingStatusPublished
|
||||
listing.InTransaction = false
|
||||
account.Status = "published"
|
||||
account.Status = accountStatusPublished
|
||||
if err := tx.Save(&order).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -286,7 +286,7 @@ func (r *Repository) ConfirmReceive(userID uint64, orderID uint64) error {
|
||||
if order.RenterID != userID {
|
||||
return ErrPermissionDenied
|
||||
}
|
||||
if order.Status != "pending_handoff" || order.HandoffStatus != "pending_renter_confirm" {
|
||||
if order.Status != orderStatusPendingHandoff || order.HandoffStatus != handoffStatusPendingRenterConfirm {
|
||||
return ErrOrderCannotReceive
|
||||
}
|
||||
now := time.Now()
|
||||
@@ -295,8 +295,8 @@ func (r *Repository) ConfirmReceive(userID uint64, orderID uint64) error {
|
||||
Update("confirmed_by_renter_at", now).Error; err != nil {
|
||||
return err
|
||||
}
|
||||
order.Status = "renting"
|
||||
order.HandoffStatus = "received"
|
||||
order.Status = orderStatusRenting
|
||||
order.HandoffStatus = handoffStatusReceived
|
||||
durationHours := orderDurationHours(order)
|
||||
order.EstimatedDurationHours = durationHours
|
||||
order.RentedAt = &now
|
||||
|
||||
Reference in New Issue
Block a user