コード例 #1
0
  @Transactional(propagation = Propagation.REQUIRED)
  public void saveReceived(Received obj) {
    if (obj.getId() == null) {
      obj.setId(Comb.getComb());
      receivedManageMapper.insertReceived(obj);
    } else {
      receivedManageMapper.updateReceived(obj);
    }

    String finish = obj.getFinish();
    if ("true".equals(finish)) {
      // 已完成收货
      String status = StoreOrderStatus.RECEIVED.getCode();
      Order order = new Order();
      order.setOrderNumber(obj.getOrderNumber());
      order.setStatus(status);
      orderManageMapper.updateOrderStatus(order);
    }
  }
コード例 #2
0
 public Order getOrder(String orderNumber) {
   // 定单基本信息
   Order order = orderManageMapper.getOrderByOrderNumber(orderNumber);
   // 初始化消费信息
   List<OrderItem> items = getOrderItemByOrderNumber(orderNumber);
   List<OrderTickets> orderTickets = orderManageMapper.getOrderTicketsByOrderNumber(orderNumber);
   initOrderConsumptionInfo(items, orderTickets);
   // 收货信息
   List<Received> receiveds = receivedManageMapper.getOrderReceivedsByOrderNumber(orderNumber);
   order.setReceiveds(receiveds);
   // 获取订单的已经退款的退款信息
   Refund refund = new Refund();
   refund.setOrderNumber(orderNumber);
   refund.setStatus(StoreOrderStatus.REFUNDED.getCode());
   List<Refund> refunds = refundManageMapper.getRefunds(refund);
   order.setItems(items);
   order.setOrderTickets(orderTickets);
   order.setRefunds(refunds);
   return order;
 }
コード例 #3
0
  @Transactional(propagation = Propagation.REQUIRED)
  public void updateOrderItem(OrderItem orderItem) {
    // 取得要修改的数据
    String itemId = orderItem.getId();
    String orderNumber = orderItem.getOrderNumber();
    Double priceItem = orderItem.getSellingPrice();
    Integer quantityItem = orderItem.getQuantity();
    Double actualSellingPriceItem = orderItem.getActualSellingPrice();
    // 将item要修改的数据转换成精确类型,并重新赋值给item
    BigDecimal priceDecimal = new BigDecimal(priceItem + "");
    priceDecimal = priceDecimal.setScale(2, RoundingMode.HALF_UP); // 精确到小数点2位,四舍五入
    BigDecimal actualSellingPriceDecimal = new BigDecimal(actualSellingPriceItem + "");
    actualSellingPriceDecimal =
        actualSellingPriceDecimal.setScale(2, RoundingMode.HALF_UP); // 精确到小数点2位,四舍五入
    BigDecimal quantityDecimal = new BigDecimal(quantityItem + "");
    BigDecimal subtotalDecimal = priceDecimal.multiply(quantityDecimal);
    BigDecimal totalDecimal = actualSellingPriceDecimal.multiply(quantityDecimal);
    BigDecimal savingsDecimal = subtotalDecimal.subtract(totalDecimal);
    orderItem.setActualSellingPrice(actualSellingPriceDecimal.doubleValue()); // 将用户输入的金额四舍五入
    orderItem.setSavings(savingsDecimal.doubleValue());
    orderItem.setSubtotal(subtotalDecimal.doubleValue());
    orderItem.setTotal(totalDecimal.doubleValue());
    // 取得订单基本信息和商品信息
    Order order = orderManageMapper.getOrderByOrderNumber(orderNumber);
    List<OrderItem> items = orderManageMapper.getOrderItemByOrderNumber(orderNumber);
    // 初始化订单统计要用到的精确类型
    Integer quantity = 0;
    BigDecimal subtotal = new BigDecimal("0");
    BigDecimal savings = new BigDecimal("0");
    BigDecimal total = new BigDecimal("0");
    String savingsInfo = "";
    // 重新计算订单总价
    for (OrderItem item : items) {
      // 判断item是否是要修改的,如果是用前面转换的精确类型
      if (StringUtils.equals(item.getId(), itemId)) {
        quantity += quantityItem;
        subtotal = subtotal.add(subtotalDecimal);
        savings = savings.add(savingsDecimal);
        total = total.add(totalDecimal);
        // 将所有商品的优惠信息去重合并到一起,放到订单的优惠信息中
        if (StringUtils.isNotBlank(orderItem.getSavingInfo())
            && !StringUtils.contains(savingsInfo, orderItem.getSavingInfo())) {
          savingsInfo += orderItem.getSavingInfo() + "<br>";
        }
        continue;
      }
      quantity += item.getQuantity();
      BigDecimal itemSubtotal = new BigDecimal(item.getSubtotal() + "");
      BigDecimal itemSavings = new BigDecimal(item.getSavings() + "");
      BigDecimal itemTotal = new BigDecimal(item.getTotal() + "");
      subtotal = subtotal.add(itemSubtotal);
      savings = savings.add(itemSavings);
      total = total.add(itemTotal);

      String savingInfo = item.getSavingInfo();
      // 设置优惠计算信息
      if (StringUtils.isNotBlank(savingInfo) && !StringUtils.contains(savingsInfo, savingInfo)) {
        savingsInfo += savingInfo + "<br>";
      }
    }
    order.setSavingsInfo(savingsInfo);

    order.setQuantity(quantity);
    order.setSubtotal(subtotal.doubleValue());
    order.setSavings(savings.doubleValue());
    order.setTotal(total.doubleValue());
    order.setUpdatedById(orderItem.getUpdatedById());
    order.setUpdatedByName(orderItem.getUpdatedByName());
    order.setUpdatedTime(orderItem.getUpdatedTime());
    // 将重新计算的订单统计信息放入订单对像中
    // 更新数据库
    orderManageMapper.updateOrderItem(orderItem);
    orderManageMapper.updateOrderFee(order);
  }