|
|
@@ -13,6 +13,7 @@ import com.ylx.massage.domain.dto.AfterSaleOrderDTO;
|
|
|
import com.ylx.massage.domain.dto.AfterSaleOrderUpdateDTO;
|
|
|
import com.ylx.massage.domain.vo.OrderAfterSaleVo;
|
|
|
import com.ylx.massage.enums.AfterSaleStatusEnum;
|
|
|
+import com.ylx.massage.enums.AfterSaleTypeEnum;
|
|
|
import com.ylx.massage.enums.ProductOrderStatusEnum;
|
|
|
import com.ylx.massage.mapper.AfterSaleOrderMapper;
|
|
|
import com.ylx.massage.service.IAfterSaleOrderService;
|
|
|
@@ -196,6 +197,145 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void agreeReturn(Long orderId) {
|
|
|
+
|
|
|
+ // 1. 查询并校验订单(公共方法提取)
|
|
|
+ ProductOrderInfo productOrderInfo = this.productOrderInfoService.getAndCheckOrder(orderId, null);
|
|
|
+
|
|
|
+ // 2. 状态校验:必须是 售后中 才能同意退货
|
|
|
+ if (!ProductOrderStatusEnum.AFTER_SALES.getCode().equals(productOrderInfo.getOrderStatus())) {
|
|
|
+ throw new ServiceException("订单状态异常,仅售后中状态可同意退货");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 判断售后单的状态为退货
|
|
|
+ LambdaQueryWrapper<AfterSaleOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AfterSaleOrder::getOrderId, orderId)
|
|
|
+ .eq(AfterSaleOrder::getAfterSaleType, AfterSaleTypeEnum.RETURN_GOODS.getCode())
|
|
|
+ .eq(AfterSaleOrder::getAfterSaleStatus, AfterSaleStatusEnum.WAIT_AUDIT.getCode());
|
|
|
+
|
|
|
+ AfterSaleOrder afterSaleOrder = this.afterSaleOrderMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNull(afterSaleOrder)) {
|
|
|
+ throw new ServiceException("未找到待审核的退货的售后单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 更新售后订单状态为等待用户寄回
|
|
|
+ afterSaleOrder.setAfterSaleStatus(AfterSaleStatusEnum.WAITING_USER_RETURN.getCode());
|
|
|
+ afterSaleOrder.setUpdateTime(LocalDateTime.now());
|
|
|
+ boolean afterSaleUpdateResult = this.updateById(afterSaleOrder);
|
|
|
+ if (!afterSaleUpdateResult) {
|
|
|
+ throw new ServiceException("更新售后单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void agreeExchange(Long orderId) {
|
|
|
+ // 1. 查询并校验订单(公共方法提取)
|
|
|
+ ProductOrderInfo productOrderInfo = this.productOrderInfoService.getAndCheckOrder(orderId, null);
|
|
|
+
|
|
|
+ // 2. 状态校验:必须是 售后中 才能同意退货
|
|
|
+ if (!ProductOrderStatusEnum.AFTER_SALES.getCode().equals(productOrderInfo.getOrderStatus())) {
|
|
|
+ throw new ServiceException("订单状态异常,仅售后中状态可同意换货");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 判断售后单的状态为换货
|
|
|
+ LambdaQueryWrapper<AfterSaleOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AfterSaleOrder::getOrderId, orderId)
|
|
|
+ .eq(AfterSaleOrder::getAfterSaleType, AfterSaleTypeEnum.EXCHANGE_GOODS.getCode())
|
|
|
+ .eq(AfterSaleOrder::getAfterSaleStatus, AfterSaleStatusEnum.WAIT_AUDIT.getCode());
|
|
|
+
|
|
|
+ AfterSaleOrder afterSaleOrder = this.afterSaleOrderMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNull(afterSaleOrder)) {
|
|
|
+ throw new ServiceException("未找到待审核的换货的售后单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 更新售后订单状态为等待用户寄回
|
|
|
+ afterSaleOrder.setAfterSaleStatus(AfterSaleStatusEnum.WAITING_USER_RETURN.getCode());
|
|
|
+ afterSaleOrder.setUpdateTime(LocalDateTime.now());
|
|
|
+ boolean afterSaleUpdateResult = this.updateById(afterSaleOrder);
|
|
|
+ if (!afterSaleUpdateResult) {
|
|
|
+ throw new ServiceException("更新售后单失败");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void agreeRefund(Long orderId) {
|
|
|
+
|
|
|
+ // 1. 查询并校验订单(公共方法提取)
|
|
|
+ ProductOrderInfo productOrderInfo = this.productOrderInfoService.getAndCheckOrder(orderId, null);
|
|
|
+
|
|
|
+ // 2. 状态校验:必须是 售后中 才能确认收货
|
|
|
+ if (!ProductOrderStatusEnum.AFTER_SALES.getCode().equals(productOrderInfo.getOrderStatus())) {
|
|
|
+ throw new ServiceException("订单状态异常,仅售后中状态可确认收货");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 获取等待商家收货的售后单
|
|
|
+ LambdaQueryWrapper<AfterSaleOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AfterSaleOrder::getOrderId, orderId)
|
|
|
+ .eq(AfterSaleOrder::getAfterSaleStatus, AfterSaleStatusEnum.WAITING_MERCHANT_RECEIVE.getCode());
|
|
|
+
|
|
|
+ AfterSaleOrder afterSaleOrder = this.afterSaleOrderMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNull(afterSaleOrder)) {
|
|
|
+ throw new ServiceException("未找到等待商家收货的售后单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 判断售后单的售后类型
|
|
|
+ if (ObjectUtil.notEqual(AfterSaleTypeEnum.RETURN_GOODS.getCode(), afterSaleOrder.getAfterSaleType())) {
|
|
|
+ throw new ServiceException("售后单类型异常,仅退货的售后单可退货");
|
|
|
+ }
|
|
|
+ // TODO 5.退款
|
|
|
+
|
|
|
+ // 6. 更新售后单数据
|
|
|
+ afterSaleOrder.setAfterSaleStatus(AfterSaleStatusEnum.REFUND_COMPLETED.getCode());
|
|
|
+ afterSaleOrder.setUpdateTime(LocalDateTime.now());
|
|
|
+ boolean afterSaleUpdateResult = this.updateById(afterSaleOrder);
|
|
|
+ if (!afterSaleUpdateResult) {
|
|
|
+ throw new ServiceException("更新售后单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void confirmReceive(Long orderId) {
|
|
|
+
|
|
|
+ // 1. 查询并校验订单(公共方法提取)
|
|
|
+ ProductOrderInfo productOrderInfo = this.productOrderInfoService.getAndCheckOrder(orderId, null);
|
|
|
+
|
|
|
+ // 2. 状态校验:必须是 售后中 才能确认收货
|
|
|
+ if (!ProductOrderStatusEnum.AFTER_SALES.getCode().equals(productOrderInfo.getOrderStatus())) {
|
|
|
+ throw new ServiceException("订单状态异常,仅售后中状态可确认收货");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 3. 获取等待商家收货的售后单
|
|
|
+ LambdaQueryWrapper<AfterSaleOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AfterSaleOrder::getOrderId, orderId)
|
|
|
+ .eq(AfterSaleOrder::getAfterSaleStatus, AfterSaleStatusEnum.WAITING_MERCHANT_RECEIVE.getCode());
|
|
|
+
|
|
|
+ AfterSaleOrder afterSaleOrder = this.afterSaleOrderMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNull(afterSaleOrder)) {
|
|
|
+ throw new ServiceException("未找到等待商家收货的售后单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 判断售后单的售后类型
|
|
|
+ if (ObjectUtil.notEqual(AfterSaleTypeEnum.EXCHANGE_GOODS.getCode(), afterSaleOrder.getAfterSaleType())) {
|
|
|
+ throw new ServiceException("售后单类型异常,仅换货的售后单可换货");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 更新售后单数据
|
|
|
+ afterSaleOrder.setAfterSaleStatus(AfterSaleStatusEnum.WAITING_MERCHANT_SHIP.getCode());
|
|
|
+ afterSaleOrder.setUpdateTime(LocalDateTime.now());
|
|
|
+ boolean afterSaleUpdateResult = this.updateById(afterSaleOrder);
|
|
|
+ if (!afterSaleUpdateResult) {
|
|
|
+ throw new ServiceException("更新售后单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
private WxLoginUser getCurrentWxLoginUser() {
|
|
|
WxLoginUser loginUser = SecurityUtils.getWxLoginUser();
|
|
|
if (ObjectUtil.isNull(loginUser)) {
|