Selaa lähdekoodia

feat(app): 添加课程购买预览功能

- 新增课程购买预览接口和相关服务实现
- 增加用户登录信息获取和课程折扣判断逻辑
-完善订单预览信息,包括课程基本信息、是否有折扣及折扣金额等
SheepHy 1 viikko sitten
vanhempi
commit
d31a206397

+ 13 - 0
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/controller/OrderController.java

@@ -48,4 +48,17 @@ public class OrderController {
                                                @RequestParam("limitNum") @Schema(description = "购买数")int limitNum){
         return Result.OK(appOrderService.checkCourseLimitNum(courseId, limitNum));
     }
+
+    /**
+     * @Author SheepHy
+     * @Description 课程购买-预览页(学校课程、体育馆课程、教练课程)
+     * @Date 15:43 2025/7/14
+     * @Param courseId
+     * @return OrderVO.PreviewOrderCourseSchool {@link OrderVO.PreviewOrderCourse}
+     **/
+    @Operation(summary="课程购买-预览页(学校课程、体育馆课程、教练课程)")
+    @GetMapping("/previewOrderCourse")
+    public Result<OrderVO.PreviewOrderCourse> previewOrderCourse(@RequestParam("courseId") @Schema(description = "课程ID")String courseId){
+        return Result.ok(appOrderService.previewOrderCourse(courseId));
+    }
 }

+ 21 - 7
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/OrderServiceImpl.java

@@ -2,6 +2,8 @@ package org.jeecg.modules.app.service.impl;
 
 import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import lombok.extern.log4j.Log4j2;
+import org.apache.shiro.SecurityUtils;
+import org.jeecg.common.system.vo.LoginUser;
 import org.jeecg.modules.app.service.IOrderService;
 import org.jeecg.modules.app.vo.OrderVO;
 import org.jeecg.modules.system.app.entity.AppCourses;
@@ -14,6 +16,7 @@ import org.jeecg.modules.system.app.mapper.AppSitePriceRulesMapper;
 import org.springframework.stereotype.Service;
 
 import javax.annotation.Resource;
+import java.math.BigDecimal;
 import java.time.LocalDate;
 import java.time.ZoneId;
 import java.util.Date;
@@ -51,15 +54,24 @@ public class OrderServiceImpl implements IOrderService {
 
     @Override
     public OrderVO.PreviewOrderCourse previewOrderCourse(String courseId) {
+        LoginUser user = (LoginUser) SecurityUtils.getSubject().getPrincipal();
         OrderVO.PreviewOrderCourse previousOrderCourse = new OrderVO.PreviewOrderCourse();
         AppCourses appCourses = appCoursesMapper.selectById(courseId);
+        boolean checkCourseDiscount = checkCourseDiscount(appCourses.getCategoryId(), user.getId());
         previousOrderCourse.setId(appCourses.getId())
                 .setCover(appCourses.getCover())
                 .setName(appCourses.getName())
                 .setSellingPrice(appCourses.getSellingPrice())
-                .setReminder(appCourses.getReminder());
-//                .setHasDiscount();
-        return null;
+                .setReminder(appCourses.getReminder())
+                .setHasDiscount(checkCourseDiscount);
+        if(checkCourseDiscount){
+            previousOrderCourse.setDiscountPrice(appCourses.getSellingPrice());
+            previousOrderCourse.setTotalDiscount(appCourses.getSellingPrice());
+        }else {
+            previousOrderCourse.setDiscountPrice(BigDecimal.ZERO);
+            previousOrderCourse.setTotalDiscount(BigDecimal.ZERO);
+        }
+        return previousOrderCourse;
     }
 
     @Override
@@ -84,10 +96,12 @@ public class OrderServiceImpl implements IOrderService {
                 .eq(AppOrder::getDelFlag, 0)
                 .eq(AppOrder::getType,2));
         if (appOrders.isEmpty()) return true;
-        appOrders.forEach(appOrder -> {
-            AppCourses appCourses = appCoursesMapper.selectById(appOrder.getProductIds());
-//            if(appCourses.getCategoryId().equals(categoryId)) success = Boolean.FALSE;
-        });
+        for (AppOrder appOrder : appOrders) {
+            if (!appOrder.getProductIds().contains(categoryId)) {
+                success = false;
+                break;
+            }
+        }
         return success;
     }
 }