| | |
| | | import com.oying.modules.pc.product.domain.enums.ProductStatusEnum; |
| | | import com.oying.modules.pc.product.service.ProductService; |
| | | import com.oying.modules.pc.store.domain.Store; |
| | | import com.oying.modules.pc.store.domain.enums.StoreStatusEnum; |
| | | import com.oying.modules.pc.store.service.StoreService; |
| | | import com.oying.modules.sh.domain.*; |
| | | import com.oying.modules.sh.domain.request.GeneratorOrder; |
| | |
| | | default: |
| | | throw new BadRequestException("支付类型暂未开放"); |
| | | } |
| | | String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); |
| | | // 总金额 |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | GeneratorOrder generator = new GeneratorOrder(); |
| | | generator.setProducts(submit.getProducts()); |
| | | generator.setStoreId(submit.getStoreId()); |
| | | OrderInfo info = generatorOrder(generator); |
| | | Store store = info.getStore(); |
| | | UserAddress address = userAddressService.getById(submit.getAddressId(), store.getLongitude(), store.getLatitude()); |
| | | if (address == null) { |
| | | throw new BadRequestException("没找到用户地址"); |
| | | } |
| | | if (!(address.getDistance().compareTo(BigDecimal.valueOf(store.getRadius())) <= 0)) { |
| | | throw new BadRequestException("超出配送范围"); |
| | | } |
| | | String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); |
| | | // 总金额 |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | // 商品快照 |
| | | List<OrderProductSnapshot> snapshots = new ArrayList<>(); |
| | | for (ProductInfo productInfo : info.getProducts()) { |
| | |
| | | String openid = SecurityUtils.getCurrentOpenid(); |
| | | if (openid == null || openid.isEmpty()) { |
| | | throw new BadRequestException("OPENID错误"); |
| | | } |
| | | |
| | | // 门店信息 |
| | | Store store = storeService.getById(submit.getStoreId()); |
| | | if (amount.compareTo(store.getDeliveryMinimum()) >= 0) { |
| | | throw new BadRequestException("起送金额:" + store.getDeliveryMinimum()); |
| | | } |
| | | // 订单信息 |
| | | Order order = new Order(); |
| | |
| | | order.setPayMessage(PayStateEnum.SUCCESS.getValue()); |
| | | order.setPayTime(DateUtil.localDateTimeFormat(now.toLocalDateTime(), DateUtil.SDF_YMDHMS)); |
| | | } |
| | | UserAddress address = userAddressService.getById(submit.getAddressId()); |
| | | |
| | | OrderAddressSnapshot addressSnapshot = getOrderAddressSnapshot(orderNum, address); |
| | | |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized OrderInfo generatorOrder(GeneratorOrder criteria) { |
| | | // 门店信息 |
| | | Store store = storeService.getById(criteria.getStoreId()); |
| | | if (!store.getBusinessStatus().equals(StoreStatusEnum.OPEN.getValue())) { |
| | | throw new BadRequestException("停止营业"); |
| | | } |
| | | List<ProductInfo> products = new ArrayList<>(); |
| | | BigDecimal amount = BigDecimal.ZERO; |
| | | for (ProductOrder productOrder : criteria.getProducts()) { |
| | |
| | | products.add(info); |
| | | amount = BigDecimalUtils.add(amount, BigDecimalUtils.multiply(product.getPrice(), productOrder.getCount())); |
| | | } |
| | | if (!(amount.compareTo(store.getDeliveryMinimum()) >= 0)) { |
| | | throw new BadRequestException("起送金额:" + store.getDeliveryMinimum()); |
| | | } |
| | | OrderInfo info = new OrderInfo(); |
| | | info.setStore(store); |
| | | info.setProducts(products); |
| | | info.setAmount(amount); |
| | | info.setPayAmount(amount); |
| | | info.setPromotionAmount(BigDecimal.ZERO); |
| | | info.setUserAddresses(userAddressService.queryUserAddress()); |
| | | info.setUserAddresses(userAddressService.queryUserAddress(store.getLongitude(), store.getLatitude())); |
| | | return info; |
| | | } |
| | | |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void operationLog(OrderResponse order, OrderStatusEnum stateEnum, String cardName) { |
| | | operationLogService.create(order, stateEnum, null); |
| | | operationLogService.create(order, stateEnum, cardName); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void closeOrder(String orderNum) { |
| | | public void cancel(String orderNum) { |
| | | OrderResponse response = getByOrderNum(orderNum); |
| | | Order order = response.getOrder(); |
| | | if (order == null) { |
| | |
| | | map.put("消息", order.getPayMessage()); |
| | | map.put("支付类型", order.getPayType()); |
| | | map.put("支付时间", order.getPayTime()); |
| | | map.put("订单失效时间RFC3339", order.getExpireTime()); |
| | | map.put("订单失效时间", order.getExpireTime()); |
| | | map.put("openid", order.getOpenid()); |
| | | map.put("APPID", order.getAppId()); |
| | | map.put("创建人", order.getCreateBy()); |