|  | @@ -5,6 +5,7 @@ import cn.hutool.core.collection.CollUtil;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSON;
 | 
	
		
			
				|  |  |  import com.alibaba.fastjson.JSONObject;
 | 
	
		
			
				|  |  |  import com.github.pagehelper.PageHelper;
 | 
	
		
			
				|  |  | +import com.yonge.cooleshow.portal.dao.PortalProductDao;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.portal.dto.OrderPayReq;
 | 
	
		
			
				|  |  |  import com.yonge.cooleshow.portal.dto.OrderPayRes;
 | 
	
		
			
				|  |  |  import com.yonge.toolset.base.exception.BizException;
 | 
	
	
		
			
				|  | @@ -98,6 +99,13 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |      @Autowired
 | 
	
		
			
				|  |  |      private PaymentProperties paymentProperties;
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private PmsProductMapper pmsProductMapper;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    @Autowired
 | 
	
		
			
				|  |  | +    private PortalProductDao productDao;
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public ConfirmOrderResult generateConfirmOrder(List<Long> cartIds) {
 | 
	
		
			
				|  |  |          ConfirmOrderResult result = new ConfirmOrderResult();
 | 
	
	
		
			
				|  | @@ -190,8 +198,12 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          //计算order_item的实付金额
 | 
	
		
			
				|  |  |          handleRealAmount(orderItemList);
 | 
	
		
			
				|  |  | -        //进行库存锁定
 | 
	
		
			
				|  |  | -        lockStock(cartPromotionItemList);
 | 
	
		
			
				|  |  | +        //进行sku库存锁定
 | 
	
		
			
				|  |  | +        lockSkuStock(cartPromotionItemList);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 进行商品库存锁定
 | 
	
		
			
				|  |  | +        lockProductStock(cartPromotionItemList);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          //根据商品合计、运费、活动优惠、优惠券、积分计算应付金额
 | 
	
		
			
				|  |  |          OmsOrder order = new OmsOrder();
 | 
	
		
			
				|  |  |          StringBuilder cartIds = new StringBuilder();
 | 
	
	
		
			
				|  | @@ -253,7 +265,6 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          if (CollUtil.isNotEmpty(orderSettings)) {
 | 
	
		
			
				|  |  |              order.setAutoConfirmDay(orderSettings.get(0).getConfirmOvertime());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        // TODO: 2018/9/3 bill_*,delivery_*
 | 
	
		
			
				|  |  |          //插入order表和order_item表
 | 
	
		
			
				|  |  |          orderMapper.insert(order);
 | 
	
		
			
				|  |  |          for (OmsOrderItem orderItem : orderItemList) {
 | 
	
	
		
			
				|  | @@ -291,10 +302,37 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          orderMapper.updateByPrimaryKeySelective(order);
 | 
	
		
			
				|  |  |          //恢复所有下单商品的锁定库存,扣减真实库存
 | 
	
		
			
				|  |  |          OmsOrderDetail orderDetail = portalOrderDao.getDetail(orderId);
 | 
	
		
			
				|  |  | +        // 减sku库存
 | 
	
		
			
				|  |  |          int count = portalOrderDao.updateSkuStock(orderDetail.getOrderItemList());
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        // 减商品库存
 | 
	
		
			
				|  |  | +        updateProductStock(orderDetail);
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |          return count;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     *  减商品库存
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private void updateProductStock(OmsOrderDetail orderDetail) {
 | 
	
		
			
				|  |  | +        Map<Long, List<OmsOrderItem>> collect = orderDetail.getOrderItemList()
 | 
	
		
			
				|  |  | +                   .stream().collect(Collectors.groupingBy(OmsOrderItem::getProductId));
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +        List<ProductStock> productStockList = new ArrayList<>();
 | 
	
		
			
				|  |  | +        for (Map.Entry<Long, List<OmsOrderItem>> entry : collect.entrySet()) {
 | 
	
		
			
				|  |  | +            ProductStock stock = new ProductStock();
 | 
	
		
			
				|  |  | +            stock.setProductId(entry.getKey());
 | 
	
		
			
				|  |  | +            List<OmsOrderItem> value = entry.getValue();
 | 
	
		
			
				|  |  | +            if(CollectionUtils.isEmpty(value)) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            int sum = value.stream().mapToInt(OmsOrderItem::getProductQuantity).sum();
 | 
	
		
			
				|  |  | +            stock.setStock(sum);
 | 
	
		
			
				|  |  | +            productStockList.add(stock);
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +        productDao.updateProductStock(productStockList);
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  |      public Integer cancelTimeOutOrder() {
 | 
	
		
			
				|  |  |          Integer count = 0;
 | 
	
	
		
			
				|  | @@ -310,14 +348,14 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |              if (timeOutOrder.getStatus() == 0) {
 | 
	
		
			
				|  |  |                  payingOrderHandle(timeOutOrder);
 | 
	
		
			
				|  |  |              } else if (timeOutOrder.getStatus() == 6) {
 | 
	
		
			
				|  |  | -                cancelOrder(timeOutOrder.getId(), "超时取消");
 | 
	
		
			
				|  |  | +                cancelOrder(timeOutOrder.getId(), "超时取消", null);
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          return timeOutOrders.size();
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      @Override
 | 
	
		
			
				|  |  | -    public void cancelOrder(Long orderId, String message) {
 | 
	
		
			
				|  |  | +    public void cancelOrder(Long orderId, String message, PaymentCallBack data) {
 | 
	
		
			
				|  |  |          //查询未付款的取消订单
 | 
	
		
			
				|  |  |          OmsOrderExample example = new OmsOrderExample();
 | 
	
		
			
				|  |  |          example.createCriteria().andIdEqualTo(orderId).andDeleteStatusEqualTo(0);
 | 
	
	
		
			
				|  | @@ -345,7 +383,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |                  memberService.updateIntegration(cancelOrder.getMemberId(), member.getIntegration() + cancelOrder.getUseIntegration());
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              // 发起关单
 | 
	
		
			
				|  |  | -            userOrderPaymentService.closePayment(cancelOrder.getOrderSn(), message);
 | 
	
		
			
				|  |  | +            userOrderPaymentService.closePayment(cancelOrder.getOrderSn(),message,data);
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
	
		
			
				|  | @@ -496,7 +534,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          //构建汇付统一下单请求
 | 
	
		
			
				|  |  |          OpenEnum openType = OpenEnum.valueOf(paymentProperties.getOpenType());
 | 
	
		
			
				|  |  |          Payment payment = new Payment(openType,
 | 
	
		
			
				|  |  | -                PaymentClientEnum.valueOf(userOrderPayment.getPaymentClient()), payReq.getPayChannel());
 | 
	
		
			
				|  |  | +                PaymentClientEnum.valueOf(payReq.getPaymentClient()), payReq.getPayChannel());
 | 
	
		
			
				|  |  |          payment.setPaymentNo(generateOrderSn(detail));
 | 
	
		
			
				|  |  |          payment.setOrderNo(payReq.getOrderNo());
 | 
	
		
			
				|  |  |          payment.setOrderTitle("酷乐秀商城订单编号-" + detail.getOrderSn());
 | 
	
	
		
			
				|  | @@ -536,22 +574,22 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          BaseResult<Payment> executePayment = paymentClient.executePayment(payment);
 | 
	
		
			
				|  |  |          if (!executePayment.getStatus()) {
 | 
	
		
			
				|  |  |              // 异常将取消订单
 | 
	
		
			
				|  |  | -            cancelOrder(detail.getId(), executePayment.getMsg());
 | 
	
		
			
				|  |  | +            cancelOrder(detail.getId(), executePayment.getMsg(), null);
 | 
	
		
			
				|  |  |              throw new BizException(executePayment.getMsg());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if (!executePayment.getData().getPayAmt().equals(detail.getPayAmount().setScale(2, RoundingMode.HALF_UP).toString())) {
 | 
	
		
			
				|  |  | -            cancelOrder(detail.getId(), "订单金额和实际支付金额不符");
 | 
	
		
			
				|  |  | +            cancelOrder(detail.getId(), "订单金额和实际支付金额不符", null);
 | 
	
		
			
				|  |  |              throw new BizException("订单金额和实际支付金额不符");
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        saveOrderPayment(executePayment.getData(), detail);
 | 
	
		
			
				|  |  | +        saveOrderPayment(executePayment.getData(), detail,payReq.getPaymentClient());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          return orderPayRes;
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    private void saveOrderPayment(Payment payment, OmsOrderDetail detail) {
 | 
	
		
			
				|  |  | +    private void saveOrderPayment(Payment payment, OmsOrderDetail detail,String paymentClient) {
 | 
	
		
			
				|  |  |          UserOrderPayment userOrderPayment;
 | 
	
		
			
				|  |  |          OmsOrder omsOrder = new OmsOrder();
 | 
	
		
			
				|  |  |          omsOrder.setId(detail.getId());
 | 
	
	
		
			
				|  | @@ -560,6 +598,8 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          orderMapper.updateByPrimaryKeySelective(omsOrder);
 | 
	
		
			
				|  |  |          // 保存订单支付表
 | 
	
		
			
				|  |  |          userOrderPayment = new UserOrderPayment();
 | 
	
		
			
				|  |  | +        userOrderPayment.setPaymentClient(paymentClient);
 | 
	
		
			
				|  |  | +        userOrderPayment.setOpenType(paymentProperties.getOpenType());
 | 
	
		
			
				|  |  |          userOrderPayment.setOrderNo(detail.getOrderSn());
 | 
	
		
			
				|  |  |          userOrderPayment.setAdapayNo(payment.getPaymentNo());
 | 
	
		
			
				|  |  |          userOrderPayment.setPayChannel(payment.getPayChannel().getCode());
 | 
	
	
		
			
				|  | @@ -605,14 +645,14 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void paymentSucceededHandle(PaymentCallBack data) {
 | 
	
		
			
				|  |  |          //订单完成
 | 
	
		
			
				|  |  | -        UserOrderPayment userOrderPayment = userOrderPaymentService.getByTranNo(data.getPaymentNo());
 | 
	
		
			
				|  |  | +        UserOrderPayment userOrderPayment = userOrderPaymentService.getByAdapayNo(data.getPaymentNo());
 | 
	
		
			
				|  |  |          if (null == userOrderPayment) {
 | 
	
		
			
				|  |  |              log.error("汇付支付回调,订单未找到。 req is {}", JSON.toJSONString(data));
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          OmsOrderDetail detail = detail(userOrderPayment.getOrderNo());
 | 
	
		
			
				|  |  |          if (detail.getStatus() == 0) {
 | 
	
		
			
				|  |  | -            orderSuccess(detail, data);
 | 
	
		
			
				|  |  | +            orderSuccess(detail, data,data.getId());
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              log.error("汇付支付回调,订单状态异常。 req is {}", detail.getOrderSn());
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -626,7 +666,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void paymentFailedHandle(PaymentCallBack data) {
 | 
	
		
			
				|  |  |          //订单完成
 | 
	
		
			
				|  |  | -        UserOrderPayment userOrderPayment = userOrderPaymentService.getByTranNo(data.getPaymentNo());
 | 
	
		
			
				|  |  | +        UserOrderPayment userOrderPayment = userOrderPaymentService.getByAdapayNo(data.getPaymentNo());
 | 
	
		
			
				|  |  |          if (null == userOrderPayment) {
 | 
	
		
			
				|  |  |              log.error("汇付支付回调,订单未找到。 req is {}", JSON.toJSONString(data));
 | 
	
		
			
				|  |  |              return;
 | 
	
	
		
			
				|  | @@ -639,7 +679,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          if (detail.getStatus() == 0) {
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -            cancelOrder(detail.getId(), data.getErrMsg());
 | 
	
		
			
				|  |  | +            cancelOrder(detail.getId(), data.getErrMsg(),data);
 | 
	
		
			
				|  |  |          } else {
 | 
	
		
			
				|  |  |              log.error("汇付支付回调,订单状态异常。 req is {}", JSON.toJSONString(data));
 | 
	
		
			
				|  |  |          }
 | 
	
	
		
			
				|  | @@ -652,12 +692,14 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |       * @updateTime 2022/4/27 15:33
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void paymentCloseSucceededHandle(PaymentCallBack data) {
 | 
	
		
			
				|  |  | -        UserOrderPayment orderPayment = userOrderPaymentService.getByTranNo(data.getPaymentNo());
 | 
	
		
			
				|  |  | +        UserOrderPayment orderPayment = userOrderPaymentService.getByAdapayNo(data.getPaymentNo());
 | 
	
		
			
				|  |  |          if (null == orderPayment) {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        orderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
 | 
	
		
			
				|  |  | -        orderPayment.setUpdateTime(new Date());
 | 
	
		
			
				|  |  | +        orderPayment.setStatus(TradeStatusEnum.failed.getCode());
 | 
	
		
			
				|  |  | +        orderPayment.setTransNo(data.getId());
 | 
	
		
			
				|  |  | +        orderPayment.setCloseStatus(TradeStatusEnum.succeeded.getCode());
 | 
	
		
			
				|  |  | +        orderPayment.setCloseTime(data.getClosePaymentCallBack().getTradeTime());
 | 
	
		
			
				|  |  |          userOrderPaymentService.saveOrUpdate(orderPayment);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -668,11 +710,13 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |       * @updateTime 2022/4/27 15:33
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      private void paymentCloseFailedHandle(PaymentCallBack data) {
 | 
	
		
			
				|  |  | -        UserOrderPayment orderPayment = userOrderPaymentService.getByTranNo(data.getPaymentNo());
 | 
	
		
			
				|  |  | +        UserOrderPayment orderPayment = userOrderPaymentService.getByAdapayNo(data.getPaymentNo());
 | 
	
		
			
				|  |  |          if (null == orderPayment) {
 | 
	
		
			
				|  |  |              return;
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          orderPayment.setStatus(TradeStatusEnum.failed.getCode());
 | 
	
		
			
				|  |  | +        orderPayment.setCloseStatus(TradeStatusEnum.failed.getCode());
 | 
	
		
			
				|  |  | +        orderPayment.setCloseTime(data.getClosePaymentCallBack().getTradeTime());
 | 
	
		
			
				|  |  |          orderPayment.setPayFailMsg("支付关单回调失败-" + data.getErrMsg());
 | 
	
		
			
				|  |  |          orderPayment.setUpdateTime(new Date());
 | 
	
		
			
				|  |  |          userOrderPaymentService.saveOrUpdate(orderPayment);
 | 
	
	
		
			
				|  | @@ -686,7 +730,7 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |          //判断汇付订单状态
 | 
	
		
			
				|  |  |          UserOrderPayment orderPayment = userOrderPaymentService.getByOrderNoAndStatusPaying(userOrder.getOrderSn());
 | 
	
		
			
				|  |  |          if (null == orderPayment) {
 | 
	
		
			
				|  |  | -            cancelOrder(userOrder.getId(), "支付超时");
 | 
	
		
			
				|  |  | +            cancelOrder(userOrder.getId(), "支付超时", null);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |          OmsOrderDetail detail = detail(orderPayment.getOrderNo());
 | 
	
		
			
				|  |  |          try {
 | 
	
	
		
			
				|  | @@ -699,15 +743,15 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |              if (res.getStatus() && TradeStatusEnum.succeeded.getCode().equals(res.getData().getStatus())
 | 
	
		
			
				|  |  |                      && (detail.getStatus() == 0 || detail.getStatus() == 1)
 | 
	
		
			
				|  |  |              ) {
 | 
	
		
			
				|  |  | -                orderSuccess(detail);
 | 
	
		
			
				|  |  | +                orderSuccess(detail,res.getData().getId());
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |              //支付失败
 | 
	
		
			
				|  |  |              if (!res.getStatus()) {
 | 
	
		
			
				|  |  | -                cancelOrder(userOrder.getId(), res.getMsg());
 | 
	
		
			
				|  |  | +                cancelOrder(userOrder.getId(), res.getMsg(), null);
 | 
	
		
			
				|  |  |                  return;
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  | -            cancelOrder(userOrder.getId(), "支付超时");
 | 
	
		
			
				|  |  | +            cancelOrder(userOrder.getId(), "支付超时", null);
 | 
	
		
			
				|  |  |          } catch (Exception e) {
 | 
	
		
			
				|  |  |              e.printStackTrace();
 | 
	
		
			
				|  |  |              log.error("轮询处理支付中订单异常,异常参数: {}", JSONObject.toJSONString(userOrder));
 | 
	
	
		
			
				|  | @@ -715,8 +759,8 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -    void orderSuccess(OmsOrder detail) {
 | 
	
		
			
				|  |  | -        orderSuccess(detail, null);
 | 
	
		
			
				|  |  | +    void orderSuccess(OmsOrder detail, String tranId) {
 | 
	
		
			
				|  |  | +        orderSuccess(detail,null,tranId);
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |      /**
 | 
	
	
		
			
				|  | @@ -726,26 +770,33 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |       * @updateTime 2022/4/13 17:17
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      @Transactional(rollbackFor = Exception.class)
 | 
	
		
			
				|  |  | -    void orderSuccess(OmsOrder detail, PaymentCallBack data) {
 | 
	
		
			
				|  |  | +    void orderSuccess(OmsOrder detail, PaymentCallBack data, String tranId) {
 | 
	
		
			
				|  |  |          //更新订单
 | 
	
		
			
				|  |  |          UserOrderPayment orderPayment = userOrderPaymentService.getByOrderNoAndStatusPaying(detail.getOrderSn());
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | +        if (orderPayment == null) {
 | 
	
		
			
				|  |  | +            log.error("支付回调,支付中订单未找到。 orderNo is {}",detail.getOrderSn());
 | 
	
		
			
				|  |  | +            return;
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  |          if (data != null) {
 | 
	
		
			
				|  |  |              String pay_amt = data.getExecutePaymentCallBack().getPayAmt();
 | 
	
		
			
				|  |  |              if (!pay_amt.equals(detail.getPayAmount().setScale(2, RoundingMode.HALF_UP).toString())) {
 | 
	
		
			
				|  |  |                  orderPayment.setPayFailMsg("订单金额和实际支付金额不符");
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  | -        if (orderPayment.getPayChannel().equals("alipay")) {
 | 
	
		
			
				|  |  | -            paySuccess(detail.getId(), 1);
 | 
	
		
			
				|  |  | -        } else if (orderPayment.getPayChannel().equals("wx_lite")) {
 | 
	
		
			
				|  |  | -            paySuccess(detail.getId(), 2);
 | 
	
		
			
				|  |  | +        if (orderPayment.getPayChannel().equals("alipay") || orderPayment.getPayChannel().equals("ali_app")) {
 | 
	
		
			
				|  |  | +            paySuccess(detail.getId(),1);
 | 
	
		
			
				|  |  | +        } else if (orderPayment.getPayChannel().equals("wx_lite") || orderPayment.getPayChannel().equals("wx_app")) {
 | 
	
		
			
				|  |  | +            paySuccess(detail.getId(),2);
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  |          orderPayment.setStatus(TradeStatusEnum.succeeded.getCode());
 | 
	
		
			
				|  |  |          orderPayment.setArrivalTime(new Date());
 | 
	
		
			
				|  |  | +        orderPayment.setTransNo(tranId);
 | 
	
		
			
				|  |  |          if (null != data) {
 | 
	
		
			
				|  |  |              try {
 | 
	
		
			
				|  |  | +                orderPayment.setArrivalTime(data.getExecutePaymentCallBack().getTradeTime());
 | 
	
		
			
				|  |  | +                orderPayment.setTransNo(data.getId());
 | 
	
		
			
				|  |  |                  orderPayment.setPayAmt(new BigDecimal(data.getExecutePaymentCallBack().getPayAmt()));
 | 
	
		
			
				|  |  |                  orderPayment.setFeeAmt(new BigDecimal(data.getExecutePaymentCallBack().getFeeAmt()));
 | 
	
		
			
				|  |  |              } catch (Exception e) {
 | 
	
	
		
			
				|  | @@ -1048,11 +1099,35 @@ public class OmsPortalOrderServiceImpl implements OmsPortalOrderService {
 | 
	
		
			
				|  |  |      /**
 | 
	
		
			
				|  |  |       * 锁定下单商品的所有库存
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  | -    private void lockStock(List<CartPromotionItem> cartPromotionItemList) {
 | 
	
		
			
				|  |  | +    private void lockSkuStock(List<CartPromotionItem> cartPromotionItemList) {
 | 
	
		
			
				|  |  |          for (CartPromotionItem cartPromotionItem : cartPromotionItemList) {
 | 
	
		
			
				|  |  | -            int i = skuStockMapper.lockStock(cartPromotionItem.getProductSkuId(), cartPromotionItem.getQuantity());
 | 
	
		
			
				|  |  | +            if (cartPromotionItem.getProductSkuId() == null) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            int i = skuStockMapper.lockStock(cartPromotionItem.getProductSkuId(),cartPromotionItem.getQuantity());
 | 
	
		
			
				|  |  |              if (i == 0) {
 | 
	
		
			
				|  |  | -                Asserts.fail("库存不足,无法下单");
 | 
	
		
			
				|  |  | +                Asserts.fail("库存不足");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +        }
 | 
	
		
			
				|  |  | +    }
 | 
	
		
			
				|  |  | +
 | 
	
		
			
				|  |  | +    /**
 | 
	
		
			
				|  |  | +     * 锁定下单商品的所有库存
 | 
	
		
			
				|  |  | +     */
 | 
	
		
			
				|  |  | +    private void lockProductStock(List<CartPromotionItem> cartPromotionItemList) {
 | 
	
		
			
				|  |  | +        Map<Long, List<CartPromotionItem>> collect = cartPromotionItemList.stream()
 | 
	
		
			
				|  |  | +                                  .collect(Collectors.groupingBy(CartPromotionItem::getProductId));
 | 
	
		
			
				|  |  | +        for (Map.Entry<Long, List<CartPromotionItem>> entry : collect.entrySet()) {
 | 
	
		
			
				|  |  | +            List<CartPromotionItem> value = entry.getValue();
 | 
	
		
			
				|  |  | +            if(CollectionUtils.isEmpty(value)) {
 | 
	
		
			
				|  |  | +                continue;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            int sum = value.stream().mapToInt(CartPromotionItem::getQuantity).sum();
 | 
	
		
			
				|  |  | +            if (sum >0 ) {
 | 
	
		
			
				|  |  | +                int i = pmsProductMapper.lockStock(entry.getKey(),sum);
 | 
	
		
			
				|  |  | +                if (i == 0) {
 | 
	
		
			
				|  |  | +                    Asserts.fail("库存不足");
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  |              }
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 |