|
@@ -1,27 +1,31 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
import com.ym.mec.biz.dal.dao.StudentInstrumentDao;
|
|
|
import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentInstrument;
|
|
|
-import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
-import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
-import com.ym.mec.biz.dal.enums.DealStatusEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.GroupType;
|
|
|
-import com.ym.mec.biz.dal.enums.OrderTypeEnum;
|
|
|
-import com.ym.mec.biz.dal.enums.PlatformCashAccountDetailTypeEnum;
|
|
|
+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.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.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
+import org.springframework.transaction.annotation.Propagation;
|
|
|
+import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
import java.util.Map;
|
|
|
+import java.util.stream.Collectors;
|
|
|
|
|
|
@Service
|
|
|
public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentInstrument> implements StudentInstrumentService {
|
|
@@ -41,7 +45,9 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
@Autowired
|
|
|
private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
@Autowired
|
|
|
- private StudentDao studentDao;
|
|
|
+ private ContractService contractService;
|
|
|
+
|
|
|
+ private final Logger logger = LoggerFactory.getLogger(this.getClass());
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, StudentInstrument> getDAO() {
|
|
@@ -49,6 +55,7 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception {
|
|
|
StudentInstrument studentInstrument = studentInstrumentDao.get(id);
|
|
|
if (studentInstrument == null) {
|
|
@@ -134,4 +141,118 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
return payMap;
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public Boolean orderCallback(StudentPaymentOrder studentPaymentOrder) {
|
|
|
+ Date nowDate = new Date();
|
|
|
+ //更新订单信息
|
|
|
+ studentPaymentOrder.setUpdateTime(nowDate);
|
|
|
+ int updateCount = studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ if (updateCount <= 0) {
|
|
|
+ throw new BizException("订单更新失败");
|
|
|
+ }
|
|
|
+ //更新维修单信息
|
|
|
+ StudentInstrument studentInstrument = get(Long.parseLong(studentPaymentOrder.getMusicGroupId()));
|
|
|
+ if (studentInstrument == null) {
|
|
|
+ throw new BizException("乐保信息不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer userId = studentPaymentOrder.getUserId();
|
|
|
+
|
|
|
+ Map<Integer, String> map = new HashMap<>();
|
|
|
+ map.put(userId, userId.toString());
|
|
|
+
|
|
|
+ if (studentPaymentOrder.getStatus() == DealStatusEnum.SUCCESS) {
|
|
|
+ try {
|
|
|
+ contractService.transferProduceContract(userId, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("产品协议生成失败", e);
|
|
|
+ }
|
|
|
+
|
|
|
+ repairInfo.setPayStatus(2);
|
|
|
+ repairInfo.setUpdateTime(nowDate);
|
|
|
+ if (this.update(repairInfo) <= 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 (StringUtils.isNotBlank(repairInfo.getGoodsJson())) {
|
|
|
+ List<Goods> goods = JSONObject.parseArray(repairInfo.getGoodsJson(), Goods.class);
|
|
|
+ List<Integer> goodsIds = goods.stream().map(Goods::getId).collect(Collectors.toList());
|
|
|
+ if (goodsIds.size() > 0) {
|
|
|
+ sellOrderService.addSellOrder(studentPaymentOrder.getId(), null, goodsIds, studentPaymentOrder.getExpectAmount(), studentPaymentOrder.getBalancePaymentAmount());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String imContent = repairInfo.getStudentName() + "学员您好,您的乐器维修已受理,我们会尽快完成保养维修";
|
|
|
+
|
|
|
+ if (repairInfo.getType().equals(1)) { //线上
|
|
|
+ imContent = repairInfo.getStudentName() + "学员您好,请尽快寄送乐器至维修点,我们会尽快完成保养维修\n" +
|
|
|
+ "联系人:" + repairInfo.getEmployeeName() + "(" + repairInfo.getEmployeePhone() + ")\n" +
|
|
|
+ "地址:" + repairInfo.getEmployeeAddress() + "";
|
|
|
+
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_ONLINE_PAYMENT_SUCCESS, map, null, 0, "1", "STUDENT",
|
|
|
+ repairInfo.getStudentName(), repairInfo.getEmployeeName(), repairInfo.getEmployeePhone(), repairInfo.getEmployeeAddress());
|
|
|
+ } else {
|
|
|
+ sysMessageService.batchSendMessage(MessageSenderPluginContext.MessageSender.JIGUANG, MessageTypeEnum.SMS_REPAIR_OFFLINE_PAYMENT_SUCCESS, map, null, 0, "1", "STUDENT",
|
|
|
+ repairInfo.getStudentName());
|
|
|
+ }
|
|
|
+ sysMessageService.sendNoAuthPrivateMessage(repairInfo.getEmployeeId().toString(), userId.toString(), imContent);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
|
+ repairInfo.setPayStatus(0);
|
|
|
+ repairInfo.setUpdateTime(nowDate);
|
|
|
+ if (this.update(repairInfo) <= 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 false;
|
|
|
+ }
|
|
|
}
|