| | |
| | | private final RedisUtils redisUtils; |
| | | private final StoreService storeService; |
| | | private final OrderOperationLogService operationLogService; |
| | | private final static String DESCRIBE = "哦应:"; |
| | | private static final String DESCRIBE = "哦应:"; |
| | | private static final String ORDER_KEY = "oying:order"; |
| | | private static final String ORDER_STORE_KEY = "oying:order:store"; |
| | | private static final String ORDER_CODE = "ORDER"; |
| | | |
| | | @Override |
| | | public PageResult<Order> queryAll(OrderQueryCriteria criteria, Page<Object> page) { |
| | |
| | | if (!(address.getDistance().compareTo(BigDecimal.valueOf(store.getRadius())) <= 0)) { |
| | | throw new BadRequestException("超出配送范围"); |
| | | } |
| | | String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); |
| | | // 订单号 |
| | | String orderNum = redisUtils.generateSn(ORDER_KEY, GenerateEnum.ORDER.getKey()); |
| | | // 总金额 |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | // 商品快照 |
| | |
| | | // 订单信息 |
| | | Order order = new Order(); |
| | | order.setOrderNum(orderNum); |
| | | order.setOrderStoreNum(redisUtils.generateOrderSn(Math.toIntExact(submit.getStoreId())).substring(orderNum.length() - 4)); |
| | | order.setOrderStoreNum(redisUtils.generateSn(ORDER_STORE_KEY, Math.toIntExact(submit.getStoreId())).substring(orderNum.length() - 4)); |
| | | order.setOrderStatus(OrderStatusEnum.ZERO.getKey()); |
| | | order.setOrderStatusDescribe(OrderStatusEnum.ZERO.getValue()); |
| | | order.setOrderRemark(submit.getRemark() != null ? submit.getRemark() : ""); |
| | |
| | | |
| | | OrderAddressSnapshot addressSnapshot = getOrderAddressSnapshot(orderNum, address); |
| | | |
| | | |
| | | addressSnapshotService.save(addressSnapshot); |
| | | orderMapper.insert(order); |
| | | productSnapshotService.saveBatch(snapshots); |
| | |
| | | } |
| | | List<ProductInfo> products = new ArrayList<>(); |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | int count = 0; |
| | | for (ProductOrder productOrder : criteria.getProducts()) { |
| | | Product product = productService.getById(productOrder.getProductId()); |
| | | if (product == null) { |
| | |
| | | info.setCount(productOrder.getCount()); |
| | | products.add(info); |
| | | amount = BigDecimalUtils.add(amount, BigDecimalUtils.multiply(product.getPrice(), productOrder.getCount())); |
| | | count += productOrder.getCount(); |
| | | } |
| | | if (!(amount.compareTo(store.getDeliveryMinimum()) >= 0)) { |
| | | throw new BadRequestException("起送金额:" + store.getDeliveryMinimum()); |
| | |
| | | info.setAmount(amount); |
| | | info.setPayAmount(amount); |
| | | info.setPromotionAmount(BigDecimal.ZERO); |
| | | info.setDeliveryPrice(store.getDeliveryFee()); |
| | | info.setPackagingPrice(BigDecimalUtils.multiply(store.getPackagingFee(), count)); |
| | | info.setUserAddresses(userAddressService.queryUserAddress(store.getLongitude(), store.getLatitude())); |
| | | return info; |
| | | } |
| | |
| | | public OrderResponse getByOrderNum(String orderNum) { |
| | | return new OrderResponse(orderMapper.getByOrderNum(orderNum), |
| | | addressSnapshotService.queryByOrderNum(orderNum), |
| | | operationLogService.getByOrderNum(orderNum)); |
| | | operationLogService.getByOrderNum(orderNum, ORDER_CODE)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public Order queryByOrderNum(String orderNum) { |
| | | return orderMapper.getByOrderNum(orderNum); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void cancel(String orderNum) { |
| | | public synchronized void cancel(String orderNum) { |
| | | OrderResponse response = getByOrderNum(orderNum); |
| | | Order order = response.getOrder(); |
| | | if (order == null) { |
| | | throw new BadRequestException("订单不存在"); |
| | | throw new BadRequestException("订单不存在!"); |
| | | } |
| | | if (!SecurityUtils.getCurrentUserId().equals(order.getUserId())) { |
| | | throw new BadRequestException("不能修改他人订单"); |
| | |
| | | case HWC: |
| | | case HWC2: |
| | | JSONObject object = swiftPassService.query(orderNum, anEnum); |
| | | if (object.getString("trade_state").equals(PayStateEnum.NOTPAY.getKey())) { |
| | | if (!object.getString("trade_state").equals(PayStateEnum.NOTPAY.getKey())) { |
| | | throw new BadRequestException(PayStateEnum.getValue(order.getPayState())); |
| | | } |
| | | swiftPassService.closeOrder(orderNum, anEnum); |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void deleteAll(List<Long> ids) { |
| | | Long userid = SecurityUtils.getCurrentUserId(); |
| | | for (Long id : ids) { |
| | | Order order = getById(id); |
| | | if (order == null) { |
| | | throw new BadRequestException("订单不存在!"); |
| | | } |
| | | if (!order.getUserId().equals(userid)) { |
| | | throw new BadRequestException("不能删除他人订单"); |
| | | } |
| | | if (!order.getPayState().equals(PayStateEnum.NOTPAY.getKey())) { |
| | | throw new BadRequestException("只能删除未支付订单"); |
| | | } |
| | | } |
| | | orderMapper.deleteBatchIds(ids); |
| | | } |
| | | |