Search in sources :

Example 1 with Order

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

the class OrderServiceImpl method submitOrder.

@Override
@Transactional
public String submitOrder(OrderSubmitVO orderSubmitVo) {
    // 0. 获取当前登录用户的信息
    MemberDetailDTO memberDetailDTO = memberFeignClient.getMemberInfo();
    // 1. 创建订单和订单详细条目
    OrderCreateInfo orderCreateInfo = createOrderInfo(memberDetailDTO, orderSubmitVo);
    // 2. 验证提交的价格和计算的价格是否一致
    if (orderSubmitVo.getTotalAmount().compareTo(orderCreateInfo.getPayPrice()) != 0) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("价格计算异常"));
    }
    // 3. 订单与订单详细条目入库
    Order order = orderCreateInfo.getOrder();
    this.save(order);
    orderItemService.saveBatch(orderCreateInfo.getOrderItemList());
    // 4. 创建一个操作日志订单状态管理器,在订单状态流转到待付款状态时记录操作记录
    orderStateManager.create(order);
    // 5. 通知库存中心订单提交了,锁定库存中心的SKU库存
    OrderCreateInfoDTO orderRequestParam = orderCreateInfo.clone(OrderCreateInfoDTO.class);
    ResponseResult updateInventoryResult = inventoryFeignClient.notifySubmitOrderEvent(orderRequestParam);
    if (!updateInventoryResult.isOk()) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("库存不足"));
    }
    // 6. 使用优惠券
    ResponseResult<Boolean> useCouponResult = promotionFeignClient.useCoupon(orderSubmitVo.getCouponId());
    if (!useCouponResult.isOk()) {
        log.error("优惠券使用失败:{}", useCouponResult.getMessage());
    }
    // 7. 发送Kafka消息到WMS中心进行处理
    // 7.1 通过商品的SKU ID查询到货位库存的明细条目,并进行遍历,一个SKU可能在多个货位上
    // 7.2 创建出需要拣货的条目和发货的条目并进行批量入库
    // 7.4 更新wms中心的库存
    OrderCreateInfoDTO orderCreateInfoDTO = new OrderCreateInfoDTO();
    BeanCopierUtils.copyProperties(orderCreateInfo, orderCreateInfoDTO);
    MQSender kafkaSender = mqSenderFactory.get(MQEnum.KAFKA);
    kafkaSender.send(MQConstants.SUBMIT_ORDER_QUEUE, JsonUtil.toJson(orderCreateInfoDTO));
    return order.getOrderSn();
}
Also used : Order(com.whoiszxl.entity.Order) MQSender(com.whoiszxl.mq.MQSender) OrderCreateInfoDTO(com.whoiszxl.dto.OrderCreateInfoDTO) OrderCreateInfo(com.whoiszxl.entity.vo.OrderCreateInfo) ResponseResult(com.whoiszxl.bean.ResponseResult) Transactional(org.springframework.transaction.annotation.Transactional)

Example 2 with Order

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

the class OrderController method orderList.

@SaCheckLogin
@PostMapping("/list")
@ApiOperation(value = "获取当前用户的订单列表", notes = "获取当前用户的订单列表", response = String.class)
public ResponseResult<IPage<OrderVO>> orderList(@RequestBody OrderListQuery query) {
    long memberId = StpUtil.getLoginIdAsLong();
    LambdaQueryWrapper<Order> queryWrapper = new LambdaQueryWrapper<>();
    queryWrapper.eq(Order::getMemberId, memberId);
    if (query.getOrderStatus() != 0) {
        queryWrapper.eq(Order::getOrderStatus, query.getOrderStatus());
    }
    IPage<Order> orderList = orderService.page(new Page<>(query.getPage(), query.getSize()), queryWrapper);
    IPage<OrderVO> orderVOList = orderList.convert(order -> {
        OrderVO orderVO = dozerUtils.map(order, OrderVO.class);
        // 获取orderItem
        List<OrderItem> orderItemList = orderItemService.list(new LambdaQueryWrapper<OrderItem>().eq(OrderItem::getOrderId, orderVO.getId()));
        List<OrderItemVO> orderItemVOS = dozerUtils.mapList(orderItemList, OrderItemVO.class);
        orderVO.setOrderItemVOList(orderItemVOS);
        return orderVO;
    });
    return ResponseResult.buildSuccess(orderVOList);
}
Also used : Order(com.whoiszxl.entity.Order) OrderVO(com.whoiszxl.entity.vo.OrderVO) OrderItem(com.whoiszxl.entity.OrderItem) OrderItemVO(com.whoiszxl.entity.vo.OrderItemVO) LambdaQueryWrapper(com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper) SaCheckLogin(cn.dev33.satoken.annotation.SaCheckLogin) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with Order

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

the class OrderServiceImpl method pay.

@Override
@Transactional
public ResponseResult pay(OrderPayVO orderPayVO) {
    // 1. 判断订单状态是否能支付
    Order order = this.getById(orderPayVO.getOrderId());
    if (!OrderStatusConstants.WAIT_FOR_PAY.equals(order.getOrderStatus())) {
        return ResponseResult.buildError("订单无法支付");
    }
    // 2. 如果是数字货币支付,判断是否存在,不存在则创建
    if (OrderPayTypeConstants.DC_PAY.equals(orderPayVO.getPayType())) {
        PayInfoDc payInfoDc = payInfoDcService.getByOrderIdAndMemberId(order.getId(), order.getMemberId());
        if (payInfoDc != null) {
            return ResponseResult.buildSuccess(payInfoDc);
        }
        payInfoDc = PayInfoDcBuilder.get().init(createDcAddressFactory, orderPayVO.getDcName()).buildBaseData(order).buildAddress(order).rateCompute(order).initStatus().create();
        boolean saveFlag = payInfoDcService.save(payInfoDc);
        if (saveFlag) {
            return ResponseResult.buildSuccess(payInfoDc);
        }
        return ResponseResult.buildError("数字货币支付失败");
    }
    return ResponseResult.buildError("TODO");
}
Also used : Order(com.whoiszxl.entity.Order) PayInfoDc(com.whoiszxl.entity.PayInfoDc) Transactional(org.springframework.transaction.annotation.Transactional)

Example 4 with Order

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

the class OrderServiceImpl method createOrderInfo.

/**
 * 创建订单和订单条目信息
 * @param orderSubmitCommand 提交的订单信息
 * @return
 */
private OrderCreateInfoDTO createOrderInfo(OrderSubmitCommand orderSubmitCommand) {
    // 1. 创建订单id和编号
    String orderNo = OrderUtils.makeOrderNo();
    long orderId = idWorker.nextId();
    // 2. 创建订单和订单条目的基本信息
    Order order = buildOrder(orderId, orderNo, orderSubmitCommand);
    List<OrderItem> orderItems = buildOrderItems(orderId, orderNo);
    // 3. 创建返回实体
    OrderCreateInfoDTO orderCreateInfoDTO = new OrderCreateInfoDTO();
    orderCreateInfoDTO.setOrder(order);
    orderCreateInfoDTO.setOrderItemList(orderItems);
    orderCreateInfoDTO.setFare(BigDecimal.ZERO);
    return orderCreateInfoDTO;
}
Also used : Order(com.whoiszxl.entity.Order) OrderCreateInfoDTO(com.whoiszxl.cqrs.dto.OrderCreateInfoDTO) OrderItem(com.whoiszxl.entity.OrderItem)

Example 5 with Order

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

the class OrderServiceImpl method pay.

@Override
public ResponseResult pay(OrderPayCommand orderPayCommand) {
    // 1. 判断订单状态是否能支付
    Order order = this.getById(orderPayCommand.getOrderId());
    if (!OrderStatusConstants.WAIT_FOR_PAY.equals(order.getOrderStatus())) {
        ExceptionCatcher.catchValidateEx(ResponseResult.buildError("订单无法支付"));
    }
    // 2. 如果是数字货币支付,判断是否存在,不存在则创建
    if (OrderPayTypeConstants.DC_PAY.equals(orderPayCommand.getPayType())) {
        PayInfoDc payInfoDc = dcPayInfoService.getByOrderIdAndMemberId(order.getId(), order.getMemberId());
        if (payInfoDc != null) {
            return ResponseResult.buildSuccess(payInfoDc);
        }
        payInfoDc = PayInfoDcBuilder.get().init(createDcAddressFactory, orderPayCommand.getDcName()).buildBaseData(order).buildAddress(order).rateCompute(order).initStatus().create();
        boolean saveFlag = dcPayInfoService.save(payInfoDc);
        if (saveFlag) {
            return ResponseResult.buildSuccess(payInfoDc);
        }
        return ResponseResult.buildError("数字货币支付失败");
    }
    // 3. TODO 微信支付,支付宝支付
    return ResponseResult.buildError("微信支付,支付宝支付 TODO");
}
Also used : Order(com.whoiszxl.entity.Order) PayInfoDc(com.whoiszxl.entity.PayInfoDc)

Aggregations

Order (com.whoiszxl.entity.Order)15 OrderItem (com.whoiszxl.entity.OrderItem)5 OrderCreateInfo (com.whoiszxl.entity.vo.OrderCreateInfo)4 ResponseResult (com.whoiszxl.bean.ResponseResult)3 Transactional (org.springframework.transaction.annotation.Transactional)3 LambdaQueryWrapper (com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper)2 OrderStatusConstants (com.whoiszxl.constants.OrderStatusConstants)2 OrderInfoDTO (com.whoiszxl.dto.OrderInfoDTO)2 PayInfoDc (com.whoiszxl.entity.PayInfoDc)2 MQSender (com.whoiszxl.mq.MQSender)2 OrderService (com.whoiszxl.service.OrderService)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)2 Slf4j (lombok.extern.slf4j.Slf4j)2 Autowired (org.springframework.beans.factory.annotation.Autowired)2 RestController (org.springframework.web.bind.annotation.RestController)2 SaCheckLogin (cn.dev33.satoken.annotation.SaCheckLogin)1 OrderCreateInfoDTO (com.whoiszxl.cqrs.dto.OrderCreateInfoDTO)1 OrderCreateInfoDTO (com.whoiszxl.dto.OrderCreateInfoDTO)1 OrderItemVO (com.whoiszxl.entity.vo.OrderItemVO)1