解决报名支付
All checks were successful
Deploy to Server / deploy (push) Successful in 36s

This commit is contained in:
jeremygan2021
2026-02-23 16:20:34 +08:00
parent 6bbbb49d90
commit 58176c6651
10 changed files with 70 additions and 19 deletions

View File

@@ -55,9 +55,9 @@ class Activity(models.Model):
@property
def current_signups(self):
"""
当前有效报名人数
当前有效报名人数(仅统计已确认/已支付的报名)
"""
return self.signups.exclude(status='cancelled').count()
return self.signups.filter(status='confirmed').count()
def __str__(self):
return self.title

View File

@@ -9,6 +9,7 @@ class ActivitySerializer(serializers.ModelSerializer):
current_signups = serializers.IntegerField(read_only=True)
has_signed_up = serializers.SerializerMethodField()
is_signed_up = serializers.SerializerMethodField()
my_signup_status = serializers.SerializerMethodField()
class Meta:
model = Activity
@@ -17,14 +18,25 @@ class ActivitySerializer(serializers.ModelSerializer):
def get_has_signed_up(self, obj):
return self.get_is_signed_up(obj)
def get_my_signup_status(self, obj):
request = self.context.get('request')
if not request:
return None
user = get_current_wechat_user(request)
if user:
# Return the status of the non-cancelled signup
signup = obj.signups.filter(user=user).exclude(status='cancelled').first()
return signup.status if signup else None
return None
def get_is_signed_up(self, obj):
request = self.context.get('request')
if not request:
return False
user = get_current_wechat_user(request)
if user:
# Check if there is a valid signup (not cancelled)
return obj.signups.filter(user=user).exclude(status='cancelled').exists()
# Check if there is a valid signup (only confirmed counts)
return obj.signups.filter(user=user, status='confirmed').exists()
return False
def get_signup_form_config(self, obj):

View File

@@ -93,6 +93,11 @@ class ActivityViewSet(viewsets.ReadOnlyModelViewSet):
contact_phone = signup_info.get('phone') or user.phone_number or ''
if contact_name: order.customer_name = contact_name
if contact_phone: order.phone_number = contact_phone
# Ensure activity is linked
if not order.activity:
order.activity = activity
order.save()
if not order:
@@ -105,6 +110,9 @@ class ActivityViewSet(viewsets.ReadOnlyModelViewSet):
if pending_order:
order = pending_order
# Ensure shipping address is up-to-date
order.shipping_address = activity.location or '线下活动'
order.save()
else:
contact_name = signup_info.get('name') or signup_info.get('participant_name') or user.nickname or 'Activity User'
contact_phone = signup_info.get('phone') or user.phone_number or ''
@@ -136,7 +144,8 @@ class ActivityViewSet(viewsets.ReadOnlyModelViewSet):
'total': int(activity.price * 100),
'currency': 'CNY'
},
notify_url=wxpay._notify_url
notify_url=wxpay._notify_url,
attach=f'{{"type":"activity","activity_id":{activity.id}}}'
)
import json