| | |
| | | |
| | | import com.oying.exception.BadRequestException; |
| | | import com.oying.modules.hwc.service.SwiftPassService; |
| | | import com.oying.modules.pc.product.service.ProductInventoryService; |
| | | import com.oying.modules.sh.domain.Order; |
| | | import com.oying.modules.sh.domain.OrderProductSnapshot; |
| | | import com.oying.modules.sh.domain.OrderReturn; |
| | |
| | | private final RedisUtils redisUtils; |
| | | private final SwiftPassService swiftPassService; |
| | | private final OrderAddressSnapshotService addressSnapshotService; |
| | | private final ProductInventoryService productInventoryService; |
| | | private static final String ORDER_RETURN_KEY = "oying:order:refund"; |
| | | private static final String ORDER_CODE = "REFUND"; |
| | | public static final Integer DAY = 30; |
| | |
| | | @Override |
| | | @Transactional(rollbackFor = Exception.class) |
| | | public synchronized void create(ReturnOrder resources) { |
| | | Order order = orderService.queryByOrderNum(resources.getOrderNum()); |
| | | OrderResponse response = orderService.getByOrderNum(resources.getOrderNum()); |
| | | Order order = response.getOrder(); |
| | | if (order == null) { |
| | | throw new BadRequestException("订单不存在!"); |
| | | } |
| | |
| | | } |
| | | OrderReturn returnOrder1 = orderReturnMapper.getByOrderNum(resources.getOrderNum(), ReturnAuditEnum.ZERO.getKey()); |
| | | if (returnOrder1 != null) { |
| | | throw new BadRequestException("退款订单已提交"); |
| | | throw new BadRequestException("申请已提交"); |
| | | } |
| | | OrderReturn returnOrder2 = orderReturnMapper.getByOrderNum(resources.getOrderNum(), ReturnAuditEnum.TWO.getKey()); |
| | | if (returnOrder2 != null) { |
| | |
| | | // 退款订单号 |
| | | String returnNum = redisUtils.generateSn(ORDER_RETURN_KEY, GenerateEnum.ORDER_RETURN.getKey()); |
| | | returnOrder.setReturnNum(returnNum); |
| | | returnOrder.setReturnStatus(ReturnAuditEnum.ZERO.getKey()); |
| | | returnOrder.setReturnStatusDescribe(ReturnAuditEnum.ZERO.getValue()); |
| | | returnOrder.setReturnStatus(OrderStatusEnum.TEN.getKey()); |
| | | returnOrder.setReturnStatusDescribe(OrderStatusEnum.TEN.getValue()); |
| | | returnOrder.setOrderNum(resources.getOrderNum()); |
| | | returnOrder.setOrderTime(order.getOrderTime()); |
| | | returnOrder.setOrderStoreNum(order.getOrderStoreNum()); |
| | |
| | | } |
| | | } |
| | | productSnapshotService.saveBatch(productSnapshots); |
| | | operationLogService.create(response, OrderStatusEnum.TEN, null); |
| | | } |
| | | |
| | | private static OrderReturnProductSnapshot getSnapshot(OrderProductSnapshot snapshot, String returnNum) { |
| | |
| | | public void cancel(String returnNum) { |
| | | OrderReturn orderReturn = orderReturnMapper.getByReturnNum(returnNum); |
| | | if (orderReturn == null) { |
| | | throw new BadRequestException("订单不存在!"); |
| | | throw new BadRequestException("申请不存在!"); |
| | | } |
| | | if (!orderReturn.getUserId().equals(SecurityUtils.getCurrentUserId())) { |
| | | throw new BadRequestException("不能修改他人订单"); |
| | | throw new BadRequestException("不能修改他人申请"); |
| | | } |
| | | if (orderReturn.getAuditStatus().equals(ReturnAuditEnum.ONE.getKey())) { |
| | | throw new BadRequestException("申请已拒绝"); |
| | | } |
| | | orderReturnMapper.updateStatus(returnNum, OrderStatusEnum.FIFTEEN.getKey(), OrderStatusEnum.FIFTEEN.getValue(), |
| | | ReturnAuditEnum.THREE.getKey()); |
| | |
| | | public synchronized void audit(AuditOrderReturn resources) { |
| | | OrderReturn orderReturn = orderReturnMapper.getByReturnNum(resources.getReturnNum()); |
| | | if (orderReturn == null) { |
| | | throw new BadRequestException("订单不存在!"); |
| | | throw new BadRequestException("申请不存在!"); |
| | | } |
| | | if (!Objects.equals(orderReturn.getReturnStatus(), ReturnAuditEnum.ZERO.getKey())) { |
| | | throw new BadRequestException("订单已处理或取消"); |
| | | throw new BadRequestException("申请已处理或取消"); |
| | | } |
| | | if (resources.getAmount().compareTo(orderReturn.getActuallyPayPrice()) > 0) { |
| | | throw new BadRequestException("退款金额超过订单金额"); |
| | |
| | | default: |
| | | throw new BadRequestException("暂未开通其余支付模式"); |
| | | } |
| | | for (OrderReturnProductSnapshot snapshot : orderReturn.getProductSnapshots()) { |
| | | productInventoryService.increaseStock(snapshot.getProductId(), snapshot.getDetailCount()); |
| | | } |
| | | break; |
| | | default: |
| | | throw new BadRequestException("审核状态错误"); |