Browse Source

feat(app): 优化课程折扣判断逻辑

- 在 checkOrderOrFree 方法中增加课程开始时间判断,已过期课程视为非首次购买
- 修改 courseInfoVO.setHasDiscount 调用,增加课程 ID 参数
- 优化代码格式,提高可读性
SheepHy 2 tuần trước cách đây
mục cha
commit
d87c15b14a

+ 9 - 4
national-motion-module-system/national-motion-system-biz/src/main/java/org/jeecg/modules/app/service/impl/DetailServiceImpl.java

@@ -219,7 +219,7 @@ public class DetailServiceImpl implements IDetailService {
         });
 
         courseInfoVO.setCourseDetail(courseDetailVOList);
-        courseInfoVO.setHasDiscount(checkOrderOrFree(loginUser.getId(),courseInfoVO.getCategoryId()));
+        courseInfoVO.setHasDiscount(checkOrderOrFree(loginUser.getId(),courseInfoVO.getCategoryId(),id));
         return courseInfoVO;
     }
 
@@ -230,9 +230,14 @@ public class DetailServiceImpl implements IDetailService {
      * @param categoryId
      * @return
      */
-    private Boolean checkOrderOrFree(String userId, String categoryId) {
+    private Boolean checkOrderOrFree(String userId, String categoryId, String coursesId) {
+        Date startTime = appCoursesMapper.selectById(coursesId).getStartTime();
+        if (startTime != null && startTime.before(new Date())) {
+            return Boolean.FALSE; // 课程已过期,视为非首次购买
+        }
         //查询当前用户的所有课程订单
-        List<AppOrder> appOrders = appOrderMapper.selectList(Wrappers.<AppOrder>lambdaQuery().eq(AppOrder::getUserId, userId).eq(AppOrder::getType, CommonConstant.ORDER_TYPE_2));
+        List<AppOrder> appOrders = appOrderMapper.selectList(Wrappers.<AppOrder>lambdaQuery().eq(AppOrder::getUserId, userId)
+                .eq(AppOrder::getType, CommonConstant.ORDER_TYPE_2));
         if (CollUtil.isNotEmpty(appOrders)){
             for (AppOrder appOrder : appOrders) {
                 if(null != appOrder){
@@ -263,7 +268,7 @@ public class DetailServiceImpl implements IDetailService {
             courseInfoVO.setPriceType(isFirstPurchase(user.getId()));
             courseInfoVO.setCover(list.get(0));
             courseInfoVO.setPeriod(Math.toIntExact(appCoursesPriceRulesMapper.selectCount(Wrappers.<AppCoursesPriceRules>lambdaQuery().eq(AppCoursesPriceRules::getCoursesId, appCourses.getId()))));
-            courseInfoVO.setHasDiscount(checkOrderOrFree(user.getId(), appCourses.getCategoryId()));
+            courseInfoVO.setHasDiscount(checkOrderOrFree(user.getId(), appCourses.getCategoryId(),appCourses.getId()));
             AppSite appSite = appSiteMapper.selectById(appCourses.getAddressSiteId());
             if (appSite!=null){
                 courseInfoVO.setAddress(appSite.getAddress());