Pārlūkot izejas kodu

fix 退团课程费用,退团删除课程购买记录

周箭河 5 gadi atpakaļ
vecāks
revīzija
11731586cc

+ 37 - 10
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -159,6 +159,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     private MusicGroupPaymentCalenderCourseSettingsDao musicGroupPaymentCalenderCourseSettingsDao;
     @Autowired
     private MusicGroupPaymentStudentCourseDetailDao musicGroupPaymentStudentCourseDetailDao;
+    @Autowired
+    private SubjectChangeDao subjectChangeDao;
 
     private SimpleDateFormat sdf_ymd = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -1518,7 +1520,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             studentRegistrationDao.update(studentRegistration);
 
             //删除用户购买的课程记录
-            musicGroupPaymentStudentCourseDetailDao.deleteByUserIdAndMusicGroupId(userId,musicGroupId);
+            musicGroupPaymentStudentCourseDetailDao.deleteByUserIdAndMusicGroupId(userId, musicGroupId);
 
             BigDecimal amount = new BigDecimal(0);
 
@@ -1534,6 +1536,17 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
             List<StudentPaymentOrderDetail> orderDetailList = studentPaymentOrderDetailDao.findApplyOrderGoods(studentPaymentOrder.getId());
 
+            Set<String> courseTypeSet = new HashSet<>();
+            if (isRefundCourseFee) {
+                List<MusicGroupPaymentCalenderCourseSettings> courseSettings = musicGroupPaymentCalenderCourseSettingsDao.getMusicGroupRegCalenderCourseSettings(studentRegistration.getMusicGroupId());
+                courseTypeSet = courseSettings.stream().map(e -> e.getCourseType().getCode()).collect(Collectors.toSet());
+            }
+
+            SubjectChange studentLastChange = null;
+            if (isRefundInstrumentFee || isRefundTeachingAssistantsFee) {
+                studentLastChange = subjectChangeDao.getStudentLastChange(userId, musicGroupId);
+            }
+
             BigDecimal remitFee = studentPaymentOrder.getRemitFee() == null ? BigDecimal.ZERO : studentPaymentOrder.getRemitFee();
             for (StudentPaymentOrderDetail detail : orderDetailList) {
                 if (remitFee.compareTo(detail.getPrice()) >= 0) {
@@ -1545,27 +1558,28 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 }
 
                 if (isRefundCourseFee) {
-                    List<MusicGroupPaymentCalenderCourseSettings> courseSettings = musicGroupPaymentCalenderCourseSettingsDao.getMusicGroupRegCalenderCourseSettings(studentRegistration.getMusicGroupId());
-                    Set<String> courseTypeSet = courseSettings.stream().map(e -> e.getCourseType().getCode()).collect(Collectors.toSet());
                     // 退课程费用
                     if (courseTypeSet.contains(detail.getType().getCode())) {
                         amount = amount.add(detail.getPrice());
                     }
                 }
-                if (isRefundInstrumentFee) {
+                if (isRefundInstrumentFee && studentLastChange == null) {
                     // 退乐器费用
                     if (detail.getType() == OrderDetailTypeEnum.MUSICAL) {
                         amount = amount.add(detail.getPrice());
                     }
 
                 }
-                if (isRefundTeachingAssistantsFee) {
+                if (isRefundTeachingAssistantsFee && studentLastChange == null) {
                     // 退教辅费用
                     if (detail.getType() == OrderDetailTypeEnum.ACCESSORIES || detail.getType() == OrderDetailTypeEnum.TEACHING) {
                         amount = amount.add(detail.getPrice());
                     }
                 }
             }
+            if (studentLastChange != null) {
+                amount = amount.add(studentLastChange.getChangeMusicalPrice()).add(studentLastChange.getChangeAccessoriesPrice());
+            }
             if (amount.doubleValue() > 0) {
                 // 增加交易流水
                 sysUserCashAccountDetailService.addCashAccountDetail(userId, amount, SysUserCashAccountDetailService.MUSIC_GROUP + musicGroupId, "",
@@ -1626,7 +1640,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         studentRegistrationDao.update(studentRegistration);
 
         //删除用户购买的课程记录
-        musicGroupPaymentStudentCourseDetailDao.deleteByUserIdAndMusicGroupId(userId,musicGroupId);
+        musicGroupPaymentStudentCourseDetailDao.deleteByUserIdAndMusicGroupId(userId, musicGroupId);
 
         BigDecimal amount = new BigDecimal(0);
 
@@ -1640,6 +1654,18 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
 
         List<StudentPaymentOrderDetail> orderDetailList = studentPaymentOrderDetailDao.findApplyOrderGoods(studentPaymentOrder.getId());
+
+        Set<String> courseTypeSet = new HashSet<>();
+        if (isRefundCourseFee) {
+            List<MusicGroupPaymentCalenderCourseSettings> courseSettings = musicGroupPaymentCalenderCourseSettingsDao.getMusicGroupRegCalenderCourseSettings(studentRegistration.getMusicGroupId());
+            courseTypeSet = courseSettings.stream().map(e -> e.getCourseType().getCode()).collect(Collectors.toSet());
+        }
+
+        SubjectChange studentLastChange = null;
+        if (isRefundInstrumentFee || isRefundTeachingAssistantsFee) {
+            studentLastChange = subjectChangeDao.getStudentLastChange(userId, musicGroupId);
+        }
+
         BigDecimal remitFee = studentPaymentOrder.getRemitFee() == null ? BigDecimal.ZERO : studentPaymentOrder.getRemitFee();
 
         for (StudentPaymentOrderDetail detail : orderDetailList) {
@@ -1651,27 +1677,28 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 remitFee = BigDecimal.ZERO;
             }
             if (isRefundCourseFee) {
-                List<MusicGroupPaymentCalenderCourseSettings> courseSettings = musicGroupPaymentCalenderCourseSettingsDao.getMusicGroupRegCalenderCourseSettings(studentRegistration.getMusicGroupId());
-                Set<String> courseTypeSet = courseSettings.stream().map(e -> e.getCourseType().getCode()).collect(Collectors.toSet());
                 // 退课程费用
                 if (courseTypeSet.contains(detail.getType().getCode())) {
                     amount = amount.add(detail.getPrice());
                 }
             }
-            if (isRefundInstrumentFee) {
+            if (isRefundInstrumentFee && studentLastChange == null) {
                 // 退乐器费用
                 if (detail.getType() == OrderDetailTypeEnum.MUSICAL) {
                     amount = amount.add(detail.getPrice());
                 }
 
             }
-            if (isRefundTeachingAssistantsFee) {
+            if (isRefundTeachingAssistantsFee && studentLastChange == null) {
                 // 退教辅费用
                 if (detail.getType() == OrderDetailTypeEnum.ACCESSORIES || detail.getType() == OrderDetailTypeEnum.TEACHING) {
                     amount = amount.add(detail.getPrice());
                 }
             }
         }
+        if (studentLastChange != null) {
+            amount = amount.add(studentLastChange.getChangeMusicalPrice()).add(studentLastChange.getChangeAccessoriesPrice());
+        }
         if (amount.doubleValue() > 0) {
             // 增加交易流水
             sysUserCashAccountDetailService.addCashAccountDetail(userId, amount, SysUserCashAccountDetailService.MUSIC_GROUP + musicGroupId, "",