撞车订单新增「接待中」状态,支持后台接待标记
已支付订单可标记为接待中,避免重复跟进;完成/取消覆盖接待中状态,前后台同步展示与筛选。
This commit is contained in:
@@ -266,13 +266,15 @@ func (r *Repository) AdminCancelOrder(ctx context.Context, orderID uint64, reaso
|
||||
}
|
||||
return err
|
||||
}
|
||||
if order.Status != model.MohongOrderStatusPendingPayment && order.Status != model.MohongOrderStatusPaid {
|
||||
if order.Status != model.MohongOrderStatusPendingPayment &&
|
||||
order.Status != model.MohongOrderStatusPaid &&
|
||||
order.Status != model.MohongOrderStatusReceiving {
|
||||
return ErrOrderCannotCancel
|
||||
}
|
||||
if order.Status == model.MohongOrderStatusPendingPayment {
|
||||
return r.cancelPendingOrderTx(tx, &order, firstNonEmpty(reason, "后台取消"))
|
||||
}
|
||||
// 已支付:仅标记取消(退款后续可接支付退款)。
|
||||
// 已支付/接待中:仅标记取消(退款后续可接支付退款)。
|
||||
now := time.Now()
|
||||
order.Status = model.MohongOrderStatusCancelled
|
||||
order.CancelledAt = &now
|
||||
@@ -285,6 +287,31 @@ func (r *Repository) AdminCancelOrder(ctx context.Context, orderID uint64, reaso
|
||||
return r.AdminFindOrder(ctx, orderID)
|
||||
}
|
||||
|
||||
// AdminReceiveOrder 标记订单为接待中(已支付 → 接待中)。
|
||||
func (r *Repository) AdminReceiveOrder(ctx context.Context, orderID uint64, remark string) (*OrderDTO, error) {
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var order model.MohongOrder
|
||||
if err := tx.Clauses(clause.Locking{Strength: "UPDATE"}).First(&order, orderID).Error; err != nil {
|
||||
if err == gorm.ErrRecordNotFound {
|
||||
return ErrOrderNotFound
|
||||
}
|
||||
return err
|
||||
}
|
||||
if order.Status != model.MohongOrderStatusPaid {
|
||||
return ErrOrderCannotReceive
|
||||
}
|
||||
order.Status = model.MohongOrderStatusReceiving
|
||||
if strings.TrimSpace(remark) != "" {
|
||||
order.AdminRemark = strings.TrimSpace(remark)
|
||||
}
|
||||
return tx.Save(&order).Error
|
||||
})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return r.AdminFindOrder(ctx, orderID)
|
||||
}
|
||||
|
||||
func (r *Repository) AdminCompleteOrder(ctx context.Context, orderID uint64, remark string) (*OrderDTO, error) {
|
||||
err := r.db.WithContext(ctx).Transaction(func(tx *gorm.DB) error {
|
||||
var order model.MohongOrder
|
||||
@@ -294,7 +321,7 @@ func (r *Repository) AdminCompleteOrder(ctx context.Context, orderID uint64, rem
|
||||
}
|
||||
return err
|
||||
}
|
||||
if order.Status != model.MohongOrderStatusPaid {
|
||||
if order.Status != model.MohongOrderStatusPaid && order.Status != model.MohongOrderStatusReceiving {
|
||||
return ErrOrderCannotComplete
|
||||
}
|
||||
now := time.Now()
|
||||
@@ -319,6 +346,7 @@ func (r *Repository) ConfirmPaidFromChannelTx(tx *gorm.DB, orderID uint64) (uint
|
||||
return 0, err
|
||||
}
|
||||
if order.Status == model.MohongOrderStatusPaid ||
|
||||
order.Status == model.MohongOrderStatusReceiving ||
|
||||
order.Status == model.MohongOrderStatusCompleted {
|
||||
return 0, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user