|
|
@@ -8,6 +8,8 @@ import com.fs.common.enums.BusinessType;
|
|
|
import com.fs.common.exception.ServiceException;
|
|
|
import com.fs.common.exception.CustomException;
|
|
|
import com.fs.company.service.ICompanyService;
|
|
|
+import com.fs.his.domain.FsHfpayConfig;
|
|
|
+import com.fs.his.mapper.FsHfpayConfigMapper;
|
|
|
import com.fs.hisStore.config.StoreConfig;
|
|
|
import com.fs.hisStore.domain.FsStorePaymentScrm;
|
|
|
import com.fs.hisStore.param.FsStoreScanPaymentStatParam;
|
|
|
@@ -37,6 +39,8 @@ import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
import java.util.*;
|
|
|
|
|
|
+
|
|
|
+
|
|
|
@Slf4j
|
|
|
@Api("扫码流水统计接口")
|
|
|
@RestController
|
|
|
@@ -55,6 +59,8 @@ public class FsStoreScanPaymentStatController extends AppBaseController {
|
|
|
private ICompanyService companyService;
|
|
|
@Autowired
|
|
|
private ICompanyUserService companyUserService;
|
|
|
+ @Autowired
|
|
|
+ private FsHfpayConfigMapper fsHfpayConfigMapper;
|
|
|
|
|
|
/**
|
|
|
* 扫码支付统计接口
|
|
|
@@ -62,9 +68,9 @@ public class FsStoreScanPaymentStatController extends AppBaseController {
|
|
|
@ApiOperation("销售收款码金额统计")
|
|
|
@PostMapping("/getScanPayStat")
|
|
|
public R getScanPayStat(@Valid @RequestBody FsStoreScanPaymentStatParam param) {
|
|
|
- //统计
|
|
|
+ // 统计
|
|
|
FsStoreScanPaymentStatVo scanPaymentStat = paymentService.getScanPaymentStat(param);
|
|
|
- return R.ok().put("data",scanPaymentStat);
|
|
|
+ return R.ok().put("data", scanPaymentStat);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -94,14 +100,14 @@ public class FsStoreScanPaymentStatController extends AppBaseController {
|
|
|
/**
|
|
|
* 扫码支付分页查询接口
|
|
|
*/
|
|
|
- @ApiOperation("销售收款码金额统计")
|
|
|
+ @ApiOperation("销售收款码分页查询")
|
|
|
@PostMapping("/getScanPayStatPage")
|
|
|
public R getScanPayStatPage(@Valid @RequestBody FsStoreScanPaymentStatParam param) {
|
|
|
- //分页
|
|
|
+ // 分页
|
|
|
PageHelper.startPage(param.getPageNum(), param.getPageSize());
|
|
|
- List<FsStoreScanPaymentStatDetailsVo> statDetailsVos=paymentService.getScanPaymentStatPage(param);
|
|
|
- PageInfo<FsStoreScanPaymentStatDetailsVo> listPageInfo=new PageInfo<>(statDetailsVos);
|
|
|
- return R.ok().put("data",listPageInfo);
|
|
|
+ List<FsStoreScanPaymentStatDetailsVo> statDetailsVos = paymentService.getScanPaymentStatPage(param);
|
|
|
+ PageInfo<FsStoreScanPaymentStatDetailsVo> listPageInfo = new PageInfo<>(statDetailsVos);
|
|
|
+ return R.ok().put("data", listPageInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
@@ -121,83 +127,348 @@ public class FsStoreScanPaymentStatController extends AppBaseController {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 扫码支付退款接口(统一入口)
|
|
|
- * 根据当前用户权限决定调用直接退款还是退款审核
|
|
|
+ * 普通员工申请退款接口
|
|
|
*/
|
|
|
- @ApiOperation("扫码支付退款统一接口")
|
|
|
- @PostMapping("/refund")
|
|
|
- @Transactional
|
|
|
- public R refundPayment(@RequestParam("token") String token,
|
|
|
- @RequestBody FsStorePaymentScrm fsStorePayment) {
|
|
|
+ @ApiOperation("申请退款接口(普通员工)")
|
|
|
+ @PostMapping("/applyRefund")
|
|
|
+ public R applyRefund(@RequestBody FsStorePaymentScrm fsStorePayment) {
|
|
|
try {
|
|
|
- // 从 Redis 中获取用户ID
|
|
|
- Long companyUserId = redisCache.getCacheObject("company-user-token:" + token);
|
|
|
- if (companyUserId == null) {
|
|
|
- return R.error("用户未登录或登录已过期,请重新登录");
|
|
|
+ // 验证支付记录
|
|
|
+ FsStorePaymentScrm payment = fsStorePaymentService.selectFsStorePaymentById(fsStorePayment.getPaymentId());
|
|
|
+ if (payment == null) {
|
|
|
+ return R.error("支付记录不存在");
|
|
|
}
|
|
|
|
|
|
- // 查询用户信息
|
|
|
- CompanyUser companyUser = companyUserService.selectCompanyUserById(companyUserId);
|
|
|
- if (companyUser == null) {
|
|
|
- return R.error("用户不存在");
|
|
|
+ if (payment.getStatus() != 1) {
|
|
|
+ return R.error("只有已支付的订单才能申请退款");
|
|
|
}
|
|
|
|
|
|
- if (!companyUser.getStatus().equals("0")) {
|
|
|
- return R.error("用户已禁用");
|
|
|
+ // 检查是否已经有退款申请
|
|
|
+ if (payment.getRefundAuditStatus() != null && payment.getRefundAuditStatus() == 0) {
|
|
|
+ return R.error("该订单已有待审核的退款申请");
|
|
|
}
|
|
|
|
|
|
- // 根据用户权限调用不同的方法
|
|
|
- if (companyUser.isAdmin()) {
|
|
|
- // 管理员直接退款
|
|
|
- log.info("管理员[{}]执行直接退款, 支付ID: {}", companyUser.getUserName(), fsStorePayment.getPaymentId());
|
|
|
- return refundStorePayment(fsStorePayment);
|
|
|
- } else {
|
|
|
- // 非管理员提交退款审核
|
|
|
- log.info("非管理员[{}]提交退款审核, 支付ID: {}", companyUser.getUserName(), fsStorePayment.getPaymentId());
|
|
|
+ if (payment.getStatus() == -1) {
|
|
|
+ return R.error("该订单已退款");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 验证退款金额
|
|
|
+ if (fsStorePayment.getRefundMoney() == null || fsStorePayment.getRefundMoney().compareTo(new BigDecimal(0)) < 1) {
|
|
|
+ return R.error("退款金额必须大于0");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (payment.getPayMoney().compareTo(fsStorePayment.getRefundMoney()) == -1) {
|
|
|
+ return R.error("退款金额必须小于等于付款金额");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 更新退款申请状态
|
|
|
+ payment.setRefundMoney(fsStorePayment.getRefundMoney());
|
|
|
+ payment.setRefundAuditStatus(0); // 0-待审核
|
|
|
+ payment.setRefundAuditBy(fsStorePayment.getRefundAuditBy());
|
|
|
+ payment.setRefundAuditTime(new Date());
|
|
|
+ payment.setRefundAuditRemark(fsStorePayment.getRefundAuditRemark() != null ? fsStorePayment.getRefundAuditRemark() : "申请退款");
|
|
|
+
|
|
|
+ fsStorePaymentService.updateFsStorePayment(payment);
|
|
|
+
|
|
|
+ log.info("提交退款申请成功, 支付ID: {}, 退款金额: {}",
|
|
|
+ payment.getPaymentId(), fsStorePayment.getRefundMoney());
|
|
|
+
|
|
|
+ return R.ok("退款申请已提交,等待管理员审核");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("申请退款失败, 支付ID: {}", fsStorePayment.getPaymentId(), e);
|
|
|
+ return R.error("申请退款失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param auditStatus 查询类型:0-查询所有, 1-只查询待审核, 2-只查询已退款, 3-只查询已拒绝
|
|
|
+ */
|
|
|
+ @ApiOperation("查询退款申请列表(管理员)")
|
|
|
+ @GetMapping("/getPendingRefundList")
|
|
|
+ public R getPendingRefundList(@RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum,
|
|
|
+ @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize,
|
|
|
+ @RequestParam(value = "companyId") Long companyId,
|
|
|
+ @RequestParam(value = "appId", required = false) String appId,
|
|
|
+ @RequestParam(value = "auditStatus", defaultValue = "1") Integer auditStatus,
|
|
|
+ @RequestParam(value = "startDate", required = false) String startDate,
|
|
|
+ @RequestParam(value = "endDate", required = false) String endDate) {
|
|
|
+ try {
|
|
|
+ log.info("查询退款申请列表 - companyId={}, appId={}, auditStatus={}, startDate={}, endDate={}",
|
|
|
+ companyId, appId, auditStatus, startDate, endDate);
|
|
|
+
|
|
|
+ // 设置时间范围查询参数
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+ if (startDate != null && !startDate.isEmpty()) {
|
|
|
+ params.put("beginTime", startDate + " 00:00:00");
|
|
|
+ }
|
|
|
+ if (endDate != null && !endDate.isEmpty()) {
|
|
|
+ params.put("endTime", endDate + " 23:59:59");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ FsStorePaymentScrm query = new FsStorePaymentScrm();
|
|
|
+ query.setBusinessType(1); // 业务类型:收款
|
|
|
+ query.setCompanyId(companyId);
|
|
|
+ query.setAppId(appId);
|
|
|
+ query.setParams(params);
|
|
|
+
|
|
|
+ // 根据 auditStatus 设置不同的查询条件
|
|
|
+ // refundAuditStatus: 0-待审核, 1-审核通过已退款, 2-审核拒绝
|
|
|
+ if (auditStatus == 1) {
|
|
|
+ // 只查询待审核的:status=1(已支付) AND refundAuditStatus=0(待审核)
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(0);
|
|
|
+
|
|
|
+ } else if (auditStatus == 2) {
|
|
|
+ // 只查询已退款的:status=-1(已退款) AND refundAuditStatus=1(审核通过已退款)
|
|
|
+ query.setStatus(-1);
|
|
|
+ query.setRefundAuditStatus(1);
|
|
|
+
|
|
|
+ } else if (auditStatus == 3) {
|
|
|
+ // 只查询已拒绝的:status=1(已支付) AND refundAuditStatus=2(审核拒绝)
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(2);
|
|
|
+
|
|
|
+ } else if (auditStatus == 0) {
|
|
|
+ // 查询所有需要手动分页,因为需要多次查询合并
|
|
|
+ List<FsStorePaymentScrm> resultList = new ArrayList<>();
|
|
|
+
|
|
|
+ // 1. 待审核:status=1 AND refundAuditStatus=0
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(0);
|
|
|
+ resultList.addAll(fsStorePaymentService.selectFsStorePaymentList(query));
|
|
|
|
|
|
- Map<String, Object> auditData = new HashMap<>();
|
|
|
- auditData.put("paymentId", fsStorePayment.getPaymentId());
|
|
|
- auditData.put("refundAuditStatus", 1); // 1表示待审核
|
|
|
- auditData.put("auditRemark", "用户提交退款申请");
|
|
|
- auditData.put("auditor", companyUser.getUserName());
|
|
|
+ // 2. 已退款:status=-1 AND refundAuditStatus=1
|
|
|
+ query.setStatus(-1);
|
|
|
+ query.setRefundAuditStatus(1);
|
|
|
+ resultList.addAll(fsStorePaymentService.selectFsStorePaymentList(query));
|
|
|
|
|
|
- return auditRefund(auditData);
|
|
|
+ // 3. 已拒绝:status=1 AND refundAuditStatus=2
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(2);
|
|
|
+ resultList.addAll(fsStorePaymentService.selectFsStorePaymentList(query));
|
|
|
+
|
|
|
+ // 手动分页处理
|
|
|
+ int total = resultList.size();
|
|
|
+ int startIndex = (pageNum - 1) * pageSize;
|
|
|
+ int endIndex = Math.min(startIndex + pageSize, total);
|
|
|
+
|
|
|
+ List<FsStorePaymentScrm> pageList = new ArrayList<>();
|
|
|
+ if (startIndex < total) {
|
|
|
+ pageList = resultList.subList(startIndex, endIndex);
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建分页结果
|
|
|
+ PageInfo<FsStorePaymentScrm> pageInfo = new PageInfo<>(pageList);
|
|
|
+ pageInfo.setTotal(total);
|
|
|
+ pageInfo.setPageNum(pageNum);
|
|
|
+ pageInfo.setPageSize(pageSize);
|
|
|
+ pageInfo.setSize(pageList.size());
|
|
|
+ pageInfo.setStartRow((long) startIndex);
|
|
|
+ pageInfo.setEndRow((long) (endIndex - 1));
|
|
|
+ int totalPages = (total + pageSize - 1) / pageSize;
|
|
|
+ pageInfo.setPages(totalPages);
|
|
|
+ pageInfo.setPrePage(pageNum > 1 ? pageNum - 1 : 0);
|
|
|
+ pageInfo.setNextPage(pageNum < totalPages ? pageNum + 1 : 0);
|
|
|
+ pageInfo.setIsFirstPage(pageNum == 1);
|
|
|
+ pageInfo.setIsLastPage(pageNum >= totalPages);
|
|
|
+ pageInfo.setHasPreviousPage(pageNum > 1);
|
|
|
+ pageInfo.setHasNextPage(pageNum < totalPages);
|
|
|
+
|
|
|
+ return R.ok().put("data", pageInfo);
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return R.error("查询类型错误,0-所有, 1-待审核, 2-已退款, 3-已拒绝");
|
|
|
}
|
|
|
+
|
|
|
+ // 单一条件查询使用 PageHelper 分页
|
|
|
+ PageHelper.startPage(pageNum, pageSize);
|
|
|
+ List<FsStorePaymentScrm> resultList = fsStorePaymentService.selectFsStorePaymentList(query);
|
|
|
+ PageInfo<FsStorePaymentScrm> pageInfo = new PageInfo<>(resultList);
|
|
|
+
|
|
|
+ return R.ok().put("data", pageInfo);
|
|
|
} catch (Exception e) {
|
|
|
- log.error("退款处理异常, token: {}, paymentId: {}", token, fsStorePayment.getPaymentId(), e);
|
|
|
- return R.error("退款处理失败:" + e.getMessage());
|
|
|
+ log.error("查询退款申请列表失败", e);
|
|
|
+ return R.error("查询失败:" + e.getMessage());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 扫码支付退款接口(管理员专用)
|
|
|
+ * 查询退款审核统计数据
|
|
|
+ * @param auditStatus 查询类型:0-查询所有, 1-只查询待审核, 2-只查询已退款, 3-只查询已拒绝
|
|
|
*/
|
|
|
+ @ApiOperation("查询退款审核统计数据")
|
|
|
+ @GetMapping("/getRefundAuditCount")
|
|
|
+ public R getRefundAuditCount(@RequestParam(value = "companyId") Long companyId,
|
|
|
+ @RequestParam(value = "appId", required = false) String appId,
|
|
|
+ @RequestParam(value = "auditStatus", defaultValue = "0") Integer auditStatus) {
|
|
|
+ try {
|
|
|
+ log.info("查询退款审核统计 - companyId={}, appId={}, auditStatus={}",
|
|
|
+ companyId, appId, auditStatus);
|
|
|
+
|
|
|
+ int count = 0;
|
|
|
+ String statusDesc = "";
|
|
|
+ Map<String, Object> params = new HashMap<>();
|
|
|
+
|
|
|
+ // 构建查询条件
|
|
|
+ FsStorePaymentScrm query = new FsStorePaymentScrm();
|
|
|
+ query.setBusinessType(1); // 业务类型:收款
|
|
|
+ query.setCompanyId(companyId);
|
|
|
+ query.setAppId(appId);
|
|
|
+ query.setParams(params);
|
|
|
+
|
|
|
+ // refundAuditStatus: 0-待审核, 1-审核通过已退款, 2-审核拒绝
|
|
|
+ if (auditStatus == 1) {
|
|
|
+ // 只查询待审核的:status=1 AND refundAuditStatus=0
|
|
|
+ statusDesc = "待审核";
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(0);
|
|
|
+ count = fsStorePaymentService.selectFsStorePaymentList(query).size();
|
|
|
+
|
|
|
+ } else if (auditStatus == 2) {
|
|
|
+ // 只查询已退款的:status=-1 AND refundAuditStatus=1
|
|
|
+ statusDesc = "已退款";
|
|
|
+ query.setStatus(-1);
|
|
|
+ query.setRefundAuditStatus(1);
|
|
|
+ count = fsStorePaymentService.selectFsStorePaymentList(query).size();
|
|
|
+
|
|
|
+ } else if (auditStatus == 3) {
|
|
|
+ // 只查询已拒绝的:status=1 AND refundAuditStatus=2
|
|
|
+ statusDesc = "已拒绝";
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(2);
|
|
|
+ count = fsStorePaymentService.selectFsStorePaymentList(query).size();
|
|
|
+
|
|
|
+ } else if (auditStatus == 0) {
|
|
|
+ // 查询所有:待审核 + 已退款 + 已拒绝
|
|
|
+ statusDesc = "所有状态";
|
|
|
+
|
|
|
+ // 1. 待审核:status=1 AND refundAuditStatus=0
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(0);
|
|
|
+ count = fsStorePaymentService.selectFsStorePaymentList(query).size();
|
|
|
+
|
|
|
+ // 2. 已退款:status=-1 AND refundAuditStatus=1
|
|
|
+ query.setStatus(-1);
|
|
|
+ query.setRefundAuditStatus(1);
|
|
|
+ count += fsStorePaymentService.selectFsStorePaymentList(query).size();
|
|
|
+
|
|
|
+ // 3. 已拒绝:status=1 AND refundAuditStatus=2
|
|
|
+ query.setStatus(1);
|
|
|
+ query.setRefundAuditStatus(2);
|
|
|
+ count += fsStorePaymentService.selectFsStorePaymentList(query).size();
|
|
|
+
|
|
|
+ } else {
|
|
|
+ return R.error("查询类型错误,0-所有, 1-待审核, 2-已退款, 3-已拒绝");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 构建返回结果
|
|
|
+ Map<String, Object> result = new HashMap<>();
|
|
|
+ result.put("count", count);
|
|
|
+ result.put("auditStatus", auditStatus);
|
|
|
+ result.put("statusDesc", statusDesc);
|
|
|
+
|
|
|
+ log.info("退款审核统计结果 - 查询类型: {}({}), 记录数: {}",
|
|
|
+ auditStatus, statusDesc, count);
|
|
|
+
|
|
|
+ return R.ok().put("data", result);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("查询退款审核统计失败", e);
|
|
|
+ return R.error("查询失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
+ /**
|
|
|
+ * 扫码支付退款接口(管理员专用,单个退款)
|
|
|
+ */
|
|
|
@ApiOperation("扫码支付退款接口(管理员专用)")
|
|
|
@PostMapping("refundStorePayment")
|
|
|
@Transactional
|
|
|
public R refundStorePayment(@RequestBody FsStorePaymentScrm fsStorePayment)
|
|
|
+ {
|
|
|
+ try {
|
|
|
+ if (fsStorePayment == null || fsStorePayment.getPaymentId() == null) {
|
|
|
+ return R.error("支付记录ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ return singleRefundInternal(fsStorePayment);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("退款失败,支付ID: {}", fsStorePayment.getPaymentId(), e);
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.error("退款失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 将 Map 转换为 FsStorePaymentScrm 对象
|
|
|
+ */
|
|
|
+ private FsStorePaymentScrm convertToPayment(Map<String, Object> map) {
|
|
|
+ FsStorePaymentScrm payment = new FsStorePaymentScrm();
|
|
|
+ if (map.get("paymentId") != null) {
|
|
|
+ payment.setPaymentId(Long.valueOf(map.get("paymentId").toString()));
|
|
|
+ }
|
|
|
+ if (map.get("refundMoney") != null) {
|
|
|
+ payment.setRefundMoney(new BigDecimal(map.get("refundMoney").toString()));
|
|
|
+ }
|
|
|
+ return payment;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单个退款内部方法
|
|
|
+ */
|
|
|
+ private R singleRefundInternal(FsStorePaymentScrm fsStorePayment)
|
|
|
{
|
|
|
FsStorePaymentScrm payment=fsStorePaymentService.selectFsStorePaymentById(fsStorePayment.getPaymentId());
|
|
|
if(payment.getStatus()!=1){
|
|
|
- return R.error("非法操作");
|
|
|
+ return R.error("只有已支付的订单才能申请退款");
|
|
|
+ }
|
|
|
+ if(fsStorePayment.getRefundMoney().compareTo(new BigDecimal(0))<1){
|
|
|
+ return R.error("退款金额必须大于0");
|
|
|
+ }
|
|
|
+ if(payment.getPayMoney().compareTo(fsStorePayment.getRefundMoney())==-1){
|
|
|
+ return R.error("退款金额必须小于等于付款金额");
|
|
|
}
|
|
|
if(payment.getPayTypeCode().equals("weixin")){
|
|
|
+
|
|
|
if (payment.getPayMode()!=null&&payment.getPayMode().equals("hf")){
|
|
|
+ // 根据 appId 获取对应的汇付商户号
|
|
|
+ String huifuId = "";
|
|
|
+ log.info("开始退款,支付记录ID:{},appId:{}", payment.getPaymentId(), payment.getAppId());
|
|
|
+
|
|
|
+ if (payment.getAppId() != null && !payment.getAppId().isEmpty()) {
|
|
|
+ FsHfpayConfig fsHfpayConfig = fsHfpayConfigMapper.selectByAppId(payment.getAppId());
|
|
|
+ log.info("根据appId查询汇付配置,appId:{},查询结果:{}", payment.getAppId(), fsHfpayConfig);
|
|
|
+ if (fsHfpayConfig != null) {
|
|
|
+ huifuId = fsHfpayConfig.getHuifuId();
|
|
|
+ log.info("获取到huifuId:{}", huifuId);
|
|
|
+ } else {
|
|
|
+ log.error("未找到appId对应的汇付配置,appId:{}", payment.getAppId());
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ log.error("支付记录的appId为空,支付记录ID:{}", payment.getPaymentId());
|
|
|
+ }
|
|
|
+
|
|
|
+ // 如果没有获取到 huifuId,返回错误
|
|
|
+ if (huifuId == null || huifuId.isEmpty()) {
|
|
|
+ return R.error("未找到对应的汇付配置信息,请检查支付记录的appId:" + payment.getAppId());
|
|
|
+ }
|
|
|
+
|
|
|
V2TradePaymentScanpayRefundRequest request = new V2TradePaymentScanpayRefundRequest();
|
|
|
+ request.setHuifuId(huifuId);
|
|
|
request.setOrdAmt(payment.getPayMoney().toString());
|
|
|
request.setOrgReqDate(new SimpleDateFormat("yyyyMMdd").format(payment.getCreateTime()));
|
|
|
request.setReqSeqId("refund-"+payment.getPayCode());
|
|
|
Map<String, Object> extendInfoMap = new HashMap<>();
|
|
|
- extendInfoMap.put("org_party_order_id", payment.getBankSerialNo());
|
|
|
+ extendInfoMap.put("org_req_seq_id", "payment-"+payment.getPayCode());
|
|
|
request.setExtendInfo(extendInfoMap);
|
|
|
HuiFuRefundResult refund = huiFuService.refund(request);
|
|
|
log.info("退款:"+refund);
|
|
|
if((refund.getResp_code().equals("00000000")||refund.getResp_code().equals("00000100"))&&(refund.getTrans_stat().equals("S")||refund.getTrans_stat().equals("P"))){
|
|
|
payment.setRefundMoney(fsStorePayment.getRefundMoney());
|
|
|
payment.setStatus(-1);
|
|
|
- payment.setRefundAuditTime(new Date());
|
|
|
- payment.setRefundAuditStatus(2);
|
|
|
+ payment.setRefundTime(new Date());
|
|
|
+ payment.setRefundAuditStatus(1); // 1-审核通过已退款
|
|
|
fsStorePaymentService.updateFsStorePayment(payment);
|
|
|
//收款 减去所有
|
|
|
if(payment.getCompanyId()!=null&&payment.getCompanyId()>0){
|
|
|
@@ -224,60 +495,9 @@ public class FsStoreScanPaymentStatController extends AppBaseController {
|
|
|
// return payService.refundOrder(refundDTO);
|
|
|
}
|
|
|
else if(payment.getPayTypeCode().equals("alipay")){
|
|
|
- try {
|
|
|
- // 注意:这里的AliPayApiConfig、AliPayApiConfigKit、AliPayApi等类需要确保项目中有相应的依赖
|
|
|
- // 如果没有,建议注释掉支付宝退款部分或添加相应依赖
|
|
|
- /*
|
|
|
- AliPayApiConfig aliPayApiConfig;
|
|
|
- try {
|
|
|
- aliPayApiConfig = AliPayApiConfigKit.getApiConfig(aliPayBean.getAppId());
|
|
|
- } catch (Exception e) {
|
|
|
- aliPayApiConfig = AliPayApiConfig.builder()
|
|
|
- .setAppId(aliPayBean.getAppId())
|
|
|
- .setAliPayPublicKey(aliPayBean.getPublicKey())
|
|
|
- .setAppCertPath(aliPayBean.getAppCertPath())
|
|
|
- .setAliPayCertPath(aliPayBean.getAliPayCertPath())
|
|
|
- .setAliPayRootCertPath(aliPayBean.getAliPayRootCertPath())
|
|
|
- .setCharset("UTF-8")
|
|
|
- .setPrivateKey(aliPayBean.getPrivateKey())
|
|
|
- .setServiceUrl(aliPayBean.getServerUrl())
|
|
|
- .setSignType("RSA2")
|
|
|
- // 普通公钥方式
|
|
|
- .build();
|
|
|
- // 证书模式
|
|
|
-// .buildByCert();
|
|
|
- }
|
|
|
- AliPayApiConfigKit.putApiConfig(aliPayApiConfig);
|
|
|
- AlipayTradeRefundModel model = new AlipayTradeRefundModel();
|
|
|
- model.setOutTradeNo("payment-"+payment.getPayCode());
|
|
|
- model.setTradeNo(payment.getTradeNo());
|
|
|
- model.setRefundAmount(fsStorePayment.getRefundMoney().toString());
|
|
|
- model.setRefundReason("退款");
|
|
|
- String result= AliPayApi.tradeRefundToResponse(model).getBody();
|
|
|
- cn.hutool.json.JSONObject json= JSONUtil.parseObj(result);
|
|
|
- cn.hutool.json.JSONObject jsonInfo= (cn.hutool.json.JSONObject) json.get("alipay_trade_refund_response");
|
|
|
- String code=(String)jsonInfo.get("code");
|
|
|
- String msg=(String)jsonInfo.get("sub_msg");
|
|
|
- //{"{"alipay_trade_refund_response":{"code":"10000","msg":"Success","buyer_logon_id":"270***@qq.com","buyer_user_id":"2088402776950529","fund_change":"Y","gmt_refund_pay":"2022-04-27 18:27:28","out_trade_no":"goods-202204271826530001","refund_fee":"0.10","send_back_fee":"0.00","trade_no":"2022042722001450521456255417"},"sign":"hU+dy17/juMYQEQpO7Yy7jxkx9h5ebSbN3xdZr58msfOfJEUknqra6w4L37pgoZSx1Vj00jK3Ds06vrph6mSEliq3PQ37PwbZiRK3ZHaaKlz+9ndjoBTFYAxP60zLASfTq+W+dczDq4KOrvwhprFGt7YwKXGU42PgfOPb5EOgWyYUP6ivP0r06OzTo0f2lB28w6AQ4m4IQjdIL/tWbDaKl+ld8MPMLIgw5k9BmMcP8LV8ENC6+Gl1u5GwgAMjwHfk0RfB/kTFTHUTa7fgaO22w3pT8YKFMnOdKA0cVuJ2LE4SdxepqlprWJdCtLOeoQUX6PkEtoJGywPWAyjgdJ6Pg=="}
|
|
|
- if(code.equals("10000")){
|
|
|
- payment.setRefundMoney(fsStorePayment.getRefundMoney());
|
|
|
- fsStorePaymentService.updateFsStorePayment(payment);
|
|
|
- fsStorePaymentService.refund(payment.getPayCode());
|
|
|
- return R.ok("退款成功");
|
|
|
-
|
|
|
- }
|
|
|
- else{
|
|
|
- TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
- return R.error("退款失败:"+msg);
|
|
|
-
|
|
|
- }
|
|
|
- */
|
|
|
- return R.error("支付宝退款功能暂未配置,请联系系统管理员");
|
|
|
- //退款成功
|
|
|
- } catch (Exception e) {
|
|
|
- e.printStackTrace();
|
|
|
- return R.error("支付宝退款异常:" + e.getMessage());
|
|
|
- }
|
|
|
+ // 支付宝退款功能暂未配置
|
|
|
+ log.warn("支付宝退款功能暂未配置,支付记录ID:{}", payment.getPaymentId());
|
|
|
+ return R.error("支付宝退款功能暂未配置,请联系系统管理员");
|
|
|
}
|
|
|
return R.error("非法操作");
|
|
|
}
|
|
|
@@ -285,18 +505,106 @@ public class FsStoreScanPaymentStatController extends AppBaseController {
|
|
|
|
|
|
|
|
|
|
|
|
- @ApiOperation("退款审核接口(非管理员专用)")
|
|
|
+ /**
|
|
|
+ * 管理员审核退款申请接口(单个审核)
|
|
|
+ * @param auditData 包含 paymentId, refundStatus, refundRemark
|
|
|
+ */
|
|
|
+ @ApiOperation("管理员审核退款申请")
|
|
|
@Log(title = "退款审核", businessType = BusinessType.UPDATE)
|
|
|
- @PutMapping("/refund/audit")
|
|
|
- public R auditRefund(@RequestBody Map<String, Object> auditData)
|
|
|
- {
|
|
|
+ @PostMapping("/auditRefund")
|
|
|
+ @Transactional
|
|
|
+ public R auditRefund(@RequestBody Map<String, Object> auditData) {
|
|
|
+ try {
|
|
|
+ // 参数校验
|
|
|
+ if (auditData == null) {
|
|
|
+ return R.error("请求参数不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (auditData.get("paymentId") == null) {
|
|
|
+ return R.error("支付记录ID不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (auditData.get("refundStatus") == null) {
|
|
|
+ return R.error("退款状态不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Integer refundStatus = Integer.valueOf(auditData.get("refundStatus").toString());
|
|
|
+ String refundRemark = auditData.get("refundRemark") != null ? auditData.get("refundRemark").toString() : "";
|
|
|
+
|
|
|
+ // 审核状态:1-通过,2-拒绝
|
|
|
+ if (refundStatus != 1 && refundStatus != 2) {
|
|
|
+ return R.error("退款状态错误,1-通过,2-拒绝");
|
|
|
+ }
|
|
|
+
|
|
|
+ return singleAuditRefundInternal(auditData, refundStatus, refundRemark);
|
|
|
+ } catch (NumberFormatException e) {
|
|
|
+ log.error("参数格式错误", e);
|
|
|
+ return R.error("参数格式错误,paymentId和refundStatus必须为数字");
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("退款审核失败", e);
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.error("退款审核失败:" + e.getMessage());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 单个审核内部方法
|
|
|
+ * refundStatus: 1-审核通过, 2-审核拒绝
|
|
|
+ */
|
|
|
+ private R singleAuditRefundInternal(Map<String, Object> auditData, Integer refundStatus, String refundRemark) {
|
|
|
Long paymentId = Long.valueOf(auditData.get("paymentId").toString());
|
|
|
- Integer auditStatus = Integer.valueOf(auditData.get("refundAuditStatus").toString());
|
|
|
- String auditRemark = auditData.get("auditRemark") != null ? auditData.get("auditRemark").toString() : "";
|
|
|
- String auditor = auditData.get("auditor") != null ? auditData.get("auditor").toString() : "";
|
|
|
-
|
|
|
- return fsStorePaymentService.auditRefund(paymentId, auditStatus, auditRemark , auditor);
|
|
|
+
|
|
|
+ // 查询支付记录
|
|
|
+ FsStorePaymentScrm payment = fsStorePaymentService.selectFsStorePaymentById(paymentId);
|
|
|
+ if (payment == null) {
|
|
|
+ return R.error("支付记录不存在");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 检查退款申请状态
|
|
|
+ if (payment.getRefundAuditStatus() == null || payment.getRefundAuditStatus() != 0) {
|
|
|
+ return R.error("该订单没有待审核的退款申请");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (payment.getStatus() == null || payment.getStatus() != 1) {
|
|
|
+ return R.error("只有已支付的订单才能退款");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (refundStatus == 1) {
|
|
|
+ // 审核通过,执行退款
|
|
|
+ log.info("审核通过退款申请, 支付ID: {}, 开始执行退款", paymentId);
|
|
|
+
|
|
|
+ FsStorePaymentScrm refundRequest = new FsStorePaymentScrm();
|
|
|
+ refundRequest.setPaymentId(payment.getPaymentId());
|
|
|
+ refundRequest.setRefundMoney(payment.getRefundMoney());
|
|
|
+
|
|
|
+ // 直接调用 singleRefundInternal
|
|
|
+ R refundResult = singleRefundInternal(refundRequest);
|
|
|
+
|
|
|
+ if (refundResult.get("code").equals(200)) {
|
|
|
+ // singleRefundInternal 已经更新了 status=-1 和 refundAuditStatus=1
|
|
|
+ // 如果需要更新备注,重新查询最新数据
|
|
|
+ if (refundRemark != null && !refundRemark.isEmpty()) {
|
|
|
+ FsStorePaymentScrm latestPayment = fsStorePaymentService.selectFsStorePaymentById(paymentId);
|
|
|
+ latestPayment.setRefundAuditRemark(refundRemark);
|
|
|
+ fsStorePaymentService.updateFsStorePayment(latestPayment);
|
|
|
+ }
|
|
|
+ log.info("退款审核通过并执行成功, 支付ID: {}", paymentId);
|
|
|
+ return R.ok("退款审核通过,退款成功");
|
|
|
+ } else {
|
|
|
+ TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();
|
|
|
+ return R.error("退款失败:" + refundResult.get("msg"));
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ // 审核拒绝:refundAuditStatus=2, status保持为1(已支付)
|
|
|
+ payment.setRefundAuditStatus(2);
|
|
|
+ payment.setRefundAuditRemark(refundRemark);
|
|
|
+ payment.setRefundAuditTime(new Date());
|
|
|
+ fsStorePaymentService.updateFsStorePayment(payment);
|
|
|
+ log.info("拒绝退款申请, 支付ID: {}, 原因: {}", paymentId, refundRemark);
|
|
|
+ return R.ok("已拒绝退款申请");
|
|
|
+ }
|
|
|
}
|
|
|
+
|
|
|
/**
|
|
|
* 验证立减配置是否有效
|
|
|
* @param config 店铺配置对象
|