记得上下班打卡 | git大法好,push需谨慎

Commit 9ca7ab4f authored by wangyifan's avatar wangyifan

增加退款锁

parent 0d43204a
...@@ -461,6 +461,12 @@ public class GoblinRedisConst { ...@@ -461,6 +461,12 @@ public class GoblinRedisConst {
*/ */
public static final String REFUND_ORDER_LOCK = PREFIX.concat("refund:lock:"); public static final String REFUND_ORDER_LOCK = PREFIX.concat("refund:lock:");
/**
* 收钱吧退款库存已归还标记(防回调重复还库存)
* {goblin:sqb:refund:stock:${orderId}}
*/
public static final String SQB_REFUND_STOCK_FLAG = PREFIX.concat("sqb:refund:stock:");
/** /**
* 收钱吧 用户订单列表 * 收钱吧 用户订单列表
*/ */
......
...@@ -67,6 +67,16 @@ public class RedisKeyExpireConst { ...@@ -67,6 +67,16 @@ public class RedisKeyExpireConst {
*/ */
public static final long SQB_ORDER_LOCK_EXPIRE = 10; public static final long SQB_ORDER_LOCK_EXPIRE = 10;
/**
* 收钱吧退款锁过期时间 (60秒,覆盖调收钱吧退款 API)
*/
public static final long SQB_REFUND_LOCK_EXPIRE = 60;
/**
* 收钱吧退款库存归还标记过期时间 (30天)
*/
public static final long SQB_REFUND_STOCK_FLAG_EXPIRE = 30 * 24 * 60 * 60;
// 已发布状态徽章过期时间:30天 // 已发布状态徽章过期时间:30天
public static final long CAOMEI_BADGE_PUBLISHED_EXPIRE = 30 * 24 * 60 * 60; public static final long CAOMEI_BADGE_PUBLISHED_EXPIRE = 30 * 24 * 60 * 60;
} }
...@@ -90,6 +90,27 @@ public class GoblinSqbRedisUtils { ...@@ -90,6 +90,27 @@ public class GoblinSqbRedisUtils {
redisUtil.uLock(key); redisUtil.uLock(key);
} }
/* ---------------------------------------- 退款锁 / 库存归还幂等 ---------------------------------------- */
/**
* 尝试获取收钱吧退款锁(发起退款与退款回调共用,按 orderId)
*/
public boolean tryRefundLock(String orderId) {
String key = GoblinRedisConst.REFUND_ORDER_LOCK.concat(orderId);
return redisUtil.lock(key, 1, RedisKeyExpireConst.SQB_REFUND_LOCK_EXPIRE);
}
public void releaseRefundLock(String orderId) {
redisUtil.uLock(GoblinRedisConst.REFUND_ORDER_LOCK.concat(orderId));
}
/**
* 标记退款库存已归还。首次标记成功返回 true(应执行 incrSkuStock),已标记过返回 false。
*/
public boolean tryMarkRefundStockRestored(String orderId) {
String key = GoblinRedisConst.SQB_REFUND_STOCK_FLAG.concat(orderId);
return redisUtil.lock(key, 1, RedisKeyExpireConst.SQB_REFUND_STOCK_FLAG_EXPIRE);
}
// 获取 收钱吧订单id列表 // 获取 收钱吧订单id列表
public List<String> getSqbOrderList(String uid) { public List<String> getSqbOrderList(String uid) {
......
...@@ -88,6 +88,28 @@ public class GoblinSqbRedisUtils { ...@@ -88,6 +88,28 @@ public class GoblinSqbRedisUtils {
redisUtil.uLock(key); redisUtil.uLock(key);
} }
/* ---------------------------------------- 退款锁 / 库存归还幂等 ---------------------------------------- */
/**
* 尝试获取收钱吧退款锁(发起退款与退款回调共用,按 orderId)
*/
public boolean tryRefundLock(String orderId) {
String key = GoblinRedisConst.REFUND_ORDER_LOCK.concat(orderId);
return redisUtil.lock(key, 1, RedisKeyExpireConst.SQB_REFUND_LOCK_EXPIRE);
}
public void releaseRefundLock(String orderId) {
redisUtil.uLock(GoblinRedisConst.REFUND_ORDER_LOCK.concat(orderId));
}
/**
* 标记退款库存已归还。首次标记成功返回 true(应执行 incrSkuStock),已标记过返回 false。
*/
public boolean tryMarkRefundStockRestored(String orderId) {
String key = GoblinRedisConst.SQB_REFUND_STOCK_FLAG.concat(orderId);
return redisUtil.lock(key, 1, RedisKeyExpireConst.SQB_REFUND_STOCK_FLAG_EXPIRE);
}
/** /**
* 添加用户 收钱吧订单列表 * 添加用户 收钱吧订单列表
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment