This commit is contained in:
@@ -601,7 +601,15 @@ class OrderViewSet(viewsets.ModelViewSet):
|
|||||||
创建订单时自动关联当前微信用户
|
创建订单时自动关联当前微信用户
|
||||||
"""
|
"""
|
||||||
user = get_current_wechat_user(self.request)
|
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'])
|
@action(detail=True, methods=['post'])
|
||||||
def prepay_miniprogram(self, request, pk=None):
|
def prepay_miniprogram(self, request, pk=None):
|
||||||
|
|||||||
@@ -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 { ArrowLeftOutlined, ClockCircleOutlined, UserOutlined, BookOutlined, FormOutlined } from '@ant-design/icons';
|
||||||
import { getVCCourseDetail, createOrder } from '../api';
|
import { getVCCourseDetail, createOrder } from '../api';
|
||||||
import { motion } from 'framer-motion';
|
import { motion } from 'framer-motion';
|
||||||
|
import { useAuth } from '../context/AuthContext';
|
||||||
|
|
||||||
const { Title, Paragraph } = Typography;
|
const { Title, Paragraph } = Typography;
|
||||||
|
|
||||||
@@ -11,6 +12,7 @@ const VCCourseDetail = () => {
|
|||||||
const { id } = useParams();
|
const { id } = useParams();
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const [searchParams] = useSearchParams();
|
const [searchParams] = useSearchParams();
|
||||||
|
const { user } = useAuth();
|
||||||
const [course, setCourse] = useState(null);
|
const [course, setCourse] = useState(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
const [isModalOpen, setIsModalOpen] = useState(false);
|
const [isModalOpen, setIsModalOpen] = useState(false);
|
||||||
@@ -34,6 +36,14 @@ const VCCourseDetail = () => {
|
|||||||
fetchDetail();
|
fetchDetail();
|
||||||
}, [id]);
|
}, [id]);
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isModalOpen && user && user.phone_number) {
|
||||||
|
form.setFieldsValue({
|
||||||
|
phone_number: user.phone_number
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}, [isModalOpen, user, form]);
|
||||||
|
|
||||||
const handleEnroll = async (values) => {
|
const handleEnroll = async (values) => {
|
||||||
setSubmitting(true);
|
setSubmitting(true);
|
||||||
try {
|
try {
|
||||||
@@ -48,7 +58,11 @@ const VCCourseDetail = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
await createOrder(orderData);
|
await createOrder(orderData);
|
||||||
message.success('报名咨询已提交,我们的课程顾问将尽快与您联系!');
|
if (course.price === 0 || parseFloat(course.price) === 0) {
|
||||||
|
message.success('报名成功!您已成功加入课程。');
|
||||||
|
} else {
|
||||||
|
message.success('报名咨询已提交,我们的课程顾问将尽快与您联系!');
|
||||||
|
}
|
||||||
setIsModalOpen(false);
|
setIsModalOpen(false);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
|||||||
@@ -88,7 +88,7 @@ const VCCourses = () => {
|
|||||||
</div>
|
</div>
|
||||||
<p style={{ color: '#aaa', marginBottom: 20, flex: 1 }}>{item.description}</p>
|
<p style={{ color: '#aaa', marginBottom: 20, flex: 1 }}>{item.description}</p>
|
||||||
<Button type="primary" block ghost style={{ borderColor: '#00f0ff', color: '#00f0ff' }}>
|
<Button type="primary" block ghost style={{ borderColor: '#00f0ff', color: '#00f0ff' }}>
|
||||||
开始学习
|
点击报名
|
||||||
</Button>
|
</Button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user