|  | @@ -5,8 +5,10 @@ import com.ym.mec.auth.api.entity.SysUser;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.MusicGroupSubjectGoodsAndInfoDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.RegisterPayDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.DealStatusEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.GoodsType;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.enums.OrderTypeEnum;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.service.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.controller.BaseController;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.entity.HttpResponseResult;
 | 
	
	
		
			
				|  | @@ -16,6 +18,7 @@ import io.swagger.annotations.ApiImplicitParam;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiImplicitParams;
 | 
	
		
			
				|  |  |  import io.swagger.annotations.ApiOperation;
 | 
	
		
			
				|  |  |  import org.springframework.beans.factory.annotation.Autowired;
 | 
	
		
			
				|  |  | +import org.springframework.http.HttpStatus;
 | 
	
		
			
				|  |  |  import org.springframework.web.bind.annotation.*;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  import javax.annotation.Resource;
 | 
	
	
		
			
				|  | @@ -97,6 +100,93 @@ public class MusicGroupController extends BaseController {
 | 
	
		
			
				|  |  |              return failed("报名信息有误,请核查");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        StudentPaymentOrder ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +        if (ApplyOrder != null) {
 | 
	
		
			
				|  |  | +            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.getSubjectId());
 | 
	
		
			
				|  |  | +        BigDecimal courseFee = musicOneSubjectClassPlan.getFee();
 | 
	
		
			
				|  |  | +        orderAmount = orderAmount.add(courseFee);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        //乐器及打包辅件
 | 
	
		
			
				|  |  | +        List<MusicGroupSubjectGoodsGroup> goodsGroups = null;
 | 
	
		
			
				|  |  | +        if (registerPayDto.getGoodsGroupIds() != null && !registerPayDto.getGoodsGroupIds().equals("")) {
 | 
	
		
			
				|  |  | +            goodsGroups = musicGroupSubjectGoodsGroupService.findGoodsGroupByIds(registerPayDto.getGoodsGroupIds());
 | 
	
		
			
				|  |  | +            for (MusicGroupSubjectGoodsGroup goodsGroup : goodsGroups) {
 | 
	
		
			
				|  |  | +                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("商品价格不符");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        IdWorker idWorker = new IdWorker(0, 0);
 | 
	
		
			
				|  |  | +        String orderNo = idWorker.nextId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Map payMap = payService.getPayMap(orderAmount, orderNo, "https://pay.dayaedu.com/api/yqpay/notify", "http://dev.dayaedu.com", "测试订单", "测试订单");
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        studentRegistrationService.addOrder(userId, amount, orderNo, "双乾", courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId().toString());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        return succeed(payMap);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @ApiOperation(value = "乐团报名重新支付")
 | 
	
		
			
				|  |  | +    @PostMapping("/rePay")
 | 
	
		
			
				|  |  | +    @ApiImplicitParams({@ApiImplicitParam(name = "registerPayDto", value = "支付信息", required = true, dataType = "Integer")})
 | 
	
		
			
				|  |  | +    public HttpResponseResult rePay(@RequestBody RegisterPayDto registerPayDto) throws Exception {
 | 
	
		
			
				|  |  | +        SysUser sysUser = sysUserFeignService.queryUserInfo();
 | 
	
		
			
				|  |  | +        Integer userId = sysUser.getId();
 | 
	
		
			
				|  |  | +        StudentRegistration studentRegistration = studentRegistrationService.get(registerPayDto.getRegisterId().longValue());
 | 
	
		
			
				|  |  | +        if (!studentRegistration.getUserId().equals(userId)) {
 | 
	
		
			
				|  |  | +            return failed("报名信息有误,请核查");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        StudentPaymentOrder ApplyOrder = studentPaymentOrderService.findMusicGroupApplyOrderByStatus(userId, studentRegistration.getMusicGroupId().toString(), DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +        if (ApplyOrder != null) {
 | 
	
		
			
				|  |  | +            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");
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -146,7 +236,7 @@ public class MusicGroupController extends BaseController {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          Map payMap = payService.getPayMap(orderAmount, orderNo, "https://pay.dayaedu.com/api/yqpay/notify", "http://dev.dayaedu.com", "测试订单", "测试订单");
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        studentRegistrationService.addOrder(userId, amount, orderNo, "双乾", courseFee, goodsGroups, goodsList, otherGoodsList);
 | 
	
		
			
				|  |  | +        studentRegistrationService.addOrder(userId, amount, orderNo, "双乾", courseFee, goodsGroups, goodsList, otherGoodsList, studentRegistration.getMusicGroupId().toString());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return succeed(payMap);
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -165,6 +255,7 @@ public class MusicGroupController extends BaseController {
 | 
	
		
			
				|  |  |      @GetMapping("/getOrderStatus")
 | 
	
		
			
				|  |  |      @ApiImplicitParams({@ApiImplicitParam(name = "orderNo", value = "订单号", required = true, dataType = "String")})
 | 
	
		
			
				|  |  |      public HttpResponseResult getOrderStatus(String orderNo) {
 | 
	
		
			
				|  |  | -        return succeed(orderNo);
 | 
	
		
			
				|  |  | +        StudentPaymentOrder order = studentPaymentOrderService.findOrderByOrderNo(orderNo);
 | 
	
		
			
				|  |  | +        return succeed(order);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  }
 |