This commit is contained in:
@@ -36,9 +36,15 @@ def send_order_notifications(sender, instance, created, **kwargs):
|
||||
# 1. 处理支付成功通知
|
||||
if getattr(instance, '_was_paid', False):
|
||||
try:
|
||||
print(f"订单 {instance.id} 支付成功,触发短信通知流程...")
|
||||
notify_admins_order_paid(instance)
|
||||
notify_user_order_paid(instance)
|
||||
# 只有当订单不是活动订单时才发送普通支付成功短信
|
||||
# 活动订单会在 views.py 中单独处理(发送报名成功短信)
|
||||
if not (hasattr(instance, 'activity') and instance.activity):
|
||||
print(f"订单 {instance.id} 支付成功,触发短信通知流程...")
|
||||
notify_admins_order_paid(instance)
|
||||
notify_user_order_paid(instance)
|
||||
else:
|
||||
print(f"订单 {instance.id} 是活动订单,跳过普通支付短信通知(已在 views.py 处理)")
|
||||
|
||||
# 清除标记防止重复发送 (虽然实例通常是新的,但保险起见)
|
||||
instance._was_paid = False
|
||||
except Exception as e:
|
||||
@@ -47,8 +53,13 @@ def send_order_notifications(sender, instance, created, **kwargs):
|
||||
# 2. 处理发货通知
|
||||
if getattr(instance, '_was_shipped', False):
|
||||
try:
|
||||
print(f"订单 {instance.id} 已发货,触发短信通知流程...")
|
||||
notify_user_order_shipped(instance)
|
||||
# 同样,活动订单不需要发送发货短信(通常活动无需发货)
|
||||
if not (hasattr(instance, 'activity') and instance.activity):
|
||||
print(f"订单 {instance.id} 已发货,触发短信通知流程...")
|
||||
notify_user_order_shipped(instance)
|
||||
else:
|
||||
print(f"订单 {instance.id} 是活动订单,跳过发货短信通知")
|
||||
|
||||
instance._was_shipped = False
|
||||
except Exception as e:
|
||||
print(f"发送发货短信失败: {str(e)}")
|
||||
|
||||
@@ -661,6 +661,12 @@ def payment_finish(request):
|
||||
notify_user_order_paid(order)
|
||||
except Exception as e:
|
||||
print(f"发送短信通知失败: {str(e)}")
|
||||
else:
|
||||
# 额外保险:如果是活动订单,手动标记不触发 signals 中的支付/发货通知
|
||||
# 因为 signals 可能会在 save() 时触发
|
||||
order._was_paid = False
|
||||
order._was_shipped = False
|
||||
# order.save() # 不需要再 save,因为已经是 post-save 或者不影响数据库的标记
|
||||
|
||||
except Exception as e:
|
||||
print(f"订单更新失败: {str(e)}")
|
||||
|
||||
Reference in New Issue
Block a user