Search in sources :

Example 6 with OrderItem

use of com.whoiszxl.entity.OrderItem in project shopzz by whoiszxl.

the class OrderServiceImpl method createOrderInfo.

/**
 * 创建订单和订单条目信息
 * @param memberDetailDTO 用户信息
 * @param orderSubmitVo 提交的订单信息
 * @return
 */
private OrderCreateInfo createOrderInfo(MemberDetailDTO memberDetailDTO, OrderSubmitVO orderSubmitVo) {
    MemberDTO member = memberDetailDTO.getMember();
    // 1. 生成订单号
    long orderId = idWorker.nextId();
    // 2. 创建订单和订单条目的基本信息
    Order order = buildOrder(member, orderId, orderSubmitVo);
    List<OrderItem> orderItems = buildOrderItems(orderId);
    // 3. 价格计算
    assert orderItems != null;
    computePrice(order, orderItems);
    OrderCreateInfo orderCreateInfo = new OrderCreateInfo();
    orderCreateInfo.setOrder(order);
    orderCreateInfo.setOrderItemList(orderItems);
    orderCreateInfo.setFare(BigDecimal.ZERO);
    orderCreateInfo.setPayPrice(order.getTotalAmount());
    return orderCreateInfo;
}
Also used : Order(com.whoiszxl.entity.Order) OrderItem(com.whoiszxl.entity.OrderItem) OrderCreateInfo(com.whoiszxl.entity.vo.OrderCreateInfo)

Example 7 with OrderItem

use of com.whoiszxl.entity.OrderItem in project shopzz by whoiszxl.

the class OrderServiceImpl method createOrderInfo.

/**
 * 创建订单和订单条目信息
 * @param memberDetailDTO 用户信息
 * @param orderSubmitVo 提交的订单信息
 * @return
 */
private OrderCreateInfo createOrderInfo(MemberDetailDTO memberDetailDTO, OrderSubmitRequest orderSubmitVo) {
    MemberDTO member = memberDetailDTO.getMember();
    // 1. 生成订单号
    long orderId = idWorker.nextId();
    // 2. 创建订单和订单条目的基本信息
    Order order = buildOrder(member, orderId, orderSubmitVo);
    List<OrderItem> orderItems = buildOrderItems(orderId);
    // 3. 价格计算,计算订单总额
    computePrice(order, orderItems);
    OrderCreateInfo orderCreateInfo = new OrderCreateInfo();
    orderCreateInfo.setOrder(order);
    orderCreateInfo.setOrderItemList(orderItems);
    orderCreateInfo.setFare(BigDecimal.ZERO);
    orderCreateInfo.setPayPrice(order.getTotalAmount());
    return orderCreateInfo;
}
Also used : Order(com.whoiszxl.entity.Order) OrderItem(com.whoiszxl.entity.OrderItem) OrderCreateInfo(com.whoiszxl.entity.vo.OrderCreateInfo)

Example 8 with OrderItem

use of com.whoiszxl.entity.OrderItem in project shopzz by whoiszxl.

the class OrderServiceImpl method computePrice.

/**
 * 价格计算
 * @param order 订单信息
 * @param orderItems 订单条目信息
 */
private void computePrice(Order order, List<OrderItem> orderItems) {
    // 运费,促销,积分,优惠券 TODO
    order.setTotalAmount(new BigDecimal("0"));
    order.setFreightAmount(new BigDecimal("0"));
    order.setPromotionAmount(new BigDecimal("0"));
    order.setPointAmount(new BigDecimal("0"));
    order.setCouponAmount(new BigDecimal("0"));
    BigDecimal total = BigDecimal.ZERO;
    for (OrderItem orderItem : orderItems) {
        // TODO 暂用sku价格
        orderItem.setRealAmount(orderItem.getSkuPrice().multiply(new BigDecimal(orderItem.getQuantity().toString())));
        total = total.add(orderItem.getRealAmount());
    }
    order.setTotalAmount(total);
}
Also used : OrderItem(com.whoiszxl.entity.OrderItem) BigDecimal(java.math.BigDecimal)

Example 9 with OrderItem

use of com.whoiszxl.entity.OrderItem in project shopzz by whoiszxl.

the class OrderServiceImpl method buildOrderItems.

private List<OrderItem> buildOrderItems(long orderId, String orderNo) {
    // 获取当前选中的购物车item列表
    CartDetailApiResponse cartDetail = cartService.getCartDetail();
    List<CartItemVO> cartItemVOList = cartDetail.getCartItemVOList();
    List<OrderItem> result = new ArrayList<>();
    for (CartItemVO item : cartItemVOList) {
        if (item.getChecked() == 1) {
            OrderItem orderItem = buildOrderItem(item);
            orderItem.setOrderId(orderId);
            orderItem.setOrderNo(orderNo);
            result.add(orderItem);
        }
    }
    return result;
}
Also used : CartDetailApiResponse(com.whoiszxl.cqrs.response.CartDetailApiResponse) OrderItem(com.whoiszxl.entity.OrderItem) ArrayList(java.util.ArrayList) CartItemVO(com.whoiszxl.cqrs.response.CartItemVO)

Example 10 with OrderItem

use of com.whoiszxl.entity.OrderItem in project shopzz by whoiszxl.

the class OrderServiceImpl method buildOrderItem.

/**
 * 创建订单详情单个条目
 * @param cartDTO 购物车条目
 * @return 订单条目
 */
private OrderItem buildOrderItem(CartItemVO cartDTO) {
    OrderItem orderItem = new OrderItem();
    Long skuId = cartDTO.getSkuId();
    // 配置sku信息
    orderItem.setSkuId(skuId);
    orderItem.setSkuName(cartDTO.getSkuName());
    // TODO 设置sku属性
    orderItem.setSkuAttrs("default");
    orderItem.setSkuPic(cartDTO.getSkuPic());
    orderItem.setSkuPrice(cartDTO.getPrice());
    orderItem.setQuantity(cartDTO.getQuantity());
    // 配置spu信息
    orderItem.setProductId(cartDTO.getProductId());
    // TODO
    orderItem.setCategoryId(0L);
    orderItem.setCreatedBy("member");
    orderItem.setUpdatedBy("member");
    return orderItem;
}
Also used : OrderItem(com.whoiszxl.entity.OrderItem)

Aggregations

OrderItem (com.whoiszxl.entity.OrderItem)10 Order (com.whoiszxl.entity.Order)5 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 OrderCreateInfo (com.whoiszxl.entity.vo.OrderCreateInfo)2 ArrayList (java.util.ArrayList)2 SaCheckLogin (cn.dev33.satoken.annotation.SaCheckLogin)1 OrderCreateInfoDTO (com.whoiszxl.cqrs.dto.OrderCreateInfoDTO)1 CartDetailApiResponse (com.whoiszxl.cqrs.response.CartDetailApiResponse)1 CartItemVO (com.whoiszxl.cqrs.response.CartItemVO)1 CartDetailVO (com.whoiszxl.entity.vo.CartDetailVO)1 CartItemVO (com.whoiszxl.entity.vo.CartItemVO)1 OrderItemVO (com.whoiszxl.entity.vo.OrderItemVO)1 OrderVO (com.whoiszxl.entity.vo.OrderVO)1 ApiOperation (io.swagger.annotations.ApiOperation)1 BigDecimal (java.math.BigDecimal)1