|
@@ -46,6 +46,10 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
|
|
|
* @param available 该笔银河币是否可用
|
|
* @param available 该笔银河币是否可用
|
|
|
*/
|
|
*/
|
|
|
public void sendGalaxyCoinHandle(Long userId, Long orderId, Integer galaxyCoin, String remark, Boolean isRecord, Boolean available, OrderDonGalaxyCoinRecord.Source source) {
|
|
public void sendGalaxyCoinHandle(Long userId, Long orderId, Integer galaxyCoin, String remark, Boolean isRecord, Boolean available, OrderDonGalaxyCoinRecord.Source source) {
|
|
|
|
|
+ //银河币为0不处理
|
|
|
|
|
+ if (galaxyCoin == 0) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
while (true) {
|
|
while (true) {
|
|
|
User user = userMapper.selectById(userId);
|
|
User user = userMapper.selectById(userId);
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
@@ -53,13 +57,27 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
|
BigDecimal userGalaxyCoin = user.getGalaxyCoin();
|
|
BigDecimal userGalaxyCoin = user.getGalaxyCoin();
|
|
|
|
|
+ if (userGalaxyCoin.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
|
|
+ log.info("用户:{}银河币数量为0", userId);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal needHandleGalaxyCoin = userGalaxyCoin.add(BigDecimal.valueOf(galaxyCoin));
|
|
|
|
|
+ BigDecimal finalRecordGalaxyCoin = BigDecimal.valueOf(galaxyCoin);
|
|
|
|
|
+ //不足部分 只扣除用户已有的银河币
|
|
|
|
|
+ if (needHandleGalaxyCoin.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
+ needHandleGalaxyCoin = BigDecimal.ZERO;
|
|
|
|
|
+ //记录该笔银河币
|
|
|
|
|
+ if (finalRecordGalaxyCoin.compareTo(BigDecimal.ZERO) < 0) {
|
|
|
|
|
+ finalRecordGalaxyCoin = userGalaxyCoin.negate();
|
|
|
|
|
+ } else finalRecordGalaxyCoin = userGalaxyCoin;
|
|
|
|
|
+ }
|
|
|
int update = userMapper.update(null, Wrappers.lambdaUpdate(User.class)
|
|
int update = userMapper.update(null, Wrappers.lambdaUpdate(User.class)
|
|
|
- .set(User::getGalaxyCoin, userGalaxyCoin.add(BigDecimal.valueOf(galaxyCoin)))
|
|
|
|
|
|
|
+ .set(User::getGalaxyCoin, needHandleGalaxyCoin)
|
|
|
.eq(User::getId, user.getId())
|
|
.eq(User::getId, user.getId())
|
|
|
.eq(User::getGalaxyCoin, userGalaxyCoin));
|
|
.eq(User::getGalaxyCoin, userGalaxyCoin));
|
|
|
if (update == 1) {
|
|
if (update == 1) {
|
|
|
if (isRecord) {
|
|
if (isRecord) {
|
|
|
- recordUseRecord(orderId, userId, BigDecimal.valueOf(galaxyCoin), remark, available, source);
|
|
|
|
|
|
|
+ recordUseRecord(orderId, userId, finalRecordGalaxyCoin, remark, available, source);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
}
|
|
}
|
|
@@ -124,14 +142,12 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
|
|
|
.eq(UserGalaxyCoinRecord::getRemark, PointsRecordConst.ORDER_CASHBACK)
|
|
.eq(UserGalaxyCoinRecord::getRemark, PointsRecordConst.ORDER_CASHBACK)
|
|
|
.last("limit 1"));
|
|
.last("limit 1"));
|
|
|
if (userGalaxyCoinRecord != null) {
|
|
if (userGalaxyCoinRecord != null) {
|
|
|
- BigDecimal remainGalaxyCoin = userGalaxyCoinRecord.getRemainGalaxyCoin();
|
|
|
|
|
- if (remainGalaxyCoin.compareTo(BigDecimal.ZERO) > 0) {
|
|
|
|
|
- //扣除记录 对应的银河币不可用
|
|
|
|
|
- log.info("订单退款,扣除该笔订单oid:{}返现的银河币", orderId);
|
|
|
|
|
- sendGalaxyCoinHandle(userGalaxyCoinRecord.getUserId(), orderId, remainGalaxyCoin.negate().intValue(), PointsRecordConst.ORDER_REFUND_SUB, true, false, source);
|
|
|
|
|
- userGalaxyCoinRecord.setIsUsed(Boolean.TRUE);
|
|
|
|
|
- userGalaxyCoinRecordMapper.updateById(userGalaxyCoinRecord);
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ BigDecimal galaxyCoin = userGalaxyCoinRecord.getGalaxyCoin();
|
|
|
|
|
+ //扣除记录 对应的银河币不可用
|
|
|
|
|
+ log.info("订单退款,扣除该笔订单oid:{}返现的银河币", orderId);
|
|
|
|
|
+ sendGalaxyCoinHandle(userGalaxyCoinRecord.getUserId(), orderId, galaxyCoin.negate().intValue(), PointsRecordConst.ORDER_REFUND_SUB, true, false, source);
|
|
|
|
|
+ userGalaxyCoinRecord.setIsUsed(Boolean.TRUE);
|
|
|
|
|
+ userGalaxyCoinRecordMapper.updateById(userGalaxyCoinRecord);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|