Переглянути джерело

Merge remote-tracking branch 'origin/saas' into saas

yanite 3 роки тому
батько
коміт
bf81e144dc
31 змінених файлів з 451 додано та 468 видалено
  1. 13 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysCouponIssueRecordDao.java
  2. 11 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/dto/SysCouponCodeDto.java
  3. 4 4
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderDetail.java
  4. 10 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderMember.java
  5. 9 0
      mec-biz/src/main/java/com/ym/mec/biz/dal/vo/CouponIssueRecordVo.java
  6. 0 9
      mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleStudentPaymentService.java
  7. 1 1
      mec-biz/src/main/java/com/ym/mec/biz/service/MusicGroupPaymentCalenderBaseService.java
  8. 1 1
      mec-biz/src/main/java/com/ym/mec/biz/service/MusicGroupPaymentCalenderDetailService.java
  9. 0 1
      mec-biz/src/main/java/com/ym/mec/biz/service/MusicGroupService.java
  10. 11 2
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderDetailService.java
  11. 4 6
      mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderService.java
  12. 5 1
      mec-biz/src/main/java/com/ym/mec/biz/service/SysCouponIssueRecordService.java
  13. 0 43
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java
  14. 17 5
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderActivityServiceImpl.java
  15. 2 2
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderCourseSettingsServiceImpl.java
  16. 14 9
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderDetailServiceImpl.java
  17. 36 15
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderMemberServiceImpl.java
  18. 17 13
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderRepairServiceImpl.java
  19. 20 11
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java
  20. 4 81
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java
  21. 108 35
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java
  22. 19 34
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java
  23. 1 1
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java
  24. 30 149
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java
  25. 18 9
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponCodeServiceImpl.java
  26. 48 11
      mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponIssueRecordServiceImpl.java
  27. 1 1
      mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderDetailMapper.xml
  28. 2 0
      mec-biz/src/main/resources/config/mybatis/SysCouponCodeMapper.xml
  29. 30 4
      mec-biz/src/main/resources/config/mybatis/SysCouponIssueRecordMapper.xml
  30. 6 18
      mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupPaymentCalenderController.java
  31. 9 2
      mec-web/src/main/java/com/ym/mec/web/controller/SysCouponIssueRecordController.java

+ 13 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dao/SysCouponIssueRecordDao.java

@@ -23,5 +23,18 @@ public interface SysCouponIssueRecordDao extends BaseMapper<SysCouponIssueRecord
 
     <T> IPage<T> queryIssueRecord(Page<T> page, @Param("param") Map<String, Object> param);
 
+    int queryCouponCode(@Param("issueId") Integer issueId,@Param("state") Integer state);
+
+    /**
+     * 撤回未使用的优惠券
+     */
+    void revoke(Integer issueId);
+
+    /**
+     * @param id sys_coupon表的id
+     * @param consumeNum 消费数量
+     */
+    void opsConsume(@Param("id") Integer id,@Param("consumeNum") Integer consumeNum);
+
 }
 

+ 11 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/SysCouponCodeDto.java

@@ -72,6 +72,9 @@ public class SysCouponCodeDto {
     @ApiModelProperty("发放类型 0手动领取 1手动发放 2交易获取")
     private Integer issueType;
 
+    @ApiModelProperty("优惠券具体类型 - CouponDetailTypeEnum")
+    private String typeDetail;
+
     public Integer getCouponCodeId() {
         return couponCodeId;
     }
@@ -231,4 +234,12 @@ public class SysCouponCodeDto {
     public void setIssueType(Integer issueType) {
         this.issueType = issueType;
     }
+
+    public String getTypeDetail() {
+        return typeDetail;
+    }
+
+    public void setTypeDetail(String typeDetail) {
+        this.typeDetail = typeDetail;
+    }
 }

+ 4 - 4
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderDetail.java

@@ -26,14 +26,14 @@ public class MusicGroupPaymentCalenderDetail extends BaseEntity {
 	
 	/**  */
 	private Integer userId;
-	
-	/**  */
+
+	/** 废弃字段,如果需要查看金额,请前往订单详情 */
 	private java.math.BigDecimal expectAmount;
 
-	/**  */
+	/** 废弃字段,如果需要查看金额,请前往订单详情 */
 	private java.math.BigDecimal expectMemberAmount = BigDecimal.ZERO;
 	
-	/**  */
+	/** 废弃字段,如果需要查看金额,请前往订单详情 */
 	private java.math.BigDecimal actualAmount;
 	
 	/**  */

+ 10 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/entity/MusicGroupPaymentCalenderMember.java

@@ -13,6 +13,16 @@ public class MusicGroupPaymentCalenderMember extends MusicGroupPaymentCalenderBa
     @ApiModelProperty(value = "会员等级编号", required = false)
     private Integer memberRankSettingId = 1;
 
+    private Integer organId;
+
+    public Integer getOrganId() {
+        return organId;
+    }
+
+    public void setOrganId(Integer organId) {
+        this.organId = organId;
+    }
+
     public String getName() {
         return name;
     }

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/vo/CouponIssueRecordVo.java

@@ -10,6 +10,7 @@ import java.util.Date;
  * Created by 2021-12-30
  */
 public class CouponIssueRecordVo implements Serializable {
+    private Integer id;
 
     @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
     private Date createdTime;
@@ -22,6 +23,14 @@ public class CouponIssueRecordVo implements Serializable {
 
     private Integer ops;
 
+    public Integer getId() {
+        return id;
+    }
+
+    public void setId(Integer id) {
+        this.id = id;
+    }
+
     public Date getCreatedTime() {
         return createdTime;
     }

+ 0 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/CourseScheduleStudentPaymentService.java

@@ -89,15 +89,6 @@ public interface CourseScheduleStudentPaymentService extends BaseService<Long, C
 	void createForMusicGroup(List<CourseSchedule> courseSchedules, List<Integer> studentIds,Integer musicGroupStudentClassAdjustId);
 
 	/**
-	 * @describe 根据缴费日历更新乐团课程学院课程价格
-	 * @author Joburgess
-	 * @date 2020.10.29
-	 * @param batchNo: 缴费日历批次号
-	 * @return void
-	 */
-	void updateForMusicGroupWithPaymentCalender(String batchNo);
-
-	/**
 	 * 获取班级未开始的的课程
 	 * @param classGroupIds
 	 * @return

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/MusicGroupPaymentCalenderBaseService.java

@@ -48,7 +48,7 @@ public interface MusicGroupPaymentCalenderBaseService<T> {
     * @author zx
     * @date 2021/12/29 15:32
     */
-    BigDecimal getCurrentAmount(T baseCalender);
+    BigDecimal getCurrentAmount(MusicGroupPaymentBaseCalender baseCalender);
 
     /**
     * @description: 缴费项目关联初始化

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/MusicGroupPaymentCalenderDetailService.java

@@ -119,5 +119,5 @@ public interface MusicGroupPaymentCalenderDetailService extends BaseService<Long
     * @author zx
     * @date 2021/12/30 15:16
     */
-    void addCalenderDetail(StudentPaymentOrder studentPaymentOrder, StudentRegistration studentRegistration);
+    void addCalenderDetail(StudentPaymentOrder studentPaymentOrder,StudentRegistration studentRegistration);
 }

+ 0 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/MusicGroupService.java

@@ -6,7 +6,6 @@ import java.util.Date;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-
 import com.ym.mec.biz.dal.dto.*;
 import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.page.MusicGroupQueryInfo;

+ 11 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderDetailService.java

@@ -1,8 +1,7 @@
 package com.ym.mec.biz.service;
 
 import com.ym.mec.biz.dal.dto.MusicalListDetailDto;
-import com.ym.mec.biz.dal.entity.Goods;
-import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.BaseService;
@@ -111,4 +110,14 @@ public interface StudentPaymentOrderDetailService extends BaseService<Long, Stud
     * @date 2021/12/30 15:13
     */
     List<StudentPaymentOrderDetail> queryOrderDetail(Long orderId);
+
+    /**
+    * @description: 处理乐团缴费完成后,课程、会员、乐保等数据的录入
+     * @param studentPaymentOrder
+     * @param musicGroup
+    * @return void
+    * @author zx
+    * @date 2021/12/30 17:00
+    */
+    void addOrderDetailTo(StudentPaymentOrder studentPaymentOrder, MusicGroup musicGroup, StudentRegistration studentRegistration);
 }

+ 4 - 6
mec-biz/src/main/java/com/ym/mec/biz/service/StudentPaymentOrderService.java

@@ -1,19 +1,13 @@
 package com.ym.mec.biz.service;
 
-import java.util.Date;
-import java.util.List;
-import java.util.Map;
-
 import com.ym.mec.biz.dal.dto.PageInfoOrder;
 import com.ym.mec.biz.dal.dto.SporadicChargeInfoDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto;
-import com.ym.mec.biz.dal.entity.Goods;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
 import com.ym.mec.biz.dal.entity.StudentPaymentOrderDetail;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.GroupType;
-import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
 import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 import com.ym.mec.biz.dal.enums.PayStatus;
 import com.ym.mec.biz.dal.page.SporadicOrderQueryInfo;
@@ -23,6 +17,10 @@ import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.BaseService;
 import org.apache.ibatis.annotations.Param;
 
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+
 public interface StudentPaymentOrderService extends BaseService<Long, StudentPaymentOrder> {
 
     StudentPaymentOrder findByUserAndActive(Integer userId, Integer activeRemark, String remark,String status);

+ 5 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/SysCouponIssueRecordService.java

@@ -18,7 +18,11 @@ public interface SysCouponIssueRecordService extends IService<SysCouponIssueReco
 
     void issueCoupon(Map<String, Object> param);
 
-    int revokeCoupon(Integer couponId);
+    void revokeCoupon(Integer couponId);
+
+    void manualIssueCoupon(Integer userId, Integer couponId);
+
+    int checkRevoke(Integer couponId);
 
     PageInfo<?> queryIssueDetail(Map<String, Object> param);
 

+ 0 - 43
mec-biz/src/main/java/com/ym/mec/biz/service/impl/CourseScheduleStudentPaymentServiceImpl.java

@@ -564,49 +564,6 @@ public class CourseScheduleStudentPaymentServiceImpl extends BaseServiceImpl<Lon
 		courseScheduleStudentPaymentDao.batchInsert(courseScheduleStudentPayments);
 	}
 
-	@Override
-	@Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
-	public void updateForMusicGroupWithPaymentCalender(String batchNo) {
-		List<CourseScheduleStudentPayment> courseScheduleStudentPayments = courseScheduleStudentPaymentDao.findByBatchNo(batchNo);
-		if(CollectionUtils.isEmpty(courseScheduleStudentPayments)){
-			return;
-		}
-		List<MusicGroupPaymentCalender> musicGroupPaymentCalenders = musicGroupPaymentCalenderDao.findByBatchNo(batchNo);
-		if(CollectionUtils.isEmpty(musicGroupPaymentCalenders)){
-			return;
-		}
-		List<Long> calenderIds = musicGroupPaymentCalenders.stream().map(MusicGroupPaymentCalender::getId).collect(Collectors.toList());
-		List<MusicGroupPaymentCalenderDetail> calenderDetails = musicGroupPaymentCalenderDetailDao.getWithCalenderIds(calenderIds);
-
-		Map<Integer, List<CourseScheduleStudentPayment>> studentStudentPaymentMap = courseScheduleStudentPayments.stream().collect(Collectors.groupingBy(CourseScheduleStudentPayment::getUserId));
-		Map<Integer, List<MusicGroupPaymentCalenderDetail>> studentCalenderDetailMap = calenderDetails.stream().collect(Collectors.groupingBy(MusicGroupPaymentCalenderDetail::getUserId));
-
-		List<CourseScheduleStudentPayment> updateStudentPayments = new ArrayList<>();
-
-		for (Map.Entry<Integer, List<CourseScheduleStudentPayment>> studentStudentPaymentMapEntry : studentStudentPaymentMap.entrySet()) {
-			List<MusicGroupPaymentCalenderDetail> musicGroupPaymentCalenderDetails = studentCalenderDetailMap.get(studentStudentPaymentMapEntry.getKey());
-
-			if(CollectionUtils.isEmpty(musicGroupPaymentCalenderDetails)){
-				continue;
-			}
-
-			//学员总缴费金额
-			BigDecimal totalActualAmount = musicGroupPaymentCalenderDetails.stream().map(e -> Objects.isNull(e.getActualAmount())?BigDecimal.ZERO:e.getActualAmount()).reduce(BigDecimal.ZERO, BigDecimal::add);
-
-			for (CourseScheduleStudentPayment courseScheduleStudentPayment : studentStudentPaymentMapEntry.getValue()) {
-				if(totalActualAmount.compareTo(courseScheduleStudentPayment.getExpectPrice())>=0){
-					courseScheduleStudentPayment.setActualPrice(courseScheduleStudentPayment.getExpectPrice());
-					totalActualAmount=totalActualAmount.subtract(courseScheduleStudentPayment.getExpectPrice());
-				}else{
-					courseScheduleStudentPayment.setActualPrice(totalActualAmount);
-					totalActualAmount=BigDecimal.ZERO;
-				}
-				updateStudentPayments.add(courseScheduleStudentPayment);
-			}
-		}
-
-		courseScheduleStudentPaymentDao.batchUpdate(updateStudentPayments);
-	}
 
 	@Override
 	public List<CourseScheduleStudentPayment> getClassGroupNoStartCourse(List<Integer> classGroupIds) {

+ 17 - 5
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderActivityServiceImpl.java

@@ -24,6 +24,7 @@ import java.util.List;
 import java.util.Map;
 import java.util.function.Consumer;
 import java.util.function.Function;
+import java.util.function.Supplier;
 import java.util.stream.Collectors;
 
 @Service
@@ -63,19 +64,30 @@ public class MusicGroupPaymentCalenderActivityServiceImpl extends BaseServiceImp
 
     @Override
     public BigDecimal getOriginalAmount(MusicGroupPaymentBaseCalender baseCalender) {
-        List<MusicGroupPaymentCalenderActivity> calenderActivityList = baseCalender.getCalenderActivityList();
+        return this.getAmount(baseCalender.getCalenderActivityList(),this::getActivityOriginalAmount);
+    }
+
+    @Override
+    public BigDecimal getCurrentAmount(MusicGroupPaymentBaseCalender baseCalender) {
+        return this.getAmount(baseCalender.getCalenderActivityList(),this::getActivityActualAmount);
+    }
+
+    private BigDecimal getAmount(List<MusicGroupPaymentCalenderActivity> calenderActivityList,Function<VipGroupActivity,BigDecimal> fun){
         if(calenderActivityList != null && calenderActivityList.size() > 0){
             List<Integer> collect = calenderActivityList.stream().map(e -> e.getActivityId()).collect(Collectors.toList());
             List<VipGroupActivity> vipGroupActivities = vipGroupActivityDao.queryByIds(StringUtils.join(collect, ","));
-            return vipGroupActivities.stream().map(e->e.getOriginalPrice()).reduce(BigDecimal.ZERO,BigDecimal::add);
+            return vipGroupActivities.stream().map(e->fun.apply(e)).reduce(BigDecimal.ZERO,BigDecimal::add);
         }
         return BigDecimal.ZERO;
     }
 
-    @Override
-    public BigDecimal getCurrentAmount(MusicGroupPaymentCalenderActivity baseCalender) {
-        return baseCalender.getActualAmount();
+    private BigDecimal getActivityOriginalAmount(VipGroupActivity activity){
+        return activity.getOriginalPrice();
     }
+    private BigDecimal getActivityActualAmount(VipGroupActivity activity){
+        return activity.getMarketPrice();
+    }
+
 
     @Override
     public <T> T initBean(T bean) {

+ 2 - 2
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderCourseSettingsServiceImpl.java

@@ -191,8 +191,8 @@ public class MusicGroupPaymentCalenderCourseSettingsServiceImpl extends BaseServ
     }
 
 	@Override
-	public BigDecimal getCurrentAmount(MusicGroupPaymentCalenderCourseSettings baseCalender) {
-		return null;
+	public BigDecimal getCurrentAmount(MusicGroupPaymentBaseCalender baseCalender) {
+		return this.getOriginalAmount(baseCalender);
 	}
 
 	@Override

+ 14 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderDetailServiceImpl.java

@@ -153,8 +153,8 @@ public class MusicGroupPaymentCalenderDetailServiceImpl extends BaseServiceImpl<
 				throw new BizException("修改失败:缴费状态不匹配");
 			}
 			e.setUpdateTime(date);
-			e.setExpectAmount(expectAmount);
-			e.setExpectMemberAmount(expectMemberAmount);
+//			e.setExpectAmount(expectAmount);
+//			e.setExpectMemberAmount(expectMemberAmount);
 
 			if(expectAmount.doubleValue() > 0 || expectMemberAmount.doubleValue() > 0){
 				if((e.getOpen() != null && e.getOpen() == 1) || calender.getStatus() == PaymentCalenderStatusEnum.OPEN){
@@ -334,10 +334,10 @@ public class MusicGroupPaymentCalenderDetailServiceImpl extends BaseServiceImpl<
 			musicGroupPaymentCalenderDetail = new MusicGroupPaymentCalenderDetail();
 			musicGroupPaymentCalenderDetail.setMusicGroupPaymentCalenderId(musicGroupPaymentCalenderId);
 			musicGroupPaymentCalenderDetail.setCreateTime(date);
-			musicGroupPaymentCalenderDetail.setExpectAmount(expectAmount);
-			musicGroupPaymentCalenderDetail.setExpectMemberAmount(expectMemberAmount);
+//			musicGroupPaymentCalenderDetail.setExpectAmount(expectAmount);
+//			musicGroupPaymentCalenderDetail.setExpectMemberAmount(expectMemberAmount);
 			if (expectAmount.doubleValue() == 0d && expectMemberAmount.doubleValue() == 0d) {
-				musicGroupPaymentCalenderDetail.setActualAmount(BigDecimal.ZERO);
+//				musicGroupPaymentCalenderDetail.setActualAmount(BigDecimal.ZERO);
 				musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
 			} else {
 				musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.NON_PAYMENT);
@@ -413,11 +413,11 @@ public class MusicGroupPaymentCalenderDetailServiceImpl extends BaseServiceImpl<
 			musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.NON_PAYMENT);
 			List<MusicGroupPaymentCalenderStudentDetail> calenderStudentDetails = collect.get(studentId);
 			BigDecimal totalPrice = calenderStudentDetails.stream().map(e->e.getCourseCurrentPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
-			musicGroupPaymentCalenderDetail.setExpectAmount(totalPrice);
+//			musicGroupPaymentCalenderDetail.setExpectAmount(totalPrice);
 			if(musicGroupPaymentCalender.getStatus() != AUDITING){
 				if (totalPrice.doubleValue() == 0d) {
 					musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
-					musicGroupPaymentCalenderDetail.setActualAmount(totalPrice);
+//					musicGroupPaymentCalenderDetail.setActualAmount(totalPrice);
 				}
 			}
 			musicGroupPaymentCalenderDetail.setMusicGroupId(musicGroupPaymentCalender.getMusicGroupId());
@@ -770,7 +770,7 @@ public class MusicGroupPaymentCalenderDetailServiceImpl extends BaseServiceImpl<
 			musicGroupPaymentCalenderDetail.setUserId(studentPaymentOrder.getUserId());
 			musicGroupPaymentCalenderDetail.setResponsibleUserId(musicGroupPaymentCalender.getOperator());
 
-			if (currentPaymentCalenderId.longValue() == musicGroupPaymentCalender.getId()) {
+/*			if (currentPaymentCalenderId.longValue() == musicGroupPaymentCalender.getId()) {
 				musicGroupPaymentCalenderDetail.setExpectAmount(courseTotalPrice);
 				if (studentPaymentOrder.getCourseRemitFee() != null && (studentPaymentOrder.getCourseRemitFee().compareTo(BigDecimal.ZERO) > 0)) {
 					musicGroupPaymentCalenderDetail.setActualAmount(optionalCourseFee);
@@ -789,8 +789,13 @@ public class MusicGroupPaymentCalenderDetailServiceImpl extends BaseServiceImpl<
 			if(orderDetailTypes.contains(OrderDetailTypeEnum.CLOUD_TEACHER.name()) || orderDetailTypes.contains(OrderDetailTypeEnum.CLOUD_TEACHER_PLUS.name())){
 				musicGroupPaymentCalenderDetail.setExpectAmount(musicGroupPaymentCalenderDetail.getExpectAmount().add(musicGroupPaymentCalender.getMemberPaymentAmount()));
 				musicGroupPaymentCalenderDetail.setActualAmount(musicGroupPaymentCalenderDetail.getActualAmount().add(musicGroupPaymentCalender.getMemberPaymentAmount()));
-			}
+			}*/
 
+			musicGroupPaymentCalenderDetail.setPaymentStatus(PAID_COMPLETED);
+			musicGroupPaymentCalenderDetail.setPayTime(nowDate);
+			musicGroupPaymentCalenderDetail.setPaymentOrderId(studentPaymentOrder.getId());
+			musicGroupPaymentCalenderDetail.setUseInCourse(0);
+			musicGroupPaymentCalenderDetail.setOpen(1);
 			musicGroupPaymentCalenderDetail.setUserStatus(null);
 			musicGroupPaymentCalenderDetail.setDeadlinePaymentDate(musicGroupPaymentCalender.getDeadlinePaymentDate());
 			musicGroupPaymentCalenderDetail.setStartPaymentDate(musicGroupPaymentCalender.getStartPaymentDate());

+ 36 - 15
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderMemberServiceImpl.java

@@ -17,6 +17,7 @@ import org.springframework.stereotype.Service;
 
 import java.math.BigDecimal;
 import java.util.List;
+import java.util.function.BiFunction;
 
 import static com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender.PaymentCalenderStatusEnum.AUDITING;
 import static com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender.PaymentCalenderStatusEnum.NO;
@@ -72,24 +73,12 @@ public class MusicGroupPaymentCalenderMemberServiceImpl extends BaseServiceImpl<
 
     @Override
     public BigDecimal getOriginalAmount(MusicGroupPaymentBaseCalender baseCalender) {
-        MusicGroupPaymentCalenderMember calenderMember = baseCalender.getCalenderMember();
-        if(calenderMember != null){
-            MusicGroup musicGroup = baseCalender.getMusicGroup();
-            //会员价格是否变动
-            MemberFeeSetting memberFee = memberFeeSettingDao.findByRankIdAndOrganId(musicGroup.getOrganId(), calenderMember.getMemberRankSettingId());
-            if(memberFee == null){
-                throw new BizException("操作失败:请配置当前分部会员收费标准");
-            }
-            //获取会员总价
-            return getGroupPurchaseFee(calenderMember.getPeriod(),memberFee).
-                    multiply(calenderMember.getNum()).setScale(0, BigDecimal.ROUND_HALF_UP);
-        }
-        return BigDecimal.ZERO;
+        return getAmount(baseCalender, this::getOriginalFee);
     }
 
     @Override
-    public BigDecimal getCurrentAmount(MusicGroupPaymentCalenderMember baseCalender) {
-        return null;
+    public BigDecimal getCurrentAmount(MusicGroupPaymentBaseCalender calenderMember) {
+        return getAmount(calenderMember, this::getGroupPurchaseFee);
     }
 
     @Override
@@ -108,6 +97,23 @@ public class MusicGroupPaymentCalenderMemberServiceImpl extends BaseServiceImpl<
     private BigDecimal getGroupPurchaseFee(PeriodEnum periodEnum,MemberFeeSetting memberFee){
         switch (periodEnum){
             case DAY :
+                return memberFee.getGroupPurchaseDayFee();
+            case MONTH :
+                return memberFee.getGroupPurchaseMonthFee();
+            case QUARTERLY :
+                return memberFee.getGroupPurchaseQuarterlyFee();
+            case YEAR_HALF :
+                return memberFee.getGroupPurchaseHalfYearFee();
+            case YEAR :
+                return memberFee.getGroupPurchaseYearFee();
+            default:
+                throw new BizException("请选择正确的会员有效期");
+        }
+    }
+
+    private BigDecimal getOriginalFee(PeriodEnum periodEnum,MemberFeeSetting memberFee){
+        switch (periodEnum){
+            case DAY :
                 return memberFee.getOriginalDayFee();
             case MONTH :
                 return memberFee.getOriginalMonthFee();
@@ -122,6 +128,21 @@ public class MusicGroupPaymentCalenderMemberServiceImpl extends BaseServiceImpl<
         }
     }
 
+    private BigDecimal getAmount(MusicGroupPaymentBaseCalender baseCalender, BiFunction<PeriodEnum,MemberFeeSetting,BigDecimal> func){
+        MusicGroupPaymentCalenderMember calenderMember = baseCalender.getCalenderMember();
+        if(calenderMember != null){
+            MusicGroup musicGroup = baseCalender.getMusicGroup();
+            //会员价格是否变动
+            MemberFeeSetting memberFee = memberFeeSettingDao.findByRankIdAndOrganId(musicGroup.getOrganId(), calenderMember.getMemberRankSettingId());
+            if(memberFee == null){
+                throw new BizException("操作失败:请配置当前分部会员收费标准");
+            }
+            //获取会员总价
+            return func.apply(calenderMember.getPeriod(),memberFee).multiply(calenderMember.getNum()).setScale(0, BigDecimal.ROUND_HALF_UP);
+        }
+        return BigDecimal.ZERO;
+    }
+
     @Override
     public void deleteByCalenderId(Long calenderId) {
         musicGroupPaymentCalenderMemberDao.deleteByCalenderId(calenderId);

+ 17 - 13
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderRepairServiceImpl.java

@@ -72,22 +72,12 @@ public class MusicGroupPaymentCalenderRepairServiceImpl extends BaseServiceImpl<
 
     @Override
     public BigDecimal getOriginalAmount(MusicGroupPaymentBaseCalender baseCalender) {
-        MusicGroupPaymentCalenderRepair musicRepair = baseCalender.getMusicRepair();
-        if(musicRepair != null){
-            Integer tenantId = TenantContextHolder.getTenantId();
-            String configValue = sysTenantConfigService.getTenantConfigValue(SysConfigService.ONE_YEAR_MUSICAL_REPAIR_ORIGINAL_AMOUNT, tenantId);
-            if(StringUtils.isEmpty(configValue)){
-                throw new BizException("操作失败:请配置乐保单价");
-            }
-            //获取会员总价
-            return new BigDecimal(configValue).multiply(musicRepair.getNum()).setScale(0, BigDecimal.ROUND_HALF_UP);
-        }
-        return BigDecimal.ZERO;
+        return getAmount(baseCalender,SysConfigService.ONE_YEAR_MUSICAL_REPAIR_ORIGINAL_AMOUNT);
     }
 
     @Override
-    public BigDecimal getCurrentAmount(MusicGroupPaymentCalenderRepair baseCalender) {
-        return null;
+    public BigDecimal getCurrentAmount(MusicGroupPaymentBaseCalender baseCalender) {
+        return getAmount(baseCalender,SysConfigService.ONE_YEAR_MUSICAL_REPAIR_AMOUNT);
     }
 
     @Override
@@ -104,4 +94,18 @@ public class MusicGroupPaymentCalenderRepairServiceImpl extends BaseServiceImpl<
     public MusicGroupPaymentCalenderRepair findByCalenderId(Long calenderId) {
         return musicGroupPaymentCalenderRepairDao.findByCalenderId(calenderId);
     }
+
+    private BigDecimal getAmount(MusicGroupPaymentBaseCalender baseCalender,String configName){
+        MusicGroupPaymentCalenderRepair musicRepair = baseCalender.getMusicRepair();
+        if(musicRepair != null){
+            Integer tenantId = TenantContextHolder.getTenantId();
+            String configValue = sysTenantConfigService.getTenantConfigValue(configName, tenantId);
+            if(StringUtils.isEmpty(configValue)){
+                throw new BizException("操作失败:请配置乐保单价");
+            }
+            //获取会员总价
+            return new BigDecimal(configValue).multiply(musicRepair.getNum()).setScale(0, BigDecimal.ROUND_HALF_UP);
+        }
+        return BigDecimal.ZERO;
+    }
 }

+ 20 - 11
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupPaymentCalenderServiceImpl.java

@@ -567,21 +567,30 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		//检测缴费项目是否有费用变更
 //		Map<CalenderBaseServiceEnum, MusicGroupPaymentCalenderBaseService> calenderBaseServiceMap = MusicGroupPaymentCalenderBaseService.calenderBaseServiceMap;
 
-		//计算缴费项目总金额
+		//计算缴费项目总金额(前端录入)
 		BigDecimal courseActualAmount = musicGroupPaymentCalenderCourseSettingsService.getActualAmount(musicGroupPaymentBaseCalender);
 		BigDecimal memberActualAmount = musicGroupPaymentCalenderMemberService.getActualAmount(musicGroupPaymentBaseCalender);
 		BigDecimal repairActualAmount = musicGroupPaymentCalenderRepairService.getActualAmount(musicGroupPaymentBaseCalender);
 		BigDecimal activityActualAmount = musicGroupPaymentCalenderActivityService.getActualAmount(musicGroupPaymentBaseCalender);
 
-		BigDecimal currentTotalAmount = courseActualAmount.add(memberActualAmount)
+		BigDecimal actualTotalAmount = courseActualAmount.add(memberActualAmount)
 				.add(repairActualAmount)
 				.add(activityActualAmount).setScale(0, BigDecimal.ROUND_HALF_UP);
+		//计算项目原现价
+		BigDecimal courseCurrentAmount = musicGroupPaymentCalenderCourseSettingsService.getCurrentAmount(musicGroupPaymentBaseCalender);
+		BigDecimal memberCurrentAmount = musicGroupPaymentCalenderMemberService.getCurrentAmount(musicGroupPaymentBaseCalender);
+		BigDecimal repairCurrentAmount = musicGroupPaymentCalenderRepairService.getCurrentAmount(musicGroupPaymentBaseCalender);
+		BigDecimal activityCurrentAmount = musicGroupPaymentCalenderActivityService.getCurrentAmount(musicGroupPaymentBaseCalender);
+
+		BigDecimal currentTotalAmount = courseCurrentAmount.add(memberCurrentAmount)
+				.add(repairCurrentAmount)
+				.add(activityCurrentAmount).setScale(0, BigDecimal.ROUND_HALF_UP);
 
 		//计算缴费项目原价
 		BigDecimal courseOriginalAmount = musicGroupPaymentCalenderCourseSettingsService.getOriginalAmount(musicGroupPaymentBaseCalender);
 		BigDecimal memberOriginalAmount = musicGroupPaymentCalenderMemberService.getOriginalAmount(musicGroupPaymentBaseCalender);
-		BigDecimal activityOriginalAmount = musicGroupPaymentCalenderRepairService.getOriginalAmount(musicGroupPaymentBaseCalender);
-		BigDecimal repairOriginalAmount = musicGroupPaymentCalenderActivityService.getOriginalAmount(musicGroupPaymentBaseCalender);
+		BigDecimal repairOriginalAmount = musicGroupPaymentCalenderRepairService.getOriginalAmount(musicGroupPaymentBaseCalender);
+		BigDecimal activityOriginalAmount = musicGroupPaymentCalenderActivityService.getOriginalAmount(musicGroupPaymentBaseCalender);
 
 		BigDecimal originalTotalAmount = courseOriginalAmount.add(memberOriginalAmount)
 				.add(activityOriginalAmount)
@@ -591,7 +600,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		if (musicGroupPaymentBaseCalender.getPayUserType() == SCHOOL) {
 			status = AUDITING;
 		} else {
-			status = currentTotalAmount.compareTo(originalTotalAmount) == 0 ? NO:AUDITING;
+			status = actualTotalAmount.compareTo(currentTotalAmount) == 0 ? NO:AUDITING;
 		}
 
 		Date date = new Date();
@@ -607,8 +616,8 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 		musicGroupPaymentCalender.setCreateTime(date);
 		musicGroupPaymentCalender.setUpdateTime(date);
 		musicGroupPaymentCalender.setPaymentType(musicGroupPaymentBaseCalender.getPaymentType());
-		musicGroupPaymentCalender.setPaymentAmount(courseActualAmount);
-		musicGroupPaymentCalender.setCurrentTotalAmount(currentTotalAmount);
+//		musicGroupPaymentCalender.setPaymentAmount(courseActualAmount);
+		musicGroupPaymentCalender.setCurrentTotalAmount(courseActualAmount);
 		musicGroupPaymentCalender.setOriginalTotalAmount(originalTotalAmount);
 		musicGroupPaymentCalender.setStatus(status);
 		musicGroupPaymentCalender.setOrganId(musicGroup.getOrganId());
@@ -692,7 +701,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 
 	@Override
 	public Map<String, Object> getDetail(Long id) {
-		Map<String, Object> result = new HashMap<>(9);
+		Map<String, Object> result = new HashMap<>(10);
 		//获取缴费项目详情
 		MusicGroupPaymentCalender calender = musicGroupPaymentCalenderDao.get(id);
 		//统计预计缴费人数
@@ -1175,8 +1184,8 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 				MusicGroupPaymentCalenderDetail musicGroupPaymentCalenderDetail = new MusicGroupPaymentCalenderDetail();
 				musicGroupPaymentCalenderDetail.setMusicGroupPaymentCalenderId(musicGroupPaymentCalender.getId());
 				musicGroupPaymentCalenderDetail.setCreateTime(date);
-				musicGroupPaymentCalenderDetail.setExpectAmount(expectAmount);
-				musicGroupPaymentCalenderDetail.setExpectMemberAmount(expectMemberAmount);
+//				musicGroupPaymentCalenderDetail.setExpectAmount(expectAmount);
+//				musicGroupPaymentCalenderDetail.setExpectMemberAmount(expectMemberAmount);
 				musicGroupPaymentCalenderDetail.setPaymentStatus(PaymentStatus.NON_PAYMENT);
 				musicGroupPaymentCalenderDetail.setUpdateTime(date);
 				musicGroupPaymentCalenderDetail.setUserId(Integer.parseInt(studentId));
@@ -1856,7 +1865,7 @@ public class MusicGroupPaymentCalenderServiceImpl extends BaseServiceImpl<Long,
 //		}
 		//更新学生的缴费记录状态
 		calenderDetail.setPaymentStatus(MusicGroupStudentFee.PaymentStatus.PAID_COMPLETED);
-		calenderDetail.setActualAmount(calenderDetail.getExpectAmount().add(calenderDetail.getExpectMemberAmount()));
+//		calenderDetail.setActualAmount(calenderDetail.getExpectAmount().add(calenderDetail.getExpectMemberAmount()));
 		calenderDetail.setPayTime(date);
 		calenderDetail.setUpdateTime(date);
 		musicGroupPaymentCalenderDetailDao.update(calenderDetail);

+ 4 - 81
mec-biz/src/main/java/com/ym/mec/biz/service/impl/MusicGroupServiceImpl.java

@@ -133,8 +133,6 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     @Autowired
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
     @Autowired
-    private SellOrderService sellOrderService;
-    @Autowired
     private PayService payService;
     @Autowired
     private SysUserFeignService sysUserFeignService;
@@ -151,8 +149,6 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     @Autowired
     private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
     @Autowired
-    private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
-    @Autowired
     private StudentRegistrationService studentRegistrationService;
     @Autowired
     private SporadicChargeInfoDao sporadicChargeInfoDao;
@@ -163,8 +159,6 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     @Autowired
     private ClassGroupStudentMapperService classGroupStudentMapperService;
     @Autowired
-    private MusicGroupPaymentCalenderDetailService musicGroupPaymentCalenderDetailService;
-    @Autowired
     private MusicGroupPaymentCalenderDetailDao musicGroupPaymentCalenderDetailDao;
     @Autowired
     private ImGroupMemberService imGroupMemberService;
@@ -190,37 +184,20 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
     private SysUserCashAccountDao sysUserCashAccountDao;
     @Autowired
     private ContractService contractService;
-
     @Autowired
     private StudentPreRegistrationDao studentPreRegistrationDao;
     @Autowired
-    private ActivityUserMapperService activityUserMapperService;
-
-    @Autowired
     private GroupEventSource groupEventSource;
-
     @Autowired
     private StudentInstrumentDao studentInstrumentDao;
-
     @Autowired
     private SysUserCashAccountLogDao sysUserCashAccountLogDao;
-
-    @Autowired
-    private CloudTeacherOrderService cloudTeacherOrderService;
-
     @Autowired
     private MusicGroupSchoolTermCourseDetailDao musicGroupSchoolTermCourseDetailDao;
-
     @Autowired
     private MusicGroupSchoolTermStudentCourseDetailDao musicGroupSchoolTermStudentCourseDetailDao;
-    
-    @Autowired
-    private StudentService studentService;
-
     @Autowired
     private SysCouponCodeService sysCouponCodeService;
-    @Autowired
-    private StudentInstrumentService studentInstrumentService;
 
     private SimpleDateFormat sdf_ymd = new SimpleDateFormat("yyyy-MM-dd");
 
@@ -694,6 +671,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         studentPaymentOrder.setCreateTime(date);
         studentPaymentOrder.setUpdateTime(date);
         studentPaymentOrder.setVersion(0);
+        studentPaymentOrder.setCalenderId(calenderId);
         studentPaymentOrderService.insert(studentPaymentOrder);
         // 订单详情
         studentPaymentOrder = studentRegistrationService.addOrder(studentRegistration,studentPaymentOrder,goodsDto,renewParamDto);
@@ -3052,6 +3030,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
     }
 
+
     @Override
     @Transactional(propagation = Propagation.REQUIRED, rollbackFor = Exception.class)
     public boolean renewForCallback(StudentPaymentOrder studentPaymentOrder) throws IOException {
@@ -3088,62 +3067,8 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
                 groupEventSource.musicGroupStudentChangeEvent(studentRegistration.getMusicGroupId(), StudentMusicGroupStatusEnum.NORMAL, new ArrayList<>(Arrays.asList(userId)));
             }
 
-            //缴费项目详情
-            musicGroupPaymentCalenderDetailService.addCalenderDetail(studentPaymentOrder, studentRegistration);
-
-            List<StudentPaymentOrderDetail> allDetails = studentPaymentOrderDetailService.getOrderGoodsDetail(studentPaymentOrder.getId());
-            BigDecimal courseFee = allDetails.stream().filter(o -> !(o.getType() == MUSICAL)
-                    && !(o.getType() == VIP)
-                    && !(o.getType() == PRACTICE)
-                    && !(o.getType() == MAINTENANCE)
-                    && !(o.getType() == CLOUD_TEACHER)
-                    && !(o.getType() == CLOUD_TEACHER)
-                    && !(o.getType() == ACCESSORIES))
-                    .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
-                    .reduce(BigDecimal.ZERO, BigDecimal::add);
-
-            //销售订单详情
-            if (allDetails.size() > 0) {
-                BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
-                if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
-                    BigDecimal musicFee = allDetails.stream().filter(o -> o.getType()==MUSICAL
-                            || o.getType()==ACCESSORIES || o.getType()==TEACHING)
-                            .map(o -> o.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
-                    BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
-                    //获取比例
-                    BigDecimal ratioAmount = musicFee.divide(expectAmount, 6, BigDecimal.ROUND_HALF_UP);
-                    //获取分配的减免金额
-                    couponRemitFee = couponRemitFee.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
-                }
-                sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup,couponRemitFee);
-            }
-
-            //活动小课包处理
-            List<StudentPaymentOrderDetail> activity = allDetails.stream().filter(o -> o.getType()==PRACTICE || o.getType() == VIP).collect(Collectors.toList());
-            if(activity != null && activity.size() > 0){
-                activityUserMapperService.addOrderDetail2Activity(studentPaymentOrder,activity);
-            }
-
-            //学生乐器与月保处理
-            StudentPaymentOrderDetail repair = allDetails.stream().filter(o -> o.getType()==MAINTENANCE).findFirst().get();
-            if(repair != null){
-                BigDecimal repairFee = allDetails.stream() .filter(o -> o.getType()==MAINTENANCE)
-                        .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
-                        .reduce(BigDecimal.ZERO, BigDecimal::add);
-                StudentPaymentOrderDetail musical = allDetails.stream().filter(o -> o.getType()==MUSICAL).findFirst().get();
-                Long studentInstrumentId = studentInstrumentService.addOrderDetail2Instrument(studentPaymentOrder, repairFee, Integer.valueOf(musical.getGoodsIdList()));
-                repair.setStudentInstrumentId(studentInstrumentId);
-                studentPaymentOrderDetailDao.update(repair);
-            }
-
-            //学生云教练处理
-            StudentPaymentOrderDetail cloudTeacher = allDetails.stream().filter(o -> o.getType()==CLOUD_TEACHER).findFirst().get();
-            if(cloudTeacher != null){
-                BigDecimal cloudTeacherFee = allDetails.stream() .filter(o -> o.getType()==CLOUD_TEACHER)
-                        .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
-                        .reduce(BigDecimal.ZERO, BigDecimal::add);
-                cloudTeacherOrderService.addOrderDetail2CloudTeacher(studentPaymentOrder,cloudTeacherFee);
-            }
+            //支付成功后处理课程、云教练、活动等数据
+            studentPaymentOrderDetailService.addOrderDetailTo(studentPaymentOrder,musicGroup,studentRegistration);
 
             //插入交易明细
             SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
@@ -3177,8 +3102,6 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
             paymentDetail.setChannel(studentPaymentOrder.getPaymentChannel());
             sysUserCashAccountDetailService.insert(paymentDetail);
 
-            studentRegistrationService.updateUserSurplusCourseFee(userId, musicGroupId, courseFee, "乐团续费", userId);
-
             try {
                 contractService.transferProduceContract(userId, musicGroupId, null);
             } catch (Exception e) {

+ 108 - 35
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderDetailServiceImpl.java

@@ -1,44 +1,28 @@
 package com.ym.mec.biz.service.impl;
 
-import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
-
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import com.ym.mec.biz.dal.entity.*;
-import org.apache.commons.lang3.StringUtils;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.stereotype.Service;
-
-import com.ym.mec.biz.dal.dao.MusicGroupDao;
-import com.ym.mec.biz.dal.dao.MusicGroupPaymentCalenderCourseSettingsDao;
-import com.ym.mec.biz.dal.dao.MusicGroupPurchaseListDao;
-import com.ym.mec.biz.dal.dao.OrganizationDao;
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDao;
-import com.ym.mec.biz.dal.dao.StudentPaymentOrderDetailDao;
-import com.ym.mec.biz.dal.dao.StudentRegistrationDao;
-import com.ym.mec.biz.dal.dao.SubjectChangeDao;
-import com.ym.mec.biz.dal.dao.SubjectDao;
-import com.ym.mec.biz.dal.dao.TeacherDao;
+import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.MusicalListDetailDto;
+import com.ym.mec.biz.dal.entity.*;
 import com.ym.mec.biz.dal.enums.DealStatusEnum;
 import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
 import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
 import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
-import com.ym.mec.biz.service.GoodsService;
-import com.ym.mec.biz.service.MusicGroupPaymentCalenderService;
-import com.ym.mec.biz.service.StudentPaymentOrderDetailService;
-import com.ym.mec.biz.service.StudentPaymentOrderService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
 import com.ym.mec.util.collection.MapUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.stereotype.Service;
+
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.ym.mec.biz.dal.enums.DealStatusEnum.SUCCESS;
+import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.*;
+import static com.ym.mec.biz.dal.enums.PaymentStatusEnum.YES;
 
 @Service
 public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrderDetail> implements StudentPaymentOrderDetailService {
@@ -56,20 +40,25 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
     @Autowired
     private MusicGroupPurchaseListDao musicGroupPurchaseListDao;
     @Autowired
-    private StudentPaymentOrderDao studentPaymentOrderDao;
-    @Autowired
     private StudentRegistrationDao studentRegistrationDao;
     @Autowired
     private SubjectDao subjectDao;
     @Autowired
     private SubjectChangeDao subjectChangeDao;
     @Autowired
-    private MusicGroupPaymentCalenderService musicGroupPaymentCalenderService;
+    private StudentCourseFeeDetailDao studentCourseFeeDetailDao;
     @Autowired
-    private MusicGroupPaymentCalenderCourseSettingsDao musicGroupPaymentCalenderCourseSettingsDao;
-
+    private SellOrderService sellOrderService;
+    @Autowired
+    private ActivityUserMapperService activityUserMapperService;
+    @Autowired
+    private StudentInstrumentService studentInstrumentService;
+    @Autowired
+    private CloudTeacherOrderService cloudTeacherOrderService;
     @Autowired
     private StudentPaymentOrderService studentPaymentOrderService;
+    @Autowired
+    private MusicGroupPaymentCalenderDetailService musicGroupPaymentCalenderDetailService;
 
     @Override
     public BaseDAO<Long, StudentPaymentOrderDetail> getDAO() {
@@ -534,4 +523,88 @@ public class StudentPaymentOrderDetailServiceImpl extends BaseServiceImpl<Long,
     public List<StudentPaymentOrderDetail> queryOrderDetail(Long orderId) {
         return studentPaymentOrderDetailDao.findApplyOrderGoods(orderId);
     }
+
+    public void addOrderDetailTo(StudentPaymentOrder studentPaymentOrder,MusicGroup musicGroup,StudentRegistration studentRegistration){
+        //SurplusCourseFee
+        List<StudentPaymentOrderDetail> allDetails = getOrderGoodsDetail(studentPaymentOrder.getId());
+        BigDecimal courseFee = allDetails.stream().filter(o -> !(o.getType() == MUSICAL)
+                && !(o.getType() == VIP)
+                && !(o.getType() == PRACTICE)
+                && !(o.getType() == MAINTENANCE)
+                && !(o.getType() == CLOUD_TEACHER)
+                && !(o.getType() == CLOUD_TEACHER)
+                && !(o.getType() == ACCESSORIES))
+                .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
+                .reduce(BigDecimal.ZERO, BigDecimal::add);
+        if (studentRegistration.getTemporaryCourseFee() != null) {
+            studentRegistration.setTemporaryCourseFee(new BigDecimal(0));
+        }
+        studentRegistration.setPaymentStatus(YES);
+        studentRegistration.setMusicGroupStatus(StudentMusicGroupStatusEnum.NORMAL);
+        if (studentPaymentOrder.getClassGroupId() == null || !studentPaymentOrder.getClassGroupId().equals(206)) {
+            studentRegistration.setPayingStatus(0);
+        }
+        if(courseFee.compareTo(BigDecimal.ZERO) > 0){
+            //累加充值金额
+            studentRegistration.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(courseFee));
+            //添加日志
+            StudentCourseFeeDetail studentCourseFeeDetail = new StudentCourseFeeDetail();
+            studentCourseFeeDetail.setTenantId(studentPaymentOrder.getTenantId());
+            studentCourseFeeDetail.setStudentRegistrationId(studentRegistration.getId());
+            studentCourseFeeDetail.setAmount(courseFee);
+            studentCourseFeeDetail.setSurplusCourseFee(studentRegistration.getSurplusCourseFee());
+            studentCourseFeeDetail.setMemo("乐团缴费充值");
+            studentCourseFeeDetail.setOperator(studentPaymentOrder.getUserId());
+            studentCourseFeeDetailDao.insert(studentCourseFeeDetail);
+        }
+        studentRegistrationDao.update(studentRegistration);
+
+
+        //缴费项目详情
+        musicGroupPaymentCalenderDetailService.addCalenderDetail(studentPaymentOrder, studentRegistration);
+
+        List<OrderDetailTypeEnum> detailTypeEnums = allDetails.stream().map(e -> e.getType()).collect(Collectors.toList());
+        //销售订单详情
+        if (allDetails.size() > 0 && (detailTypeEnums.contains(MUSICAL) ||detailTypeEnums.contains(ACCESSORIES) ||detailTypeEnums.contains(TEACHING))) {
+            BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
+            if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
+                BigDecimal musicFee = allDetails.stream().filter(o -> o.getType()==MUSICAL
+                        || o.getType()==ACCESSORIES || o.getType()==TEACHING)
+                        .map(o -> o.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
+                BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
+                //获取比例
+                BigDecimal ratioAmount = musicFee.divide(expectAmount, 6, BigDecimal.ROUND_HALF_UP);
+                //获取分配的减免金额
+                couponRemitFee = couponRemitFee.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
+            }
+            sellOrderService.addOrderDetail2SellOrder(allDetails, studentPaymentOrder, musicGroup,couponRemitFee);
+        }
+
+        //活动小课包处理
+        List<StudentPaymentOrderDetail> activity = allDetails.stream().filter(o -> o.getType()==PRACTICE || o.getType() == VIP).collect(Collectors.toList());
+        if(activity != null && activity.size() > 0){
+            activityUserMapperService.addOrderDetail2Activity(studentPaymentOrder,activity);
+        }
+
+        //学生乐器与月保处理
+        if(detailTypeEnums.contains(MAINTENANCE)){
+            StudentPaymentOrderDetail repair = allDetails.stream().filter(o -> o.getType()==MAINTENANCE).findFirst().get();
+            BigDecimal repairFee = allDetails.stream() .filter(o -> o.getType()==MAINTENANCE)
+                    .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            StudentPaymentOrderDetail musical = allDetails.stream().filter(o -> o.getType()==MUSICAL).findFirst().get();
+            Long studentInstrumentId = studentInstrumentService.addOrderDetail2Instrument(studentPaymentOrder, repairFee, Integer.valueOf(musical.getGoodsIdList()));
+            repair.setStudentInstrumentId(studentInstrumentId);
+            studentPaymentOrderDetailDao.update(repair);
+        }
+
+        //学生云教练处理
+        if(detailTypeEnums.contains(CLOUD_TEACHER)){
+            StudentPaymentOrderDetail cloudTeacher = allDetails.stream().filter(o -> o.getType()==CLOUD_TEACHER).findFirst().get();
+            BigDecimal cloudTeacherFee = allDetails.stream() .filter(o -> o.getType()==CLOUD_TEACHER)
+                    .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
+                    .reduce(BigDecimal.ZERO, BigDecimal::add);
+            cloudTeacherOrderService.addOrderDetail2CloudTeacher(studentPaymentOrder,cloudTeacherFee);
+        }
+    }
 }

+ 19 - 34
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentOrderServiceImpl.java

@@ -1,43 +1,19 @@
 package com.ym.mec.biz.service.impl;
 
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.stream.Collectors;
-
-import com.ym.mec.biz.dal.dao.*;
-import com.ym.mec.biz.dal.entity.*;
-import com.ym.mec.biz.dal.enums.*;
-import com.ym.mec.biz.service.*;
-
-import com.ym.mec.common.controller.BaseController;
-import com.ym.mec.common.entity.HttpResponseResult;
-import com.ym.mec.common.tenant.TenantContextHolder;
-import com.ym.mec.util.excel.POIUtil;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.context.annotation.Lazy;
-import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-
 import com.alibaba.fastjson.JSON;
+import com.ym.mec.biz.dal.dao.*;
 import com.ym.mec.biz.dal.dto.PageInfoOrder;
 import com.ym.mec.biz.dal.dto.SporadicChargeInfoDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderDto;
 import com.ym.mec.biz.dal.dto.StudentPaymentOrderExportDto;
+import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.enums.*;
 import com.ym.mec.biz.dal.page.SporadicOrderQueryInfo;
 import com.ym.mec.biz.dal.page.StudentPaymentOrderQueryInfo;
+import com.ym.mec.biz.service.*;
+import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.dal.BaseDAO;
+import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.IdGeneratorService;
@@ -50,6 +26,19 @@ import com.ym.mec.thirdparty.yqpay.YqPayFeignService;
 import com.ym.mec.thirdparty.yqpay.YqPayUtil;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.context.annotation.Lazy;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
 
 @Service
 public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, StudentPaymentOrder> implements StudentPaymentOrderService {
@@ -81,10 +70,8 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     private DegreeRegistrationService degreeRegistrationService;
     @Autowired
     private StudentPaymentRouteOrderDao studentPaymentRouteOrderDao;
-
     @Autowired
     private StudentPaymentOrderDetailService studentPaymentOrderDetailService;
-
     @Autowired
     private IdGeneratorService idGeneratorService;
     @Autowired
@@ -97,14 +84,12 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
     private ReplacementInstrumentActivityService replacementInstrumentActivityService;
     @Autowired
     private ChildrenDayReserveService childrenDayReserveService;
-
     @Autowired
     private MemberRankSettingService memberRankSettingService;
     @Autowired
     private PayService payService;
     @Autowired
     private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
-
     @Autowired
     private CloudTeacherOrderService cloudTeacherOrderService;
     @Autowired

+ 1 - 1
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentPaymentRouteOrderServiceImpl.java

@@ -315,7 +315,7 @@ public class StudentPaymentRouteOrderServiceImpl extends BaseServiceImpl<Long, S
                 musicGroupPaymentCalenderDao.update(musicGroupPaymentCalender);
 
                 for (MusicGroupPaymentCalenderDetail calenderDetail : calenderDetails) {
-                    calenderDetail.setActualAmount(calenderDetail.getExpectAmount().add(calenderDetail.getExpectMemberAmount()));
+//                    calenderDetail.setActualAmount(calenderDetail.getExpectAmount().add(calenderDetail.getExpectMemberAmount()));
                     calenderDetail.setPaymentStatus(MusicGroupStudentFee.PaymentStatus.PAID_COMPLETED);
                     calenderDetail.setPayTime(nowDate);
                     calenderDetail.setUpdateTime(nowDate);

+ 30 - 149
mec-biz/src/main/java/com/ym/mec/biz/service/impl/StudentRegistrationServiceImpl.java

@@ -1,64 +1,16 @@
 package com.ym.mec.biz.service.impl;
 
-import static com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus.NON_PAYMENT;
-import static com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus.PAID_COMPLETED;
-import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.*;
-import static com.ym.mec.biz.dal.enums.PaymentStatusEnum.YES;
-
-import java.io.IOException;
-import java.math.BigDecimal;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-import java.util.Objects;
-import java.util.Set;
-import java.util.stream.Collectors;
-
-import javax.annotation.Resource;
-
-import com.ym.mec.biz.dal.dao.*;
-import com.ym.mec.biz.dal.dto.*;
-import com.ym.mec.biz.dal.entity.*;
-import com.ym.mec.biz.dal.page.*;
-import com.ym.mec.biz.service.*;
-import com.ym.mec.common.constant.CommonConstants;
-import com.ym.mec.common.tenant.TenantContextHolder;
-import org.apache.commons.lang3.StringUtils;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.beans.factory.annotation.Autowired;
-import org.springframework.http.HttpStatus;
-import org.springframework.stereotype.Service;
-import org.springframework.transaction.annotation.Isolation;
-import org.springframework.transaction.annotation.Propagation;
-import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
-
 import com.alibaba.fastjson.JSONObject;
 import com.ym.mec.auth.api.client.SysUserFeignService;
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.auth.api.entity.SysUserRole;
 import com.ym.mec.auth.api.enums.CertificateTypeEnum;
-import com.ym.mec.biz.dal.enums.ClassGroupStudentStatusEnum;
-import com.ym.mec.biz.dal.enums.ClassGroupTypeEnum;
-import com.ym.mec.biz.dal.enums.CourseStatusEnum;
-import com.ym.mec.biz.dal.enums.CourseViewTypeEnum;
-import com.ym.mec.biz.dal.enums.DealStatusEnum;
-import com.ym.mec.biz.dal.enums.GoodsType;
-import com.ym.mec.biz.dal.enums.GroupType;
-import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
-import com.ym.mec.biz.dal.enums.MessageTypeEnum;
-import com.ym.mec.biz.dal.enums.MusicGroupStatusEnum;
-import com.ym.mec.biz.dal.enums.OrderDetailTypeEnum;
-import com.ym.mec.biz.dal.enums.OrderTypeEnum;
-import com.ym.mec.biz.dal.enums.PaymentStatusEnum;
-import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
-import com.ym.mec.biz.dal.enums.StudentMusicGroupStatusEnum;
+import com.ym.mec.biz.dal.dao.*;
+import com.ym.mec.biz.dal.dto.*;
+import com.ym.mec.biz.dal.entity.*;
+import com.ym.mec.biz.dal.enums.*;
+import com.ym.mec.biz.dal.page.*;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.dal.BaseDAO;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.entity.ImResult;
@@ -66,11 +18,32 @@ import com.ym.mec.common.entity.ImUserModel;
 import com.ym.mec.common.exception.BizException;
 import com.ym.mec.common.page.PageInfo;
 import com.ym.mec.common.service.impl.BaseServiceImpl;
+import com.ym.mec.common.tenant.TenantContextHolder;
 import com.ym.mec.im.ImFeignService;
 import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 import com.ym.mec.util.collection.MapUtil;
 import com.ym.mec.util.date.DateUtil;
 import com.ym.mec.util.http.HttpUtil;
+import org.apache.commons.lang3.StringUtils;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.http.HttpStatus;
+import org.springframework.stereotype.Service;
+import org.springframework.transaction.annotation.Propagation;
+import org.springframework.transaction.annotation.Transactional;
+import org.springframework.util.CollectionUtils;
+
+import javax.annotation.Resource;
+import java.io.IOException;
+import java.math.BigDecimal;
+import java.util.*;
+import java.util.stream.Collectors;
+
+import static com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus.NON_PAYMENT;
+import static com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus.PAID_COMPLETED;
+import static com.ym.mec.biz.dal.enums.OrderDetailTypeEnum.*;
+import static com.ym.mec.biz.dal.enums.PaymentStatusEnum.YES;
 
 @Service
 public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, StudentRegistration> implements StudentRegistrationService {
@@ -130,8 +103,6 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Autowired
     private SysUserFeignService sysUserFeignService;
     @Autowired
-    private SellOrderService sellOrderService;
-    @Autowired
     private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
     @Autowired
     private SubjectChangeDao subjectChangeDao;
@@ -140,20 +111,14 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Autowired
     private MusicGroupPaymentCalenderDetailDao musicGroupPaymentCalenderDetailDao;
     @Autowired
-    private MusicGroupPaymentCalenderDetailService musicGroupPaymentCalenderDetailService;
-    @Autowired
     private MusicGroupPaymentCalenderDao musicGroupPaymentCalenderDao;
     @Autowired
     private MusicGroupPaymentStudentCourseDetailDao musicGroupPaymentStudentCourseDetailDao;
     @Autowired
-    private MusicGroupPaymentCalenderCourseSettingsDao musicGroupPaymentCalenderCourseSettingsDao;
-    @Autowired
     private StudentCourseFeeDetailDao studentCourseFeeDetailDao;
     @Autowired
     private CourseScheduleDao courseScheduleDao;
     @Autowired
-    private StudentInstrumentService studentInstrumentService;
-    @Autowired
     private OrganizationDao organizationDao;
     @Autowired
     private StudentService studentService;
@@ -172,8 +137,6 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     @Autowired
     private SysUserCashAccountLogService sysUserCashAccountLogService;
     @Autowired
-    private ActivityUserMapperService activityUserMapperService;
-    @Autowired
     private MusicGroupPaymentCalenderActivityService musicGroupPaymentCalenderActivityService;
     @Autowired
     private MusicGroupPaymentCalenderMemberService musicGroupPaymentCalenderMemberService;
@@ -1102,43 +1065,8 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
 
         if (studentPaymentOrder.getStatus().equals(DealStatusEnum.SUCCESS)) {
             MusicGroup musicGroup = musicGroupDao.get(studentRegistration.getMusicGroupId());
-
-            if (studentRegistration.getTemporaryCourseFee() != null) {
-                studentRegistration.setTemporaryCourseFee(new BigDecimal(0));
-            }
-            studentRegistration.setPaymentStatus(YES);
-            studentRegistration.setMusicGroupStatus(StudentMusicGroupStatusEnum.NORMAL);
-            
-            if (studentPaymentOrder.getClassGroupId() == null || !studentPaymentOrder.getClassGroupId().equals(206)) {
-                studentRegistration.setPayingStatus(0);
-            }
-
-            List<Long> orderIdList = new ArrayList<>();
-            orderIdList.add(studentPaymentOrder.getId());
-            List<StudentPaymentOrderDetail> allDetails = studentPaymentOrderDetailDao.getOrderDetailByOrderId(orderIdList);
-            BigDecimal courseFee = allDetails.stream().filter(o -> !(o.getType() == MUSICAL)
-                    && !(o.getType() == VIP)
-                    && !(o.getType() == PRACTICE)
-                    && !(o.getType() == MAINTENANCE)
-                    && !(o.getType() == CLOUD_TEACHER)
-                    && !(o.getType() == CLOUD_TEACHER)
-                    && !(o.getType() == ACCESSORIES))
-                    .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
-                    .reduce(BigDecimal.ZERO, BigDecimal::add);
-            
-            //累加充值金额
-            studentRegistration.setSurplusCourseFee(studentRegistration.getSurplusCourseFee().add(courseFee));
-            studentRegistrationDao.update(studentRegistration);
-
-            //添加日志
-            StudentCourseFeeDetail studentCourseFeeDetail = new StudentCourseFeeDetail();
-            studentCourseFeeDetail.setTenantId(tenantId);
-            studentCourseFeeDetail.setStudentRegistrationId(studentRegistration.getId());
-            studentCourseFeeDetail.setAmount(courseFee);
-            studentCourseFeeDetail.setSurplusCourseFee(studentRegistration.getSurplusCourseFee());
-            studentCourseFeeDetail.setMemo("充值");
-            studentCourseFeeDetail.setOperator(studentPaymentOrder.getUserId());
-            studentCourseFeeDetailDao.insert(studentCourseFeeDetail);
+            //支付成功后处理课程、云教练、活动等数据
+            studentPaymentOrderDetailService.addOrderDetailTo(studentPaymentOrder,musicGroup,studentRegistration);
 
             //插入交易明细
             BigDecimal amount = studentPaymentOrder.getActualAmount();
@@ -1179,53 +1107,6 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
             paymentDetail.setTenantId(tenantId);
             sysUserCashAccountDetailService.insert(paymentDetail);
 
-            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.getOrderGoodsDetail(studentPaymentOrder.getId());
-            //销售订单详情
-            if (orderDetails.size() > 0) {
-                BigDecimal couponRemitFee = studentPaymentOrder.getCouponRemitFee();
-                if(couponRemitFee.compareTo(BigDecimal.ZERO) > 0){
-                    BigDecimal musicFee = orderDetails.stream().filter(o -> o.getType()==MUSICAL
-                            || o.getType()==ACCESSORIES || o.getType()==TEACHING)
-                            .map(o -> o.getPrice()).reduce(BigDecimal.ZERO, BigDecimal::add);
-                    BigDecimal expectAmount = studentPaymentOrder.getExpectAmount();
-                    //获取比例
-                    BigDecimal ratioAmount = musicFee.divide(expectAmount, 6, BigDecimal.ROUND_HALF_UP);
-                    //获取分配的减免金额
-                    couponRemitFee = couponRemitFee.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
-                }
-                sellOrderService.addOrderDetail2SellOrder(orderDetails, studentPaymentOrder, musicGroup,couponRemitFee);
-            }
-
-            //课程处理
-            musicGroupPaymentCalenderDetailService.addCalenderDetail(studentPaymentOrder, studentRegistration);
-
-            //活动小课包处理
-            List<StudentPaymentOrderDetail> activity = allDetails.stream().filter(o -> o.getType()==PRACTICE || o.getType() == VIP).collect(Collectors.toList());
-            if(activity != null && activity.size() > 0){
-                activityUserMapperService.addOrderDetail2Activity(studentPaymentOrder,activity);
-            }
-
-            //学生乐器与月保处理
-            StudentPaymentOrderDetail repair = allDetails.stream().filter(o -> o.getType()==MAINTENANCE).findFirst().get();
-            if(repair != null){
-                BigDecimal repairFee = allDetails.stream() .filter(o -> o.getType()==MAINTENANCE)
-                        .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
-                        .reduce(BigDecimal.ZERO, BigDecimal::add);
-                StudentPaymentOrderDetail musical = allDetails.stream().filter(o -> o.getType()==MUSICAL).findFirst().get();
-                Long studentInstrumentId = studentInstrumentService.addOrderDetail2Instrument(studentPaymentOrder, repairFee, Integer.valueOf(musical.getGoodsIdList()));
-                repair.setStudentInstrumentId(studentInstrumentId);
-                studentPaymentOrderDetailDao.update(repair);
-            }
-
-            //学生云教练处理
-            StudentPaymentOrderDetail cloudTeacher = allDetails.stream().filter(o -> o.getType()==CLOUD_TEACHER).findFirst().get();
-            if(cloudTeacher != null){
-                BigDecimal cloudTeacherFee = allDetails.stream() .filter(o -> o.getType()==CLOUD_TEACHER)
-                        .map(o -> o.getPrice().subtract(o.getRemitFee() == null ? BigDecimal.ZERO : o.getRemitFee()))
-                        .reduce(BigDecimal.ZERO, BigDecimal::add);
-                cloudTeacherOrderService.addOrderDetail2CloudTeacher(studentPaymentOrder,cloudTeacherFee);
-            }
-
             //合并学员处理
             if (studentRegistration.getIsMerge().equals(1) && studentPaymentOrder.getExpectAmount().compareTo(BigDecimal.ZERO) <= 0) {
                 return studentPaymentOrder;
@@ -1579,7 +1460,7 @@ public class StudentRegistrationServiceImpl extends BaseServiceImpl<Long, Studen
     }
 
     @Override
-    @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
+    @Transactional(rollbackFor = Exception.class)
     public BigDecimal updateUserSurplusCourseFee(Integer userId, String musicGroupId, BigDecimal amount, String memo, Integer operatorId) {
         StudentRegistration studentRegistration = studentRegistrationDao.lockWithUserAndMusic(userId, musicGroupId);
         if (Objects.isNull(studentRegistration)) {

+ 18 - 9
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponCodeServiceImpl.java

@@ -65,7 +65,7 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
      * @param couponId:       优惠券编号
      * @param paymentOrderId: 订单编号
      * @param exchangeNum:    兑换数量
-     * @param type:          2有paymentOrderId属于订单送券,交易获取,0手动领取 1手动发放
+     * @param type:           2有paymentOrderId属于订单送券,交易获取,0手动领取 1手动发放
      */
     @Override
     @Transactional(rollbackFor = Exception.class, isolation = Isolation.READ_COMMITTED)
@@ -84,17 +84,26 @@ public class SysCouponCodeServiceImpl extends BaseServiceImpl<Long, SysCouponCod
     }
 
     private SysCouponCode checkParam(Integer userId, Integer couponId, Long paymentOrderId, Integer exchangeNum, int type, Integer issueId) {
+        if (type > 2 || type < 0) {
+            throw new BizException("优惠券获取途径的参数错误!");
+        }
         SysCouponCode sysCouponCode = new SysCouponCode();
-        if (type == 2 && WrapperUtil.checkObj(userId, couponId, paymentOrderId, exchangeNum)) {
-            StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(paymentOrderId);
-            if (Objects.isNull(studentPaymentOrder)) {
-                throw new BizException("无效订单");
+        //校验参数
+        if (WrapperUtil.checkObj(userId, couponId, exchangeNum)) {
+            //2 订单满减
+            if (type == 2 && Objects.nonNull(paymentOrderId)) {
+                StudentPaymentOrder studentPaymentOrder = studentPaymentOrderDao.get(paymentOrderId);
+                if (Objects.isNull(studentPaymentOrder)) {
+                    throw new BizException("无效订单");
+                }
+                sysCouponCode.setPaymentOrderId(paymentOrderId);
+            } else if (type == 1 && Objects.nonNull(issueId)) {
+                //1 手动发券
+                sysCouponCode.setIssueId(issueId);
             }
-            sysCouponCode.setPaymentOrderId(paymentOrderId);
-        } else if ((type == 0 || type == 1) && WrapperUtil.checkObj(userId, couponId, issueId, exchangeNum)) {
-            sysCouponCode.setIssueId(issueId);
+            //0 手动领券
         } else {
-            throw new BizException("领取失败");
+            throw new BizException("领取失败,参数错误!");
         }
         sysCouponCode.setType(type);
         return sysCouponCode;

+ 48 - 11
mec-biz/src/main/java/com/ym/mec/biz/service/impl/SysCouponIssueRecordServiceImpl.java

@@ -22,7 +22,6 @@ import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.stereotype.Service;
 import org.springframework.transaction.annotation.Transactional;
-import org.springframework.util.CollectionUtils;
 
 import java.util.Date;
 import java.util.List;
@@ -86,18 +85,56 @@ public class SysCouponIssueRecordServiceImpl extends ServiceImpl<SysCouponIssueR
 
     }
 
+    /**
+     * 手动领取优惠券
+     *
+     * @param userId   用户id
+     * @param couponId 优惠券id
+     */
     @Override
-    public int revokeCoupon(Integer id) {
-        List<SysCouponIssueRecord> issueRecords = this.list(new WrapperUtil<SysCouponIssueRecord>()
-                .hasEq("id_", id)
-                .hasEq("ops", 0)
-                .queryWrapper());
-        if (CollectionUtils.isEmpty(issueRecords)) {
-            throw new BizException("未查询到该优惠券的发放记录!");
-        }
+    @Transactional(rollbackFor = Exception.class)
+    public void manualIssueCoupon(Integer userId, Integer couponId) {
+        sysCouponCodeService.exchangeCoupon(userId, couponId,
+                null, 1, 1, null);
+    }
 
+    /**
+     * 撤回优惠券
+     *
+     * @param issueId 发放记录
+     */
+    @Override
+    public void revokeCoupon(Integer issueId) {
+        SysCouponIssueRecord issueRecord = Optional.ofNullable(issueId)
+                .map(this::getById)
+                .orElseThrow(() -> new BizException("未查询到该发放记录!"));
+
+        //修改未使用的优惠券为撤回状态
+        baseMapper.revoke(issueId);
+        //查询券的信息
+        SysCoupon sysCoupon = Optional.ofNullable(issueRecord.getCouponId())
+                .map(sysCouponService::get)
+                .orElseThrow(() -> new BizException("未查询到该优惠券!"));
+
+        //查询未使用的优惠券有多少
+        int useCount = baseMapper.queryCouponCode(issueId, 0);
+        if (useCount >= 0) {
+            //返还库存
+            baseMapper.opsConsume(sysCoupon.getId(), useCount);
+        }
+        //发放记录修改为撤回状态
+        issueRecord.setOps(1);
+        issueRecord.setUpdatedBy(getUserId());
+        issueRecord.setUpdatedTime(new Date());
+        this.updateById(issueRecord);
+    }
 
-        return 0;
+    /**
+     * 检查已使用的优惠券数量
+     */
+    @Override
+    public int checkRevoke(Integer issueId) {
+        return baseMapper.queryCouponCode(issueId, 1);//0 未使用 1已使用
     }
 
     /**
@@ -106,7 +143,7 @@ public class SysCouponIssueRecordServiceImpl extends ServiceImpl<SysCouponIssueR
     @Override
     public PageInfo<CouponIssueRecordVo> queryIssueRecord(Map<String, Object> param) {
         Page<CouponIssueRecordVo> pageInfo = PageUtil.getPageInfo(param);
-        pageInfo.setAsc("a.create_time_");
+        pageInfo.setAsc("a.created_time_");
         return PageUtil.pageInfo(baseMapper.queryIssueRecord(pageInfo, param));
     }
 

+ 1 - 1
mec-biz/src/main/resources/config/mybatis/MusicGroupPaymentCalenderDetailMapper.xml

@@ -74,7 +74,7 @@
             (#{item.musicGroupPaymentCalenderId},#{item.userId},#{item.expectAmount},
             #{item.actualAmount},#{item.paymentStatus,typeHandler=com.ym.mec.common.dal.CustomEnumTypeHandler},#{item.userStatus},#{item.payTime},
             #{item.updateTime},#{item.createTime},#{item.startPaymentDate},#{item.deadlinePaymentDate},
-             #{item.paymentOrderId},#{item.useInCourse},#{item.responsibleUserId},#{item.responsibleRecord},#{item.expectMemberAmount},#{item.tenantid})
+             #{item.paymentOrderId},#{item.useInCourse},#{item.responsibleUserId},#{item.responsibleRecord},#{item.expectMemberAmount},#{item.tenantId})
         </foreach>
     </insert>
 

+ 2 - 0
mec-biz/src/main/resources/config/mybatis/SysCouponCodeMapper.xml

@@ -43,6 +43,7 @@
 		<result column="use_start_date_" property="useStartDate"/>
 		<result column="use_deadline_date_" property="useDeadlineDate"/>
 		<result column="issueType" property="issueType"/>
+		<result column="typeDetail" property="typeDetail"/>
 	</resultMap>
 
 	<!-- 根据主键查询一条记录 -->
@@ -196,6 +197,7 @@
 		    sc.face_value_,
 		    sc.full_amount_,
 			sc.description_ coupon_description_,
+            sc.type_detail_ as typeDetail,
 			scc.code_,
 			scc.payment_order_id_,
 			scc.use_start_date_,

+ 30 - 4
mec-biz/src/main/resources/config/mybatis/SysCouponIssueRecordMapper.xml

@@ -37,6 +37,7 @@
         , su.phone_ as phone
         , sb.name_ as subjectName
         , scc.usage_status_ as usageStatus
+        , scc.id_ as couponCodeId
         FROM student s
         LEFT JOIN sys_user su ON su.id_ = s.user_id_
         LEFT JOIN organization o ON o.id_ = su.organ_id_
@@ -58,7 +59,9 @@
     </select>
 
     <select id="queryIssueRecord" parameterType="map" resultType="com.ym.mec.biz.dal.vo.CouponIssueRecordVo">
-        select a.created_time_ as createdTime,
+        select
+        a.id_ as id,
+        a.created_time_ as createdTime,
         a.coupon_name_ as couponName,
         a.num_ as num,
         u.real_name_ as `name`,
@@ -66,11 +69,34 @@
         from sys_coupon_issue_record as a
         left join sys_user as u on a.created_by_ = u.id_
         where a.tenant_id_ = #{param.tenantId}
+        <if test="param.ops !=null">
+            and a.ops_ = #{param.ops}
+        </if>
         <if test="param.couponId !=null">
           and a.coupon_id_ =#{param.couponId}
         </if>
-        <if test="param.search !=null">
-            and a.coupon_name_ like concat('%',#{param.search},'%')
-        </if>
     </select>
+
+    <select id="queryCouponCode" resultType="integer">
+        select count(id_)
+        from sys_coupon_code
+        where issue_id_ = #{issueId}
+          and usage_status_ = #{state}
+    </select>
+
+    <update id="revoke">
+        UPDATE sys_coupon_code
+        SET usage_status_ = 2,
+            used_time_    = NOW(),
+            update_time_  = NOW()
+        WHERE issue_id_ = #{issueId}
+          and usage_status_ = 0
+    </update>
+
+    <update id="opsConsume" parameterType="object">
+        UPDATE sys_coupon
+        SET consume_num_ = consume_num_ - #{consumeNum}
+        WHERE id_ = #{id}
+    </update>
+
 </mapper>

+ 6 - 18
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupPaymentCalenderController.java

@@ -11,10 +11,7 @@ import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalender.PaymentCalenderStatus
 import com.ym.mec.biz.dal.entity.MusicGroupPaymentCalenderDetail;
 import com.ym.mec.biz.dal.entity.MusicGroupStudentFee.PaymentStatus;
 import com.ym.mec.biz.dal.entity.StudentRegistration;
-import com.ym.mec.biz.service.MemberRankPrivilegesService;
-import com.ym.mec.biz.service.MusicGroupPaymentCalenderActivityService;
-import com.ym.mec.biz.service.MusicGroupPaymentCalenderService;
-import com.ym.mec.biz.service.StudentRegistrationService;
+import com.ym.mec.biz.service.*;
 import com.ym.mec.common.controller.BaseController;
 import com.ym.mec.common.entity.HttpResponseResult;
 import com.ym.mec.common.exception.BizException;
@@ -29,6 +26,8 @@ import org.springframework.web.bind.annotation.RequestMapping;
 import org.springframework.web.bind.annotation.RestController;
 
 import javax.annotation.Resource;
+import java.util.HashMap;
+import java.util.Map;
 
 @RequestMapping("musicGroupPaymentCalender")
 @Api(tags = "乐团缴费项目服务")
@@ -47,10 +46,6 @@ public class MusicGroupPaymentCalenderController extends BaseController {
     private MusicGroupPaymentCalenderDetailDao musicGroupPaymentCalenderDetailDao;
     @Autowired
     private MusicGroupPaymentCalenderStudentDetailDao musicGroupPaymentCalenderStudentDetailDao;
-    @Autowired
-    private MusicGroupPaymentStudentCourseDetailDao musicGroupPaymentStudentCourseDetailDao;
-    @Autowired
-    private MusicGroupPaymentCalenderActivityService musicGroupPaymentCalenderActivityService;
 	@Autowired
 	private MemberRankPrivilegesService memberRankPrivilegesService;
 
@@ -78,21 +73,14 @@ public class MusicGroupPaymentCalenderController extends BaseController {
             if (studentRegistration == null) {
                 return failed("乐团报名信息不存在");
             }
-            ModelMap model = new ModelMap();
             //课程相关信息
-            if(calender.getPaymentType() == MusicGroupPaymentCalender.PaymentType.SPAN_GROUP_CLASS_ADJUST){
-                model.put("musicGroupPaymentCalenderStudentDetails",musicGroupPaymentCalenderStudentDetailDao.findByBatchNoAndUserId(calender.getBatchNo(),userId));
-            }else {
-                model.put("calenderCourseSettings", musicGroupPaymentStudentCourseDetailDao.findByCalenderAndUserId(calenderId,userId));
-            }
-            //活动相关信息
-            model.put("activity",musicGroupPaymentCalenderActivityService.findByCalenderId(calenderId));
-            calender.setMemberPaymentAmount(calenderDetail.getExpectMemberAmount());
+            Map model = new HashMap<>(10);
+            model.put("musicGroupPaymentCalenderStudentDetails",musicGroupPaymentCalenderStudentDetailDao.findByBatchNoAndUserId(calender.getBatchNo(),userId));
             model.put("musicGroup",musicGroupDao.get(musicGroupId));
-            model.put("amount", calender.getCurrentTotalAmount());
             model.put("balance",studentRegistration.getBalance());
             model.put("calender",calender);
             model.put("memberPrivilegesItemList", memberRankPrivilegesService.queryByMemberRankId(calender.getMemberRankSettingId()));
+            musicGroupPaymentCalenderService.getCalenderDetail(model,calenderId);
             return succeed(model);
         }else if(calender.getStatus() == PaymentCalenderStatusEnum.OVER){
             throw new BizException("缴费已截止,如有问题请联系指导老师");

+ 9 - 2
mec-web/src/main/java/com/ym/mec/web/controller/SysCouponIssueRecordController.java

@@ -38,10 +38,17 @@ public class SysCouponIssueRecordController extends BaseController {
         return succeed();
     }
 
+    @ApiOperation("检查撤销的优惠券")
+    @PostMapping(value = "/checkRevoke")
+    public HttpResponseResult checkRevoke(Integer id) {
+        return succeed(couponIssueRecordService.checkRevoke(id));
+    }
+
     @ApiOperation("撤销发放优惠券")
     @PostMapping(value = "/revokeCoupon")
-    public HttpResponseResult revokeCoupon(Integer couponId) {
-        return succeed(couponIssueRecordService.revokeCoupon(couponId));
+    public HttpResponseResult revokeCoupon(Integer id) {
+        couponIssueRecordService.revokeCoupon(id);
+        return succeed();
     }
 
     @ApiOperation("查询优惠券发放名单")