yonge 5 years ago
parent
commit
3fcef71ddf

+ 9 - 0
mec-biz/src/main/java/com/ym/mec/biz/dal/dto/RegisterPayDto.java

@@ -11,6 +11,7 @@ public class RegisterPayDto {
     private String goodsGroupIds;
     private String goodsIds;
     private String otherGoodsIds;
+    Boolean isUseBalancePayment = false;
 
     public Integer getRegisterId() {
         return registerId;
@@ -51,4 +52,12 @@ public class RegisterPayDto {
     public void setOtherGoodsIds(String otherGoodsIds) {
         this.otherGoodsIds = otherGoodsIds;
     }
+
+	public Boolean getIsUseBalancePayment() {
+		return isUseBalancePayment;
+	}
+
+	public void setIsUseBalancePayment(Boolean isUseBalancePayment) {
+		this.isUseBalancePayment = isUseBalancePayment;
+	}
 }

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

@@ -7,10 +7,13 @@ import java.util.List;
 import java.util.Map;
 import java.util.Set;
 
+import org.springframework.web.bind.annotation.RequestBody;
+
 import com.ym.mec.auth.api.entity.SysUser;
 import com.ym.mec.biz.dal.dto.BasicUserDto;
 import com.ym.mec.biz.dal.dto.CourseScheduleTeachersDto;
 import com.ym.mec.biz.dal.dto.MusicCardDto;
+import com.ym.mec.biz.dal.dto.RegisterPayDto;
 import com.ym.mec.biz.dal.dto.SubFeeSettingDto;
 import com.ym.mec.biz.dal.dto.UpdateExpectedNumDto;
 import com.ym.mec.biz.dal.entity.ApprovalStatus;
@@ -30,6 +33,20 @@ public interface MusicGroupService extends BaseService<String, MusicGroup> {
 	String createGroup(SubFeeSettingDto subFeeSettingDto) throws Exception;
 
 	/**
+	 * 缴费
+	 * @param registerPayDto
+	 * @return
+	 */
+	Map pay(RegisterPayDto registerPayDto) throws Exception;
+
+	/**
+	 * 继续缴费
+	 * @param registerPayDto
+	 * @return
+	 */
+	Map rePay(RegisterPayDto registerPayDto) throws Exception;
+
+	/**
 	 * 获取学生所在乐团详情
 	 * @return
 	 */

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

@@ -24,6 +24,7 @@ import com.ym.mec.util.http.HttpUtil;
 
 import org.apache.commons.lang3.StringUtils;
 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;
@@ -125,6 +126,15 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 	
 	@Autowired
     private StudentPaymentOrderDetailDao studentPaymentOrderDetailDao;
+	
+    @Autowired
+    private MusicGroupSubjectPlanService musicGroupSubjectPlanService;
+    @Autowired
+    private StudentRegistrationService studentRegistrationService;
+    @Autowired
+    private MusicGroupSubjectGoodsGroupService musicGroupSubjectGoodsGroupService;
+    @Autowired
+    private GoodsService goodsService;
 
     @Override
     public BaseDAO<String, MusicGroup> getDAO() {
@@ -215,6 +225,285 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
 
     @Override
     @Transactional(rollbackFor = Exception.class)
+	public Map pay(RegisterPayDto registerPayDto) throws Exception {
+
+        StudentRegistration studentRegistration = studentRegistrationService.get(registerPayDto.getRegisterId().longValue());
+        if (studentRegistration == null) {
+            throw new BizException("报名信息有误,请核查");
+        }
+
+        Integer userId = studentRegistration.getUserId();
+
+        BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
+        BigDecimal orderAmount = new BigDecimal("0");
+
+        //获取课程价格
+        MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
+        BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
+        if (studentRegistration.getTemporaryCourseFee() != null) {
+            courseFee = studentRegistration.getTemporaryCourseFee();
+        }
+        orderAmount = orderAmount.add(courseFee);
+
+
+        //乐器及打包辅件
+        List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
+
+        if (studentRegistration.getTemporaryCourseFee() != null) {
+            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), DealStatusEnum.WAIT_PAY);
+            for (StudentPaymentOrderDetail orderDetail : orderDetails) {
+                if (orderDetail == null || orderDetail.getPrice() == null){
+                    continue;
+                }
+                MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup = new MusicGroupSubjectGoodsGroup();
+                GoodsType goodsType = orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) ? GoodsType.INSTRUMENT : GoodsType.ACCESSORIES;
+                musicGroupSubjectGoodsGroup.setType(goodsType);
+                musicGroupSubjectGoodsGroup.setGoodsIdList(orderDetail.getGoodsIdList());
+                musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
+
+                goodsGroups.add(musicGroupSubjectGoodsGroup);
+
+                orderAmount = orderAmount.add(orderDetail.getPrice());
+            }
+        } else if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
+            goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
+            for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
+                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
+                    continue;
+                }
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
+                    continue;
+                }
+                orderAmount = orderAmount.add(goodsGroup.getPrice());
+                //团购乐器减免课程费用
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
+                    orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
+                }
+            }
+        }
+
+        //单独辅件
+        List<Goods> goodsList = null;
+        if (registerPayDto.getGoodsIds() != null && !registerPayDto.getGoodsIds().equals("")) {
+            goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
+            for (Goods goods : goodsList) {
+                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+            }
+        }
+
+        //单独教谱
+        List<Goods> otherGoodsList = null;
+        if (registerPayDto.getOtherGoodsIds() != null && !registerPayDto.getOtherGoodsIds().equals("")) {
+            otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
+            for (Goods goods : otherGoodsList) {
+                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+            }
+        }
+        if (amount.compareTo(orderAmount) != 0) {
+            throw new BizException("商品价格不符");
+        }
+
+        String orderNo = idGeneratorService.generatorId("payment") + "";
+        
+        String channelType = "";
+
+        StudentPaymentOrder studentPaymentOrder = studentRegistrationService.addOrder(studentRegistration, amount, orderNo, channelType, courseFee, goodsGroups, goodsList, otherGoodsList);
+
+        Date date = new Date();
+        
+        if(registerPayDto.getIsUseBalancePayment() || amount.doubleValue() == 0){
+        	SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
+        	if(userCashAccount == null){
+        		throw new BizException("用户账户找不到");
+        	}
+        	if(userCashAccount.getBalance().subtract(amount).doubleValue() > 0){
+        		// 更新订单信息
+        		studentPaymentOrder.setBalancePaymentAmount(amount);
+                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
+                studentPaymentOrder.setUpdateTime(date);
+                studentPaymentOrderService.update(studentPaymentOrder);
+                
+        		sysUserCashAccountService.updateBalance(userId, amount.negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"乐团续费");
+        		
+        		//更新下次续费时间
+        		/*musicGroupStudentFee.setUpdateTime(date);
+                musicGroupStudentFee.setLatestPaidTime(date);
+                musicGroupStudentFee.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
+                musicGroupStudentFee.setTemporaryCourseFee(new BigDecimal(0));
+                musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId));
+                musicGroupStudentFeeDao.update(musicGroupStudentFee);*/
+                
+        		return null;
+        	}else{
+				if (userCashAccount.getBalance().doubleValue() > 0) {
+					sysUserCashAccountService.updateBalance(userId, userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团续费");
+					amount = amount.subtract(userCashAccount.getBalance());
+					studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
+				} else {
+					studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
+				}
+        	}
+        }
+        
+
+        Map payMap = payService.getPayMap(
+                orderAmount,
+                orderNo,
+                "http://mstudev.dayaedu.com/api-student/studentOrder/notify",
+                "http://mstudev.dayaedu.com/#/paymentresult?orderNo=" + orderNo,
+                "测试订单",
+                "测试订单");
+        
+        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
+        studentPaymentOrder.setUpdateTime(date);
+        studentPaymentOrderService.update(studentPaymentOrder);
+        
+		return payMap;
+	}
+
+	@Override
+    @Transactional(rollbackFor = Exception.class)
+	public Map rePay(RegisterPayDto registerPayDto) throws Exception {
+		StudentRegistration studentRegistration = studentRegistrationService.get(registerPayDto.getRegisterId().longValue());
+        if (studentRegistration == null) {
+            throw new BizException("报名信息有误,请核查");
+        }
+
+        Integer userId = studentRegistration.getUserId();
+        
+        StudentPaymentOrder ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.ING);
+        if (ApplyOrder == null) {
+            throw new BizException("没有支付中的订单,请勿非法请求");
+        }
+
+        BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
+        BigDecimal orderAmount = new BigDecimal("0");
+
+        //获取课程价格
+        MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
+        BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
+        if (studentRegistration.getTemporaryCourseFee() != null) {
+            courseFee = studentRegistration.getTemporaryCourseFee();
+        }
+        orderAmount = orderAmount.add(courseFee);
+
+
+        //乐器及打包辅件
+        List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
+        if (studentRegistration.getTemporaryCourseFee() != null) {
+            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), DealStatusEnum.WAIT_PAY);
+            for (StudentPaymentOrderDetail orderDetail : orderDetails) {
+                if (orderDetail == null || orderDetail.getPrice() == null){
+                    continue;
+                }
+                MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup = new MusicGroupSubjectGoodsGroup();
+                GoodsType goodsType = orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) ? GoodsType.INSTRUMENT : GoodsType.ACCESSORIES;
+                musicGroupSubjectGoodsGroup.setType(goodsType);
+                musicGroupSubjectGoodsGroup.setGoodsIdList(orderDetail.getGoodsIdList());
+                musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
+                goodsGroups.add(musicGroupSubjectGoodsGroup);
+                orderAmount = orderAmount.add(orderDetail.getPrice());
+            }
+        } else if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
+            goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
+            for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
+                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
+                    continue;
+                }
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
+                    continue;
+                }
+
+                orderAmount = orderAmount.add(goodsGroup.getPrice());
+                //团购乐器减免课程费用
+                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
+                    orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
+                }
+            }
+        }
+
+        //单独辅件
+        List<Goods> goodsList = null;
+        if (registerPayDto.getGoodsIds() != null && !registerPayDto.getGoodsIds().equals("")) {
+            goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
+            for (Goods goods : goodsList) {
+                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+            }
+        }
+
+        //单独教谱
+        List<Goods> otherGoodsList = null;
+        if (registerPayDto.getOtherGoodsIds() != null && !registerPayDto.getOtherGoodsIds().equals("")) {
+            otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
+            for (Goods goods : otherGoodsList) {
+                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
+            }
+        }
+        if (amount.compareTo(orderAmount) != 0) {
+            throw new BizException("商品价格不符");
+        }
+
+        String orderNo = idGeneratorService.generatorId("payment") + "";
+        
+        String channelType = "";
+
+        StudentPaymentOrder studentPaymentOrder = studentRegistrationService.reAddOrder(userId, amount, orderNo, channelType, courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId(), ApplyOrder);
+
+        Date date = new Date();
+        
+        if(registerPayDto.getIsUseBalancePayment() || amount.doubleValue() == 0){
+        	SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
+        	if(userCashAccount == null){
+        		throw new BizException("用户账户找不到");
+        	}
+        	if(userCashAccount.getBalance().subtract(amount).doubleValue() > 0){
+        		// 更新订单信息
+        		studentPaymentOrder.setBalancePaymentAmount(amount);
+                studentPaymentOrder.setStatus(DealStatusEnum.SUCCESS);
+                studentPaymentOrder.setUpdateTime(date);
+                studentPaymentOrderService.update(studentPaymentOrder);
+                
+        		sysUserCashAccountService.updateBalance(userId, amount.negate(),PlatformCashAccountDetailTypeEnum.PAY_FEE,"乐团续费");
+        		
+        		//更新下次续费时间
+        		/*musicGroupStudentFee.setUpdateTime(date);
+                musicGroupStudentFee.setLatestPaidTime(date);
+                musicGroupStudentFee.setPaymentStatus(PaymentStatus.PAID_COMPLETED);
+                musicGroupStudentFee.setTemporaryCourseFee(new BigDecimal(0));
+                musicGroupStudentFee.setNextPaymentDate(musicGroupPaymentCalenderService.getNextPaymentDate(musicGroupId));
+                musicGroupStudentFeeDao.update(musicGroupStudentFee);*/
+                
+        		return null;
+        	}else{
+				if (userCashAccount.getBalance().doubleValue() > 0) {
+					sysUserCashAccountService.updateBalance(userId, userCashAccount.getBalance().negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团续费");
+					amount = amount.subtract(userCashAccount.getBalance());
+					studentPaymentOrder.setBalancePaymentAmount(userCashAccount.getBalance());
+				} else {
+					studentPaymentOrder.setBalancePaymentAmount(new BigDecimal(0));
+				}
+        	}
+        }
+
+        Map payMap = payService.getPayMap(
+                orderAmount,
+                orderNo,
+                "http://mstudev.dayaedu.com/api-student/studentOrder/notify",
+                "http://mstudev.dayaedu.com/#/paymentresult?orderNo=" + orderNo,
+                "测试订单",
+                "测试订单");
+        
+        studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
+        studentPaymentOrder.setUpdateTime(date);
+        studentPaymentOrderService.update(studentPaymentOrder);
+        
+		return payMap;
+	}
+
+	@Override
+    @Transactional(rollbackFor = Exception.class)
     public void updateSubjectInfo(SubFeeSettingDto subFeeSettingDto) throws Exception {
         SysUser sysUser = sysUserFeignService.queryUserInfo();
         if(sysUser == null){
@@ -777,7 +1066,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         studentPaymentOrder.setMusicGroupId(musicGroupId);
         studentPaymentOrder.setCreateTime(date);
         studentPaymentOrder.setUpdateTime(date);
-        studentPaymentOrder.setVersion(1);
+        studentPaymentOrder.setVersion(0);
         studentPaymentOrderService.insert(studentPaymentOrder);
 
         ArrayList<StudentPaymentOrderDetail> studentPaymentOrderDetailList = new ArrayList<>();
@@ -826,7 +1115,7 @@ public class MusicGroupServiceImpl extends BaseServiceImpl<String, MusicGroup> i
         }
 
         try {
-            Map<String, Object> payMap = payService.getPayMap(amount, idGeneratorService.generatorId("payment") + "", "https://pay.dayaedu.com/api/yqpay/notify",
+            Map<String, Object> payMap = payService.getPayMap(amount, studentPaymentOrder.getOrderNo(), "https://pay.dayaedu.com/api/yqpay/notify",
                     "http://dev.dayaedu.com", "续费", "乐团续费");
             studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
             studentPaymentOrder.setUpdateTime(date);

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

@@ -25,7 +25,7 @@
 
     <!-- 全查询 -->
     <select id="findAll" resultMap="CooperationOrgan">
-		SELECT * FROM cooperation_organ AND del_flag_ = 0
+		SELECT * FROM cooperation_organ AND del_flag_ != 1
 		ORDER BY id_
 	</select>
 
@@ -92,7 +92,7 @@
     <select id="queryCount" resultType="int">
 		SELECT COUNT(*) FROM cooperation_organ
         <where>
-            del_flag_ = 0
+            del_flag_ != 1
             <if test="search != null">
                 AND organ_id_ = #{search}
             </if>
@@ -100,11 +100,11 @@
 	</select>
 
     <select id="queryByOrganId" resultMap="CooperationOrgan">
-        SELECT * FROM cooperation_organ WHERE FIND_IN_SET(organ_id_,#{organId}) AND del_flag_ = 0
+        SELECT * FROM cooperation_organ WHERE FIND_IN_SET(organ_id_,#{organId}) AND del_flag_ != 1
     </select>
 
     <select id="queryNameByIds" resultType="java.util.Map">
         SELECT co.id_ 'key',co.name_ 'value' FROM cooperation_organ co
-        WHERE FIND_IN_SET(co.id_,#{organIds}) AND co.del_flag_ = 0
+        WHERE FIND_IN_SET(co.id_,#{organIds}) AND co.del_flag_ != 1
     </select>
 </mapper>

+ 6 - 6
mec-biz/src/main/resources/config/mybatis/SchoolMapper.xml

@@ -92,7 +92,7 @@
 
     <!-- 分页查询 -->
     <select id="queryPage" resultMap="School" parameterType="map">
-        SELECT * FROM school where del_flag_ = 0
+        SELECT * FROM school where del_flag_ != 1
         <if test="cooperationOrganId != null">
             AND cooperation_organ_id_ = #{cooperationOrganId}
         </if>
@@ -102,7 +102,7 @@
 
     <!-- 查询当前表的总记录数 -->
     <select id="queryCount" resultType="int">
-		SELECT COUNT(*) FROM school where del_flag_ = 0
+		SELECT COUNT(*) FROM school where del_flag_ != 1
         <if test="cooperationOrganId != null">
             AND cooperation_organ_id_ = #{cooperationOrganId}
         </if>
@@ -110,18 +110,18 @@
     <select id="queryByOrganId" resultMap="School">
         SELECT * FROM school
         <where>
-            del_flag_ = 0
+            del_flag_ != 1
             <if test="organId != null">
                 AND FIND_IN_SET(organ_id_,#{organId})
             </if>
         </where>
     </select>
     <select id="queryNameByIds" resultType="java.util.Map" >
-        select id_ `key`,name_ `value` FROM school s WHERE FIND_IN_SET(id_,#{schoolIds}) AND s.del_flag_ = 0
+        select id_ `key`,name_ `value` FROM school s WHERE FIND_IN_SET(id_,#{schoolIds}) AND s.del_flag_ != 1
     </select>
     
     <select id="findByUserId" resultMap="School">
-        select * from school where del_flag_ = 0 and user_id_ = #{userId}
+        select * from school where del_flag_ != 1 and user_id_ = #{userId}
     </select>
     <select id="findVipSchoolByUserId" resultMap="School">
         SELECT
@@ -129,7 +129,7 @@
         FROM
             school
         WHERE
-            del_flag_ = 0
+            del_flag_ != 1
             <if test="isDefault==null">
                 AND ( user_id_ IS NULL OR user_id_ = #{userId} )
             </if>

+ 2 - 171
mec-student/src/main/java/com/ym/mec/student/controller/MusicGroupController.java

@@ -246,90 +246,7 @@ public class MusicGroupController extends BaseController {
             return failed(HttpStatus.CONTINUE, "您有待支付的订单");
         }
 
-        BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
-        BigDecimal orderAmount = new BigDecimal("0");
-
-        //获取课程价格
-        MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
-        BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
-        if (studentRegistration.getTemporaryCourseFee() != null) {
-            courseFee = studentRegistration.getTemporaryCourseFee();
-        }
-        orderAmount = orderAmount.add(courseFee);
-
-
-        //乐器及打包辅件
-        List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
-
-        if (studentRegistration.getTemporaryCourseFee() != null) {
-            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), DealStatusEnum.WAIT_PAY);
-            for (StudentPaymentOrderDetail orderDetail : orderDetails) {
-                if (orderDetail == null || orderDetail.getPrice() == null){
-                    continue;
-                }
-                MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup = new MusicGroupSubjectGoodsGroup();
-                GoodsType goodsType = orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) ? GoodsType.INSTRUMENT : GoodsType.ACCESSORIES;
-                musicGroupSubjectGoodsGroup.setType(goodsType);
-                musicGroupSubjectGoodsGroup.setGoodsIdList(orderDetail.getGoodsIdList());
-                musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
-
-                goodsGroups.add(musicGroupSubjectGoodsGroup);
-
-                orderAmount = orderAmount.add(orderDetail.getPrice());
-            }
-        } else if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
-            goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
-            for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
-                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
-                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
-                    continue;
-                }
-                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
-                    continue;
-                }
-                orderAmount = orderAmount.add(goodsGroup.getPrice());
-                //团购乐器减免课程费用
-                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
-                    orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
-                }
-            }
-        }
-
-        //单独辅件
-        List<Goods> goodsList = null;
-        if (registerPayDto.getGoodsIds() != null && !registerPayDto.getGoodsIds().equals("")) {
-            goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
-            for (Goods goods : goodsList) {
-                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
-            }
-        }
-
-        //单独教谱
-        List<Goods> otherGoodsList = null;
-        if (registerPayDto.getOtherGoodsIds() != null && !registerPayDto.getOtherGoodsIds().equals("")) {
-            otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
-            for (Goods goods : otherGoodsList) {
-                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
-            }
-        }
-        if (amount.compareTo(orderAmount) != 0) {
-            return failed("商品价格不符");
-        }
-
-
-        String orderNo = idGeneratorService.generatorId("payment") + "";
-
-        Map payMap = payService.getPayMap(
-                orderAmount,
-                orderNo,
-                "http://mstudev.dayaedu.com/api-student/studentOrder/notify",
-                "http://mstudev.dayaedu.com/#/paymentresult?orderNo=" + orderNo,
-                "测试订单",
-                "测试订单");
-
-        studentRegistrationService.addOrder(studentRegistration, amount, orderNo, (String) payMap.get("type"), courseFee, goodsGroups, goodsList, otherGoodsList);
-
-        return succeed(payMap);
+        return succeed(musicGroupService.pay(registerPayDto));
     }
 
     @ApiOperation(value = "乐团报名重新支付")
@@ -348,93 +265,7 @@ public class MusicGroupController extends BaseController {
             return failed("您已支付成功,请勿重复支付");
         }
 
-        //判断用户是否已存在订单
-        ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.ING);
-        if (ApplyOrder == null) {
-            return failed(HttpStatus.CONTINUE, "没有支付中的订单,请勿非法请求");
-        }
-
-        BigDecimal amount = registerPayDto.getAmount(); //前端获取的价格
-        BigDecimal orderAmount = new BigDecimal("0");
-
-        //获取课程价格
-        MusicGroupSubjectPlan musicOneSubjectClassPlan = musicGroupSubjectPlanService.getMusicOneSubjectClassPlan(studentRegistration.getMusicGroupId(), studentRegistration.getActualSubjectId());
-        BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
-        if (studentRegistration.getTemporaryCourseFee() != null) {
-            courseFee = studentRegistration.getTemporaryCourseFee();
-        }
-        orderAmount = orderAmount.add(courseFee);
-
-
-        //乐器及打包辅件
-        List<MusicGroupSubjectGoodsGroup> goodsGroups = new ArrayList<>();
-        if (studentRegistration.getTemporaryCourseFee() != null) {
-            List<StudentPaymentOrderDetail> orderDetails = studentPaymentOrderDetailService.findUserApplyOrder(studentRegistration.getUserId(), DealStatusEnum.WAIT_PAY);
-            for (StudentPaymentOrderDetail orderDetail : orderDetails) {
-                if (orderDetail == null || orderDetail.getPrice() == null){
-                    continue;
-                }
-                MusicGroupSubjectGoodsGroup musicGroupSubjectGoodsGroup = new MusicGroupSubjectGoodsGroup();
-                GoodsType goodsType = orderDetail.getType().equals(OrderDetailTypeEnum.MUSICAL) ? GoodsType.INSTRUMENT : GoodsType.ACCESSORIES;
-                musicGroupSubjectGoodsGroup.setType(goodsType);
-                musicGroupSubjectGoodsGroup.setGoodsIdList(orderDetail.getGoodsIdList());
-                musicGroupSubjectGoodsGroup.setPrice(orderDetail.getPrice());
-                goodsGroups.add(musicGroupSubjectGoodsGroup);
-                orderAmount = orderAmount.add(orderDetail.getPrice());
-            }
-        } else if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
-            goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
-            for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
-                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.LEASE)) {
-                    orderAmount = orderAmount.add(musicOneSubjectClassPlan.getDepositFee());
-                    continue;
-                }
-                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.FREE)) {
-                    continue;
-                }
-
-                orderAmount = orderAmount.add(goodsGroup.getPrice());
-                //团购乐器减免课程费用
-                if (goodsGroup.getType().equals(GoodsType.INSTRUMENT) && goodsGroup.getRemissionCourseFee() != null && musicOneSubjectClassPlan.getKitGroupPurchaseType().equals(KitGroupPurchaseTypeEnum.GROUP)) {//团购
-                    orderAmount = orderAmount.subtract(goodsGroup.getRemissionCourseFee());
-                }
-            }
-        }
-
-        //单独辅件
-        List<Goods> goodsList = null;
-        if (registerPayDto.getGoodsIds() != null && !registerPayDto.getGoodsIds().equals("")) {
-            goodsList = goodsService.findGoodsByIds(registerPayDto.getGoodsIds());
-            for (Goods goods : goodsList) {
-                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
-            }
-        }
-
-        //单独教谱
-        List<Goods> otherGoodsList = null;
-        if (registerPayDto.getOtherGoodsIds() != null && !registerPayDto.getOtherGoodsIds().equals("")) {
-            otherGoodsList = goodsService.findGoodsByIds(registerPayDto.getOtherGoodsIds());
-            for (Goods goods : otherGoodsList) {
-                orderAmount = orderAmount.add(goods.getGroupPurchasePrice());
-            }
-        }
-        if (amount.compareTo(orderAmount) != 0) {
-            return failed("商品价格不符");
-        }
-
-        String orderNo = idGeneratorService.generatorId("payment") + "";
-
-        Map payMap = payService.getPayMap(
-                orderAmount,
-                orderNo,
-                "http://mstudev.dayaedu.com/api-student/studentOrder/notify",
-                "http://mstudev.dayaedu.com/#/paymentresult?orderNo=" + orderNo,
-                "测试订单",
-                "测试订单");
-
-        studentRegistrationService.reAddOrder(userId, amount, orderNo, (String) payMap.get("type"), courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId(), ApplyOrder);
-
-        return succeed(payMap);
+        return succeed(musicGroupService.rePay(registerPayDto));
     }
 
     @ApiOperation(value = "订单状态查询")