|
@@ -0,0 +1,161 @@
|
|
|
+package com.ym.mec.biz.service.impl;
|
|
|
+
|
|
|
+import com.ym.mec.biz.dal.dao.GoodsDao;
|
|
|
+import com.ym.mec.biz.dal.dao.StudentDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SubjectChangeDao;
|
|
|
+import com.ym.mec.biz.dal.dao.SysConfigDao;
|
|
|
+import com.ym.mec.biz.dal.entity.StudentPaymentOrder;
|
|
|
+import com.ym.mec.biz.dal.entity.SubjectChange;
|
|
|
+import com.ym.mec.biz.dal.entity.SysUserCashAccount;
|
|
|
+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 org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.stereotype.Service;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@Service
|
|
|
+public class SubjectChangeServiceImpl extends BaseServiceImpl<Integer, SubjectChange> implements SubjectChangeService {
|
|
|
+
|
|
|
+ @Autowired
|
|
|
+ private SubjectChangeDao subjectChangeDao;
|
|
|
+ @Autowired
|
|
|
+ private GoodsDao goodsDao;
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
+ @Autowired
|
|
|
+ private IdGeneratorService idGeneratorService;
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
+ @Autowired
|
|
|
+ private SysUserCashAccountService sysUserCashAccountService;
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
|
|
|
+ @Autowired
|
|
|
+ private SysConfigDao sysConfigDao;
|
|
|
+ @Autowired
|
|
|
+ private PayService payService;
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public BaseDAO<Integer, SubjectChange> getDAO() {
|
|
|
+ return subjectChangeDao;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public SubjectChange getChangeInfo(Integer id) {
|
|
|
+ SubjectChange subjectChange = subjectChangeDao.getChangeInfo(id);
|
|
|
+ if (subjectChange == null) {
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+ if (subjectChange.getOriginalMusical() != null) {
|
|
|
+ subjectChange.setOriginalMusicalGoods(goodsDao.get(subjectChange.getOriginalMusical()));
|
|
|
+ }
|
|
|
+ if (subjectChange.getOriginalAccessories() != null) {
|
|
|
+ subjectChange.setChangeAccessoriesGoods(goodsDao.findGoodsByIds(subjectChange.getOriginalAccessories()));
|
|
|
+ }
|
|
|
+
|
|
|
+ if (subjectChange.getChangeMusical() != null) {
|
|
|
+ subjectChange.setChangeMusicalGoods(goodsDao.get(subjectChange.getChangeMusical()));
|
|
|
+ }
|
|
|
+ if (subjectChange.getChangeAccessories() != null) {
|
|
|
+ subjectChange.setChangeAccessoriesGoods(goodsDao.findGoodsByIds(subjectChange.getChangeAccessories()));
|
|
|
+ }
|
|
|
+
|
|
|
+ return subjectChange;
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public Map payChange(Integer id, BigDecimal viewAmount, Boolean isUseBalancePayment) throws Exception {
|
|
|
+ SubjectChange subjectChange = subjectChangeDao.get(id);
|
|
|
+ BigDecimal amount = subjectChange.getGoodsMargin().add(subjectChange.getCourseMargin());
|
|
|
+
|
|
|
+ Date date = new Date();
|
|
|
+ studentDao.lockUser(subjectChange.getStudentId());
|
|
|
+ subjectChange.setUpdateTime(date);
|
|
|
+ subjectChange.setStatus(SubjectChangeStatusEnum.ING);
|
|
|
+ if (subjectChangeDao.update(subjectChange) <= 0) {
|
|
|
+ throw new BizException("下单失败,请重试");
|
|
|
+ }
|
|
|
+
|
|
|
+ String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
+
|
|
|
+ String channelType = "";
|
|
|
+
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+ studentPaymentOrder.setUserId(subjectChange.getStudentId());
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.SUBJECT_CHANGE);
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.SUBJECT_CHANGE);
|
|
|
+ studentPaymentOrder.setExpectAmount(amount);
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setMusicGroupId(subjectChange.getId().toString());
|
|
|
+ studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrder.setOrganId(subjectChange.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(subjectChange.getOrganId());
|
|
|
+
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
+
|
|
|
+ BigDecimal balance = BigDecimal.ZERO;
|
|
|
+ if (isUseBalancePayment != null && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(subjectChange.getStudentId());
|
|
|
+ if (userCashAccount == null) {
|
|
|
+ throw new BizException("用户账户找不到");
|
|
|
+ }
|
|
|
+ if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
|
|
|
+ amount = amount.subtract(balance);
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(balance);
|
|
|
+ sysUserCashAccountService.updateBalance(subjectChange.getStudentId(), balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐器维修");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if (amount.compareTo(viewAmount) != 0) {
|
|
|
+ throw new BizException("价格异常");
|
|
|
+ }
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+
|
|
|
+ studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
|
|
|
+
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
+ studentPaymentRouteOrderService.addRouteOrder(orderNo, subjectChange.getOrganId(), studentPaymentOrder.getExpectAmount());
|
|
|
+ Map<String, String> notifyMap = new HashMap<>();
|
|
|
+ notifyMap.put("tradeState", "1");
|
|
|
+ notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
|
|
|
+ notifyMap.put("channelType", channelType);
|
|
|
+ notifyMap.put("orderNo", "");
|
|
|
+ studentPaymentOrderService.updateOrder(notifyMap);
|
|
|
+ notifyMap.put("orderNo", orderNo);
|
|
|
+ return notifyMap;
|
|
|
+ }
|
|
|
+
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
|
|
|
+
|
|
|
+ Map<String, Object> payMap = payService.getPayMap(
|
|
|
+ amount,
|
|
|
+ balance,
|
|
|
+ orderNo,
|
|
|
+ baseApiUrl + "/api-student/studentOrder/notify",
|
|
|
+ baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
+ "声部更换",
|
|
|
+ "声部更换",
|
|
|
+ subjectChange.getOrganId(),
|
|
|
+ "subjectChange"
|
|
|
+ );
|
|
|
+
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
+ studentPaymentOrder.setUpdateTime(date);
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
+ return payMap;
|
|
|
+ }
|
|
|
+}
|