|
@@ -1471,6 +1471,168 @@ public class StudentPaymentOrderServiceImpl extends BaseServiceImpl<Long, Studen
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
+ public void mallBuyOrderCallback1(Long orderId) {
|
|
|
+ Date nowDate = new Date();
|
|
|
+ StudentPaymentOrder studentPaymentOrder = studentPaymentOrderService.get(orderId);
|
|
|
+
|
|
|
+ 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, studentPaymentOrder.getType());
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("产品协议生成失败", e);
|
|
|
+ }
|
|
|
+ Long paymentOrderId = studentPaymentOrder.getId();
|
|
|
+ Integer organId = studentPaymentOrder.getOrganId();
|
|
|
+ String transNo = studentPaymentOrder.getTransNo();
|
|
|
+ String orderNo = studentPaymentOrder.getOrderNo();
|
|
|
+ BigDecimal balancePaymentAmount = studentPaymentOrder.getBalancePaymentAmount();
|
|
|
+ //解析student_goods_sell字段goodsJson,生成订单详情和sellOrder
|
|
|
+ StudentGoodsSellDto studentGoodsSellDto = studentGoodsSellDao.getStudentGoodsSellDto(studentPaymentOrder.getOrderNo());
|
|
|
+ if(Objects.nonNull(studentGoodsSellDto)){
|
|
|
+ if(StringUtils.isNotEmpty(studentGoodsSellDto.getGoodsJson())){
|
|
|
+ JSONObject jsonObject = JSON.parseObject(studentGoodsSellDto.getGoodsJson());
|
|
|
+ String orderItemList = jsonObject.getString("orderItemList");
|
|
|
+ if(StringUtils.isNotEmpty(orderItemList)){
|
|
|
+ List<GoodsOrderItemVO> goodsOrderItemVOS = JSON.parseArray(orderItemList, GoodsOrderItemVO.class);
|
|
|
+ long count = goodsOrderItemVOS.stream().filter(e -> StringUtils.isEmpty(e.getOrderSn())).count();
|
|
|
+ //如果有空的商品货号,不处理
|
|
|
+ if(count == 0l){
|
|
|
+ List<String> productSns = goodsOrderItemVOS.stream().map(e -> e.getProductSn()).distinct().collect(Collectors.toList());
|
|
|
+ List<Goods> goodsList = goodsDao.findBySns(productSns);
|
|
|
+ //如果有不匹配的商品货号,不处理
|
|
|
+ if(CollectionUtils.isEmpty(goodsList) || goodsList.size() < productSns.size()){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ Map<String, Goods> goodsSnMap = goodsList.stream().collect(Collectors.groupingBy(e -> e.getSn(),
|
|
|
+ Collectors.collectingAndThen(Collectors.toList(), v -> v.get(0))));
|
|
|
+ List<StudentPaymentOrderDetail> orderDetails = new ArrayList<>();
|
|
|
+ List<SellOrder> sellOrders = new ArrayList<>();
|
|
|
+ BigDecimal subjectBalance = balancePaymentAmount;
|
|
|
+ for (int i = 0; i < goodsOrderItemVOS.size(); i++) {
|
|
|
+ GoodsOrderItemVO goodsVo = goodsOrderItemVOS.get(i);
|
|
|
+ Goods goods = goodsSnMap.get(goodsVo.getProductSn());
|
|
|
+ for (int j = 0; j < goodsVo.getProductQuantity(); j++) {
|
|
|
+ StudentPaymentOrderDetail detail = new StudentPaymentOrderDetail();
|
|
|
+ detail.setType(OrderDetailTypeEnum.valueOf(goods.getType() == GoodsType.INSTRUMENT?"MUSICAL":goods.getType().getCode()));
|
|
|
+ detail.setGoodsIdList(goods.getId().toString());
|
|
|
+ detail.setPrice(goodsVo.getRealAmount());
|
|
|
+ detail.setRemitFee(BigDecimal.ZERO);
|
|
|
+ detail.setPaymentOrderId(paymentOrderId);
|
|
|
+ orderDetails.add(detail);
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal totalAmount = goodsVo.getRealAmount().multiply(new BigDecimal(goodsVo.getProductQuantity()));
|
|
|
+ SellOrder sellOrder = new SellOrder();
|
|
|
+ sellOrder.setOrganId(organId);
|
|
|
+ sellOrder.setTransNo(transNo);
|
|
|
+ sellOrder.setOrderId(paymentOrderId);
|
|
|
+ sellOrder.setOrderNo(orderNo);
|
|
|
+ sellOrder.setExpectAmount(totalAmount);
|
|
|
+ if(goodsOrderItemVOS.size() - 1 == i){
|
|
|
+ sellOrder.setBalanceAmount(subjectBalance);
|
|
|
+ }else {
|
|
|
+ //获取比例
|
|
|
+ BigDecimal ratioAmount = totalAmount.divide(studentGoodsSellDto.getExpectAmount(), 6, BigDecimal.ROUND_HALF_UP);
|
|
|
+ BigDecimal multiply = balancePaymentAmount.multiply(ratioAmount).setScale(2, BigDecimal.ROUND_HALF_UP);
|
|
|
+ subjectBalance = subjectBalance.subtract(multiply);
|
|
|
+ sellOrder.setBalanceAmount(multiply);
|
|
|
+ }
|
|
|
+ sellOrder.setActualAmount(totalAmount.subtract(sellOrder.getBalanceAmount()));
|
|
|
+
|
|
|
+ AccountType accountType = sysPaymentConfigService.checkAccountType(PaymentChannelEnum.valueOf(studentPaymentOrder.getPaymentChannel()), studentPaymentOrder.getMerNos(), studentPaymentOrder.getTenantId());
|
|
|
+ GoodsProcurement goodsProcurement = null;
|
|
|
+ if(StockType.INTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.INTERNAL.equals(accountType))){
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithStockSurplusProcurement(goods.getId());
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurement.setStockSoldNum(new AtomicInteger(goodsProcurement.getStockSoldNum()).incrementAndGet());
|
|
|
+ }
|
|
|
+ }else if(StockType.EXTERNAL.equals(goods.getStockType())||(StockType.ALL.equals(goods.getStockType())&&AccountType.EXTERNAL.equals(accountType))){
|
|
|
+ goodsProcurement = goodsProcurementDao.getWithTaxStockSurplusProcurement(goods.getId());
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurement.setTaxStockSoldNum(new AtomicInteger(goodsProcurement.getTaxStockSoldNum()).incrementAndGet());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //如果有采购清单,初始化总部成本价
|
|
|
+ if(Objects.nonNull(goodsProcurement)){
|
|
|
+ goodsProcurementDao.update(goodsProcurement);
|
|
|
+ sellOrder.setBatchNo(goodsProcurement.getBatchNo());
|
|
|
+ sellOrder.setSellCost(goodsProcurement.getDiscountPrice());
|
|
|
+ Map<String, BigDecimal> CostMap = new HashMap<>();
|
|
|
+ CostMap.put("sellCost", goodsProcurement.getDiscountPrice());
|
|
|
+ if (Objects.nonNull(goodsProcurement.getAgreeCostPrice())) {
|
|
|
+ CostMap.put("SellCost2", goodsProcurement.getAgreeCostPrice());
|
|
|
+ }
|
|
|
+ sellOrder.setSellCost2(JSON.toJSONString(CostMap));
|
|
|
+ sellOrder.setBatchNo(goodsProcurement.getBatchNo());
|
|
|
+ sellOrder.setOrganSellCost(goods.getOrganCostPrice());
|
|
|
+ }
|
|
|
+ sellOrder.setNum(goodsVo.getProductQuantity());
|
|
|
+ sellOrder.setUserId(userId);
|
|
|
+ sellOrder.setPaymentChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
+ sellOrder.setMerNo(studentPaymentOrder.getMerNos());
|
|
|
+ sellOrder.setStockType(goods.getStockType());
|
|
|
+ sellOrder.setAccountType(accountType);
|
|
|
+ sellOrder.setStatus(SellStatus.NORMAL);
|
|
|
+ sellOrder.setSellTime(studentPaymentOrder.getPayTime());
|
|
|
+ sellOrder.setGoodsId(goods.getId());
|
|
|
+ sellOrder.setGoodsName(goods.getName());
|
|
|
+ sellOrder.setType(SellTypeEnum.valueOf(goods.getType().getCode()));
|
|
|
+ sellOrders.add(sellOrder);
|
|
|
+ }
|
|
|
+ sellOrderDao.batchInsert(sellOrders);
|
|
|
+ studentPaymentOrderDetailService.batchAdd(orderDetails);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ // 完全余额支付 不生成下面的记录
|
|
|
+ if (BigDecimal.ZERO.compareTo(studentPaymentOrder.getActualAmount()) == 0) return;
|
|
|
+
|
|
|
+ //插入交易明细
|
|
|
+ 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.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ rechargeDetail.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
+ rechargeDetail.setType(PlatformCashAccountDetailTypeEnum.RECHARGE);
|
|
|
+ rechargeDetail.setUserId(userId);
|
|
|
+ rechargeDetail.setChannel(studentPaymentOrder.getPaymentChannel());
|
|
|
+ if (studentPaymentOrder.getComAmount() != null) {
|
|
|
+ rechargeDetail.setComAmount(studentPaymentOrder.getComAmount().negate());
|
|
|
+ rechargeDetail.setPerAmount(studentPaymentOrder.getPerAmount().negate());
|
|
|
+ }
|
|
|
+ sysUserCashAccountDetailService.insert(rechargeDetail);
|
|
|
+ //缴费
|
|
|
+ SysUserCashAccountDetail paymentDetail = new SysUserCashAccountDetail();
|
|
|
+ paymentDetail.setAmount(amount.negate());
|
|
|
+ paymentDetail.setBalance(cashAccount.getBalance());
|
|
|
+ paymentDetail.setComment("商品销售");
|
|
|
+ paymentDetail.setStatus(DealStatusEnum.SUCCESS);
|
|
|
+ paymentDetail.setTransNo(studentPaymentOrder.getTransNo());
|
|
|
+ paymentDetail.setType(PlatformCashAccountDetailTypeEnum.GOODS_SELL);
|
|
|
+ paymentDetail.setUserId(userId);
|
|
|
+ sysUserCashAccountDetailService.insert(paymentDetail);
|
|
|
+ } else if (studentPaymentOrder.getStatus() == DealStatusEnum.CLOSE || studentPaymentOrder.getStatus() == DealStatusEnum.FAILED) {
|
|
|
+
|
|
|
+ if (studentPaymentOrder.getBalancePaymentAmount() != null && studentPaymentOrder.getBalancePaymentAmount().compareTo(BigDecimal.ZERO) > 0) {
|
|
|
+ sysUserCashAccountService.updateBalance(studentPaymentOrder.getUserId(), studentPaymentOrder.getBalancePaymentAmount(), PlatformCashAccountDetailTypeEnum.REFUNDS, "商城购买支付失败");
|
|
|
+ }
|
|
|
+ sysCouponCodeService.quit(studentPaymentOrder.getCouponCodeId());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional
|
|
|
public void mallSaveOrderInfo(MallCreateOrderModel model) {
|
|
|
|
|
|
StudentGoodsSell studentGoodsSell = studentGoodsSellDao.findByOrderNo(model.getOrderNo());
|