VC课程页面
All checks were successful
Deploy to Server / deploy (push) Successful in 37s

This commit is contained in:
jeremygan2021
2026-02-23 23:34:54 +08:00
parent 3f363dbd8e
commit 0d01a5f2a8
3 changed files with 25 additions and 3 deletions

View File

@@ -601,7 +601,15 @@ class OrderViewSet(viewsets.ModelViewSet):
创建订单时自动关联当前微信用户
"""
user = get_current_wechat_user(self.request)
serializer.save(wechat_user=user)
instance = serializer.save(wechat_user=user)
# Check if free course and set to paid
if instance.course and instance.course.price == 0 and instance.status == 'pending':
instance.status = 'paid'
instance.save()
# Trigger post payment logic
from .services import handle_post_payment
handle_post_payment(instance)
@action(detail=True, methods=['post'])
def prepay_miniprogram(self, request, pk=None):

View File

@@ -4,6 +4,7 @@ import { Typography, Button, Spin, Empty, Descriptions, Tag, Row, Col, Modal, Fo
import { ArrowLeftOutlined, ClockCircleOutlined, UserOutlined, BookOutlined, FormOutlined } from '@ant-design/icons';
import { getVCCourseDetail, createOrder } from '../api';
import { motion } from 'framer-motion';
import { useAuth } from '../context/AuthContext';
const { Title, Paragraph } = Typography;
@@ -11,6 +12,7 @@ const VCCourseDetail = () => {
const { id } = useParams();
const navigate = useNavigate();
const [searchParams] = useSearchParams();
const { user } = useAuth();
const [course, setCourse] = useState(null);
const [loading, setLoading] = useState(true);
const [isModalOpen, setIsModalOpen] = useState(false);
@@ -34,6 +36,14 @@ const VCCourseDetail = () => {
fetchDetail();
}, [id]);
useEffect(() => {
if (isModalOpen && user && user.phone_number) {
form.setFieldsValue({
phone_number: user.phone_number
});
}
}, [isModalOpen, user, form]);
const handleEnroll = async (values) => {
setSubmitting(true);
try {
@@ -48,7 +58,11 @@ const VCCourseDetail = () => {
};
await createOrder(orderData);
if (course.price === 0 || parseFloat(course.price) === 0) {
message.success('报名成功!您已成功加入课程。');
} else {
message.success('报名咨询已提交,我们的课程顾问将尽快与您联系!');
}
setIsModalOpen(false);
} catch (error) {
console.error(error);

View File

@@ -88,7 +88,7 @@ const VCCourses = () => {
</div>
<p style={{ color: '#aaa', marginBottom: 20, flex: 1 }}>{item.description}</p>
<Button type="primary" block ghost style={{ borderColor: '#00f0ff', color: '#00f0ff' }}>
开始学习
点击报名
</Button>
</div>
</div>