|  | @@ -1,5 +1,6 @@
 | 
	
		
			
				|  |  |  package com.ym.mec.biz.service.impl;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.dao.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.entity.*;
 | 
	
		
			
				|  |  |  import com.ym.mec.biz.dal.enums.*;
 | 
	
	
		
			
				|  | @@ -8,12 +9,14 @@ import com.ym.mec.common.dal.BaseDAO;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.exception.BizException;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.IdGeneratorService;
 | 
	
		
			
				|  |  |  import com.ym.mec.common.service.impl.BaseServiceImpl;
 | 
	
		
			
				|  |  | +import com.ym.mec.thirdparty.message.MessageSenderPluginContext;
 | 
	
		
			
				|  |  |  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;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  @Service
 | 
	
		
			
				|  |  |  public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectChange> implements SubjectChangeService {
 | 
	
	
		
			
				|  | @@ -42,6 +45,10 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
 | 
	
		
			
				|  |  |      private MusicGroupDao musicGroupDao;
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private SellOrderDao sellOrderDao;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysUserCashAccountDetailService sysUserCashAccountDetailService;
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private SysMessageService sysMessageService;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public BaseDAO<Integer, SubjectChange> getDAO() {
 | 
	
	
		
			
				|  | @@ -265,4 +272,89 @@ public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectCh
 | 
	
		
			
				|  |  |          subjectChange.setOriginalCost(orderSellCost == null ? BigDecimal.ZERO : orderSellCost);
 | 
	
		
			
				|  |  |          return subjectChange;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Override
 | 
	
		
			
				|  |  | +    public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
 | 
	
		
			
				|  |  | +        Date nowDate = new Date();
 | 
	
		
			
				|  |  | +        //更新订单信息
 | 
	
		
			
				|  |  | +        studentPaymentOrder.setUpdateTime(nowDate);
 | 
	
		
			
				|  |  | +        int updateCount = studentPaymentOrderService.update(studentPaymentOrder);
 | 
	
		
			
				|  |  | +        if (updateCount <= 0) {
 | 
	
		
			
				|  |  | +            throw new BizException("订单更新失败");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        //更新维修单信息
 | 
	
		
			
				|  |  | +        SubjectChange subjectChange = subjectChangeDao.get(Integer.parseInt(studentPaymentOrder.getMusicGroupId()));
 | 
	
		
			
				|  |  | +        if (subjectChange == null) {
 | 
	
		
			
				|  |  | +            throw new BizException("声部更换订单不存在");
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        if (!subjectChange.getStatus().equals(SubjectChangeStatusEnum.WAIT_PAY)) {
 | 
	
		
			
				|  |  | +            return true;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Integer userId = studentPaymentOrder.getUserId();
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        Map<Integer, String> map = new HashMap<>();
 | 
	
		
			
				|  |  | +        map.put(userId, userId.toString());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
 | 
	
		
			
				|  |  | +            subjectChange.setStatus(SubjectChangeStatusEnum.SUCCESSED);
 | 
	
		
			
				|  |  | +            subjectChange.setUpdateTime(nowDate);
 | 
	
		
			
				|  |  | +            if (this.update(subjectChange) <= 0) {
 | 
	
		
			
				|  |  | +                throw new BizException("维修单更新失败");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //插入交易明细
 | 
	
		
			
				|  |  | +            BigDecimal amount = studentPaymentOrder.getActualAmount();
 | 
	
		
			
				|  |  | +            SysUserCashAccount cashAccount = sysUserCashAccountService.get(userId);
 | 
	
		
			
				|  |  | +            //充值
 | 
	
		
			
				|  |  | +            SysUserCashAccountDetail rechargeDetail = new SysUserCashAccountDetail();
 | 
	
		
			
				|  |  | +            rechargeDetail.setAmount(amount);
 | 
	
		
			
				|  |  | +            rechargeDetail.setBalance(cashAccount.getBalance().add(amount));
 | 
	
		
			
				|  |  | +            rechargeDetail.setComment("缴费前充值");
 | 
	
		
			
				|  |  | +            rechargeDetail.setCreateTime(nowDate);
 | 
	
		
			
				|  |  | +            rechargeDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +            rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
 | 
	
		
			
				|  |  | +            rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
 | 
	
		
			
				|  |  | +            rechargeDetail.setUpdateTime(nowDate);
 | 
	
		
			
				|  |  | +            rechargeDetail.setUserId(userId);
 | 
	
		
			
				|  |  | +            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
 | 
	
		
			
				|  |  | +            rechargeDetail.setComAmount(studentPaymentOrder.getComAmount());
 | 
	
		
			
				|  |  | +            rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount());
 | 
	
		
			
				|  |  | +            sysUserCashAccountDetailService.insert(rechargeDetail);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            //缴费
 | 
	
		
			
				|  |  | +            SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
 | 
	
		
			
				|  |  | +            paymentDetail.setAmount(amount.negate());
 | 
	
		
			
				|  |  | +            paymentDetail.setBalance(cashAccount.getBalance());
 | 
	
		
			
				|  |  | +            paymentDetail.setComment("乐器维修");
 | 
	
		
			
				|  |  | +            paymentDetail.setCreateTime(nowDate);
 | 
	
		
			
				|  |  | +            paymentDetail.setStatus(DealStatusEnum.SUCCESS);
 | 
	
		
			
				|  |  | +            paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
 | 
	
		
			
				|  |  | +            paymentDetail.setType(PlatformCashAccountDetailTypeEnum.PAY_FEE);
 | 
	
		
			
				|  |  | +            paymentDetail.setUpdateTime(nowDate);
 | 
	
		
			
				|  |  | +            paymentDetail.setUserId(userId);
 | 
	
		
			
				|  |  | +            rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
 | 
	
		
			
				|  |  | +            if (studentPaymentOrder.getComAmount() != null) {
 | 
	
		
			
				|  |  | +                rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
 | 
	
		
			
				|  |  | +                rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            sysUserCashAccountDetailService.insert(paymentDetail);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
 | 
	
		
			
				|  |  | +            subjectChange.setStatus(SubjectChangeStatusEnum.WAIT_PAY);
 | 
	
		
			
				|  |  | +            subjectChange.setUpdateTime(nowDate);
 | 
	
		
			
				|  |  | +            if (this.update(subjectChange) <= 0) {
 | 
	
		
			
				|  |  | +                throw new BizException("声部更改订单更新失败");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
 | 
	
		
			
				|  |  | +                sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "声部更改支付失败");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +            sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_SPORADIC_PAYMENT_FAILED, map, null, 0, "", "STUDENT",
 | 
	
		
			
				|  |  | +                    studentPaymentOrder.getActualAmount(), "声部更换");
 | 
	
		
			
				|  |  | +            return false;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        return true;
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  |  }
 |