|
@@ -251,6 +251,92 @@ public class StudentRepairServiceImpl extends BaseServiceImpl<Integer, StudentRe
|
|
}
|
|
}
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
+ @Transactional(rollbackFor = Exception.class,isolation = Isolation.SERIALIZABLE)
|
|
|
|
+ public Map studentPaymentGoodsOrder(Integer goodsSellId) throws Exception {
|
|
|
|
+ StudentGoodsSell studentGoodsSell = studentGoodsSellDao.get(goodsSellId);
|
|
|
|
+ Integer studentId = studentGoodsSell.getUserId();
|
|
|
|
+ studentDao.lockUser(studentId);
|
|
|
|
+ SysUser student = sysUserFeignService.queryUserById(studentId);
|
|
|
|
+ List<GoodsSellDto> goodsSellDtos = studentGoodsSell.getGoodsSellDtos();
|
|
|
|
+ List<Integer> goodsIds = goodsSellDtos.stream().map(e -> e.getGoodsId()).collect(Collectors.toList());
|
|
|
|
+
|
|
|
|
+ Map<Integer, BigDecimal> map = getMap("goods", "id_", "market_price_", goodsIds, Integer.class, BigDecimal.class);
|
|
|
|
+ for (GoodsSellDto goodsSellDto : goodsSellDtos) {
|
|
|
|
+ goodsSellDto.setGoodsPrice(map.get(goodsSellDto.getGoodsId()));
|
|
|
|
+ goodsSellDto.setTotalGoodsPrice(map.get(goodsSellDto.getGoodsId()).multiply(new BigDecimal(goodsSellDto.getGoodsNum())));
|
|
|
|
+ }
|
|
|
|
+ Map<Integer, List<GoodsSellDto>> goodsMap = goodsSellDtos.stream().collect(Collectors.groupingBy(GoodsSellDto::getGoodsId));
|
|
|
|
+ BigDecimal amount = BigDecimal.ZERO;
|
|
|
|
+ for (Integer id : goodsIds) {
|
|
|
|
+ GoodsSellDto goodsSellDto = goodsMap.get(id).get(0);
|
|
|
|
+ amount = amount.add(goodsSellDto.getTotalGoodsPrice());
|
|
|
|
+ }
|
|
|
|
+ amount = amount.subtract(studentGoodsSell.getMarketAmount());
|
|
|
|
+ if(amount.signum() < 0){
|
|
|
|
+ throw new BizException("操作失败:订单金额异常");
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ StudentPaymentOrder studentPaymentOrder = new StudentPaymentOrder();
|
|
|
|
+ studentPaymentOrder.setUserId(studentId);
|
|
|
|
+ studentPaymentOrder.setGroupType(GroupType.GOODS_SELL);
|
|
|
|
+ studentPaymentOrder.setOrderNo(studentGoodsSell.getOrderNo());
|
|
|
|
+ studentPaymentOrder.setType(OrderTypeEnum.GOODS_SELL);
|
|
|
|
+ studentPaymentOrder.setExpectAmount(amount);
|
|
|
|
+ studentPaymentOrder.setActualAmount(amount);
|
|
|
|
+ studentPaymentOrder.setStatus(DealStatusEnum.ING);
|
|
|
|
+ studentPaymentOrder.setOrganId(student.getOrganId());
|
|
|
|
+ studentPaymentOrder.setRoutingOrganId(student.getOrganId());
|
|
|
|
+ studentPaymentOrderService.insert(studentPaymentOrder);
|
|
|
|
+
|
|
|
|
+ studentPaymentOrder.setVersion(0);
|
|
|
|
+ BigDecimal balance = BigDecimal.ZERO;
|
|
|
|
+ if (studentGoodsSell.getIsUseBalancePayment() && amount.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
+ SysUserCashAccount userCashAccount = sysUserCashAccountService.getLocked(studentId);
|
|
|
|
+ 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(studentId, balance.negate(), PlatformCashAccountDetailTypeEnum.PAY_FEE, "商品销售");
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
|
+ studentPaymentOrder.setVersion(studentPaymentOrder.getVersion() + 1);
|
|
|
|
+
|
|
|
|
+ if (amount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
+ studentPaymentRouteOrderService.addRouteOrder(studentGoodsSell.getOrderNo(), student.getOrganId(), balance);
|
|
|
|
+ Map<String, String> notifyMap = new HashMap<>();
|
|
|
|
+ notifyMap.put("tradeState", "1");
|
|
|
|
+ notifyMap.put("merOrderNo", studentPaymentOrder.getOrderNo());
|
|
|
|
+ studentPaymentOrderService.updateOrder(notifyMap);
|
|
|
|
+ notifyMap.put("orderNo", studentGoodsSell.getOrderNo());
|
|
|
|
+ return notifyMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ String baseApiUrl = sysConfigDao.findConfigValue(SysConfigService.BASE_API_URL);
|
|
|
|
+
|
|
|
|
+ Map payMap = payService.getPayMap(
|
|
|
|
+ amount,
|
|
|
|
+ balance,
|
|
|
|
+ studentGoodsSell.getOrderNo(),
|
|
|
|
+ baseApiUrl + "/api-student/studentOrder/notify",
|
|
|
|
+ baseApiUrl + "/api-student/studentOrder/paymentResult?type=edu&orderNo=" + studentGoodsSell.getOrderNo(),
|
|
|
|
+ "商品销售",
|
|
|
|
+ "商品销售",
|
|
|
|
+ student.getOrganId(),
|
|
|
|
+ "goodsSell"
|
|
|
|
+ );
|
|
|
|
+
|
|
|
|
+ studentPaymentOrder.setMerNos((String) payMap.get("routingMerNos"));
|
|
|
|
+ studentPaymentOrder.setPaymentChannel((String) payMap.get("type"));
|
|
|
|
+ studentPaymentOrderService.update(studentPaymentOrder);
|
|
|
|
+ return payMap;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @Override
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
public Map addRepair(StudentRepair repairInfo) throws Exception {
|
|
public Map addRepair(StudentRepair repairInfo) throws Exception {
|
|
studentDao.lockUser(repairInfo.getEmployeeId());
|
|
studentDao.lockUser(repairInfo.getEmployeeId());
|