Browse Source

01-10 增加旧订单飞书报警,红包退款优化

milestone-20251215-红包修改
lijianlin 17 hours ago
parent
commit
2928dabf04
  1. 2
      src/main/java/com/example/demo/config/GlobalExceptionHandler.java
  2. 2
      src/main/java/com/example/demo/controller/Temporary/RedController.java
  3. 24
      src/main/java/com/example/demo/serviceImpl/Temporary/RedServiceImpl.java
  4. 37
      src/main/java/com/example/demo/serviceImpl/coin/AuditServiceImpl.java
  5. 3
      src/main/resources/application-test.yml

2
src/main/java/com/example/demo/config/GlobalExceptionHandler.java

@ -220,7 +220,7 @@ public class GlobalExceptionHandler {
/**
* 发送飞书报警
*/
private void sendFeishuAlert(Exception e, String title, String detail) {
public static void sendFeishuAlert(Exception e, String title, String detail) {
ExecutionContext context = ExecutionContextUtil.getExecutionContext();
if (context != null) {
String message = title;

2
src/main/java/com/example/demo/controller/Temporary/RedController.java

@ -51,10 +51,12 @@ public class RedController {
public Result selectRedTest(@RequestBody AuditRequest request) throws Exception {
try {
redService.checkRed(request.getPrice(),request.getLinkId());
//redService.consumeRed(request.getLinkId());
}
catch (Exception e) {
return Result.error(e.getMessage());
}
return Result.success(redService.checkRed(request.getPrice(),request.getLinkId()));
// return Result.success(redService.consumeRed(request.getLinkId()));
}
}

24
src/main/java/com/example/demo/serviceImpl/Temporary/RedServiceImpl.java

@ -58,7 +58,7 @@ public class RedServiceImpl implements RedService {
@Value("${red.urllogin}")
private String BASE_URL_LOGIN;
private static final String BASE_URLDev = "http://af9c6249.natappfree.cc";
private static final String BASE_URL_Margen = "http://pcc8496a.natappfree.cc";
private static final String BASE_URL_Margen = "http://k56a8a96.natappfree.cc";
private static final String PATH = "/api/coupon/IssueRechargeRedPacket";
private static final String PATHRED = "/api/coupon/getTotalDiscount";
private static final String BASE_URL = "http://localhost:8080";
@ -126,7 +126,7 @@ public class RedServiceImpl implements RedService {
String body = JSON.toJSONString(java.util.Map.of("jwcode", jwcode,"order_id",orderId));
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URLProd + PATH)) //URL记得换
.uri(URI.create(BASE_URL_Margen + PATH)) //URL记得换
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
@ -147,7 +147,7 @@ public class RedServiceImpl implements RedService {
try {
String body = JSON.toJSONString(java.util.Map.of("jwcode", jwcode,"coupon_ids",redIds,"order_id",orderId));
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(BASE_URLProd + CONSUME_PATH)) //URL记得换
.uri(URI.create(BASE_URL_Margen + CONSUME_PATH)) //URL记得换
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(body))
.build();
@ -258,23 +258,23 @@ public class RedServiceImpl implements RedService {
boolean flag = root.path("data").path("flag").asBoolean();
int num = root.path("data").path("num").asInt(); // 获取 num
if (code == 400) {
// 400 状态码表示参数错误
if (dataNode.asInt() == 1) {
throw new RuntimeException("该订单不符合退款条件,请手动处理!");
}
if (dataNode.asInt() == 0){
return "old";
}else
{
log.warn("该订单无法处理,status:{},body:{}",
resp.statusCode(), resp.body());
throw new RuntimeException("该订单无法自动处理,请联系管理员");
throw new RuntimeException("该订单无法自动处理,请联系管理员");}
}
// 业务判断
if (code == 200 ) {
if (dataNode.asInt() == 1) {
throw new RuntimeException("该订单不符合退款条件,请手动处理!");
}
if (dataNode.asInt() == 0){
return "old";
}
if (flag) {
return "success";
} else {

37
src/main/java/com/example/demo/serviceImpl/coin/AuditServiceImpl.java

@ -2,6 +2,7 @@ package com.example.demo.serviceImpl.coin;
import com.example.demo.Util.GoldTistV2;
import com.example.demo.Util.SimpleIdGenerator;
import com.example.demo.config.GlobalExceptionHandler;
import com.example.demo.domain.entity.User;
import com.example.demo.domain.entity.UserGoldRecord;
import com.example.demo.domain.vo.coin.*;
@ -60,7 +61,13 @@ public class AuditServiceImpl implements AuditService {
@Transactional(rollbackFor = Exception.class)
@Override
public boolean auditOrder(String token, String orderCode, Integer auditId, Integer action,String rejectReason,BigDecimal price,String linkId) throws Exception {
if (linkId== null){
linkId=orderCode;
}
UserGoldRecord order=auditMapper.selectOrderByOrderCode(orderCode);
if (price== null){
price= BigDecimal.valueOf(order.getPermanentGold());
}
Date date =new Date();
//状态为0待审核或4第一次红包退款失败的订单才能审核
if (order == null || (order.getAuditStatus() != 0 && order.getAuditStatus() !=4)) {
@ -151,6 +158,8 @@ public class AuditServiceImpl implements AuditService {
if (order.getAuditStatus()!=4){
try {
String result = redService.checkRed(price, linkId);
// 设置到全局上下文
AuditContext.setRedCheckResult(result);
} catch (RedCheckException e) {
// 业务失败flag=false
int num = e.getNum();
@ -207,12 +216,9 @@ public class AuditServiceImpl implements AuditService {
GoldTistV2.addCoinNew(order.getJwcode().toString(), 59, //退款任务+永久金币-充值
(double) (order.getTaskGold()+order.getPermanentGold() ) /100,SimpleIdGenerator.generateId(),
order.getRemark(),(double) order.getPermanentGold() / 100, auditName, "退款金币充值");}
//金币退款的原价为充值的永久金币
if (order.getRefundType().equals("金币退款")){
price= BigDecimal.valueOf(order.getPermanentGold());
}
//额外扣金币抵扣红包
if (order.getAuditStatus()==4&&price!= null&&linkId!= null){
if (order.getAuditStatus()==4){
int type = 1; //红包充值累计
GoldUser user = userMapper.selectUser(order.getJwcode().toString());
// 检查用户余额是否足够抵扣红包差额
@ -260,9 +266,18 @@ public class AuditServiceImpl implements AuditService {
redMapper.update(order.getJwcode(),type,order.getPrice());
}
if (!redService.checkRed(price, linkId).equals("old")){
//link扣除已有红包
redService.consumeRed(linkId);}
if (!AuditContext.getRedCheckResult().equals("old")){
redService.consumeRed(linkId);
}
else {
Exception e = new Exception("旧订单退款");
String title = "旧订单退款";
String detail= (order.getJwcode()).toString()+"金币订单号"+orderCode;
GlobalExceptionHandler.sendFeishuAlert(e, title, detail);
}
}
}
@ -396,6 +411,7 @@ public class AuditServiceImpl implements AuditService {
public class AuditContext {
private static final ThreadLocal<String> FAIL_MSG = new ThreadLocal<>();
private static final ThreadLocal<String> RED_CHECK_RESULT = new ThreadLocal<>();
public static void setFailMsg(String msg) {
FAIL_MSG.set(msg);
@ -404,9 +420,16 @@ public class AuditServiceImpl implements AuditService {
public static String getFailMsg() {
return FAIL_MSG.get();
}
public static void setRedCheckResult(String result) {
RED_CHECK_RESULT.set(result);
}
public static String getRedCheckResult() {
return RED_CHECK_RESULT.get();
}
public static void clear() {
FAIL_MSG.remove();
RED_CHECK_RESULT.remove();
}
}

3
src/main/resources/application-test.yml

@ -93,7 +93,8 @@ file:
url: http://39.101.133.168:8828/hljw/api/aws/upload
feishu:
webhook:
url: https://open.feishu.cn/open-apis/bot/v2/hook/384c78aa-8df1-498b-9c47-04e890ed9877
url: https://open.feishu.cn/open-apis/bot/v2/hook/8dd2bcc4-6492-487b-9dc5-bb7b27d43ccf
bean:
recharge:
# url: http://api.homilychart.com/hljwgo/api/wallet/recharge

Loading…
Cancel
Save