Merge pull request 'test' (#57) from test into prod
Reviewed-on: http://220.205.16.27:18081/goflytec/GoFly-platform-services/pulls/57
This commit is contained in:
@@ -0,0 +1,75 @@
|
||||
-- 携程退款功能表结构更新脚本
|
||||
-- 执行前请备份数据
|
||||
|
||||
USE `coupon-center`;
|
||||
|
||||
-- 更新 t_ctrip_refund 表结构(如果表已存在则修改,否则创建)
|
||||
DROP TABLE IF EXISTS `t_ctrip_refund_backup`;
|
||||
|
||||
-- 检查表是否存在,如果存在则备份
|
||||
CREATE TABLE IF NOT EXISTS `t_ctrip_refund_backup` AS SELECT * FROM `t_ctrip_refund` WHERE 1=0;
|
||||
INSERT INTO `t_ctrip_refund_backup` SELECT * FROM `t_ctrip_refund` WHERE 1=1;
|
||||
|
||||
-- 删除旧表并重建
|
||||
DROP TABLE IF EXISTS `t_ctrip_refund`;
|
||||
|
||||
CREATE TABLE `t_ctrip_refund` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`ota_order_id` varchar(100) NOT NULL COMMENT '携程订单号',
|
||||
`supplier_order_id` varchar(100) DEFAULT NULL COMMENT '供应商订单号',
|
||||
`sequence_id` varchar(100) NOT NULL COMMENT '携程批次流水号',
|
||||
`refund_amount` decimal(10,2) NOT NULL COMMENT '退款金额',
|
||||
`currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
||||
`refund_status` int(11) DEFAULT 0 COMMENT '退款状态:0-待确认,1-已确认,2-已拒绝',
|
||||
`confirm_result_code` varchar(50) DEFAULT NULL COMMENT '确认结果码',
|
||||
`confirm_result_message` varchar(500) DEFAULT NULL COMMENT '确认结果信息',
|
||||
`last_confirm_time` datetime DEFAULT NULL COMMENT '最晚确认时间',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`create_by` varchar(50) DEFAULT NULL COMMENT '创建人',
|
||||
`update_by` varchar(50) DEFAULT NULL COMMENT '更新人',
|
||||
`remark` varchar(500) DEFAULT NULL COMMENT '备注',
|
||||
`tenant_id` varchar(12) DEFAULT '000000' COMMENT '租户ID',
|
||||
PRIMARY KEY (`id`),
|
||||
UNIQUE KEY `uk_sequence_id` (`sequence_id`),
|
||||
KEY `idx_ota_order_id` (`ota_order_id`),
|
||||
KEY `idx_supplier_order_id` (`supplier_order_id`),
|
||||
KEY `idx_refund_status` (`refund_status`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程退款表';
|
||||
|
||||
-- 更新 t_ctrip_refund_item 表结构
|
||||
DROP TABLE IF EXISTS `t_ctrip_refund_item_backup`;
|
||||
|
||||
-- 检查表是否存在,如果存在则备份
|
||||
CREATE TABLE IF NOT EXISTS `t_ctrip_refund_item_backup` AS SELECT * FROM `t_ctrip_refund_item` WHERE 1=0;
|
||||
INSERT INTO `t_ctrip_refund_item_backup` SELECT * FROM `t_ctrip_refund_item` WHERE 1=1;
|
||||
|
||||
-- 删除旧表并重建
|
||||
DROP TABLE IF EXISTS `t_ctrip_refund_item`;
|
||||
|
||||
CREATE TABLE `t_ctrip_refund_item` (
|
||||
`id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '主键ID',
|
||||
`refund_id` bigint(20) NOT NULL COMMENT '退款ID',
|
||||
`item_id` varchar(100) DEFAULT NULL COMMENT '订单项编号',
|
||||
`plu` varchar(100) DEFAULT NULL COMMENT '供应商产品最小单位',
|
||||
`refund_amount` decimal(10,2) DEFAULT NULL COMMENT '退款金额',
|
||||
`currency` varchar(10) DEFAULT 'CNY' COMMENT '货币类型',
|
||||
`create_time` datetime DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
|
||||
`update_time` datetime DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
|
||||
`deleted` tinyint(1) DEFAULT 0 COMMENT '是否删除:0-未删除,1-已删除',
|
||||
PRIMARY KEY (`id`),
|
||||
KEY `idx_refund_id` (`refund_id`),
|
||||
KEY `idx_item_id` (`item_id`)
|
||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='携程退款项表';
|
||||
|
||||
-- 确保 t_ctrip_order 表有 status 字段(整数类型)
|
||||
-- 订单状态:0-待确认,1-已确认,2-已取消,3-已过期,4-退款中,5-已退款
|
||||
ALTER TABLE `t_ctrip_order`
|
||||
MODIFY COLUMN `status` int(11) DEFAULT 0 COMMENT '订单状态:0-待确认,1-已确认,2-已取消,3-已过期,4-退款中,5-已退款';
|
||||
|
||||
-- 如果 status 字段不存在,则添加
|
||||
-- ALTER TABLE `t_ctrip_order` ADD COLUMN `status` int(11) DEFAULT 0 COMMENT '订单状态:0-待确认,1-已确认,2-已取消,3-已过期,4-退款中,5-已退款';
|
||||
|
||||
-- 清理备份表(可选,确认数据无误后执行)
|
||||
-- DROP TABLE IF EXISTS `t_ctrip_refund_backup`;
|
||||
-- DROP TABLE IF EXISTS `t_ctrip_refund_item_backup`;
|
||||
+278
@@ -0,0 +1,278 @@
|
||||
package com.central.coupon.controller;
|
||||
|
||||
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
||||
import com.baomidou.mybatisplus.core.metadata.IPage;
|
||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.entity.CtripOrder;
|
||||
import com.central.coupon.entity.CtripRefund;
|
||||
import com.central.coupon.enums.CtripOrderStatus;
|
||||
import com.central.coupon.mapper.CtripOrderMapper;
|
||||
import com.central.coupon.mapper.CtripRefundMapper;
|
||||
import com.central.coupon.model.CtripAdminRefundRequest;
|
||||
import com.central.coupon.service.ICtripAdminRefundService;
|
||||
import io.swagger.v3.oas.annotations.Operation;
|
||||
import io.swagger.v3.oas.annotations.Parameter;
|
||||
import io.swagger.v3.oas.annotations.tags.Tag;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.util.StringUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 携程管理后台退款控制器
|
||||
* 用于管理后台发起携程订单退款
|
||||
*/
|
||||
@Slf4j
|
||||
@Tag(name = "携程管理后台退款接口")
|
||||
@RestController
|
||||
@RequestMapping("/coupon/ctrip/admin/refund")
|
||||
public class CtripAdminRefundController {
|
||||
|
||||
@Autowired
|
||||
private ICtripAdminRefundService ctripAdminRefundService;
|
||||
|
||||
@Autowired
|
||||
private CtripOrderMapper ctripOrderMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripRefundMapper ctripRefundMapper;
|
||||
|
||||
/**
|
||||
* 管理后台发起携程退款
|
||||
*/
|
||||
@Operation(summary = "管理后台发起携程退款")
|
||||
@PostMapping("/apply")
|
||||
public Result<String> applyRefund(@RequestBody CtripAdminRefundRequest request) {
|
||||
log.info("管理后台发起携程退款请求,orderNo: {}, refundAmount: {}",
|
||||
request.getOrderNo(), request.getRefundAmount());
|
||||
|
||||
try {
|
||||
return ctripAdminRefundService.processAdminRefund(request);
|
||||
} catch (Exception e) {
|
||||
log.error("管理后台携程退款异常,orderNo: {}", request.getOrderNo(), e);
|
||||
return Result.failed("退款处理异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取可退金额
|
||||
*/
|
||||
@Operation(summary = "获取订单可退金额")
|
||||
@GetMapping("/available/{orderNo}")
|
||||
public Result<Map<String, Object>> getAvailableRefundAmount(
|
||||
@Parameter(description = "订单中心订单号") @PathVariable String orderNo) {
|
||||
log.info("获取订单可退金额,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
// 根据orderNo查询携程订单
|
||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
||||
if (ctripOrder == null) {
|
||||
return Result.failed("未找到关联的携程订单");
|
||||
}
|
||||
|
||||
BigDecimal availableAmount = ctripAdminRefundService.getAvailableRefundAmount(orderNo);
|
||||
boolean canRefund = ctripAdminRefundService.canRefund(orderNo);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("orderNo", orderNo);
|
||||
result.put("otaOrderId", ctripOrder.getOtaOrderId());
|
||||
result.put("totalAmount", ctripOrder.getTotalAmount());
|
||||
result.put("availableRefundAmount", availableAmount);
|
||||
result.put("canRefund", canRefund);
|
||||
result.put("orderStatus", ctripOrder.getStatus());
|
||||
result.put("orderStatusDesc", getOrderStatusDesc(ctripOrder.getStatus()));
|
||||
|
||||
return Result.succeed(result);
|
||||
} catch (Exception e) {
|
||||
log.error("获取可退金额异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("获取可退金额异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查订单是否可退款
|
||||
*/
|
||||
@Operation(summary = "检查订单是否可退款")
|
||||
@GetMapping("/check/{orderNo}")
|
||||
public Result<Map<String, Object>> checkCanRefund(
|
||||
@Parameter(description = "订单中心订单号") @PathVariable String orderNo) {
|
||||
log.info("检查订单是否可退款,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
||||
if (ctripOrder == null) {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("orderNo", orderNo);
|
||||
result.put("canRefund", false);
|
||||
result.put("reason", "未找到关联的携程订单");
|
||||
return Result.succeed(result);
|
||||
}
|
||||
|
||||
boolean canRefund = ctripAdminRefundService.canRefund(orderNo);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("orderNo", orderNo);
|
||||
result.put("otaOrderId", ctripOrder.getOtaOrderId());
|
||||
result.put("canRefund", canRefund);
|
||||
result.put("orderStatus", ctripOrder.getStatus());
|
||||
result.put("orderStatusDesc", getOrderStatusDesc(ctripOrder.getStatus()));
|
||||
if (!canRefund) {
|
||||
result.put("reason", "订单状态不支持退款,当前状态: " + getOrderStatusDesc(ctripOrder.getStatus()));
|
||||
}
|
||||
|
||||
return Result.succeed(result);
|
||||
} catch (Exception e) {
|
||||
log.error("检查订单是否可退款异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("检查失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询退款记录
|
||||
*/
|
||||
@Operation(summary = "查询订单退款记录")
|
||||
@GetMapping("/records/{orderNo}")
|
||||
public Result<List<CtripRefund>> getRefundRecords(
|
||||
@Parameter(description = "订单中心订单号") @PathVariable String orderNo) {
|
||||
log.info("查询订单退款记录,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
// 根据orderNo查询携程订单
|
||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
||||
if (ctripOrder == null) {
|
||||
return Result.failed("未找到关联的携程订单");
|
||||
}
|
||||
|
||||
List<CtripRefund> refunds = ctripRefundMapper.selectByOtaOrderId(ctripOrder.getOtaOrderId());
|
||||
return Result.succeed(refunds);
|
||||
} catch (Exception e) {
|
||||
log.error("查询退款记录异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单状态描述
|
||||
*/
|
||||
private String getOrderStatusDesc(Integer status) {
|
||||
if (status == null) {
|
||||
return "未知";
|
||||
}
|
||||
try {
|
||||
return CtripOrderStatus.fromNumericValue(status).getDescription();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return "未知状态";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取退款状态描述
|
||||
*/
|
||||
private String getRefundStatusDesc(Integer status) {
|
||||
if (status == null) {
|
||||
return "未知";
|
||||
}
|
||||
switch (status) {
|
||||
case 0:
|
||||
return "待确认";
|
||||
case 1:
|
||||
return "已确认";
|
||||
case 2:
|
||||
return "已拒绝";
|
||||
default:
|
||||
return "未知状态";
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询携程订单列表
|
||||
*/
|
||||
@Operation(summary = "分页查询携程订单列表")
|
||||
@GetMapping("/orders")
|
||||
public Result<Map<String, Object>> getCtripOrderList(
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer limit,
|
||||
@Parameter(description = "携程订单号") @RequestParam(required = false) String otaOrderId,
|
||||
@Parameter(description = "关联订单号") @RequestParam(required = false) String orderNo,
|
||||
@Parameter(description = "订单状态") @RequestParam(required = false) Integer status) {
|
||||
log.info("分页查询携程订单列表,page: {}, limit: {}, otaOrderId: {}, orderNo: {}, status: {}",
|
||||
page, limit, otaOrderId, orderNo, status);
|
||||
|
||||
try {
|
||||
LambdaQueryWrapper<CtripOrder> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.hasText(otaOrderId)) {
|
||||
queryWrapper.like(CtripOrder::getOtaOrderId, otaOrderId);
|
||||
}
|
||||
if (StringUtils.hasText(orderNo)) {
|
||||
queryWrapper.like(CtripOrder::getOrderNo, orderNo);
|
||||
}
|
||||
if (status != null) {
|
||||
queryWrapper.eq(CtripOrder::getStatus, status);
|
||||
}
|
||||
queryWrapper.orderByDesc(CtripOrder::getCreateTime);
|
||||
|
||||
Page<CtripOrder> pageParam = new Page<>(page, limit);
|
||||
IPage<CtripOrder> pageResult = ctripOrderMapper.selectPage(pageParam, queryWrapper);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("data", pageResult.getRecords());
|
||||
result.put("count", pageResult.getTotal());
|
||||
result.put("page", page);
|
||||
result.put("limit", limit);
|
||||
|
||||
return Result.succeed(result);
|
||||
} catch (Exception e) {
|
||||
log.error("查询携程订单列表异常", e);
|
||||
return Result.failed("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 分页查询携程退款列表
|
||||
*/
|
||||
@Operation(summary = "分页查询携程退款列表")
|
||||
@GetMapping("/refunds")
|
||||
public Result<Map<String, Object>> getCtripRefundList(
|
||||
@Parameter(description = "页码") @RequestParam(defaultValue = "1") Integer page,
|
||||
@Parameter(description = "每页数量") @RequestParam(defaultValue = "20") Integer limit,
|
||||
@Parameter(description = "携程订单号") @RequestParam(required = false) String otaOrderId,
|
||||
@Parameter(description = "供应商订单号") @RequestParam(required = false) String supplierOrderId,
|
||||
@Parameter(description = "退款状态") @RequestParam(required = false) Integer refundStatus) {
|
||||
log.info("分页查询携程退款列表,page: {}, limit: {}, otaOrderId: {}, supplierOrderId: {}, refundStatus: {}",
|
||||
page, limit, otaOrderId, supplierOrderId, refundStatus);
|
||||
|
||||
try {
|
||||
LambdaQueryWrapper<CtripRefund> queryWrapper = new LambdaQueryWrapper<>();
|
||||
if (StringUtils.hasText(otaOrderId)) {
|
||||
queryWrapper.like(CtripRefund::getOtaOrderId, otaOrderId);
|
||||
}
|
||||
if (StringUtils.hasText(supplierOrderId)) {
|
||||
queryWrapper.like(CtripRefund::getSupplierOrderId, supplierOrderId);
|
||||
}
|
||||
if (refundStatus != null) {
|
||||
queryWrapper.eq(CtripRefund::getRefundStatus, refundStatus);
|
||||
}
|
||||
queryWrapper.orderByDesc(CtripRefund::getCreateTime);
|
||||
|
||||
Page<CtripRefund> pageParam = new Page<>(page, limit);
|
||||
IPage<CtripRefund> pageResult = ctripRefundMapper.selectPage(pageParam, queryWrapper);
|
||||
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
result.put("data", pageResult.getRecords());
|
||||
result.put("count", pageResult.getTotal());
|
||||
result.put("page", page);
|
||||
result.put("limit", limit);
|
||||
|
||||
return Result.succeed(result);
|
||||
} catch (Exception e) {
|
||||
log.error("查询携程退款列表异常", e);
|
||||
return Result.failed("查询失败: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
+5
-1
@@ -21,7 +21,11 @@ public enum CtripOrderStatus {
|
||||
WAITING_PAYMENT(11, "WAITING_PAYMENT", "待支付"),
|
||||
PAYMENT_PENDING(12, "PAYMENT_PENDING", "支付待确认"),
|
||||
PAYMENT_CONFIRMED(13, "PAYMENT_CONFIRMED", "支付已确认"),
|
||||
PRE_ORDER_CANCELLED(14, "PRE_ORDER_CANCELLED", "预下单取消成功");
|
||||
PRE_ORDER_CANCELLED(14, "PRE_ORDER_CANCELLED", "预下单取消成功"),
|
||||
// 管理后台主动发起退款的状态
|
||||
ADMIN_REFUNDING(15, "ADMIN_REFUNDING", "退款中"),
|
||||
ADMIN_REFUNDED(16, "ADMIN_REFUNDED", "已退款"),
|
||||
ADMIN_PART_REFUNDED(17, "ADMIN_PART_REFUNDED", "部分退款");
|
||||
|
||||
private final int numericValue;
|
||||
private final String stringValue;
|
||||
|
||||
+23
-2
@@ -9,21 +9,42 @@ import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PathVariable;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
@FeignClient(name = ServiceNameConstants.ORDER_SERVICE, dismiss404 = true)
|
||||
public interface OrderCenterService {
|
||||
@GetMapping("/qrcode/{codeId}")
|
||||
Result<QrCodeInfo> getQrCode(@PathVariable("codeId") String codeId);
|
||||
|
||||
|
||||
/**
|
||||
* 根据订单号获取订单信息
|
||||
*/
|
||||
@GetMapping("/order/{orderNo}")
|
||||
Result<OrderInfo> getOrderByOrderNo(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
|
||||
/**
|
||||
* 更新订单状态为已支付(优惠券核销成功后调用)
|
||||
*/
|
||||
@PostMapping("/order/{orderNo}/status/paid")
|
||||
Result<String> updateOrderStatusToPaid(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 更新订单状态为退款中
|
||||
*/
|
||||
@PostMapping("/order/{orderNo}/status/refunding")
|
||||
Result<String> updateOrderStatusToRefunding(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 更新订单状态为已退款
|
||||
*/
|
||||
@PostMapping("/order/{orderNo}/status/refunded")
|
||||
Result<String> updateOrderStatusToRefunded(@PathVariable("orderNo") String orderNo);
|
||||
|
||||
/**
|
||||
* 创建退款记录
|
||||
*/
|
||||
@PostMapping("/refund/ctrip/{orderNo}")
|
||||
Result<String> createCtripRefund(@PathVariable("orderNo") String orderNo, @RequestBody Map<String, Object> refundInfo);
|
||||
}
|
||||
+59
@@ -0,0 +1,59 @@
|
||||
package com.central.coupon.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 管理后台携程退款请求
|
||||
*/
|
||||
@Data
|
||||
public class CtripAdminRefundRequest {
|
||||
|
||||
/**
|
||||
* 订单中心订单号
|
||||
*/
|
||||
private String orderNo;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal refundAmount;
|
||||
|
||||
/**
|
||||
* 退款原因
|
||||
*/
|
||||
private String refundReason;
|
||||
|
||||
/**
|
||||
* 退款项列表(可选)
|
||||
*/
|
||||
private List<RefundItem> items;
|
||||
|
||||
/**
|
||||
* 退款项
|
||||
*/
|
||||
@Data
|
||||
public static class RefundItem {
|
||||
/**
|
||||
* 订单项编号
|
||||
*/
|
||||
private String itemId;
|
||||
|
||||
/**
|
||||
* PLU编码
|
||||
*/
|
||||
private String plu;
|
||||
|
||||
/**
|
||||
* 退款金额
|
||||
*/
|
||||
private BigDecimal amount;
|
||||
|
||||
/**
|
||||
* 货币类型
|
||||
*/
|
||||
private String amountCurrency;
|
||||
}
|
||||
}
|
||||
+36
@@ -0,0 +1,36 @@
|
||||
package com.central.coupon.service;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.model.CtripAdminRefundRequest;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
/**
|
||||
* 携程管理后台退款服务接口
|
||||
*/
|
||||
public interface ICtripAdminRefundService {
|
||||
|
||||
/**
|
||||
* 管理后台发起携程退款
|
||||
*
|
||||
* @param request 退款请求
|
||||
* @return 退款结果
|
||||
*/
|
||||
Result<String> processAdminRefund(CtripAdminRefundRequest request);
|
||||
|
||||
/**
|
||||
* 根据订单中心订单号获取可退金额
|
||||
*
|
||||
* @param orderNo 订单中心订单号
|
||||
* @return 可退金额
|
||||
*/
|
||||
BigDecimal getAvailableRefundAmount(String orderNo);
|
||||
|
||||
/**
|
||||
* 检查订单是否可以退款
|
||||
*
|
||||
* @param orderNo 订单中心订单号
|
||||
* @return 是否可退款
|
||||
*/
|
||||
boolean canRefund(String orderNo);
|
||||
}
|
||||
+15
-1
@@ -44,11 +44,25 @@ public interface ICtripApiService {
|
||||
|
||||
/**
|
||||
* 取消携程优惠券
|
||||
*
|
||||
*
|
||||
* @param ctripCouponId 携程优惠券ID
|
||||
* @param userPhone 用户手机号
|
||||
* @param reason 取消原因
|
||||
* @return 取消结果
|
||||
*/
|
||||
boolean cancelCoupon(String ctripCouponId, String userPhone, String reason);
|
||||
|
||||
/**
|
||||
* 调用携程退款接口
|
||||
*
|
||||
* @param otaOrderId 携程订单号
|
||||
* @param supplierOrderId 供应商订单号
|
||||
* @param totalAmount 退款总金额
|
||||
* @param currency 货币类型
|
||||
* @param items 退款项列表(可选)
|
||||
* @return 退款结果:1-退款已确认,2-退款待确认,0-退款失败
|
||||
*/
|
||||
int sendRefundOrder(String otaOrderId, String supplierOrderId,
|
||||
java.math.BigDecimal totalAmount, String currency,
|
||||
java.util.List<java.util.Map<String, Object>> items);
|
||||
}
|
||||
+379
@@ -0,0 +1,379 @@
|
||||
package com.central.coupon.service.impl;
|
||||
|
||||
import com.central.common.model.Result;
|
||||
import com.central.coupon.entity.CtripOrder;
|
||||
import com.central.coupon.entity.CtripOrderItem;
|
||||
import com.central.coupon.entity.CtripRefund;
|
||||
import com.central.coupon.entity.CtripRefundItem;
|
||||
import com.central.coupon.enums.CtripOrderStatus;
|
||||
import com.central.coupon.feign.OrderCenterService;
|
||||
import com.central.coupon.mapper.CtripOrderItemMapper;
|
||||
import com.central.coupon.mapper.CtripOrderMapper;
|
||||
import com.central.coupon.mapper.CtripRefundItemMapper;
|
||||
import com.central.coupon.mapper.CtripRefundMapper;
|
||||
import com.central.coupon.model.CtripAdminRefundRequest;
|
||||
import com.central.coupon.service.ICtripAdminRefundService;
|
||||
import com.central.coupon.service.ICtripApiService;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
|
||||
/**
|
||||
* 携程管理后台退款服务实现
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
public class CtripAdminRefundServiceImpl implements ICtripAdminRefundService {
|
||||
|
||||
@Autowired
|
||||
private CtripOrderMapper ctripOrderMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripOrderItemMapper ctripOrderItemMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripRefundMapper ctripRefundMapper;
|
||||
|
||||
@Autowired
|
||||
private CtripRefundItemMapper ctripRefundItemMapper;
|
||||
|
||||
@Autowired
|
||||
private ICtripApiService ctripApiService;
|
||||
|
||||
@Autowired
|
||||
private OrderCenterService orderCenterService;
|
||||
|
||||
@Override
|
||||
@Transactional(rollbackFor = Exception.class)
|
||||
public Result<String> processAdminRefund(CtripAdminRefundRequest request) {
|
||||
log.info("管理后台发起携程退款,orderNo: {}, refundAmount: {}",
|
||||
request.getOrderNo(), request.getRefundAmount());
|
||||
|
||||
try {
|
||||
// 1. 验证参数
|
||||
if (request.getOrderNo() == null || request.getOrderNo().trim().isEmpty()) {
|
||||
return Result.failed("订单号不能为空");
|
||||
}
|
||||
if (request.getRefundAmount() == null || request.getRefundAmount().compareTo(BigDecimal.ZERO) <= 0) {
|
||||
return Result.failed("退款金额必须大于0");
|
||||
}
|
||||
|
||||
// 2. 根据orderNo查询携程订单
|
||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(request.getOrderNo());
|
||||
if (ctripOrder == null) {
|
||||
return Result.failed("未找到关联的携程订单,orderNo: " + request.getOrderNo());
|
||||
}
|
||||
|
||||
log.info("找到携程订单,otaOrderId: {}, orderNo: {}", ctripOrder.getOtaOrderId(), ctripOrder.getOrderNo());
|
||||
|
||||
// 3. 检查订单状态是否可退款
|
||||
if (!canRefundByCtripOrder(ctripOrder)) {
|
||||
return Result.failed("订单状态不支持退款,当前状态: " + getOrderStatusDesc(ctripOrder.getStatus()));
|
||||
}
|
||||
|
||||
// 4. 验证退款金额
|
||||
BigDecimal availableAmount = getAvailableRefundAmountByCtripOrder(ctripOrder);
|
||||
if (request.getRefundAmount().compareTo(availableAmount) > 0) {
|
||||
return Result.failed("退款金额超过可退金额,可退金额: " + availableAmount);
|
||||
}
|
||||
|
||||
// 5. 生成sequenceId
|
||||
String sequenceId = LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd"))
|
||||
+ UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
// 6. 创建退款记录 t_ctrip_refund
|
||||
CtripRefund ctripRefund = new CtripRefund();
|
||||
ctripRefund.setOtaOrderId(ctripOrder.getOtaOrderId());
|
||||
ctripRefund.setSupplierOrderId(ctripOrder.getSupplierOrderId());
|
||||
ctripRefund.setSequenceId(sequenceId);
|
||||
ctripRefund.setRefundAmount(request.getRefundAmount());
|
||||
ctripRefund.setCurrency("CNY");
|
||||
ctripRefund.setRefundStatus(0); // 待确认
|
||||
ctripRefund.setCreateTime(LocalDateTime.now());
|
||||
ctripRefund.setUpdateTime(LocalDateTime.now());
|
||||
ctripRefund.setCreateBy("ADMIN");
|
||||
ctripRefund.setUpdateBy("ADMIN");
|
||||
ctripRefund.setRemark(request.getRefundReason() != null ? request.getRefundReason() : "管理后台发起退款");
|
||||
ctripRefund.setTenantId(ctripOrder.getTenantId());
|
||||
|
||||
int insertResult = ctripRefundMapper.insert(ctripRefund);
|
||||
if (insertResult <= 0) {
|
||||
return Result.failed("创建退款记录失败");
|
||||
}
|
||||
log.info("创建携程退款记录成功,refundId: {}", ctripRefund.getId());
|
||||
|
||||
// 7. 创建退款项记录 t_ctrip_refund_item
|
||||
List<Map<String, Object>> refundItems = new ArrayList<>();
|
||||
if (request.getItems() != null && !request.getItems().isEmpty()) {
|
||||
for (CtripAdminRefundRequest.RefundItem item : request.getItems()) {
|
||||
CtripRefundItem refundItem = new CtripRefundItem();
|
||||
refundItem.setRefundId(ctripRefund.getId());
|
||||
refundItem.setItemId(item.getItemId());
|
||||
refundItem.setPlu(item.getPlu());
|
||||
refundItem.setRefundAmount(item.getAmount());
|
||||
refundItem.setCurrency(item.getAmountCurrency() != null ? item.getAmountCurrency() : "CNY");
|
||||
refundItem.setCreateTime(LocalDateTime.now());
|
||||
refundItem.setUpdateTime(LocalDateTime.now());
|
||||
refundItem.setDeleted(0);
|
||||
ctripRefundItemMapper.insert(refundItem);
|
||||
|
||||
// 构建携程API需要的items参数
|
||||
Map<String, Object> itemMap = new HashMap<>();
|
||||
itemMap.put("itemId", item.getItemId());
|
||||
if (item.getPlu() != null) {
|
||||
itemMap.put("PLU", item.getPlu());
|
||||
}
|
||||
itemMap.put("amount", item.getAmount());
|
||||
itemMap.put("amountCurrency", item.getAmountCurrency() != null ? item.getAmountCurrency() : "CNY");
|
||||
refundItems.add(itemMap);
|
||||
}
|
||||
} else {
|
||||
// 如果没有指定退款项,从订单项中获取
|
||||
List<CtripOrderItem> orderItems = ctripOrderItemMapper.selectByOrderId(ctripOrder.getId());
|
||||
if (orderItems != null && !orderItems.isEmpty()) {
|
||||
for (CtripOrderItem orderItem : orderItems) {
|
||||
CtripRefundItem refundItem = new CtripRefundItem();
|
||||
refundItem.setRefundId(ctripRefund.getId());
|
||||
refundItem.setItemId(orderItem.getItemId());
|
||||
refundItem.setPlu(orderItem.getPlu());
|
||||
// 按比例分配退款金额
|
||||
BigDecimal itemRefundAmount = request.getRefundAmount();
|
||||
if (ctripOrder.getTotalAmount() != null && ctripOrder.getTotalAmount().compareTo(BigDecimal.ZERO) > 0
|
||||
&& orderItem.getTotalPrice() != null) {
|
||||
itemRefundAmount = request.getRefundAmount()
|
||||
.multiply(orderItem.getTotalPrice())
|
||||
.divide(ctripOrder.getTotalAmount(), 2, BigDecimal.ROUND_HALF_UP);
|
||||
}
|
||||
refundItem.setRefundAmount(itemRefundAmount);
|
||||
refundItem.setCurrency("CNY");
|
||||
refundItem.setCreateTime(LocalDateTime.now());
|
||||
refundItem.setUpdateTime(LocalDateTime.now());
|
||||
refundItem.setDeleted(0);
|
||||
ctripRefundItemMapper.insert(refundItem);
|
||||
|
||||
// 构建携程API需要的items参数
|
||||
Map<String, Object> itemMap = new HashMap<>();
|
||||
itemMap.put("itemId", orderItem.getItemId());
|
||||
if (orderItem.getPlu() != null) {
|
||||
itemMap.put("PLU", orderItem.getPlu());
|
||||
}
|
||||
itemMap.put("amount", itemRefundAmount);
|
||||
itemMap.put("amountCurrency", "CNY");
|
||||
refundItems.add(itemMap);
|
||||
}
|
||||
}
|
||||
}
|
||||
log.info("创建携程退款项记录成功,共{}条", refundItems.size());
|
||||
|
||||
// 8. 调用携程退款API
|
||||
int refundResult = ctripApiService.sendRefundOrder(
|
||||
ctripOrder.getOtaOrderId(),
|
||||
ctripOrder.getSupplierOrderId(),
|
||||
request.getRefundAmount(),
|
||||
"CNY",
|
||||
refundItems.isEmpty() ? null : refundItems
|
||||
);
|
||||
|
||||
if (refundResult == 0) {
|
||||
// 退款失败,更新退款记录状态
|
||||
ctripRefund.setRefundStatus(2); // 已拒绝
|
||||
ctripRefund.setConfirmResultCode("FAILED");
|
||||
ctripRefund.setConfirmResultMessage("调用携程退款API失败");
|
||||
ctripRefund.setUpdateTime(LocalDateTime.now());
|
||||
ctripRefundMapper.updateById(ctripRefund);
|
||||
return Result.failed("调用携程退款接口失败");
|
||||
}
|
||||
|
||||
// 9. 更新退款记录状态
|
||||
if (refundResult == 1) {
|
||||
// 退款已确认
|
||||
ctripRefund.setRefundStatus(1);
|
||||
ctripRefund.setConfirmResultCode("0000");
|
||||
ctripRefund.setConfirmResultMessage("退款已确认");
|
||||
} else if (refundResult == 2) {
|
||||
// 退款待确认
|
||||
ctripRefund.setRefundStatus(0);
|
||||
ctripRefund.setConfirmResultCode("0000");
|
||||
ctripRefund.setConfirmResultMessage("退款待确认");
|
||||
}
|
||||
ctripRefund.setUpdateTime(LocalDateTime.now());
|
||||
ctripRefundMapper.updateById(ctripRefund);
|
||||
|
||||
// 10. 更新携程订单状态(使用管理后台退款专用状态)
|
||||
if (refundResult == 1) {
|
||||
// 判断是全额退款还是部分退款
|
||||
if (request.getRefundAmount().compareTo(ctripOrder.getTotalAmount()) >= 0) {
|
||||
ctripOrder.setStatus(CtripOrderStatus.ADMIN_REFUNDED.getNumericValue()); // 16-已退款(管理后台)
|
||||
} else {
|
||||
ctripOrder.setStatus(CtripOrderStatus.ADMIN_PART_REFUNDED.getNumericValue()); // 17-部分退款(管理后台)
|
||||
}
|
||||
} else {
|
||||
ctripOrder.setStatus(CtripOrderStatus.ADMIN_REFUNDING.getNumericValue()); // 15-退款中(管理后台)
|
||||
}
|
||||
ctripOrder.setUpdateTime(LocalDateTime.now());
|
||||
ctripOrder.setUpdateBy("ADMIN");
|
||||
ctripOrderMapper.updateById(ctripOrder);
|
||||
|
||||
// 11. 更新order-center的订单和退款表状态
|
||||
try {
|
||||
if (refundResult == 1) {
|
||||
// 退款已确认,更新订单状态为已退款
|
||||
Result<String> orderResult = orderCenterService.updateOrderStatusToRefunded(request.getOrderNo());
|
||||
if (orderResult != null && orderResult.getResp_code() == 0) {
|
||||
log.info("更新order-center订单状态为已退款成功,orderNo: {}", request.getOrderNo());
|
||||
} else {
|
||||
log.warn("更新order-center订单状态失败,orderNo: {}", request.getOrderNo());
|
||||
}
|
||||
} else {
|
||||
// 退款待确认,更新订单状态为退款中
|
||||
Result<String> orderResult = orderCenterService.updateOrderStatusToRefunding(request.getOrderNo());
|
||||
if (orderResult != null && orderResult.getResp_code() == 0) {
|
||||
log.info("更新order-center订单状态为退款中成功,orderNo: {}", request.getOrderNo());
|
||||
} else {
|
||||
log.warn("更新order-center订单状态失败,orderNo: {}", request.getOrderNo());
|
||||
}
|
||||
}
|
||||
// 创建退款记录
|
||||
Map<String, Object> refundInfo = new HashMap<>();
|
||||
refundInfo.put("refundAmount", request.getRefundAmount().toString());
|
||||
refundInfo.put("refundReason", request.getRefundReason() != null ? request.getRefundReason() : "携程退款");
|
||||
refundInfo.put("refundStatus", refundResult == 1 ? 1 : 0);
|
||||
Result<String> refundRecordResult = orderCenterService.createCtripRefund(request.getOrderNo(), refundInfo);
|
||||
if (refundRecordResult != null && refundRecordResult.getResp_code() == 0) {
|
||||
log.info("创建order-center退款记录成功,orderNo: {}", request.getOrderNo());
|
||||
} else {
|
||||
log.warn("创建order-center退款记录失败,orderNo: {}", request.getOrderNo());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("更新order-center状态异常,orderNo: {}", request.getOrderNo(), e);
|
||||
// 不影响主流程
|
||||
}
|
||||
|
||||
String message = refundResult == 1 ? "退款成功" : "退款申请已提交,等待携程确认";
|
||||
log.info("管理后台携程退款处理完成,orderNo: {}, otaOrderId: {}, result: {}",
|
||||
request.getOrderNo(), ctripOrder.getOtaOrderId(), message);
|
||||
return Result.succeed(message);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("管理后台携程退款处理异常,orderNo: {}", request.getOrderNo(), e);
|
||||
return Result.failed("退款处理异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public BigDecimal getAvailableRefundAmount(String orderNo) {
|
||||
log.info("获取可退金额,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
// 根据orderNo查询携程订单
|
||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
||||
if (ctripOrder == null) {
|
||||
log.warn("未找到关联的携程订单,orderNo: {}", orderNo);
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
return getAvailableRefundAmountByCtripOrder(ctripOrder);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取可退金额异常,orderNo: {}", orderNo, e);
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRefund(String orderNo) {
|
||||
try {
|
||||
CtripOrder ctripOrder = ctripOrderMapper.selectByOrderNo(orderNo);
|
||||
if (ctripOrder == null) {
|
||||
return false;
|
||||
}
|
||||
return canRefundByCtripOrder(ctripOrder);
|
||||
} catch (Exception e) {
|
||||
log.error("检查订单是否可退款异常,orderNo: {}", orderNo, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 根据携程订单获取可退金额
|
||||
*/
|
||||
private BigDecimal getAvailableRefundAmountByCtripOrder(CtripOrder ctripOrder) {
|
||||
// 检查订单状态
|
||||
if (!canRefundByCtripOrder(ctripOrder)) {
|
||||
log.warn("订单状态不支持退款,otaOrderId: {}, status: {}", ctripOrder.getOtaOrderId(), ctripOrder.getStatus());
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
// 计算已退款金额
|
||||
BigDecimal refundedAmount = getRefundedAmount(ctripOrder.getOtaOrderId());
|
||||
|
||||
// 可退金额 = 订单总金额 - 已退款金额
|
||||
BigDecimal totalAmount = ctripOrder.getTotalAmount() != null ? ctripOrder.getTotalAmount() : BigDecimal.ZERO;
|
||||
BigDecimal availableAmount = totalAmount.subtract(refundedAmount);
|
||||
|
||||
log.info("可退金额计算: 订单总金额={}, 已退款金额={}, 可退金额={}",
|
||||
totalAmount, refundedAmount, availableAmount);
|
||||
|
||||
return availableAmount.compareTo(BigDecimal.ZERO) > 0 ? availableAmount : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* 检查携程订单是否可退款
|
||||
*/
|
||||
private boolean canRefundByCtripOrder(CtripOrder ctripOrder) {
|
||||
if (ctripOrder.getStatus() == null) {
|
||||
return false;
|
||||
}
|
||||
int status = ctripOrder.getStatus();
|
||||
// 可退款的状态:已确认、部分取消、退款中(管理后台)、部分退款(管理后台)
|
||||
return status == CtripOrderStatus.CONFIRMED.getNumericValue()
|
||||
|| status == CtripOrderStatus.PARTIAL_CANCELLED.getNumericValue()
|
||||
|| status == CtripOrderStatus.ADMIN_REFUNDING.getNumericValue()
|
||||
|| status == CtripOrderStatus.ADMIN_PART_REFUNDED.getNumericValue();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已退款金额
|
||||
*/
|
||||
private BigDecimal getRefundedAmount(String otaOrderId) {
|
||||
try {
|
||||
List<CtripRefund> refunds = ctripRefundMapper.selectByOtaOrderId(otaOrderId);
|
||||
BigDecimal totalRefunded = BigDecimal.ZERO;
|
||||
|
||||
for (CtripRefund refund : refunds) {
|
||||
// 只计算已确认的退款
|
||||
if (refund.getRefundStatus() != null && refund.getRefundStatus() == 1) {
|
||||
totalRefunded = totalRefunded.add(refund.getRefundAmount());
|
||||
}
|
||||
}
|
||||
|
||||
return totalRefunded;
|
||||
} catch (Exception e) {
|
||||
log.error("获取已退款金额异常,otaOrderId: {}", otaOrderId, e);
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取订单状态描述
|
||||
*/
|
||||
private String getOrderStatusDesc(Integer status) {
|
||||
if (status == null) {
|
||||
return "未知";
|
||||
}
|
||||
try {
|
||||
return CtripOrderStatus.fromNumericValue(status).getDescription();
|
||||
} catch (IllegalArgumentException e) {
|
||||
return "未知状态";
|
||||
}
|
||||
}
|
||||
}
|
||||
+139
-2
@@ -544,9 +544,9 @@ public class CtripApiServiceImpl implements ICtripApiService {
|
||||
String testUrl = "https://ttdopen.ctrip.com";
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.set("User-Agent", "CouponCenter/1.0");
|
||||
|
||||
|
||||
HttpEntity<String> request = new HttpEntity<>(headers);
|
||||
|
||||
|
||||
ResponseEntity<String> response = restTemplate.getForEntity(testUrl, String.class);
|
||||
log.info("网络连接测试成功,状态码: {}", response.getStatusCode());
|
||||
return true;
|
||||
@@ -557,4 +557,141 @@ public class CtripApiServiceImpl implements ICtripApiService {
|
||||
return true; // 临时返回true,避免阻塞业务逻辑
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int sendRefundOrder(String otaOrderId, String supplierOrderId,
|
||||
java.math.BigDecimal totalAmount, String currency,
|
||||
List<Map<String, Object>> items) {
|
||||
log.info("调用携程退款接口,otaOrderId: {}, supplierOrderId: {}, totalAmount: {}, currency: {}",
|
||||
otaOrderId, supplierOrderId, totalAmount, currency);
|
||||
|
||||
// 网络连接测试
|
||||
if (!testNetworkConnection()) {
|
||||
log.error("网络连接测试失败,无法访问携程API");
|
||||
return 0;
|
||||
}
|
||||
|
||||
try {
|
||||
// 构建请求体
|
||||
Map<String, Object> requestBody = new HashMap<>();
|
||||
// 生成sequenceId: 处理日期(yyyyMMdd) + 32位去分隔符的GUID
|
||||
String sequenceId = java.time.LocalDate.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyyMMdd"))
|
||||
+ java.util.UUID.randomUUID().toString().replace("-", "");
|
||||
requestBody.put("sequenceId", sequenceId);
|
||||
requestBody.put("otaOrderId", otaOrderId);
|
||||
requestBody.put("supplierOrderId", supplierOrderId);
|
||||
requestBody.put("totalAmount", totalAmount);
|
||||
requestBody.put("totalAmountCurrency", currency != null ? currency : "CNY");
|
||||
|
||||
// 添加退款项(如果有)
|
||||
if (items != null && !items.isEmpty()) {
|
||||
requestBody.put("items", items);
|
||||
}
|
||||
|
||||
log.info("携程退款请求参数: {}", requestBody);
|
||||
|
||||
// 构建完整的请求(包含header和body)
|
||||
Map<String, Object> request = new HashMap<>();
|
||||
|
||||
// 构建header
|
||||
Map<String, Object> header = new HashMap<>();
|
||||
header.put("accountId", accountId);
|
||||
header.put("serviceName", "RefundOrder");
|
||||
String requestTime = java.time.LocalDateTime.now().format(java.time.format.DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
header.put("requestTime", requestTime);
|
||||
header.put("version", "1.0");
|
||||
|
||||
// 生成签名和加密body
|
||||
String bodyJson = objectMapper.writeValueAsString(requestBody);
|
||||
String encryptedBody = ctripDecryptUtil.encryptAES(bodyJson);
|
||||
if (encryptedBody == null) {
|
||||
log.error("加密请求body失败");
|
||||
return 0;
|
||||
}
|
||||
|
||||
String sign = ctripDecryptUtil.generateSign(accountId, "RefundOrder",
|
||||
requestTime, encryptedBody, "1.0");
|
||||
header.put("sign", sign);
|
||||
|
||||
request.put("header", header);
|
||||
request.put("body", encryptedBody);
|
||||
|
||||
log.info("携程退款完整请求: {}", request);
|
||||
|
||||
// 发送HTTP请求到携程API
|
||||
String url = baseUrl + "/order/refund.do";
|
||||
log.info("准备发送退款请求到URL: {}", url);
|
||||
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
headers.set("User-Agent", "CouponCenter/1.0");
|
||||
|
||||
HttpEntity<Map<String, Object>> httpRequest = new HttpEntity<>(request, headers);
|
||||
|
||||
// 重试机制
|
||||
for (int i = 0; i < retryTimes; i++) {
|
||||
try {
|
||||
log.info("第{}次尝试调用携程退款API,URL: {}", i + 1, url);
|
||||
ResponseEntity<Map> response = restTemplate.postForEntity(url, httpRequest, Map.class);
|
||||
|
||||
log.info("携程退款API响应状态码: {}", response.getStatusCode());
|
||||
|
||||
if (response.getStatusCode() == HttpStatus.OK) {
|
||||
Map<String, Object> responseBody = response.getBody();
|
||||
log.info("携程退款API响应内容: {}", responseBody);
|
||||
|
||||
if (responseBody != null) {
|
||||
Map<String, Object> responseHeader = (Map<String, Object>) responseBody.get("header");
|
||||
if (responseHeader != null && "0000".equals(responseHeader.get("resultCode"))) {
|
||||
// 解密响应body
|
||||
Object encryptedResponseBody = responseBody.get("body");
|
||||
if (encryptedResponseBody != null) {
|
||||
String decryptedBody = ctripDecryptUtil.decryptAES(encryptedResponseBody.toString());
|
||||
if (decryptedBody != null) {
|
||||
Map<String, Object> bodyMap = objectMapper.readValue(decryptedBody, Map.class);
|
||||
Integer supplierConfirmType = (Integer) bodyMap.get("supplierConfirmType");
|
||||
log.info("携程退款接口调用成功,supplierConfirmType: {}", supplierConfirmType);
|
||||
return supplierConfirmType != null ? supplierConfirmType : 1;
|
||||
}
|
||||
}
|
||||
log.info("携程退款接口调用成功,otaOrderId: {}", otaOrderId);
|
||||
return 1; // 默认返回已确认
|
||||
} else {
|
||||
String resultCode = responseHeader != null ? (String) responseHeader.get("resultCode") : "null";
|
||||
String resultMessage = responseHeader != null ? (String) responseHeader.get("resultMessage") : "null";
|
||||
log.warn("携程退款接口返回失败,resultCode: {}, resultMessage: {}", resultCode, resultMessage);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.warn("携程退款接口HTTP状态码异常,status: {}", response.getStatusCode());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("携程退款接口调用异常,第{}次重试,otaOrderId: {}", i + 1, otaOrderId, e);
|
||||
|
||||
if (i == retryTimes - 1) {
|
||||
log.error("所有重试都失败了,最后一次错误详情: {}", e.getMessage());
|
||||
throw e;
|
||||
}
|
||||
|
||||
// 等待后重试,使用指数退避
|
||||
int waitTime = 1000 * (i + 1) * (i + 1);
|
||||
log.info("等待{}毫秒后进行第{}次重试", waitTime, i + 2);
|
||||
try {
|
||||
Thread.sleep(waitTime);
|
||||
} catch (InterruptedException ie) {
|
||||
Thread.currentThread().interrupt();
|
||||
log.warn("重试等待被中断");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
log.error("携程退款接口调用失败,已重试{}次,otaOrderId: {}", retryTimes, otaOrderId);
|
||||
return 0;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("携程退款接口调用失败,otaOrderId: {}", otaOrderId, e);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,20 +8,17 @@
|
||||
<result column="refund_id" property="refundId" jdbcType="BIGINT"/>
|
||||
<result column="item_id" property="itemId" jdbcType="VARCHAR"/>
|
||||
<result column="plu" property="plu" jdbcType="VARCHAR"/>
|
||||
<result column="amount" property="amount" jdbcType="DECIMAL"/>
|
||||
<result column="amount_currency" property="amountCurrency" jdbcType="VARCHAR"/>
|
||||
<result column="refund_amount" property="refundAmount" jdbcType="DECIMAL"/>
|
||||
<result column="currency" property="currency" jdbcType="VARCHAR"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
<result column="update_by" property="updateBy" jdbcType="VARCHAR"/>
|
||||
<result column="remark" property="remark" jdbcType="VARCHAR"/>
|
||||
<result column="tenant_id" property="tenantId" jdbcType="VARCHAR"/>
|
||||
<result column="deleted" property="deleted" jdbcType="INTEGER"/>
|
||||
</resultMap>
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, refund_id, item_id, plu, amount, amount_currency,
|
||||
create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
id, refund_id, item_id, plu, refund_amount, currency,
|
||||
create_time, update_time, deleted
|
||||
</sql>
|
||||
|
||||
<!-- 根据退款ID查询退款项列表 -->
|
||||
@@ -30,6 +27,17 @@
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_refund_item
|
||||
WHERE refund_id = #{refundId,jdbcType=BIGINT}
|
||||
AND (deleted = 0 OR deleted IS NULL)
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
<!-- 根据订单项编号查询退款项 -->
|
||||
<select id="selectByItemId" parameterType="string" resultMap="BaseResultMap">
|
||||
SELECT
|
||||
<include refid="Base_Column_List"/>
|
||||
FROM t_ctrip_refund_item
|
||||
WHERE item_id = #{itemId,jdbcType=VARCHAR}
|
||||
AND (deleted = 0 OR deleted IS NULL)
|
||||
ORDER BY create_time ASC
|
||||
</select>
|
||||
|
||||
|
||||
@@ -8,12 +8,12 @@
|
||||
<result column="ota_order_id" property="otaOrderId" jdbcType="VARCHAR"/>
|
||||
<result column="supplier_order_id" property="supplierOrderId" jdbcType="VARCHAR"/>
|
||||
<result column="sequence_id" property="sequenceId" jdbcType="VARCHAR"/>
|
||||
<result column="total_amount" property="totalAmount" jdbcType="DECIMAL"/>
|
||||
<result column="total_amount_currency" property="totalAmountCurrency" jdbcType="VARCHAR"/>
|
||||
<result column="last_confirm_time" property="lastConfirmTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="status" property="status" jdbcType="INTEGER"/>
|
||||
<result column="refund_amount" property="refundAmount" jdbcType="DECIMAL"/>
|
||||
<result column="currency" property="currency" jdbcType="VARCHAR"/>
|
||||
<result column="refund_status" property="refundStatus" jdbcType="INTEGER"/>
|
||||
<result column="confirm_result_code" property="confirmResultCode" jdbcType="VARCHAR"/>
|
||||
<result column="confirm_result_message" property="confirmResultMessage" jdbcType="VARCHAR"/>
|
||||
<result column="last_confirm_time" property="lastConfirmTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_time" property="createTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="update_time" property="updateTime" jdbcType="TIMESTAMP"/>
|
||||
<result column="create_by" property="createBy" jdbcType="VARCHAR"/>
|
||||
@@ -24,8 +24,8 @@
|
||||
|
||||
<!-- 基础字段 -->
|
||||
<sql id="Base_Column_List">
|
||||
id, ota_order_id, supplier_order_id, sequence_id, total_amount, total_amount_currency,
|
||||
last_confirm_time, status, confirm_result_code, confirm_result_message,
|
||||
id, ota_order_id, supplier_order_id, sequence_id, refund_amount, currency,
|
||||
refund_status, confirm_result_code, confirm_result_message, last_confirm_time,
|
||||
create_time, update_time, create_by, update_by, remark, tenant_id
|
||||
</sql>
|
||||
|
||||
|
||||
+71
@@ -1637,4 +1637,75 @@ public class OrderController {
|
||||
return new PageResult();
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订单状态为退款中(携程退款调用)")
|
||||
@PostMapping("/order/{orderNo}/status/refunding")
|
||||
public Result<String> updateOrderStatusToRefunding(@PathVariable("orderNo") String orderNo) {
|
||||
log.info("携程退款,更新订单状态为退款中,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
log.error("订单不存在,orderNo: {}", orderNo);
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
|
||||
// 检查订单当前状态是否允许退款
|
||||
if (OrderStatus.canRefund(order.getOrderStatus())) {
|
||||
order.setOrderStatus(OrderStatus.REFUNDING.getId());
|
||||
boolean result = orderService.updateOrder(order);
|
||||
if (result) {
|
||||
log.info("订单状态更新为退款中成功,orderNo: {}", orderNo);
|
||||
return Result.succeed("订单状态更新成功");
|
||||
} else {
|
||||
log.error("订单状态更新失败,orderNo: {}", orderNo);
|
||||
return Result.failed("订单状态更新失败");
|
||||
}
|
||||
} else {
|
||||
log.warn("订单状态不支持退款,orderNo: {}, 当前状态: {}",
|
||||
orderNo, order.getOrderStatus());
|
||||
return Result.failed("订单状态不支持退款");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单状态异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("更新订单状态异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "更新订单状态为已退款(携程退款调用)")
|
||||
@PostMapping("/order/{orderNo}/status/refunded")
|
||||
public Result<String> updateOrderStatusToRefunded(@PathVariable("orderNo") String orderNo) {
|
||||
log.info("携程退款完成,更新订单状态为已退款,orderNo: {}", orderNo);
|
||||
|
||||
try {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
log.error("订单不存在,orderNo: {}", orderNo);
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
|
||||
// 检查订单当前状态
|
||||
if (order.getOrderStatus().equals(OrderStatus.REFUNDING.getId())
|
||||
|| OrderStatus.canRefund(order.getOrderStatus())) {
|
||||
order.setOrderStatus(OrderStatus.REFUNDED.getId());
|
||||
boolean result = orderService.updateOrder(order);
|
||||
if (result) {
|
||||
log.info("订单状态更新为已退款成功,orderNo: {}", orderNo);
|
||||
return Result.succeed("订单状态更新成功");
|
||||
} else {
|
||||
log.error("订单状态更新失败,orderNo: {}", orderNo);
|
||||
return Result.failed("订单状态更新失败");
|
||||
}
|
||||
} else {
|
||||
log.warn("订单状态不正确,无法更新为已退款,orderNo: {}, 当前状态: {}",
|
||||
orderNo, order.getOrderStatus());
|
||||
return Result.failed("订单状态不正确,无法更新为已退款");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("更新订单状态异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("更新订单状态异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+73
@@ -421,4 +421,77 @@ public class RefundController {
|
||||
throw new RuntimeException("退款失败: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
@Operation(summary = "创建携程退款记录")
|
||||
@PostMapping("/ctrip/{orderNo}")
|
||||
public Result<String> createCtripRefund(@PathVariable String orderNo, @RequestBody Map<String, Object> refundInfo) {
|
||||
log.info("创建携程退款记录,orderNo: {}, refundInfo: {}", orderNo, refundInfo);
|
||||
|
||||
try {
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order == null) {
|
||||
log.error("订单不存在,orderNo: {}", orderNo);
|
||||
return Result.failed("订单不存在");
|
||||
}
|
||||
|
||||
// 检查是否已存在退款记录
|
||||
String refundNo = "RF" + orderNo;
|
||||
com.central.order.model.Refund existRefund = refundService.getRefundByNo(refundNo);
|
||||
if (existRefund != null) {
|
||||
log.info("退款记录已存在,orderNo: {}, refundNo: {}", orderNo, refundNo);
|
||||
// 更新退款状态
|
||||
String refundAmountStr = refundInfo.get("refundAmount") != null ? refundInfo.get("refundAmount").toString() : null;
|
||||
Integer refundStatus = refundInfo.get("refundStatus") != null ? Integer.parseInt(refundInfo.get("refundStatus").toString()) : null;
|
||||
if (refundAmountStr != null) {
|
||||
existRefund.setRefundAmount(refundAmountStr);
|
||||
}
|
||||
if (refundStatus != null && refundStatus == 1) {
|
||||
existRefund.setState(RefundState.APPROVED.getId());
|
||||
existRefund.setStatus(OrderStatus.REFUNDED.getId());
|
||||
}
|
||||
refundService.updateById(existRefund);
|
||||
return Result.succeed("退款记录已更新");
|
||||
}
|
||||
|
||||
// 创建新的退款记录
|
||||
com.central.order.model.Refund refund = new com.central.order.model.Refund();
|
||||
refund.setRefundNo(refundNo);
|
||||
refund.setOrderNo(orderNo);
|
||||
refund.setUserId(order.getUserId());
|
||||
refund.setOrderAmount(order.getOrderAmount());
|
||||
|
||||
// 设置退款金额
|
||||
String refundAmountStr = refundInfo.get("refundAmount") != null ? refundInfo.get("refundAmount").toString() : order.getOrderAmount();
|
||||
refund.setRefundAmount(refundAmountStr);
|
||||
|
||||
// 设置退款原因
|
||||
String refundReason = refundInfo.get("refundReason") != null ? refundInfo.get("refundReason").toString() : "携程退款";
|
||||
refund.setRefundReason(refundReason);
|
||||
|
||||
// 设置退款状态
|
||||
Integer refundStatus = refundInfo.get("refundStatus") != null ? Integer.parseInt(refundInfo.get("refundStatus").toString()) : 0;
|
||||
if (refundStatus == 1) {
|
||||
refund.setState(RefundState.APPROVED.getId());
|
||||
refund.setStatus(OrderStatus.REFUNDED.getId());
|
||||
} else {
|
||||
refund.setState(RefundState.APPROVING.getId());
|
||||
refund.setStatus(OrderStatus.REFUNDING.getId());
|
||||
}
|
||||
|
||||
refund.setTenantId(order.getTenantId());
|
||||
|
||||
boolean result = refundService.createRefund(refund);
|
||||
if (result) {
|
||||
log.info("创建携程退款记录成功,orderNo: {}, refundNo: {}", orderNo, refundNo);
|
||||
return Result.succeed("创建退款记录成功");
|
||||
} else {
|
||||
log.error("创建携程退款记录失败,orderNo: {}", orderNo);
|
||||
return Result.failed("创建退款记录失败");
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("创建携程退款记录异常,orderNo: {}", orderNo, e);
|
||||
return Result.failed("创建退款记录异常: " + e.getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -131,6 +131,12 @@ public class RefundServiceImpl extends SuperServiceImpl<RefundMapper, Refund> im
|
||||
result.put("refundTime", refund.getRefundTime());
|
||||
result.put("applyTime", refund.getCreateTime());
|
||||
|
||||
// 获取订单的支付类型
|
||||
Order order = orderService.getOrderByNumber(orderNo);
|
||||
if (order != null) {
|
||||
result.put("payType", order.getPayType());
|
||||
}
|
||||
|
||||
// 处理图片列表 - refundImgs 可能是逗号分隔的字符串或JSON
|
||||
List<String> images = new ArrayList<>();
|
||||
if (refund.getRefundImgs() != null && !refund.getRefundImgs().isEmpty()) {
|
||||
|
||||
+2
-1
@@ -117,7 +117,8 @@ public class OpenMeteoWeatherProvider implements IWeatherProvider {
|
||||
|
||||
// 风速(m/s)
|
||||
if (current.has("wind_speed_10m")) {
|
||||
weatherData.setWindSpeed(current.get("wind_speed_10m").asDouble());
|
||||
double windSpeedKmh = current.get("wind_speed_10m").asDouble();
|
||||
weatherData.setWindSpeed(windSpeedKmh/3.6); // km/h -> m/s
|
||||
}
|
||||
|
||||
// 风向(°)
|
||||
|
||||
+1
-1
@@ -198,7 +198,7 @@ public class QWeatherProvider implements IWeatherProvider {
|
||||
// 风速(km/h 转换为 m/s)
|
||||
if (now.has("windSpeed")) {
|
||||
double windSpeedKmh = now.get("windSpeed").asDouble();
|
||||
weatherData.setWindSpeed(windSpeedKmh / 3.6);
|
||||
weatherData.setWindSpeed(windSpeedKmh / 3.6); // km/h -> m/s
|
||||
}
|
||||
|
||||
// 风向
|
||||
|
||||
@@ -38,6 +38,10 @@ export default [
|
||||
{ path: '/orders/qrcodeOrder.html', component: '@/pages/orders/QrcodeOrder' },
|
||||
// 天气规则管理
|
||||
{ path: '/orders/weatherRule.html', component: '@/pages/orders/WeatherRule' },
|
||||
// 携程订单管理
|
||||
{ path: '/orders/ctripOrder.html', component: '@/pages/orders/CtripOrder' },
|
||||
// 携程退款管理
|
||||
{ path: '/orders/ctripRefund.html', component: '@/pages/orders/CtripRefund' },
|
||||
],
|
||||
},
|
||||
{
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
||||
import React from 'react';
|
||||
import { Tag } from 'antd';
|
||||
import { CTRIP_ORDER_STATUS_OPTIONS, CTRIP_REFUND_STATUS_OPTIONS, findLabel, findColor } from './constants';
|
||||
|
||||
// 携程订单状态标签
|
||||
export const CtripOrderStatusTag: React.FC<{ value?: number }> = ({ value }) => {
|
||||
const label = findLabel(CTRIP_ORDER_STATUS_OPTIONS, value);
|
||||
const color = findColor(CTRIP_ORDER_STATUS_OPTIONS, value);
|
||||
return <Tag color={color}>{label}</Tag>;
|
||||
};
|
||||
|
||||
// 携程退款状态标签
|
||||
export const CtripRefundStatusTag: React.FC<{ value?: number }> = ({ value }) => {
|
||||
const label = findLabel(CTRIP_REFUND_STATUS_OPTIONS, value);
|
||||
const color = findColor(CTRIP_REFUND_STATUS_OPTIONS, value);
|
||||
return <Tag color={color}>{label}</Tag>;
|
||||
};
|
||||
@@ -0,0 +1,47 @@
|
||||
import React from 'react';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import { CtripOrderStatusTag } from './Tags';
|
||||
|
||||
export interface CtripOrderItem {
|
||||
id: number;
|
||||
otaOrderId: string;
|
||||
orderNo?: string;
|
||||
supplierOrderId?: string;
|
||||
sequenceId?: string;
|
||||
confirmType?: number;
|
||||
orderLastConfirmTime?: string;
|
||||
status?: number;
|
||||
totalAmount?: number;
|
||||
currency?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
remark?: string;
|
||||
tenantId?: string;
|
||||
}
|
||||
|
||||
// 格式化金额
|
||||
const formatAmount = (amount: any): string => {
|
||||
if (!amount && amount !== 0) return '0.00';
|
||||
const num = parseFloat(amount);
|
||||
return num.toFixed(2);
|
||||
};
|
||||
|
||||
export const buildCtripOrderColumns = (): ProColumns<CtripOrderItem>[] => [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 56 },
|
||||
{ title: 'ID', dataIndex: 'id', width: 80 },
|
||||
{ title: '携程订单号', dataIndex: 'otaOrderId', width: 200, copyable: true, ellipsis: true },
|
||||
{ title: '关联订单号', dataIndex: 'orderNo', width: 180, copyable: true, ellipsis: true },
|
||||
{ title: '供应商订单号', dataIndex: 'supplierOrderId', width: 180, copyable: true, ellipsis: true },
|
||||
{ title: '订单金额', dataIndex: 'totalAmount', width: 120, render: (v, record) => <span>{record.currency || 'CNY'} {formatAmount(v)}</span> },
|
||||
{ title: '状态', dataIndex: 'status', width: 100, render: (v) => <CtripOrderStatusTag value={v as number} /> },
|
||||
{
|
||||
title: '确认类型',
|
||||
dataIndex: 'confirmType',
|
||||
width: 100,
|
||||
render: (v) => v === 1 ? '仅通知' : v === 2 ? '需确认' : '-'
|
||||
},
|
||||
{ title: '最晚确认时间', dataIndex: 'orderLastConfirmTime', width: 180, valueType: 'dateTime' },
|
||||
{ title: '创建时间', dataIndex: 'createTime', width: 180, valueType: 'dateTime' },
|
||||
{ title: '更新时间', dataIndex: 'updateTime', width: 180, valueType: 'dateTime' },
|
||||
{ title: '备注', dataIndex: 'remark', width: 150, ellipsis: true },
|
||||
];
|
||||
@@ -0,0 +1,32 @@
|
||||
// 携程订单状态常量
|
||||
export const CTRIP_ORDER_STATUS_OPTIONS: { label: string; value: number; color?: string }[] = [
|
||||
{ label: '待确认', value: 0, color: 'default' },
|
||||
{ label: '已确认', value: 1, color: 'green' },
|
||||
{ label: '已取消', value: 2, color: 'red' },
|
||||
{ label: '已过期', value: 3, color: 'default' },
|
||||
{ label: '部分取消', value: 4, color: 'orange' },
|
||||
{ label: '全部取消', value: 5, color: 'red' },
|
||||
{ label: '已取物品', value: 6, color: 'cyan' },
|
||||
{ label: '部分使用', value: 7, color: 'blue' },
|
||||
{ label: '全部使用', value: 8, color: 'green' },
|
||||
{ label: '已还物品', value: 9, color: 'purple' },
|
||||
{ label: '已过期', value: 10, color: 'default' },
|
||||
{ label: '待支付', value: 11, color: 'gold' },
|
||||
{ label: '支付待确认', value: 12, color: 'orange' },
|
||||
{ label: '支付已确认', value: 13, color: 'green' },
|
||||
{ label: '预下单取消成功', value: 14, color: 'default' },
|
||||
// 管理后台主动发起退款的状态
|
||||
{ label: '退款中', value: 15, color: 'orange' },
|
||||
{ label: '已退款', value: 16, color: 'lime' },
|
||||
{ label: '部分退款', value: 17, color: 'volcano' },
|
||||
];
|
||||
|
||||
// 携程退款状态常量
|
||||
export const CTRIP_REFUND_STATUS_OPTIONS: { label: string; value: number; color?: string }[] = [
|
||||
{ label: '待确认', value: 0, color: 'orange' },
|
||||
{ label: '已确认', value: 1, color: 'green' },
|
||||
{ label: '已拒绝', value: 2, color: 'red' },
|
||||
];
|
||||
|
||||
export const findLabel = (arr: { label: string; value: number }[], v?: number) => arr.find(o => o.value === v)?.label || '未知';
|
||||
export const findColor = (arr: { color?: string; value: number }[], v?: number) => arr.find(o => o.value === v)?.color;
|
||||
@@ -0,0 +1,57 @@
|
||||
import React, { useRef, useMemo, useState } from 'react';
|
||||
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
|
||||
import type { ActionType } from '@ant-design/pro-components';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { GlassCard, SearchBarPlus } from '@/components/ui';
|
||||
import { CTRIP_ORDER_STATUS_OPTIONS } from './components/constants';
|
||||
import { buildCtripOrderColumns, CtripOrderItem } from './components/buildColumns';
|
||||
|
||||
const CtripOrderPage: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
|
||||
|
||||
const handleSearch = (values: Record<string, any>) => {
|
||||
setSearchParams(values);
|
||||
actionRef.current?.reset?.();
|
||||
};
|
||||
|
||||
const columns = useMemo(() => buildCtripOrderColumns(), []);
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '携程订单管理' }}>
|
||||
<SearchBarPlus
|
||||
defaultCollapsed={false}
|
||||
split
|
||||
span={6}
|
||||
showTenant={false}
|
||||
onFinish={handleSearch}
|
||||
hideReset
|
||||
>
|
||||
<ProFormText name="otaOrderId" label="携程订单号" placeholder="请输入携程订单号" />
|
||||
<ProFormText name="orderNo" label="关联订单号" placeholder="请输入关联订单号" />
|
||||
<ProFormSelect name="status" label="订单状态" options={CTRIP_ORDER_STATUS_OPTIONS} allowClear />
|
||||
</SearchBarPlus>
|
||||
|
||||
<GlassCard>
|
||||
<ProTable<CtripOrderItem>
|
||||
rowKey="id"
|
||||
headerTitle="携程订单列表"
|
||||
actionRef={actionRef}
|
||||
request={(p) => {
|
||||
const params = {
|
||||
...p,
|
||||
...searchParams
|
||||
};
|
||||
return ordersApi.ctripOrderList(params as any);
|
||||
}}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true, defaultPageSize: 20 }}
|
||||
scroll={{ x: 1800 }}
|
||||
/>
|
||||
</GlassCard>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default CtripOrderPage;
|
||||
@@ -0,0 +1,10 @@
|
||||
import React from 'react';
|
||||
import { Tag } from 'antd';
|
||||
import { CTRIP_REFUND_STATUS_OPTIONS, findLabel, findColor } from './constants';
|
||||
|
||||
// 携程退款状态标签
|
||||
export const CtripRefundStatusTag: React.FC<{ value?: number }> = ({ value }) => {
|
||||
const label = findLabel(CTRIP_REFUND_STATUS_OPTIONS, value);
|
||||
const color = findColor(CTRIP_REFUND_STATUS_OPTIONS, value);
|
||||
return <Tag color={color}>{label}</Tag>;
|
||||
};
|
||||
@@ -0,0 +1,43 @@
|
||||
import React from 'react';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import { CtripRefundStatusTag } from './Tags';
|
||||
|
||||
export interface CtripRefundItem {
|
||||
id: number;
|
||||
otaOrderId: string;
|
||||
supplierOrderId?: string;
|
||||
sequenceId?: string;
|
||||
refundAmount?: number;
|
||||
currency?: string;
|
||||
refundStatus?: number;
|
||||
confirmResultCode?: string;
|
||||
confirmResultMessage?: string;
|
||||
lastConfirmTime?: string;
|
||||
createTime?: string;
|
||||
updateTime?: string;
|
||||
remark?: string;
|
||||
tenantId?: string;
|
||||
}
|
||||
|
||||
// 格式化金额
|
||||
const formatAmount = (amount: any): string => {
|
||||
if (!amount && amount !== 0) return '0.00';
|
||||
const num = parseFloat(amount);
|
||||
return num.toFixed(2);
|
||||
};
|
||||
|
||||
export const buildCtripRefundColumns = (): ProColumns<CtripRefundItem>[] => [
|
||||
{ dataIndex: 'index', valueType: 'indexBorder', width: 56 },
|
||||
{ title: 'ID', dataIndex: 'id', width: 80 },
|
||||
{ title: '携程订单号', dataIndex: 'otaOrderId', width: 200, copyable: true, ellipsis: true },
|
||||
{ title: '供应商订单号', dataIndex: 'supplierOrderId', width: 180, copyable: true, ellipsis: true },
|
||||
{ title: '批次流水号', dataIndex: 'sequenceId', width: 180, copyable: true, ellipsis: true },
|
||||
{ title: '退款金额', dataIndex: 'refundAmount', width: 120, render: (v, record) => <span>{record.currency || 'CNY'} {formatAmount(v)}</span> },
|
||||
{ title: '退款状态', dataIndex: 'refundStatus', width: 100, render: (v) => <CtripRefundStatusTag value={v as number} /> },
|
||||
{ title: '确认结果码', dataIndex: 'confirmResultCode', width: 120, ellipsis: true },
|
||||
{ title: '确认结果信息', dataIndex: 'confirmResultMessage', width: 180, ellipsis: true },
|
||||
{ title: '最晚确认时间', dataIndex: 'lastConfirmTime', width: 180, valueType: 'dateTime' },
|
||||
{ title: '创建时间', dataIndex: 'createTime', width: 180, valueType: 'dateTime' },
|
||||
{ title: '更新时间', dataIndex: 'updateTime', width: 180, valueType: 'dateTime' },
|
||||
{ title: '备注', dataIndex: 'remark', width: 150, ellipsis: true },
|
||||
];
|
||||
@@ -0,0 +1,9 @@
|
||||
// 携程退款状态常量
|
||||
export const CTRIP_REFUND_STATUS_OPTIONS: { label: string; value: number; color?: string }[] = [
|
||||
{ label: '待确认', value: 0, color: 'orange' },
|
||||
{ label: '已确认', value: 1, color: 'green' },
|
||||
{ label: '已拒绝', value: 2, color: 'red' },
|
||||
];
|
||||
|
||||
export const findLabel = (arr: { label: string; value: number }[], v?: number) => arr.find(o => o.value === v)?.label || '未知';
|
||||
export const findColor = (arr: { color?: string; value: number }[], v?: number) => arr.find(o => o.value === v)?.color;
|
||||
@@ -0,0 +1,57 @@
|
||||
import React, { useRef, useMemo, useState } from 'react';
|
||||
import { PageContainer, ProFormSelect, ProFormText, ProTable } from '@ant-design/pro-components';
|
||||
import type { ActionType } from '@ant-design/pro-components';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { GlassCard, SearchBarPlus } from '@/components/ui';
|
||||
import { CTRIP_REFUND_STATUS_OPTIONS } from './components/constants';
|
||||
import { buildCtripRefundColumns, CtripRefundItem } from './components/buildColumns';
|
||||
|
||||
const CtripRefundPage: React.FC = () => {
|
||||
const actionRef = useRef<ActionType>();
|
||||
const [searchParams, setSearchParams] = useState<Record<string, any>>({});
|
||||
|
||||
const handleSearch = (values: Record<string, any>) => {
|
||||
setSearchParams(values);
|
||||
actionRef.current?.reset?.();
|
||||
};
|
||||
|
||||
const columns = useMemo(() => buildCtripRefundColumns(), []);
|
||||
|
||||
return (
|
||||
<PageContainer header={{ title: '携程退款管理' }}>
|
||||
<SearchBarPlus
|
||||
defaultCollapsed={false}
|
||||
split
|
||||
span={6}
|
||||
showTenant={false}
|
||||
onFinish={handleSearch}
|
||||
hideReset
|
||||
>
|
||||
<ProFormText name="otaOrderId" label="携程订单号" placeholder="请输入携程订单号" />
|
||||
<ProFormText name="supplierOrderId" label="供应商订单号" placeholder="请输入供应商订单号" />
|
||||
<ProFormSelect name="refundStatus" label="退款状态" options={CTRIP_REFUND_STATUS_OPTIONS} allowClear />
|
||||
</SearchBarPlus>
|
||||
|
||||
<GlassCard>
|
||||
<ProTable<CtripRefundItem>
|
||||
rowKey="id"
|
||||
headerTitle="携程退款列表"
|
||||
actionRef={actionRef}
|
||||
request={(p) => {
|
||||
const params = {
|
||||
...p,
|
||||
...searchParams
|
||||
};
|
||||
return ordersApi.ctripRefundList(params as any);
|
||||
}}
|
||||
columns={columns}
|
||||
search={false}
|
||||
pagination={{ showSizeChanger: true, showQuickJumper: true, defaultPageSize: 20 }}
|
||||
scroll={{ x: 1800 }}
|
||||
/>
|
||||
</GlassCard>
|
||||
</PageContainer>
|
||||
);
|
||||
};
|
||||
|
||||
export default CtripRefundPage;
|
||||
@@ -1,8 +1,8 @@
|
||||
// UTF-8: 退款审核弹框组件
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { Modal, Form, Select, Input, message, Empty, Image, Space, Row, Col, Divider, InputNumber, Button, Tag } from 'antd';
|
||||
import { Modal, Form, Select, Input, message, Empty, Image, Space, Row, Col, Divider, InputNumber, Button, Tag, Alert } from 'antd';
|
||||
import { ordersApi } from '@/services/orders';
|
||||
import { ORDER_STATUS_OPTIONS, findLabel, findColor } from './constants';
|
||||
import { ORDER_STATUS_OPTIONS, PAY_TYPE_OPTIONS, findLabel, findColor } from './constants';
|
||||
|
||||
interface RefundReviewModalProps {
|
||||
visible: boolean;
|
||||
@@ -10,6 +10,7 @@ interface RefundReviewModalProps {
|
||||
onCancel: () => void;
|
||||
onSuccess?: () => void;
|
||||
isReviewMode: boolean; // true: 审核模式,false: 查看模式
|
||||
payType?: number; // 支付类型:1-微信支付,2-优惠券支付
|
||||
}
|
||||
|
||||
const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
@@ -18,6 +19,7 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
onCancel,
|
||||
onSuccess,
|
||||
isReviewMode = true,
|
||||
payType,
|
||||
}) => {
|
||||
const [form] = Form.useForm();
|
||||
const [loading, setLoading] = useState(false);
|
||||
@@ -26,6 +28,8 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
const [editingAmount, setEditingAmount] = useState(false);
|
||||
const [customRefundAmount, setCustomRefundAmount] = useState<number | null>(null);
|
||||
const [selectedReviewResult, setSelectedReviewResult] = useState<number | null>(null);
|
||||
const [orderPayType, setOrderPayType] = useState<number | undefined>(payType);
|
||||
const [ctripRefundInfo, setCtripRefundInfo] = useState<any>(null); // 携程退款信息
|
||||
|
||||
// 审核结果选项
|
||||
const reviewResults = [
|
||||
@@ -79,8 +83,27 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
setCustomRefundAmount(null);
|
||||
setSelectedReviewResult(1); // 1 = 全额退款
|
||||
form.setFieldsValue({ reviewResult: 1 });
|
||||
setCtripRefundInfo(null);
|
||||
|
||||
// 如果是优惠券支付,获取携程退款信息
|
||||
if (payType === 2) {
|
||||
fetchCtripRefundInfo();
|
||||
}
|
||||
}
|
||||
}, [visible, orderNo]);
|
||||
}, [visible, orderNo, payType]);
|
||||
|
||||
// 获取携程退款信息
|
||||
const fetchCtripRefundInfo = async () => {
|
||||
try {
|
||||
const data = await ordersApi.ctripRefundAvailable(orderNo);
|
||||
if (data) {
|
||||
setCtripRefundInfo(data);
|
||||
console.log('携程退款信息:', data);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('获取携程退款信息失败:', error);
|
||||
}
|
||||
};
|
||||
|
||||
const fetchRefundDetail = async () => {
|
||||
setFetching(true);
|
||||
@@ -90,6 +113,10 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
|
||||
if (data) {
|
||||
setRefundData(data);
|
||||
// 保存支付类型
|
||||
if (data.payType !== undefined) {
|
||||
setOrderPayType(data.payType);
|
||||
}
|
||||
console.log('退款详情:', data);
|
||||
} else {
|
||||
message.warning('未找到该订单的退款记录');
|
||||
@@ -133,21 +160,17 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
}
|
||||
}
|
||||
|
||||
// 调用自定义金额的退款审核接口
|
||||
const res = await ordersApi.approveRefundWithCustomAmount({
|
||||
orderNo: refundData?.orderNo,
|
||||
refundNo: refundData?.refundNo,
|
||||
refundAmount: String(actualRefundAmount), // 后端期望字符串格式
|
||||
status: 7, // 退款中状态码
|
||||
state: values.reviewResult, // 审核状态:1=通过(APPROVED),2=拒绝(REFUSED)
|
||||
approveReason: values.reviewComment, // 审核意见
|
||||
});
|
||||
// 根据支付类型调用不同的退款接口
|
||||
const currentPayType = orderPayType || payType || refundData?.payType;
|
||||
|
||||
if (currentPayType === 2) {
|
||||
// 优惠券支付 - 调用携程退款接口
|
||||
await handleCtripRefund(values, actualRefundAmount);
|
||||
} else {
|
||||
// 微信支付 - 调用微信退款接口
|
||||
await handleWxRefund(values, actualRefundAmount);
|
||||
}
|
||||
|
||||
// 显示后端返回的实际消息
|
||||
const successMsg = res?.resp_msg || res?.message || '审核已提交';
|
||||
message.success(successMsg);
|
||||
onSuccess?.();
|
||||
onCancel();
|
||||
} catch (error) {
|
||||
console.error('提交审核失败:', error);
|
||||
message.error('提交审核失败');
|
||||
@@ -156,6 +179,66 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
}
|
||||
};
|
||||
|
||||
// 微信退款处理
|
||||
const handleWxRefund = async (values: any, actualRefundAmount: number) => {
|
||||
// 调用自定义金额的退款审核接口
|
||||
const res = await ordersApi.approveRefundWithCustomAmount({
|
||||
orderNo: refundData?.orderNo,
|
||||
refundNo: refundData?.refundNo,
|
||||
refundAmount: String(actualRefundAmount), // 后端期望字符串格式
|
||||
status: 7, // 退款中状态码
|
||||
state: values.reviewResult, // 审核状态:1=通过(APPROVED),2=拒绝(REFUSED)
|
||||
approveReason: values.reviewComment, // 审核意见
|
||||
});
|
||||
|
||||
// 显示后端返回的实际消息
|
||||
const successMsg = res?.resp_msg || res?.message || '审核已提交';
|
||||
message.success(successMsg);
|
||||
onSuccess?.();
|
||||
onCancel();
|
||||
};
|
||||
|
||||
// 携程退款处理
|
||||
const handleCtripRefund = async (values: any, actualRefundAmount: number) => {
|
||||
// 如果是拒绝退款,只更新本地状态
|
||||
if (values.reviewResult === 2) {
|
||||
const res = await ordersApi.approveRefundWithCustomAmount({
|
||||
orderNo: refundData?.orderNo,
|
||||
refundNo: refundData?.refundNo,
|
||||
refundAmount: String(actualRefundAmount),
|
||||
status: 7,
|
||||
state: values.reviewResult,
|
||||
approveReason: values.reviewComment,
|
||||
});
|
||||
const successMsg = res?.resp_msg || res?.message || '已拒绝退款';
|
||||
message.success(successMsg);
|
||||
onSuccess?.();
|
||||
onCancel();
|
||||
return;
|
||||
}
|
||||
|
||||
// 计算退款金额(元)
|
||||
const refundAmountYuan = customRefundAmount !== null
|
||||
? customRefundAmount
|
||||
: parseFloat(formatAmount(refundData?.refundAmount));
|
||||
|
||||
// 调用携程退款接口
|
||||
const res = await ordersApi.ctripRefundApply({
|
||||
orderNo: refundData?.orderNo || orderNo,
|
||||
refundAmount: refundAmountYuan,
|
||||
refundReason: values.reviewComment || '管理后台审核退款',
|
||||
});
|
||||
|
||||
if (res?.resp_code === 0) {
|
||||
const successMsg = res?.datas || res?.resp_msg || '携程退款申请已提交';
|
||||
message.success(successMsg);
|
||||
onSuccess?.();
|
||||
onCancel();
|
||||
} else {
|
||||
message.error(res?.resp_msg || '携程退款申请失败');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<Modal
|
||||
title={isReviewMode ? '退款审核' : '退款查看'}
|
||||
@@ -294,7 +377,7 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
|
||||
{/* 状态信息 */}
|
||||
<Row gutter={[16, 16]}>
|
||||
<Col span={12}>
|
||||
<Col span={8}>
|
||||
<div>
|
||||
<span style={{ fontWeight: 'bold' }}>退款状态</span>
|
||||
<div style={{ marginTop: 4 }}>
|
||||
@@ -314,7 +397,7 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={12}>
|
||||
<Col span={8}>
|
||||
<div>
|
||||
<span style={{ fontWeight: 'bold' }}>订单状态</span>
|
||||
<div style={{ marginTop: 4 }}>
|
||||
@@ -324,8 +407,31 @@ const RefundReviewModal: React.FC<RefundReviewModalProps> = ({
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
<Col span={8}>
|
||||
<div>
|
||||
<span style={{ fontWeight: 'bold' }}>支付方式</span>
|
||||
<div style={{ marginTop: 4 }}>
|
||||
<Tag color={findColor(PAY_TYPE_OPTIONS, orderPayType || payType)}>
|
||||
{findLabel(PAY_TYPE_OPTIONS, orderPayType || payType)}
|
||||
</Tag>
|
||||
</div>
|
||||
</div>
|
||||
</Col>
|
||||
</Row>
|
||||
|
||||
{/* 携程退款提示 */}
|
||||
{(orderPayType === 2 || payType === 2) && isReviewMode && (
|
||||
<>
|
||||
<Divider />
|
||||
<Alert
|
||||
message="优惠券支付订单"
|
||||
description="该订单为携程优惠券支付,退款将通过携程退款接口处理。"
|
||||
type="info"
|
||||
showIcon
|
||||
/>
|
||||
</>
|
||||
)}
|
||||
|
||||
<Divider />
|
||||
|
||||
{/* 退款原因 */}
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// UTF-8: 订单列表列定义(按截图样式)
|
||||
import React, { useState } from 'react';
|
||||
import type { ProColumns } from '@ant-design/pro-components';
|
||||
import { Space, Typography } from 'antd';
|
||||
import { Space, Typography, Tooltip } from 'antd';
|
||||
import { PayTypeTag, OrderStatusTag } from './Tags';
|
||||
import StatusUpdater from './StatusUpdater';
|
||||
import OrderResourcesModal from './OrderResourcesModal';
|
||||
@@ -17,7 +17,14 @@ const ORDER_STATUS = {
|
||||
REFUNDING: 7, // 退款中
|
||||
REFUND_SUCCESS: 8, // 退款成功
|
||||
REFUND_FAILED: 9, // 退款失败
|
||||
REFUND_PART: 10, // 退款失败
|
||||
REFUND_PART: 10, // 部分退款
|
||||
};
|
||||
|
||||
// 支付类型常量
|
||||
const PAY_TYPE = {
|
||||
WECHAT: 1, // 微信支付
|
||||
COUPON: 2, // 优惠券支付
|
||||
THIRD_PARTY: 3, // 第三方支付
|
||||
};
|
||||
|
||||
// 资源列表操作组件
|
||||
@@ -32,6 +39,10 @@ const ResourcesActionCell: React.FC<{ record: OrderItem; onReload?: () => void;
|
||||
const isRefunding = record.orderStatus === ORDER_STATUS.REFUNDING;
|
||||
// 判断是否显示退款查看按钮(订单状态为退款成功或退款失败)
|
||||
const isRefundResolved = record.orderStatus === ORDER_STATUS.REFUND_SUCCESS || record.orderStatus === ORDER_STATUS.REFUND_FAILED || record.orderStatus === ORDER_STATUS.REFUND_PART;
|
||||
// 判断是否为第三方支付(不支持退款)
|
||||
const isThirdPartyPay = record.payType === PAY_TYPE.THIRD_PARTY;
|
||||
// 是否可以创建退款(任务完成 且 非第三方支付)
|
||||
const canCreateRefund = isTaskComplete && !isThirdPartyPay;
|
||||
|
||||
return (
|
||||
<>
|
||||
@@ -39,7 +50,13 @@ const ResourcesActionCell: React.FC<{ record: OrderItem; onReload?: () => void;
|
||||
<Link onClick={() => setResourceModalVisible(true)}>资源列表</Link>
|
||||
<StatusUpdater record={record} onUpdated={onReload} canModifyStatus={canModifyStatus} />
|
||||
{canModifyStatus && isTaskComplete && (
|
||||
<Link onClick={() => setCreateRefundModalVisible(true)}>创建退款</Link>
|
||||
isThirdPartyPay ? (
|
||||
<Tooltip title="第三方支付订单不支持退款">
|
||||
<span style={{ color: '#999', cursor: 'not-allowed' }}>创建退款</span>
|
||||
</Tooltip>
|
||||
) : (
|
||||
<Link onClick={() => setCreateRefundModalVisible(true)}>创建退款</Link>
|
||||
)
|
||||
)}
|
||||
{canModifyStatus && isRefunding && (
|
||||
<Link onClick={() => setRefundModalVisible(true)}>退款审核</Link>
|
||||
@@ -56,6 +73,7 @@ const ResourcesActionCell: React.FC<{ record: OrderItem; onReload?: () => void;
|
||||
<RefundReviewModal
|
||||
visible={refundModalVisible}
|
||||
orderNo={record.orderNo || ''}
|
||||
payType={record.payType}
|
||||
onCancel={() => setRefundModalVisible(false)}
|
||||
onSuccess={onReload}
|
||||
isReviewMode={isRefunding}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
export const PAY_TYPE_OPTIONS: { label: string; value: number; color?: string }[] = [
|
||||
{ label: '微信支付', value: 1, color: 'green' },
|
||||
{ label: '优惠券支付', value: 2, color: 'blue' },
|
||||
{ label: '第三方支付', value: 3, color: 'purple' },
|
||||
];
|
||||
|
||||
export const ORDER_STATUS_OPTIONS: { label: string; value: number; color?: string }[] = [
|
||||
|
||||
@@ -578,4 +578,48 @@ export const ordersApi = {
|
||||
const list = (res as any)?.data ?? [];
|
||||
return list.length > 0 ? list[0] : null;
|
||||
},
|
||||
|
||||
// ==================== 携程退款 ====================
|
||||
|
||||
// 携程退款 - 发起退款申请
|
||||
ctripRefundApply: async (data: { orderNo: string; refundAmount: number; refundReason?: string }) => {
|
||||
const res = await request('/api-coupon/coupon/ctrip/admin/refund/apply', { method: 'POST', data });
|
||||
return res as any;
|
||||
},
|
||||
|
||||
// 携程退款 - 获取可退金额
|
||||
ctripRefundAvailable: async (orderNo: string) => {
|
||||
const res = await request(`/api-coupon/coupon/ctrip/admin/refund/available/${orderNo}`, { method: 'GET' });
|
||||
return (res as any)?.data || res;
|
||||
},
|
||||
|
||||
// 携程退款 - 检查是否可退款
|
||||
ctripRefundCheck: async (orderNo: string) => {
|
||||
const res = await request(`/api-coupon/coupon/ctrip/admin/refund/check/${orderNo}`, { method: 'GET' });
|
||||
return (res as any)?.data || res;
|
||||
},
|
||||
|
||||
// 携程退款 - 查询退款记录
|
||||
ctripRefundRecords: async (orderNo: string) => {
|
||||
const res = await request(`/api-coupon/coupon/ctrip/admin/refund/records/${orderNo}`, { method: 'GET' });
|
||||
return (res as any)?.data || res;
|
||||
},
|
||||
|
||||
// ==================== 携程订单管理 ====================
|
||||
|
||||
// 携程订单列表 - 分页查询
|
||||
ctripOrderList: async (params: { current?: number; pageSize?: number; otaOrderId?: string; orderNo?: string; status?: number }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-coupon/coupon/ctrip/admin/refund/orders', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
const data = (res as any)?.data;
|
||||
return { data: data?.data || [], total: data?.count || 0 };
|
||||
},
|
||||
|
||||
// 携程退款列表 - 分页查询
|
||||
ctripRefundList: async (params: { current?: number; pageSize?: number; otaOrderId?: string; supplierOrderId?: string; refundStatus?: number }) => {
|
||||
const { current, pageSize, ...rest } = params || {};
|
||||
const res = await request('/api-coupon/coupon/ctrip/admin/refund/refunds', { method: 'GET', params: { page: current, limit: pageSize, ...rest } });
|
||||
const data = (res as any)?.data;
|
||||
return { data: data?.data || [], total: data?.count || 0 };
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user