|
@@ -6,9 +6,11 @@ import com.etotem.cfc.common.Result;
|
|
|
import com.etotem.cfc.dto.CreateProductOrderDTO;
|
|
import com.etotem.cfc.dto.CreateProductOrderDTO;
|
|
|
import com.etotem.cfc.dto.OrderItemVO;
|
|
import com.etotem.cfc.dto.OrderItemVO;
|
|
|
import com.etotem.cfc.dto.ProductOrderDTO;
|
|
import com.etotem.cfc.dto.ProductOrderDTO;
|
|
|
|
|
+import com.etotem.cfc.entity.AfterSalesRequest;
|
|
|
import com.etotem.cfc.entity.Product;
|
|
import com.etotem.cfc.entity.Product;
|
|
|
import com.etotem.cfc.entity.ProductOrder;
|
|
import com.etotem.cfc.entity.ProductOrder;
|
|
|
import com.etotem.cfc.entity.User;
|
|
import com.etotem.cfc.entity.User;
|
|
|
|
|
+import com.etotem.cfc.mapper.AfterSalesRequestMapper;
|
|
|
import com.etotem.cfc.mapper.ProductMapper;
|
|
import com.etotem.cfc.mapper.ProductMapper;
|
|
|
import com.etotem.cfc.mapper.ProductOrderMapper;
|
|
import com.etotem.cfc.mapper.ProductOrderMapper;
|
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
import com.etotem.cfc.mapper.UserMapper;
|
|
@@ -62,6 +64,9 @@ public class ProductOrderService {
|
|
|
@Resource
|
|
@Resource
|
|
|
private PointsService pointsService;
|
|
private PointsService pointsService;
|
|
|
|
|
|
|
|
|
|
+ @Resource
|
|
|
|
|
+ private AfterSalesRequestMapper afterSalesRequestMapper;
|
|
|
|
|
+
|
|
|
public Result<ProductOrderDTO> create(CreateProductOrderDTO dto, Long buyerId) {
|
|
public Result<ProductOrderDTO> create(CreateProductOrderDTO dto, Long buyerId) {
|
|
|
if (buyerId == null) {
|
|
if (buyerId == null) {
|
|
|
return Result.error("请先登录");
|
|
return Result.error("请先登录");
|
|
@@ -377,22 +382,20 @@ public class ProductOrderService {
|
|
|
if (order.getRefundStatus() == null || order.getRefundStatus() != 1) {
|
|
if (order.getRefundStatus() == null || order.getRefundStatus() != 1) {
|
|
|
return Result.error("没有待处理的退款申请");
|
|
return Result.error("没有待处理的退款申请");
|
|
|
}
|
|
}
|
|
|
- // 调用微信支付退款
|
|
|
|
|
try {
|
|
try {
|
|
|
paymentService.refund(orderNo, order.getTotalAmount(), order.getRefundReason());
|
|
paymentService.refund(orderNo, order.getTotalAmount(), order.getRefundReason());
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
|
log.error("微信退款失败: orderNo={}, error={}", orderNo, e.getMessage());
|
|
log.error("微信退款失败: orderNo={}, error={}", orderNo, e.getMessage());
|
|
|
return Result.error("退款失败: " + e.getMessage());
|
|
return Result.error("退款失败: " + e.getMessage());
|
|
|
}
|
|
}
|
|
|
- // 更新订单状态
|
|
|
|
|
- order.setRefundStatus(2); // 已退款
|
|
|
|
|
|
|
+ order.setRefundStatus(2);
|
|
|
order.setRefundAmount(order.getTotalAmount());
|
|
order.setRefundAmount(order.getTotalAmount());
|
|
|
order.setRefundTime(new Date());
|
|
order.setRefundTime(new Date());
|
|
|
order.setStatus("refunded");
|
|
order.setStatus("refunded");
|
|
|
order.setUpdatedAt(new Date());
|
|
order.setUpdatedAt(new Date());
|
|
|
orderMapper.updateById(order);
|
|
orderMapper.updateById(order);
|
|
|
- // 恢复库存
|
|
|
|
|
productService.increaseStock(order.getProductId(), order.getQuantity());
|
|
productService.increaseStock(order.getProductId(), order.getQuantity());
|
|
|
|
|
+ syncAfterSalesRequestStatus(orderNo, "approved", adminId);
|
|
|
log.info("退款完成: orderNo={}, adminId={}", orderNo, adminId);
|
|
log.info("退款完成: orderNo={}, adminId={}", orderNo, adminId);
|
|
|
return Result.success("退款已处理");
|
|
return Result.success("退款已处理");
|
|
|
}
|
|
}
|
|
@@ -406,14 +409,36 @@ public class ProductOrderService {
|
|
|
if (order.getRefundStatus() == null || order.getRefundStatus() != 1) {
|
|
if (order.getRefundStatus() == null || order.getRefundStatus() != 1) {
|
|
|
return Result.error("没有待处理的退款申请");
|
|
return Result.error("没有待处理的退款申请");
|
|
|
}
|
|
}
|
|
|
- order.setRefundStatus(3); // 拒绝
|
|
|
|
|
- order.setStatus("paid"); // 恢复原状态
|
|
|
|
|
|
|
+ order.setRefundStatus(3);
|
|
|
|
|
+ order.setStatus("paid");
|
|
|
order.setUpdatedAt(new Date());
|
|
order.setUpdatedAt(new Date());
|
|
|
orderMapper.updateById(order);
|
|
orderMapper.updateById(order);
|
|
|
|
|
+ syncAfterSalesRequestStatus(orderNo, "rejected", adminId);
|
|
|
log.info("退款申请被拒绝: orderNo={}, adminId={}, reason={}", orderNo, adminId, reason);
|
|
log.info("退款申请被拒绝: orderNo={}, adminId={}, reason={}", orderNo, adminId, reason);
|
|
|
return Result.success("已拒绝退款申请");
|
|
return Result.success("已拒绝退款申请");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void syncAfterSalesRequestStatus(String orderNo, String status, Long adminId) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ LambdaQueryWrapper<AfterSalesRequest> wrapper = new LambdaQueryWrapper<AfterSalesRequest>()
|
|
|
|
|
+ .eq(AfterSalesRequest::getOrderNo, orderNo)
|
|
|
|
|
+ .eq(AfterSalesRequest::getStatus, "pending");
|
|
|
|
|
+ AfterSalesRequest request = afterSalesRequestMapper.selectOne(wrapper);
|
|
|
|
|
+ if (request != null) {
|
|
|
|
|
+ request.setStatus(status);
|
|
|
|
|
+ request.setHandledBy(adminId);
|
|
|
|
|
+ request.setHandledAt(new Date());
|
|
|
|
|
+ request.setUpdatedAt(new Date());
|
|
|
|
|
+ if ("rejected".equals(status)) {
|
|
|
|
|
+ request.setRejectReason("管理员拒绝退款");
|
|
|
|
|
+ }
|
|
|
|
|
+ afterSalesRequestMapper.updateById(request);
|
|
|
|
|
+ }
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("同步AfterSalesRequest状态失败: orderNo={}, status={}", orderNo, status, e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
public Result<List<ProductOrderDTO>> myOrders(Long buyerId, String status) {
|
|
public Result<List<ProductOrderDTO>> myOrders(Long buyerId, String status) {
|
|
|
return myOrders(buyerId, status, null);
|
|
return myOrders(buyerId, status, null);
|
|
|
}
|
|
}
|