|
@@ -1,17 +1,16 @@
|
|
|
package com.ym.mec.biz.service.impl;
|
|
|
|
|
|
-
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
-import com.alibaba.fastjson.TypeReference;
|
|
|
+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.*;
|
|
|
-import com.ym.mec.biz.dal.enums.GoodsType;
|
|
|
-import com.ym.mec.biz.dal.enums.KitGroupPurchaseTypeEnum;
|
|
|
+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.service.PayService;
|
|
|
-import com.ym.mec.biz.service.StudentInstrumentService;
|
|
|
-import com.ym.mec.biz.service.SysUserCashAccountService;
|
|
|
+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;
|
|
@@ -20,8 +19,9 @@ import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.*;
|
|
|
-import java.util.stream.Collectors;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Service
|
|
|
public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentInstrument> implements StudentInstrumentService {
|
|
@@ -36,6 +36,12 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
private PayService payService;
|
|
|
@Autowired
|
|
|
private SysConfigDao sysConfigDao;
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentRouteOrderService studentPaymentRouteOrderService;
|
|
|
+ @Autowired
|
|
|
+ private StudentPaymentOrderService studentPaymentOrderService;
|
|
|
+ @Autowired
|
|
|
+ private StudentDao studentDao;
|
|
|
|
|
|
@Override
|
|
|
public BaseDAO<Long, StudentInstrument> getDAO() {
|
|
@@ -43,7 +49,7 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
- public Map pay(Long id,BigDecimal amount) {
|
|
|
+ public Map pay(Long id, BigDecimal amount, boolean isUseBalance) throws Exception {
|
|
|
StudentInstrument studentInstrument = studentInstrumentDao.get(id);
|
|
|
if (studentInstrument == null) {
|
|
|
throw new BizException("所选乐器不存在,请核查");
|
|
@@ -51,7 +57,6 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
Integer userId = studentInstrument.getStudentId();
|
|
|
BigDecimal orderAmount = new BigDecimal(400);
|
|
|
|
|
|
-
|
|
|
if (amount.compareTo(orderAmount) != 0) {
|
|
|
throw new BizException("商品价格不符");
|
|
|
}
|
|
@@ -59,10 +64,10 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
String orderNo = idGeneratorService.generatorId("payment") + "";
|
|
|
|
|
|
String channelType = "";
|
|
|
-
|
|
|
Date date = new Date();
|
|
|
+
|
|
|
BigDecimal balance = BigDecimal.ZERO;
|
|
|
- if (registerPayDto.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ if (isUseBalance && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(userId);
|
|
|
if (userCashAccount == null) {
|
|
|
throw new BizException("用户账户找不到");
|
|
@@ -70,23 +75,32 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
if (userCashAccount.getBalance() != null && userCashAccount.getBalance().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
balance = amount.compareTo(userCashAccount.getBalance()) >= 0 ? userCashAccount.getBalance() : amount;
|
|
|
amount = amount.subtract(balance);
|
|
|
- studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
- studentPaymentOrder.setActualAmount(amount);
|
|
|
- studentPaymentOrder.setBalancePaymentAmount(balance);
|
|
|
- sysUserCashAccountService.updateBalance(userId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐团报名");
|
|
|
+ sysUserCashAccountService.updateBalance(userId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "乐保购买");
|
|
|
}
|
|
|
}
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
+
|
|
|
studentPaymentOrder.setPaymentChannel("BALANCE");
|
|
|
+ studentPaymentOrder.setUserId(userId);
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.MAINTENANCE);
|
|
|
+ studentPaymentOrder.setOrderNo(orderNo);
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.MAINTENANCE);
|
|
|
+ studentPaymentOrder.setExpectAmount(amount);
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
+ studentPaymentOrder.setBalancePaymentAmount(balance);
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
+ studentPaymentOrder.setMusicGroupId(studentInstrument.getId().toString());
|
|
|
studentPaymentOrder.setRemitFee(BigDecimal.ZERO);
|
|
|
studentPaymentOrder.setCourseRemitFee(BigDecimal.ZERO);
|
|
|
- studentPaymentOrder.setOrganId(musicGroup.getOrganId());
|
|
|
- studentPaymentOrder.setRoutingOrganId(musicGroup.getOrganId());
|
|
|
+ studentPaymentOrder.setOrganId(studentInstrument.getOrganId());
|
|
|
+ studentPaymentOrder.setRoutingOrganId(studentInstrument.getOrganId());
|
|
|
+ studentPaymentOrder.setCreateTime(date);
|
|
|
studentPaymentOrder.setUpdateTime(date);
|
|
|
- studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
- studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
|
|
|
if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- studentPaymentRouteOrderService.addRouteOrder(orderNo, musicGroup.getOrganId(), balance);
|
|
|
+ studentPaymentRouteOrderService.addRouteOrder(orderNo, studentInstrument.getOrganId(), balance);
|
|
|
Map<String, String> notifyMap = new HashMap<>();
|
|
|
notifyMap.put("tradeState", "1");
|
|
|
notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
|
|
@@ -109,11 +123,11 @@ public class StudentInstrumentServiceImpl extends BaseServiceImpl<Long, StudentI
|
|
|
baseApiUrl + "/api-student/studentOrder/paymentResult?orderNo=" + orderNo,
|
|
|
orderSubject,
|
|
|
orderSubject,
|
|
|
- musicGroup.getOrganId(),
|
|
|
+ studentInstrument.getOrganId(),
|
|
|
receiver
|
|
|
);
|
|
|
|
|
|
- studentPaymentOrder.setOrganId(musicGroup.getOrganId());
|
|
|
+ studentPaymentOrder.setOrganId(studentInstrument.getOrganId());
|
|
|
studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
studentPaymentOrder.setUpdateTime(date);
|