| | |
| | | import com.oying.modules.pc.store.domain.Store; |
| | | 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.request.GeneratorOrder; |
| | | import com.oying.modules.sh.domain.request.ProductOrder; |
| | | import com.oying.modules.sh.domain.request.SubmitOrder; |
| | | import com.oying.modules.sh.domain.vo.OrderInfo; |
| | | 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.utils.*; |
| | |
| | | private final ProductService productService; |
| | | private final SwiftPassService swiftPassService; |
| | | private final OrderProductSnapshotService productSnapshotService; |
| | | private final OrderAddressSnapshotService addressSnapshotService; |
| | | private final RedisUtils redisUtils; |
| | | private final StoreService storeService; |
| | | private final static String DESCRIBE = "哦应:"; |
| | | |
| | | @Override |
| | | public PageResult<Order> queryAll(OrderQueryCriteria criteria, Page<Object> page) { |
| | | return PageUtil.toPage(orderMapper.findAll(criteria, page)); |
| | | criteria.setOffset(page.offset()); |
| | | List<Order> list = orderMapper.findAll(criteria); |
| | | Long total = orderMapper.countAll(criteria); |
| | | return PageUtil.toPage(list, total); |
| | | } |
| | | |
| | | @Override |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized Order submitOrder(SubmitOrder submit, HttpServletRequest request) { |
| | | if (!submit.getPayType().equals(PayTypeEnum.HWC)) { |
| | | switch (submit.getPayType()) { |
| | | case HWC: |
| | | case HWC2: |
| | | break; |
| | | default: |
| | | throw new BadRequestException("支付类型暂未开放"); |
| | | } |
| | | String orderNum = redisUtils.generateOrderSn(GenerateEnum.ORDER.getKey()); |
| | |
| | | OrderInfo info = generatorOrder(generator); |
| | | // 商品快照 |
| | | List<OrderProductSnapshot> snapshots = new ArrayList<>(); |
| | | |
| | | for (ProductInfo productInfo : info.getProducts()) { |
| | | Product product = productInfo.getProduct(); |
| | | OrderProductSnapshot snapshot = new OrderProductSnapshot(); |
| | |
| | | order.setOrderNum(orderNum); |
| | | order.setOrderStatus(OrderStatusEnum.ZERO.getKey()); |
| | | order.setOrderStatusDescribe(OrderStatusEnum.ZERO.getValue()); |
| | | order.setOrderRemark(submit.getRemark() != null ? submit.getRemark() : ""); |
| | | order.setOrderTime(submit.getDateTime()); |
| | | order.setUserId(SecurityUtils.getCurrentUserId()); |
| | | order.setUsername(SecurityUtils.getCurrentUsername()); |
| | | Store store = storeService.getById(submit.getStoreId()); |
| | |
| | | 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); |
| | | orderMapper.insert(order); |
| | | productSnapshotService.saveBatch(snapshots); |
| | | return order; |
| | | } |
| | | |
| | | private static OrderAddressSnapshot getOrderAddressSnapshot(String orderNum, UserAddress address) { |
| | | OrderAddressSnapshot snapshot = new OrderAddressSnapshot(); |
| | | snapshot.setOrderNum(orderNum); |
| | | snapshot.setReceiverName(address.getReceiverName()); |
| | | snapshot.setReceiverPhone(address.getReceiverPhone()); |
| | | snapshot.setProvince(address.getProvince() != null ? address.getProvince() : ""); |
| | | snapshot.setCity(address.getCity() != null ? address.getCity() : ""); |
| | | snapshot.setDistrict(address.getDistrict() != null ? address.getDistrict() : ""); |
| | | snapshot.setStreet(address.getStreet() != null ? address.getStreet() : ""); |
| | | snapshot.setShortAddress(address.getShortAddress()); |
| | | snapshot.setDetail(address.getDetail()); |
| | | snapshot.setLongitude(address.getLongitude()); |
| | | snapshot.setLatitude(address.getLatitude()); |
| | | snapshot.setTag(address.getTag()); |
| | | return snapshot; |
| | | } |
| | | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized OrderInfo generatorOrder(GeneratorOrder criteria) { |