彻底关闭订单超时自动结算:总开关+移除 orders.tasks 注册
This commit is contained in:
@@ -42,54 +42,29 @@ ensure_redis_loaded()
|
||||
@receiver(pre_save, sender='orders.Dingdan')
|
||||
def handle_order_status_8(sender, instance, **kwargs):
|
||||
"""
|
||||
订单状态变为8时,提交定时任务
|
||||
订单状态变为8时的信号处理。
|
||||
ORDER_AUTO_SETTLEMENT_ENABLED=False 时不提交任何 Celery 超时结算任务。
|
||||
"""
|
||||
# 跳过新增的订单
|
||||
if instance.pk is None:
|
||||
if not getattr(settings, 'ORDER_AUTO_SETTLEMENT_ENABLED', False):
|
||||
if instance.pk is None:
|
||||
return
|
||||
try:
|
||||
from orders.models import Dingdan
|
||||
old = Dingdan.query.filter(pk=instance.pk).values_list('zhuangtai', flat=True).first()
|
||||
if old != 8 and instance.zhuangtai == 8:
|
||||
instance.status_8_time = timezone.now()
|
||||
instance.pending_dispatch = False
|
||||
instance.auto_task_id = ''
|
||||
instance.auto_expire_at = None
|
||||
elif old == 8 and instance.zhuangtai != 8:
|
||||
instance.status_8_time = None
|
||||
instance.pending_dispatch = False
|
||||
instance.auto_task_id = ''
|
||||
except Exception as e:
|
||||
logger.error(f'信号处理失败: {e}')
|
||||
return
|
||||
|
||||
try:
|
||||
# 动态导入,避免循环依赖
|
||||
from orders.models import Dingdan
|
||||
|
||||
# 获取旧状态
|
||||
old = Dingdan.query.filter(pk=instance.pk).values_list('zhuangtai', flat=True).first()
|
||||
|
||||
# 状态从 非8 变为 8
|
||||
if old != 8 and instance.zhuangtai == 8:
|
||||
# 订单自动结算已关闭:仅记录时间标记,不再提交 Celery 延时结算任务
|
||||
instance.status_8_time = timezone.now()
|
||||
instance.pending_dispatch = False
|
||||
instance.auto_task_id = ''
|
||||
instance.auto_expire_at = None
|
||||
logger.info(f"订单 {instance.dingdan_id} 状态变为8(自动结算已禁用,不提交结算任务)")
|
||||
|
||||
# --- 原自动结算逻辑(已禁用,保留代码备查)---
|
||||
# expire_seconds = getattr(settings, 'ORDER_EXPIRE_SECONDS', 48 * 60 * 60)
|
||||
# try:
|
||||
# from orders.tasks import process_expired_order
|
||||
# task_result = process_expired_order.apply_async(
|
||||
# args=[instance.dingdan_id],
|
||||
# countdown=expire_seconds,
|
||||
# queue='order_tasks',
|
||||
# priority=9
|
||||
# )
|
||||
# instance.auto_task_id = task_result.id
|
||||
# instance.auto_expire_at = timezone.now() + timezone.timedelta(seconds=expire_seconds)
|
||||
# except Exception as e:
|
||||
# logger.error(f"❌ 任务提交失败: {e}")
|
||||
# instance.pending_dispatch = True
|
||||
# instance.auto_task_id = f"failed_{timezone.now().timestamp()}"
|
||||
|
||||
# 状态从 8 变为 非8
|
||||
elif old == 8 and instance.zhuangtai != 8:
|
||||
instance.status_8_time = None
|
||||
instance.pending_dispatch = False
|
||||
instance.auto_task_id = ''
|
||||
logger.info(f"📅 订单 {instance.dingdan_id} 状态离开8")
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"信号处理失败: {e}")
|
||||
# --- 以下原自动结算逻辑保留备查(开关打开时才启用,当前生产应为 False)---
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user