| | |
| | | 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.Order; |
| | | import com.oying.modules.sh.domain.OrderAddressSnapshot; |
| | | import com.oying.modules.sh.domain.OrderProductSnapshot; |
| | | import com.oying.modules.sh.domain.UserAddress; |
| | | import com.oying.modules.sh.domain.*; |
| | | import com.oying.modules.sh.domain.request.GeneratorOrder; |
| | | import com.oying.modules.sh.domain.request.ProductOrder; |
| | | import com.oying.modules.sh.domain.request.StatusOrder; |
| | | import com.oying.modules.sh.domain.request.SubmitOrder; |
| | | import com.oying.modules.sh.domain.vo.OrderInfo; |
| | | import com.oying.modules.sh.domain.vo.OrderResponse; |
| | | import com.oying.modules.sh.domain.vo.ProductInfo; |
| | | import com.oying.modules.sh.service.OrderAddressSnapshotService; |
| | | import com.oying.modules.sh.service.OrderProductSnapshotService; |
| | | import com.oying.modules.sh.service.UserAddressService; |
| | | import com.oying.modules.sh.service.*; |
| | | import com.oying.utils.*; |
| | | import com.oying.utils.enums.GenerateEnum; |
| | | import com.oying.utils.enums.OrderStatusEnum; |
| | | import com.oying.utils.enums.PayStateEnum; |
| | | import com.oying.utils.enums.PayTypeEnum; |
| | | import com.oying.utils.enums.*; |
| | | import lombok.RequiredArgsConstructor; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | | import com.oying.modules.sh.service.OrderService; |
| | | import com.oying.modules.sh.domain.dto.OrderQueryCriteria; |
| | | import com.oying.modules.sh.mapper.OrderMapper; |
| | | import org.springframework.stereotype.Service; |
| | |
| | | private final OrderAddressSnapshotService addressSnapshotService; |
| | | private final RedisUtils redisUtils; |
| | | private final StoreService storeService; |
| | | private final OrderOperationLogService operationLogService; |
| | | private final static String DESCRIBE = "哦应:"; |
| | | |
| | | @Override |
| | | public PageResult<Order> queryAll(OrderQueryCriteria criteria, Page<Object> page) { |
| | | criteria.setOffset(page.offset()); |
| | | List<Order> list = orderMapper.findAll(criteria); |
| | | Long total = orderMapper.countAll(criteria); |
| | | List<Order> list = orderMapper.findAll(criteria, criteria.getBlurry()); |
| | | Long total = orderMapper.countAll(criteria, criteria.getBlurry()); |
| | | return PageUtil.toPage(list, total); |
| | | } |
| | | |
| | | @Override |
| | | public List<Order> queryAll(OrderQueryCriteria criteria) { |
| | | return orderMapper.findAll(criteria); |
| | | return orderMapper.findAll(criteria, criteria.getBlurry()); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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()) { |
| | |
| | | // 订单信息 |
| | | Order order = new Order(); |
| | | order.setOrderNum(orderNum); |
| | | order.setOrderStoreNum(redisUtils.generateOrderSn(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() : ""); |
| | | order.setOrderTime(submit.getDateTime()); |
| | | order.setSendPrice(store.getDeliveryFee()); |
| | | order.setSendType(SendTypeEnum.LY.getKey()); |
| | | order.setUserId(SecurityUtils.getCurrentUserId()); |
| | | order.setUsername(SecurityUtils.getCurrentUsername()); |
| | | Store store = storeService.getById(submit.getStoreId()); |
| | | order.setStoreId(submit.getStoreId()); |
| | | order.setStoreName(store.getStoreName()); |
| | | order.setStoreLogo(store.getLogoImageUrl()); |
| | | order.setStoreAddress(store.getAddress()); |
| | | order.setStoreLongitude(BigDecimal.valueOf(store.getLongitude())); |
| | | order.setStoreLatitude(BigDecimal.valueOf(store.getLatitude())); |
| | | order.setOrderDescribe(DESCRIBE + submit.getStoreId()); |
| | | order.setOriginalPrice(amount); |
| | | order.setPaidPrice(amount); |
| | |
| | | order.setPayMessage(PayStateEnum.SUCCESS.getValue()); |
| | | order.setPayTime(DateUtil.localDateTimeFormat(now.toLocalDateTime(), DateUtil.SDF_YMDHMS)); |
| | | } |
| | | UserAddress address = userAddressService.getById(submit.getAddressId()); |
| | | OrderAddressSnapshot snapshot = getOrderAddressSnapshot(orderNum, address); |
| | | addressSnapshotService.save(snapshot); |
| | | |
| | | OrderAddressSnapshot addressSnapshot = getOrderAddressSnapshot(orderNum, address); |
| | | |
| | | |
| | | addressSnapshotService.save(addressSnapshot); |
| | | orderMapper.insert(order); |
| | | productSnapshotService.saveBatch(snapshots); |
| | | |
| | | order.setProductSnapshots(new HashSet<>(snapshots)); |
| | | OrderResponse response = new OrderResponse(order, addressSnapshot, null); |
| | | |
| | | operationLogService.create(response, OrderStatusEnum.ZERO, null); |
| | | return order; |
| | | } |
| | | |
| | |
| | | @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 Order getByOrderNum(String orderNum) { |
| | | return orderMapper.getByOrderNum(orderNum); |
| | | public void statusOrder(StatusOrder statusOrder) { |
| | | operationLog(getByOrderNum(statusOrder.getOrderNum()), statusOrder.getStatus(), null); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void paySuccess(Order order) { |
| | | public OrderResponse getByOrderNum(String orderNum) { |
| | | return new OrderResponse(orderMapper.getByOrderNum(orderNum), |
| | | addressSnapshotService.queryByOrderNum(orderNum), |
| | | operationLogService.getByOrderNum(orderNum)); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void operationLog(OrderResponse order, OrderStatusEnum stateEnum, String cardName) { |
| | | operationLogService.create(order, stateEnum, cardName); |
| | | } |
| | | |
| | | @Override |
| | |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void closeOrder(String orderNum) { |
| | | Order order = getByOrderNum(orderNum); |
| | | public synchronized void cancel(String orderNum) { |
| | | OrderResponse response = getByOrderNum(orderNum); |
| | | Order order = response.getOrder(); |
| | | if (order == null) { |
| | | throw new BadRequestException("订单不存在"); |
| | | } |
| | | if (!SecurityUtils.getCurrentUserId().equals(order.getUserId())) { |
| | | throw new BadRequestException("不能修改他人订单"); |
| | | } |
| | | if (!order.getPayState().equals(PayStateEnum.NOTPAY.getKey())) { |
| | | throw new BadRequestException(PayStateEnum.getValue(order.getPayState())); |
| | | } |
| | | PayTypeEnum anEnum = PayTypeEnum.find(order.getPayType()); |
| | | switch (anEnum) { |
| | | case HWC: |
| | | case HWC2: |
| | | JSONObject object = swiftPassService.query(orderNum, anEnum); |
| | | if (object.getString("trade_state").equals(PayStateEnum.SUCCESS.getKey())) { |
| | | throw new BadRequestException("订单已支付"); |
| | | } |
| | | if (object.getString("trade_state").equals(PayStateEnum.CLOSED.getKey())) { |
| | | throw new BadRequestException("订单已关闭"); |
| | | if (object.getString("trade_state").equals(PayStateEnum.NOTPAY.getKey())) { |
| | | throw new BadRequestException(PayStateEnum.getValue(order.getPayState())); |
| | | } |
| | | swiftPassService.closeOrder(orderNum, anEnum); |
| | | break; |
| | | } |
| | | orderMapper.updateCloseStatus(orderNum, PayStateEnum.CLOSED.getKey()); |
| | | operationLogService.create(response, OrderStatusEnum.NINE, null); |
| | | orderMapper.updateCloseStatus(orderNum, PayStateEnum.CLOSED.getKey(), PayStateEnum.CLOSED.getValue()); |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public void create(Order resources) { |
| | | orderMapper.insert(resources); |
| | | throw new BadRequestException("未开放"); |
| | | } |
| | | |
| | | @Override |
| | |
| | | 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()); |