Browse Source

Changes

master
主管理员 2 weeks ago
parent
commit
22dd1558aa
4 changed files with 114 additions and 6 deletions
  1. +7
    -0
      CatmDogd-Mall-Front-test/src/views/model/AppletAmountLog/audit.vue
  2. +95
    -6
      ruoyi-catdog/src/main/java/com/ruoyi/applet/service/impl/AppletAmountService.java
  3. +4
    -0
      ruoyi-catdog/src/main/java/com/ruoyi/model/domain/AppletAmountLog.java
  4. +8
    -0
      ruoyi-common/src/main/java/com/ruoyi/common/core/sms/AliyunSmsUtils.java

+ 7
- 0
CatmDogd-Mall-Front-test/src/views/model/AppletAmountLog/audit.vue View File

@ -231,6 +231,13 @@
</el-form-item>
</el-col>
</el-row>
<el-row v-if="form.auditRemark">
<el-col :span="24">
<el-form-item label="错误信息" v-if="form.errorInfo">
{{ form.errorInfo }}
</el-form-item>
</el-col>
</el-row>
</el-form>
<div slot="footer" class="dialog-footer">
<el-button @click="cancel"> </el-button>


+ 95
- 6
ruoyi-catdog/src/main/java/com/ruoyi/applet/service/impl/AppletAmountService.java View File

@ -2,6 +2,7 @@ package com.ruoyi.applet.service.impl;
import com.baomidou.mybatisplus.core.toolkit.IdWorker;
import com.ruoyi.applet.transfer.TransferToUser;
import com.ruoyi.common.core.sms.AliyunSmsUtils;
import com.ruoyi.model.domain.AppUsers;
import com.ruoyi.model.domain.AppletAmountLog;
import com.ruoyi.model.service.IAppUsersService;
@ -278,6 +279,8 @@ public class AppletAmountService {
appletAmountLogService.updateById(appletAmountLog);
// 3. 执行实际的微信提现操作
boolean wechatCallFailed = false;
String failReason = null;
try {
TransferToUser.TransferToUserResponse response = this.cashOut(appletAmountLog);
@ -297,8 +300,10 @@ public class AppletAmountService {
appletAmountLog.getUserId(), appletAmountLog.getAmount(), response.state);
break;
case FAIL:
appletAmountLog.setState(2); // 2-失败
log.error("提现审核通过但微信提现失败,用户ID: {}, 金额: {}", appletAmountLog.getUserId(), appletAmountLog.getAmount());
// 标记失败准备退回金额与记录错误信息
wechatCallFailed = true;
failReason = response.packageInfo != null ? ("微信接口失败:" + response.packageInfo) : "微信接口失败";
log.error("微信提现失败,用户ID: {}, 金额: {}, 原因: {}", appletAmountLog.getUserId(), appletAmountLog.getAmount(), failReason);
break;
default:
appletAmountLog.setState(0); // 0-处理中
@ -310,19 +315,31 @@ public class AppletAmountService {
appletAmountLog.setPackageInfo(response.packageInfo);
}
} else {
appletAmountLog.setState(2); // 2-失败
log.error("提现审核通过但微信提现返回空结果,用户ID: {}, 金额: {}", appletAmountLog.getUserId(), appletAmountLog.getAmount());
wechatCallFailed = true;
failReason = "微信提现返回空结果";
log.error("微信提现返回空结果,用户ID: {}, 金额: {}", appletAmountLog.getUserId(), appletAmountLog.getAmount());
}
} catch (Exception e) {
wechatCallFailed = true;
failReason = "微信提现执行异常:" + e.getMessage();
log.error("微信提现执行异常,用户ID: {}, 金额: {}", appletAmountLog.getUserId(), appletAmountLog.getAmount(), e);
appletAmountLog.setState(2); // 2-失败
}
// 失败时回退金额记录错误信息生成退款流水并标记审核不通过
if (wechatCallFailed) {
handleWithdrawFail(appletAmountLog, auditRemark, failReason);
}
appletAmountLogService.updateById(appletAmountLog);
log.info("审核通过处理完成,用户ID: {}, 金额: {}, 审核备注: {}",
appletAmountLog.getUserId(), appletAmountLog.getAmount(), auditRemark);
// 只有在非失败情况下发送审核通过通知
if (appletAmountLog.getAuditStatus() != null && appletAmountLog.getAuditStatus() == 1 && appletAmountLog.getState() != null && appletAmountLog.getState() != 2) {
AliyunSmsUtils.sendWithdrawalApprovalNotice(appUsersService.getById(appletAmountLog.getUserId()).getUserTelephone());
}
return true;
} catch (Exception e) {
log.error("审核通过处理失败,用户ID: {}, 金额: {}", appletAmountLog.getUserId(), appletAmountLog.getAmount(), e);
@ -330,4 +347,76 @@ public class AppletAmountService {
}
}
/**
* 微信接口失败时退回金额记录错误并生成退款流水
*/
private void handleWithdrawFail(AppletAmountLog appletAmountLog, String auditRemark, String errorInfo) {
try {
AppUsers user = appUsersService.selectAppUsersByUserId(appletAmountLog.getUserId());
if (user == null) {
log.error("退款失败:用户不存在,userId: {}", appletAmountLog.getUserId());
// 标记原记录为审核不通过
appletAmountLog.setAuditStatus(2);
appletAmountLog.setState(2);
appletAmountLog.setRemark((auditRemark == null ? "" : auditRemark) + ";退款失败:用户不存在");
appletAmountLog.setErrorInfo(errorInfo);
appletAmountLogService.updateById(appletAmountLog);
return;
}
BigDecimal refundAmount = appletAmountLog.getAmount() == null ? BigDecimal.ZERO : appletAmountLog.getAmount();
if (appletAmountLog.getMoneyType() == 0) {
BigDecimal original = user.getMoney() == null ? BigDecimal.ZERO : user.getMoney();
BigDecimal updated = original.add(refundAmount);
user.setMoney(updated);
log.info("合伙人钱包退款:{},用户ID: {},原余额: {},新余额: {}", refundAmount, user.getUserId(), original, updated);
} else if (appletAmountLog.getMoneyType() == 1) {
BigDecimal original = user.getPrice() == null ? BigDecimal.ZERO : user.getPrice();
BigDecimal updated = original.add(refundAmount);
user.setPrice(updated);
log.info("伴宠师钱包退款:{},用户ID: {},原余额: {},新余额: {}", refundAmount, user.getUserId(), original, updated);
} else if (appletAmountLog.getMoneyType() == 2) {
BigDecimal original = user.getBaoPrice() == null ? BigDecimal.ZERO : user.getBaoPrice();
BigDecimal updated = original.subtract(refundAmount);
user.setBaoPrice(updated);
log.info("保证金退款:{},用户ID: {},原余额: {},新余额: {}", refundAmount, user.getUserId(), original, updated);
}
appUsersService.updateAppUsers(user);
// 更新原提现记录
appletAmountLog.setAuditStatus(2); // 审核不通过
appletAmountLog.setState(2); // 失败/已退回
String baseRemark = (auditRemark == null ? "" : auditRemark);
String fail = (errorInfo == null ? "未知错误" : errorInfo);
String remark = "如需帮助请联系客服";
appletAmountLog.setRemark(remark);
appletAmountLog.setErrorInfo(errorInfo);
appletAmountLogService.updateById(appletAmountLog);
// 记录退款流水
AppletAmountLog refundLog = new AppletAmountLog();
refundLog.setUserId(user.getUserId());
if (appletAmountLog.getMoneyType() == 0) {
refundLog.setTitle("合伙人钱包提现审核不通过退款");
} else if (appletAmountLog.getMoneyType() == 1) {
refundLog.setTitle("伴宠师钱包提现审核不通过退款");
} else if (appletAmountLog.getMoneyType() == 2) {
refundLog.setTitle("保证金提现审核不通过退款");
}
refundLog.setAmount(refundAmount);
refundLog.setType(0); // 收入退款
refundLog.setState(1); // 成功
refundLog.setCreateTime(LocalDateTime.now());
refundLog.setMoneyType(appletAmountLog.getMoneyType());
refundLog.setNameValue(appletAmountLog.getNameValue());
refundLog.setAuditStatus(1); // 退款记录自动通过
appletAmountLogService.save(refundLog);
log.info("微信失败已退款,用户ID: {},金额: {},原因: {}", user.getUserId(), refundAmount, errorInfo);
} catch (Exception ex) {
log.error("处理微信失败退款异常,用户ID: {},金额: {}", appletAmountLog.getUserId(), appletAmountLog.getAmount(), ex);
}
}
}

+ 4
- 0
ruoyi-catdog/src/main/java/com/ruoyi/model/domain/AppletAmountLog.java View File

@ -73,4 +73,8 @@ public class AppletAmountLog extends BaseEntity
@TableField(exist = false)
private Boolean audit;
// 错误信息
@Excel(name = "错误信息")
private String errorInfo;
}

+ 8
- 0
ruoyi-common/src/main/java/com/ruoyi/common/core/sms/AliyunSmsUtils.java View File

@ -63,6 +63,9 @@ public class AliyunSmsUtils {
// 猫妈狗爸修改订单通知消费者
private static String NotifyOrderUpdate = "SMS_493915117";
// 猫妈狗爸提现通过通知
private static String withdrawalApprovalNotice = "SMS_495915517";
@SneakyThrows(Exception.class)
public AliyunSmsUtils(SmsProperties smsProperties) {
if (client == null) {
@ -278,4 +281,9 @@ public class AliyunSmsUtils {
return null;
}
public static SmsResult sendWithdrawalApprovalNotice(String phones) {
return send(phones, withdrawalApprovalNotice, new HashMap<>());
}
}

Loading…
Cancel
Save