| | |
| | | AppUser user = requireEnabledUser(userId); |
| | | HealthCourse course = requireEnabledCourse(courseId); |
| | | String paymentMethod = normalizePaymentMethod(request == null ? null : request.getPaymentMethod()); |
| | | if (course.getSalePrice() == null || course.getSalePrice().compareTo(BigDecimal.ZERO) <= 0) { |
| | | throw new IllegalArgumentException("当前课程无需购买"); |
| | | } |
| | | CoursePurchaseOrder existingOrder = findLatestActivePaidCourseOrder(userId, courseId); |
| | | if (existingOrder != null) { |
| | | return buildPurchaseResult(existingOrder, true, resolvePurchasedVideoIds(userId, courseId, true)); |
| | |
| | | |
| | | const courseBuyButtonText = computed(() => { |
| | | if (courseDetail.value.courseOwned) { |
| | | return '已领取' |
| | | return '已加入' |
| | | } |
| | | if (isFreeCourse()) { |
| | | return '加入我的课程' |
| | | } |
| | | return '领取' |
| | | }) |
| | |
| | | * 提交当前领取目标的 0 元订单,占位支付方式仅用于兼容后端校验。 |
| | | */ |
| | | async function submitZeroPricePurchase() { |
| | | const successTitle = activePurchaseTarget.value === 'COURSE' && isFreeCourse() |
| | | ? '已加入我的课程' |
| | | : '领取成功' |
| | | await submitPurchaseWithPayload({ |
| | | paymentMethod: 'WECHAT', |
| | | }, '领取成功') |
| | | }, successTitle) |
| | | } |
| | | |
| | | /** |
| | | * 判断整课是否为 0 元课程,用于区分按钮文案和加入提示。 |
| | | */ |
| | | function isFreeCourse() { |
| | | const salePrice = Number(courseDetail.value.salePrice || 0) |
| | | return Number.isFinite(salePrice) && salePrice <= 0 |
| | | } |
| | | |
| | | /** |