This commit is contained in:
@@ -19,7 +19,7 @@ class ActivityViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
"""
|
||||
社区活动接口
|
||||
"""
|
||||
queryset = Activity.objects.filter(is_active=True).order_by('-created_at')
|
||||
queryset = Activity.objects.filter(is_active=True, is_visible=True).order_by('-created_at')
|
||||
serializer_class = ActivitySerializer
|
||||
|
||||
def retrieve(self, request, *args, **kwargs):
|
||||
@@ -198,6 +198,32 @@ class ActivityViewSet(viewsets.ReadOnlyModelViewSet):
|
||||
signup_info=signup_info,
|
||||
status=status_val
|
||||
)
|
||||
|
||||
# Send SMS for free activity signup (if confirmed)
|
||||
if status_val == 'confirmed':
|
||||
try:
|
||||
from shop.sms_utils import notify_user_activity_signup_success
|
||||
|
||||
# Mock an order object for the SMS template
|
||||
# The template expects: customer_name, wechat_user, phone_number
|
||||
class MockOrder:
|
||||
def __init__(self, user, signup_info):
|
||||
# Ensure we get the name and phone from signup_info first
|
||||
# signup_info keys might vary, let's try common ones
|
||||
self.customer_name = signup_info.get('name') or signup_info.get('username') or user.nickname or "用户"
|
||||
self.wechat_user = user
|
||||
self.phone_number = signup_info.get('phone') or signup_info.get('mobile') or user.phone_number or ""
|
||||
|
||||
mock_order = MockOrder(user, signup_info)
|
||||
|
||||
# Check if we have a valid phone number before sending
|
||||
if mock_order.phone_number:
|
||||
notify_user_activity_signup_success(mock_order, signup)
|
||||
else:
|
||||
print(f"Skipping SMS for signup {signup.id}: No phone number found")
|
||||
except Exception as e:
|
||||
print(f"发送免费活动报名短信失败: {str(e)}")
|
||||
|
||||
serializer = ActivitySignupSerializer(signup)
|
||||
return Response(serializer.data, status=201)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user