账号上下架增加统计
This commit is contained in:
@@ -35,7 +35,9 @@ func (r *Repository) AdminClose(ctx context.Context, adminID uint64, orderID uin
|
||||
order.HandoffStatus = handoffStatusAdminClosed
|
||||
order.SettlementStatus = settlementStatusClosed
|
||||
order.SettledAt = &now
|
||||
archiveAssets(listing, account)
|
||||
if err := archiveAssets(tx, listing, account); err != nil {
|
||||
return err
|
||||
}
|
||||
if beforeOrderStatus != orderStatusPendingPayment {
|
||||
totalCent := order.RentAmountCent + order.DepositAmountCent
|
||||
// 押金暂扣:若订单已暂扣,拦截退款中的押金部分挂起不退,其余照常原路退。
|
||||
@@ -118,7 +120,9 @@ func (r *Repository) AdminMarkAbnormal(ctx context.Context, adminID uint64, orde
|
||||
beforeAccountStatus := account.Status
|
||||
order.Status = orderStatusAbnormal
|
||||
order.HandoffStatus = handoffStatusAdminAbnormal
|
||||
markAssetsAbnormal(listing, account)
|
||||
if err := markAssetsAbnormal(tx, listing, account); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := notification.Append(tx,
|
||||
notification.Entry{
|
||||
UserID: order.RenterID,
|
||||
@@ -450,7 +454,9 @@ func (r *Repository) AdminRejectRefund(ctx context.Context, orderID uint64, acti
|
||||
order.SettlementStatus = settlementStatusUnsettled
|
||||
order.SettledAt = nil
|
||||
reserveListingForOrder(listing)
|
||||
markAssetsRented(listing, account)
|
||||
if err := markAssetsRented(tx, listing, account); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
case "close":
|
||||
now := time.Now()
|
||||
@@ -458,7 +464,9 @@ func (r *Repository) AdminRejectRefund(ctx context.Context, orderID uint64, acti
|
||||
order.HandoffStatus = handoffStatusAdminClosed
|
||||
order.SettlementStatus = settlementStatusClosed
|
||||
order.SettledAt = &now
|
||||
archiveAssets(listing, account)
|
||||
if err := archiveAssets(tx, listing, account); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
default:
|
||||
return errors.New("无效的驳回操作,可选 restore 或 close")
|
||||
@@ -500,7 +508,9 @@ func (r *Repository) AdminSeal(ctx context.Context, adminID uint64, orderID uint
|
||||
order.HandoffStatus = handoffStatusAdminClosed
|
||||
order.SettlementStatus = settlementStatusClosed
|
||||
order.SettledAt = &now
|
||||
sealAssets(listing, account)
|
||||
if err := sealAssets(tx, listing, account); err != nil {
|
||||
return err
|
||||
}
|
||||
if beforeOrderStatus != orderStatusPendingPayment {
|
||||
totalCent := order.RentAmountCent + order.DepositAmountCent
|
||||
// 押金暂扣:若订单已暂扣,拦截退款中的押金部分挂起不退,其余照常原路退。
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package order
|
||||
|
||||
import (
|
||||
"hfb_sys/backend/internal/listingstatus"
|
||||
"hfb_sys/backend/internal/model"
|
||||
|
||||
"gorm.io/gorm"
|
||||
@@ -45,41 +46,53 @@ func reserveListingForOrder(listing *model.RentalListing) {
|
||||
listing.InTransaction = true
|
||||
}
|
||||
|
||||
func markAssetsRented(listing *model.RentalListing, account *model.GameAccount) {
|
||||
func markAssetsRented(tx *gorm.DB, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
from := listing.Status
|
||||
listing.Status = listingStatusRented
|
||||
account.Status = accountStatusRented
|
||||
return listingstatus.AppendTransition(tx, listing, from, listingstatus.SourceOrder, listingstatus.ActorSystem, 0, "支付成功租出")
|
||||
}
|
||||
|
||||
func releaseAssetsForRental(listing *model.RentalListing, account *model.GameAccount) {
|
||||
func releaseAssetsForRental(tx *gorm.DB, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
from := listing.Status
|
||||
listing.Status = listingStatusPublished
|
||||
listing.InTransaction = false
|
||||
account.Status = accountStatusPublished
|
||||
return listingstatus.AppendTransition(tx, listing, from, listingstatus.SourceOrder, listingstatus.ActorSystem, 0, "订单取消恢复上架")
|
||||
}
|
||||
|
||||
func archiveAssets(listing *model.RentalListing, account *model.GameAccount) {
|
||||
func archiveAssets(tx *gorm.DB, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
from := listing.Status
|
||||
listing.Status = listingStatusOffline
|
||||
listing.InTransaction = false
|
||||
listing.PublishedAt = nil
|
||||
account.Status = accountStatusOffline
|
||||
return listingstatus.AppendTransition(tx, listing, from, listingstatus.SourceOrder, listingstatus.ActorSystem, 0, "订单归档下架")
|
||||
}
|
||||
|
||||
func sealAssets(listing *model.RentalListing, account *model.GameAccount) {
|
||||
func sealAssets(tx *gorm.DB, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
from := listing.Status
|
||||
listing.Status = listingStatusSealed
|
||||
listing.InTransaction = false
|
||||
listing.PublishedAt = nil
|
||||
account.Status = accountStatusSealed
|
||||
return listingstatus.AppendTransition(tx, listing, from, listingstatus.SourceOrder, listingstatus.ActorSystem, 0, "订单封存")
|
||||
}
|
||||
|
||||
func completeAssets(listing *model.RentalListing, account *model.GameAccount) {
|
||||
func completeAssets(tx *gorm.DB, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
from := listing.Status
|
||||
listing.Status = listingStatusCompleted
|
||||
listing.InTransaction = false
|
||||
listing.PublishedAt = nil
|
||||
account.Status = accountStatusOffline
|
||||
return listingstatus.AppendTransition(tx, listing, from, listingstatus.SourceOrder, listingstatus.ActorSystem, 0, "订单完成售出")
|
||||
}
|
||||
|
||||
func markAssetsAbnormal(listing *model.RentalListing, account *model.GameAccount) {
|
||||
func markAssetsAbnormal(tx *gorm.DB, listing *model.RentalListing, account *model.GameAccount) error {
|
||||
from := listing.Status
|
||||
listing.Status = listingStatusAbnormal
|
||||
listing.InTransaction = false
|
||||
listing.PublishedAt = nil
|
||||
account.Status = accountStatusAbnormal
|
||||
return listingstatus.AppendTransition(tx, listing, from, listingstatus.SourceOrder, listingstatus.ActorSystem, 0, "标记异常")
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ func (r *Repository) finalizeCheckout(tx *gorm.DB, order *model.RentalOrder, che
|
||||
order.SettlementStatus = settlementStatusSettled
|
||||
order.SettledAt = &now
|
||||
order.OwnerSettledAt = &now
|
||||
completeAssets(listing, account)
|
||||
if err := completeAssets(tx, listing, account); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
settlement := buildCheckoutSettlement(*order, checkout)
|
||||
if err := appendCheckoutOwnerIncome(tx, order, settlement); err != nil {
|
||||
|
||||
@@ -181,7 +181,9 @@ func (r *Repository) ConfirmPaidFromChannelTx(tx *gorm.DB, orderID uint64) (uint
|
||||
order.Status = orderStatusPendingHandoff
|
||||
order.HandoffStatus = handoffStatusPendingOwner
|
||||
order.HandoffStartedAt = &now
|
||||
markAssetsRented(listing, account)
|
||||
if err := markAssetsRented(tx, listing, account); err != nil {
|
||||
return 0, err
|
||||
}
|
||||
|
||||
// 拉租客进发布群(替代原来的建订单群)
|
||||
conversationID := uint64(0)
|
||||
@@ -275,7 +277,9 @@ func (r *Repository) Cancel(ctx context.Context, userID uint64, orderID uint64)
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
releaseAssetsForRental(listing, account)
|
||||
if err := releaseAssetsForRental(tx, listing, account); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := closePendingOrderPayments(tx, order.ID, "order_cancel"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@@ -149,7 +149,9 @@ func TestArchiveAssetsMovesListingOffline(t *testing.T) {
|
||||
}
|
||||
account := model.GameAccount{Status: accountStatusRented}
|
||||
|
||||
archiveAssets(&listing, &account)
|
||||
if err := archiveAssets(nil, &listing, &account); err != nil {
|
||||
t.Fatalf("archiveAssets: %v", err)
|
||||
}
|
||||
|
||||
if listing.Status != listingStatusOffline {
|
||||
t.Fatalf("listing.Status = %q, want %q", listing.Status, listingStatusOffline)
|
||||
@@ -174,7 +176,9 @@ func TestCompleteAssetsMovesListingCompleted(t *testing.T) {
|
||||
}
|
||||
account := model.GameAccount{Status: accountStatusRented}
|
||||
|
||||
completeAssets(&listing, &account)
|
||||
if err := completeAssets(nil, &listing, &account); err != nil {
|
||||
t.Fatalf("completeAssets: %v", err)
|
||||
}
|
||||
|
||||
if listing.Status != listingStatusCompleted {
|
||||
t.Fatalf("listing.Status = %q, want %q", listing.Status, listingStatusCompleted)
|
||||
|
||||
Reference in New Issue
Block a user