修复平台代管订单流程
This commit is contained in:
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"hfb_sys/backend/internal/model"
|
||||
"hfb_sys/backend/internal/modules/adminnotification"
|
||||
"hfb_sys/backend/internal/modules/chat"
|
||||
"hfb_sys/backend/internal/modules/notification"
|
||||
|
||||
@@ -55,6 +56,25 @@ func New(db *gorm.DB, redisClient *redis.Client, logger *zap.Logger) *Job {
|
||||
}
|
||||
}
|
||||
|
||||
func isPlatformManagedOrder(order *model.RentalOrder) bool {
|
||||
if order == nil {
|
||||
return false
|
||||
}
|
||||
return order.HandoffMode == "platform" || order.SettlementMode == "platform_managed"
|
||||
}
|
||||
|
||||
func appendManagedTimeoutNotification(tx *gorm.DB, order *model.RentalOrder, title string, content string) error {
|
||||
if order == nil || order.ManagedAdminID == nil || *order.ManagedAdminID == 0 {
|
||||
return nil
|
||||
}
|
||||
return adminnotification.Append(tx, adminnotification.Entry{
|
||||
AdminUserID: *order.ManagedAdminID,
|
||||
Type: "timeout",
|
||||
Title: title,
|
||||
Content: content,
|
||||
})
|
||||
}
|
||||
|
||||
// acquireLock 通过 Redis 分布式锁确保同一时刻只有一个实例执行超时扫描。
|
||||
// 未配置 Redis 时直接执行;Redis 出错时降级执行(事务内行锁与状态二次校验可兜底,不会写坏数据)。
|
||||
func (j *Job) acquireLock(ctx context.Context) (func(), bool) {
|
||||
@@ -314,6 +334,22 @@ func (j *Job) handleOwnerSubmitTimeout(ctx context.Context, now time.Time, cfg t
|
||||
before := snapshot(order)
|
||||
order.HandoffStatus = "owner_timeout"
|
||||
orderID := order.ID
|
||||
if isPlatformManagedOrder(order) {
|
||||
if err := notification.Append(tx, notification.Entry{
|
||||
UserID: order.RenterID,
|
||||
Type: "timeout",
|
||||
Title: "客服代交接超时",
|
||||
Content: "客服未在规定时间内提交交接说明,你可以取消订单或发起申诉。",
|
||||
BizType: "order",
|
||||
BizID: &orderID,
|
||||
}); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := appendManagedTimeoutNotification(tx, order, "代管订单交接超时", "订单已超过交接时限,请尽快进入订单详情处理。"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return before, nil
|
||||
}
|
||||
if err := notification.Append(tx,
|
||||
notification.Entry{
|
||||
UserID: order.RenterID,
|
||||
@@ -506,6 +542,22 @@ func (j *Job) handleOwnerReturnConfirmTimeout(ctx context.Context, now time.Time
|
||||
order.Status = "abnormal"
|
||||
order.HandoffStatus = "owner_checkout_confirm_timeout"
|
||||
orderID := order.ID
|
||||
if isPlatformManagedOrder(order) {
|
||||
if err := notification.Append(tx, notification.Entry{
|
||||
UserID: order.RenterID,
|
||||
Type: "timeout",
|
||||
Title: "客服确认结账超时",
|
||||
Content: "客服未在规定时间内确认结账,订单已进入客服复核状态。",
|
||||
BizType: "order",
|
||||
BizID: &orderID,
|
||||
}); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if err := appendManagedTimeoutNotification(tx, order, "代管订单确认结账超时", "订单已超过确认结账时限,请尽快进入订单详情处理。"); err != nil {
|
||||
return "", err
|
||||
}
|
||||
return before, nil
|
||||
}
|
||||
if err := notification.Append(tx,
|
||||
notification.Entry{
|
||||
UserID: order.RenterID,
|
||||
|
||||
Reference in New Issue
Block a user