|  | @@ -9,6 +9,7 @@ import com.ym.mec.biz.dal.dao.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.BasicUserDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.GoodsSellDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dto.RepairGoodsDto;
 | 
	
		
			
				|  |  | +import com.ym.mec.biz.dal.dto.SysCouponCodeDto;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.page.RepairStudentQueryInfo;
 | 
	
	
		
			
				|  | @@ -79,7 +80,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private StudentGoodsSellService studentGoodsSellService;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  | -    private SysCouponCodeDao sysCouponCodeDao;
 | 
	
		
			
				|  |  | +    private SysCouponCodeService sysCouponCodeService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      private final Logger logger = LoggerFactory.getLogger(this.getClass());
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -147,10 +148,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |                      sysUserCashAccountService.updateBalance(orderByOrderNo.getUserId(), orderByOrderNo.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "关闭订单");
 | 
	
		
			
				|  |  |                  }
 | 
	
		
			
				|  |  |                  //退优惠券
 | 
	
		
			
				|  |  | -                String couponCodeId = orderByOrderNo.getCouponCodeId();
 | 
	
		
			
				|  |  | -                if(StringUtils.isNotEmpty(couponCodeId)){
 | 
	
		
			
				|  |  | -                    sysCouponCodeDao.quit(couponCodeId);
 | 
	
		
			
				|  |  | -                }
 | 
	
		
			
				|  |  | +                sysCouponCodeService.quit(orderByOrderNo.getCouponCodeId());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              StudentGoodsSell byOrderNo = studentGoodsSellDao.findByOrderNo(studentGoodsSell.getOrderNo());
 | 
	
		
			
				|  |  |              if (byOrderNo != null) {
 | 
	
	
		
			
				|  | @@ -209,6 +207,14 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |          if (amount.signum() < 0) {
 | 
	
		
			
				|  |  |              throw new BizException("操作失败:订单金额异常");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | +        //使用优惠券
 | 
	
		
			
				|  |  | +        StudentPaymentOrder studentPaymentOrder = sysCouponCodeService.use(studentGoodsSell.getCouponIdList(),amount);
 | 
	
		
			
				|  |  | +        amount = studentPaymentOrder.getActualAmount();
 | 
	
		
			
				|  |  | +        // 判断金额是否正确
 | 
	
		
			
				|  |  | +//        if (studentGoodsSell.getTotalAmount().compareTo(amount) != 0) {
 | 
	
		
			
				|  |  | +//            throw new BizException("非法请求");
 | 
	
		
			
				|  |  | +//        }
 | 
	
		
			
				|  |  | +        studentGoodsSell.setCouponMarketAmount(studentPaymentOrder.getCouponRemitFee());
 | 
	
		
			
				|  |  |          studentGoodsSell.setOrganId(student.getOrganId());
 | 
	
		
			
				|  |  |          studentGoodsSell.setTotalAmount(amount);
 | 
	
		
			
				|  |  |          studentGoodsSell.setGoodsJson(JSONObject.toJSONString(goodsSellDtos));
 | 
	
	
		
			
				|  | @@ -222,13 +228,10 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |              return repairInfoMap;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
 | 
	
		
			
				|  |  |          studentPaymentOrder.setUserId(studentId);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setOrderNo(orderNo);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setType(OrderTypeEnum.GOODS_SELL);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setExpectAmount(amount);
 | 
	
		
			
				|  |  | -        studentPaymentOrder.setActualAmount(amount);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setStatus(DealStatusEnum.ING);
 | 
	
		
			
				|  |  |          studentPaymentOrder.setOrganId(student.getOrganId());
 | 
	
		
			
				|  |  |          studentPaymentOrder.setRoutingOrganId(student.getOrganId());
 | 
	
	
		
			
				|  | @@ -762,6 +765,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |              if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  |                  sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "乐器购买支付失败");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | +            sysCouponCodeService.quit(studentPaymentOrder.getCouponCodeId());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -814,7 +818,7 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
 | 
	
		
			
				|  |  |          BigDecimal balancePaymentAmount = orderByOrderNo.getBalancePaymentAmount();
 | 
	
		
			
				|  |  |          //可用余额
 | 
	
		
			
				|  |  |          BigDecimal usableBalance = balancePaymentAmount;
 | 
	
		
			
				|  |  | -        BigDecimal marketAmount = studentGoodsSell.getMarketAmount();
 | 
	
		
			
				|  |  | +        BigDecimal marketAmount = studentGoodsSell.getMarketAmount().add(studentGoodsSell.getCouponMarketAmount());
 | 
	
		
			
				|  |  |          //可用减免金额
 | 
	
		
			
				|  |  |          BigDecimal usableMarketAmount = marketAmount;
 | 
	
		
			
				|  |  |          //包含减免余额的总金额
 |