|
|
@@ -17,6 +17,7 @@ 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 lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
@@ -24,6 +25,7 @@ import javax.annotation.Resource;
|
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
@Service
|
|
|
+@Slf4j
|
|
|
public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper, AfterSaleOrder> implements IAfterSaleOrderService {
|
|
|
|
|
|
@Resource
|
|
|
@@ -34,16 +36,31 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public void add(AfterSaleOrderDTO dto) {
|
|
|
-
|
|
|
// 1. 获取当前登录用户(公共方法提取)
|
|
|
WxLoginUser loginUser = getCurrentWxLoginUser();
|
|
|
|
|
|
// 2. 查询并校验订单(公共方法提取)
|
|
|
ProductOrderInfo productOrderInfo = this.productOrderInfoService.getAndCheckOrder(dto.getOrderId(), loginUser.getCOpenid());
|
|
|
|
|
|
- // 3. 状态校验:必须不能是 售后中 才能发起售后
|
|
|
- if (ProductOrderStatusEnum.AFTER_SALES.getCode().equals(productOrderInfo.getOrderStatus())) {
|
|
|
- throw new ServiceException("订单状态异常,不能重复发起售后");
|
|
|
+ // 3. 校验订单状态是否允许售后
|
|
|
+ Integer orderStatus = productOrderInfo.getOrderStatus();
|
|
|
+ log.info("订单状态:{}", orderStatus);
|
|
|
+ // 明确不允许的状态
|
|
|
+ if (orderStatus == 0) {
|
|
|
+ throw new ServiceException("待付款订单请直接取消");
|
|
|
+ }
|
|
|
+ if (orderStatus == 1) {
|
|
|
+ throw new ServiceException("待发货订单请申请取消");
|
|
|
+ }
|
|
|
+ if (orderStatus == 4) {
|
|
|
+ throw new ServiceException("售后申请已在处理中");
|
|
|
+ }
|
|
|
+ if (orderStatus == 11) {
|
|
|
+ throw new ServiceException("已取消订单不支持售后");
|
|
|
+ }
|
|
|
+ // 只允许 3(已收货)发起售后,如需支持2则加上
|
|
|
+ if (orderStatus != 3 || orderStatus != 2) {
|
|
|
+ throw new ServiceException("当前订单状态不支持发起售后");
|
|
|
}
|
|
|
|
|
|
// 4. 添加售后订单
|
|
|
@@ -204,6 +221,11 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
return loginUser;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 生成售后单号
|
|
|
+ * @param orderId 订单ID
|
|
|
+ * @return String 售后单号
|
|
|
+ */
|
|
|
private String generateAfterSaleNo(Long orderId) {
|
|
|
return "AFTERSALE" + orderId + System.currentTimeMillis();
|
|
|
}
|