|
|
@@ -2,17 +2,21 @@ package com.ylx.massage.service.impl;
|
|
|
|
|
|
import cn.hutool.core.bean.BeanUtil;
|
|
|
import cn.hutool.core.util.ObjectUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
import com.ylx.common.core.domain.model.WxLoginUser;
|
|
|
import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.common.utils.SecurityUtils;
|
|
|
import com.ylx.massage.domain.AfterSaleOrder;
|
|
|
+import com.ylx.massage.domain.ProductOrderInfo;
|
|
|
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.ProductOrderStatusEnum;
|
|
|
import com.ylx.massage.mapper.AfterSaleOrderMapper;
|
|
|
import com.ylx.massage.service.IAfterSaleOrderService;
|
|
|
+import com.ylx.massage.service.IProductOrderInfoService;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -24,6 +28,8 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
|
|
|
@Resource
|
|
|
private AfterSaleOrderMapper afterSaleOrderMapper;
|
|
|
+ @Resource
|
|
|
+ private IProductOrderInfoService productOrderInfoService;
|
|
|
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
@@ -32,7 +38,15 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
// 1. 获取当前登录用户(公共方法提取)
|
|
|
WxLoginUser loginUser = getCurrentWxLoginUser();
|
|
|
|
|
|
- // 2. 添加售后订单
|
|
|
+ // 2. 查询并校验订单(公共方法提取)
|
|
|
+ ProductOrderInfo productOrderInfo = this.productOrderInfoService.getAndCheckOrder(dto.getOrderId(), loginUser.getCOpenid());
|
|
|
+
|
|
|
+ // 3. 状态校验:必须不能是 售后中 才能发起售后
|
|
|
+ if (ProductOrderStatusEnum.AFTER_SALES.getCode().equals(productOrderInfo.getOrderStatus())) {
|
|
|
+ throw new ServiceException("订单状态异常,不能重复发起售后");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 添加售后订单
|
|
|
AfterSaleOrder entity = new AfterSaleOrder();
|
|
|
BeanUtil.copyProperties(dto, entity);
|
|
|
entity.setOpenId(loginUser.getCOpenid());
|
|
|
@@ -40,7 +54,21 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
entity.setAfterSaleStatus(AfterSaleStatusEnum.WAIT_AUDIT.getCode());
|
|
|
entity.setAfterSaleNo(generateAfterSaleNo(dto.getOrderId()));
|
|
|
|
|
|
- this.afterSaleOrderMapper.insert(entity);
|
|
|
+ boolean insertResult = super.save(entity);
|
|
|
+ if (!insertResult) {
|
|
|
+ throw new ServiceException("创建售后订单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 更新订单状态
|
|
|
+ ProductOrderInfo updateInfo = new ProductOrderInfo();
|
|
|
+ updateInfo.setId(productOrderInfo.getId());
|
|
|
+ updateInfo.setOrderStatus(ProductOrderStatusEnum.AFTER_SALES.getCode());
|
|
|
+ updateInfo.setUpdateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ boolean updateResult = this.productOrderInfoService.updateById(updateInfo);
|
|
|
+ if (!updateResult) {
|
|
|
+ throw new ServiceException("订单状态已变更,请刷新后重试");
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
@@ -61,6 +89,52 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
this.afterSaleOrderMapper.updateById(afterSaleOrder);
|
|
|
}
|
|
|
|
|
|
+ @Override
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
+ public void cancel(Long orderId) {
|
|
|
+
|
|
|
+ // 1. 获取当前登录用户(公共方法提取)
|
|
|
+ WxLoginUser loginUser = getCurrentWxLoginUser();
|
|
|
+
|
|
|
+ // 2. 查询并校验订单(公共方法提取)
|
|
|
+ ProductOrderInfo productOrderInfo = this.productOrderInfoService.getAndCheckOrder(orderId, loginUser.getCOpenid());
|
|
|
+
|
|
|
+ // 3. 状态校验:必须是 退货中/退款中 才能取消退货
|
|
|
+ if (!ProductOrderStatusEnum.AFTER_SALES.getCode().equals(productOrderInfo.getOrderStatus())) {
|
|
|
+ throw new ServiceException("订单状态异常,仅售后中状态可取消售后");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 取消售后订单
|
|
|
+ LambdaQueryWrapper<AfterSaleOrder> queryWrapper = new LambdaQueryWrapper<>();
|
|
|
+ queryWrapper.eq(AfterSaleOrder::getOrderId, orderId)
|
|
|
+ .eq(AfterSaleOrder::getOpenId, loginUser.getCOpenid())
|
|
|
+ .eq(AfterSaleOrder::getAfterSaleStatus, AfterSaleStatusEnum.WAIT_AUDIT.getCode());
|
|
|
+
|
|
|
+ AfterSaleOrder afterSaleOrder = this.afterSaleOrderMapper.selectOne(queryWrapper);
|
|
|
+ if (ObjectUtil.isNull(afterSaleOrder)) {
|
|
|
+ throw new ServiceException("未找到可取消的售后订单");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新售后订单状态为已取消
|
|
|
+ afterSaleOrder.setAfterSaleStatus(AfterSaleStatusEnum.CANCELLED.getCode());
|
|
|
+ afterSaleOrder.setUpdateTime(LocalDateTime.now());
|
|
|
+ boolean afterSaleUpdateResult = this.updateById(afterSaleOrder);
|
|
|
+ if (!afterSaleUpdateResult ) {
|
|
|
+ throw new ServiceException("取消售后订单失败");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 5. 更新订单状态
|
|
|
+ ProductOrderInfo updateInfo = new ProductOrderInfo();
|
|
|
+ updateInfo.setId(productOrderInfo.getId());
|
|
|
+ updateInfo.setOrderStatus(ProductOrderStatusEnum.WAIT_RECEIVE.getCode());
|
|
|
+ updateInfo.setUpdateTime(LocalDateTime.now());
|
|
|
+
|
|
|
+ boolean orderUpdateResult = this.productOrderInfoService.updateById(updateInfo);
|
|
|
+ if (!orderUpdateResult ) {
|
|
|
+ throw new ServiceException("订单状态已变更,请刷新后重试");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
private WxLoginUser getCurrentWxLoginUser() {
|
|
|
WxLoginUser loginUser = SecurityUtils.getWxLoginUser();
|
|
|
if (ObjectUtil.isNull(loginUser)) {
|