|
@@ -9,6 +9,7 @@ import com.ylx.common.exception.ServiceException;
|
|
|
import com.ylx.common.utils.SecurityUtils;
|
|
import com.ylx.common.utils.SecurityUtils;
|
|
|
import com.ylx.massage.domain.AfterSaleOrder;
|
|
import com.ylx.massage.domain.AfterSaleOrder;
|
|
|
import com.ylx.massage.domain.ProductOrderInfo;
|
|
import com.ylx.massage.domain.ProductOrderInfo;
|
|
|
|
|
+import com.ylx.massage.domain.ProductOrderPayment;
|
|
|
import com.ylx.massage.domain.dto.AfterSaleOrderDTO;
|
|
import com.ylx.massage.domain.dto.AfterSaleOrderDTO;
|
|
|
import com.ylx.massage.domain.dto.AfterSaleOrderUpdateDTO;
|
|
import com.ylx.massage.domain.dto.AfterSaleOrderUpdateDTO;
|
|
|
import com.ylx.massage.domain.vo.OrderAfterSaleVo;
|
|
import com.ylx.massage.domain.vo.OrderAfterSaleVo;
|
|
@@ -16,13 +17,16 @@ import com.ylx.massage.enums.AfterSaleStatusEnum;
|
|
|
import com.ylx.massage.enums.AfterSaleTypeEnum;
|
|
import com.ylx.massage.enums.AfterSaleTypeEnum;
|
|
|
import com.ylx.massage.enums.ProductOrderStatusEnum;
|
|
import com.ylx.massage.enums.ProductOrderStatusEnum;
|
|
|
import com.ylx.massage.mapper.AfterSaleOrderMapper;
|
|
import com.ylx.massage.mapper.AfterSaleOrderMapper;
|
|
|
|
|
+import com.ylx.massage.mapper.ProductOrderPaymentMapper;
|
|
|
import com.ylx.massage.service.IAfterSaleOrderService;
|
|
import com.ylx.massage.service.IAfterSaleOrderService;
|
|
|
import com.ylx.massage.service.IProductOrderInfoService;
|
|
import com.ylx.massage.service.IProductOrderInfoService;
|
|
|
|
|
+import com.ylx.massage.service.TRechargeService;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
|
|
|
+import java.math.BigDecimal;
|
|
|
import java.time.LocalDateTime;
|
|
import java.time.LocalDateTime;
|
|
|
|
|
|
|
|
@Service
|
|
@Service
|
|
@@ -33,6 +37,10 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
private AfterSaleOrderMapper afterSaleOrderMapper;
|
|
private AfterSaleOrderMapper afterSaleOrderMapper;
|
|
|
@Resource
|
|
@Resource
|
|
|
private IProductOrderInfoService productOrderInfoService;
|
|
private IProductOrderInfoService productOrderInfoService;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private ProductOrderPaymentMapper productOrderPaymentMapper;
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private TRechargeService rechargeService;
|
|
|
|
|
|
|
|
@Override
|
|
@Override
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@Transactional(rollbackFor = Exception.class)
|
|
@@ -59,7 +67,7 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
if (orderStatus == 11) {
|
|
if (orderStatus == 11) {
|
|
|
throw new ServiceException("已取消订单不支持售后");
|
|
throw new ServiceException("已取消订单不支持售后");
|
|
|
}
|
|
}
|
|
|
- // 只允许 2(待发货)或者3(已收货)发起售后
|
|
|
|
|
|
|
+ // 只允许 2(待收货)或者3(已收货)发起售后
|
|
|
if (orderStatus != 2 && orderStatus != 3) {
|
|
if (orderStatus != 2 && orderStatus != 3) {
|
|
|
throw new ServiceException("当前订单状态不支持发起售后");
|
|
throw new ServiceException("当前订单状态不支持发起售后");
|
|
|
}
|
|
}
|
|
@@ -70,6 +78,7 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
entity.setOpenId(loginUser.getCOpenid());
|
|
entity.setOpenId(loginUser.getCOpenid());
|
|
|
entity.setCreateTime(LocalDateTime.now());
|
|
entity.setCreateTime(LocalDateTime.now());
|
|
|
entity.setAfterSaleStatus(AfterSaleStatusEnum.WAIT_AUDIT.getCode());
|
|
entity.setAfterSaleStatus(AfterSaleStatusEnum.WAIT_AUDIT.getCode());
|
|
|
|
|
+ // 生成售后单号
|
|
|
entity.setAfterSaleNo(generateAfterSaleNo(dto.getOrderId()));
|
|
entity.setAfterSaleNo(generateAfterSaleNo(dto.getOrderId()));
|
|
|
|
|
|
|
|
boolean insertResult = super.save(entity);
|
|
boolean insertResult = super.save(entity);
|
|
@@ -329,10 +338,28 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
if (ObjectUtil.notEqual(AfterSaleTypeEnum.RETURN_GOODS.getCode(), afterSaleOrder.getAfterSaleType())) {
|
|
if (ObjectUtil.notEqual(AfterSaleTypeEnum.RETURN_GOODS.getCode(), afterSaleOrder.getAfterSaleType())) {
|
|
|
throw new ServiceException("售后单类型异常,仅退货的售后单可退货");
|
|
throw new ServiceException("售后单类型异常,仅退货的售后单可退货");
|
|
|
}
|
|
}
|
|
|
- // TODO 5.退款
|
|
|
|
|
|
|
|
|
|
|
|
+ // 5. 查询支付记录获取微信交易流水号
|
|
|
|
|
+ ProductOrderPayment payment = productOrderPaymentMapper.selectOne(
|
|
|
|
|
+ new LambdaQueryWrapper<ProductOrderPayment>()
|
|
|
|
|
+ .eq(ProductOrderPayment::getOrderId, String.valueOf(productOrderInfo.getId()))
|
|
|
|
|
+ .eq(ProductOrderPayment::getPayStatus, "1"));
|
|
|
|
|
+ if (ObjectUtil.isNull(payment)) {
|
|
|
|
|
+ throw new ServiceException("未找到支付记录,无法退款");
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 6. 调用微信退款接口
|
|
|
|
|
+ // 生成退款单号
|
|
|
|
|
+ String outRefundNo = generateRefundNo();
|
|
|
|
|
+ // 退款金额
|
|
|
|
|
+ BigDecimal refundAmount = new BigDecimal(afterSaleOrder.getApplyAmount());
|
|
|
|
|
+ String refundResult = rechargeService.refund(outRefundNo, payment.getThirdPaymentNo(), productOrderInfo.getOrderNo(), refundAmount);
|
|
|
|
|
+ log.info("退款结果:{}", refundResult);
|
|
|
|
|
+ if (refundResult == null || refundResult.contains("\"code\":\"FAIL\"")) {
|
|
|
|
|
+ throw new ServiceException("退款失败:" + refundResult);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
- // 6. 更新售后单数据
|
|
|
|
|
|
|
+ // 7. 更新售后单数据
|
|
|
afterSaleOrder.setAfterSaleStatus(AfterSaleStatusEnum.REFUND_COMPLETED.getCode());
|
|
afterSaleOrder.setAfterSaleStatus(AfterSaleStatusEnum.REFUND_COMPLETED.getCode());
|
|
|
afterSaleOrder.setUpdateTime(LocalDateTime.now());
|
|
afterSaleOrder.setUpdateTime(LocalDateTime.now());
|
|
|
boolean afterSaleUpdateResult = this.updateById(afterSaleOrder);
|
|
boolean afterSaleUpdateResult = this.updateById(afterSaleOrder);
|
|
@@ -391,6 +418,7 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 生成售后单号
|
|
* 生成售后单号
|
|
|
|
|
+ *
|
|
|
* @param orderId 订单ID
|
|
* @param orderId 订单ID
|
|
|
* @return String 售后单号
|
|
* @return String 售后单号
|
|
|
*/
|
|
*/
|
|
@@ -398,4 +426,13 @@ public class AfterSaleOrderServiceImpl extends ServiceImpl<AfterSaleOrderMapper,
|
|
|
return "AFTERSALE" + orderId + System.currentTimeMillis();
|
|
return "AFTERSALE" + orderId + System.currentTimeMillis();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 生成退款单号
|
|
|
|
|
+ *
|
|
|
|
|
+ * @return String 退款单号
|
|
|
|
|
+ */
|
|
|
|
|
+ private String generateRefundNo() {
|
|
|
|
|
+ return "REFUND" + System.currentTimeMillis();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
}
|
|
}
|