|
@@ -17,6 +17,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
|
|
+import java.util.List;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 项目名: yhlxj
|
|
* 项目名: yhlxj
|
|
@@ -145,6 +146,45 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
|
|
|
BigDecimal galaxyCoin = userGalaxyCoinRecord.getGalaxyCoin();
|
|
BigDecimal galaxyCoin = userGalaxyCoinRecord.getGalaxyCoin();
|
|
|
//扣除记录 对应的银河币不可用
|
|
//扣除记录 对应的银河币不可用
|
|
|
log.info("订单退款,扣除该笔订单oid:{}返现的银河币", orderId);
|
|
log.info("订单退款,扣除该笔订单oid:{}返现的银河币", orderId);
|
|
|
|
|
+ BigDecimal remainGalaxyCoin = userGalaxyCoinRecord.getRemainGalaxyCoin();
|
|
|
|
|
+ //扣除其他
|
|
|
|
|
+ if (remainGalaxyCoin.compareTo(galaxyCoin) < 0) {
|
|
|
|
|
+ //银河币抵扣
|
|
|
|
|
+ List<UserGalaxyCoinRecord> availableGalaxyCoinList = userGalaxyCoinRecordMapper.selectList(Wrappers.lambdaQuery(UserGalaxyCoinRecord.class)
|
|
|
|
|
+ .eq(UserGalaxyCoinRecord::getUserId, userGalaxyCoinRecord.getUserId())
|
|
|
|
|
+ .eq(UserGalaxyCoinRecord::getIsUsed, Boolean.FALSE)
|
|
|
|
|
+ .gt(UserGalaxyCoinRecord::getExpiryTime, DateTime.now())
|
|
|
|
|
+ .gt(UserGalaxyCoinRecord::getRemainGalaxyCoin, 0));
|
|
|
|
|
+ //需要使用的银河币
|
|
|
|
|
+ BigDecimal userFinalUseGalaxyCoin = galaxyCoin.subtract(remainGalaxyCoin);
|
|
|
|
|
+ for (UserGalaxyCoinRecord galaxyCoinRecord : availableGalaxyCoinList) {
|
|
|
|
|
+ if (userFinalUseGalaxyCoin.compareTo(BigDecimal.ZERO) <= 0) {
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ BigDecimal thisRemainGalaxyCoin = galaxyCoinRecord.getRemainGalaxyCoin();
|
|
|
|
|
+ Long galaxyCoinRecordId = galaxyCoinRecord.getId();
|
|
|
|
|
+ //扣完
|
|
|
|
|
+ if (thisRemainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) == 0) {
|
|
|
|
|
+ //完全抵扣
|
|
|
|
|
+ Integer update = deductUserGalaxyCoin(galaxyCoinRecordId, remainGalaxyCoin, remainGalaxyCoin, true);
|
|
|
|
|
+ if (update == 1) {
|
|
|
|
|
+ userFinalUseGalaxyCoin = BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (thisRemainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) < 0) {
|
|
|
|
|
+ //不足以抵扣
|
|
|
|
|
+ Integer update = deductUserGalaxyCoin(galaxyCoinRecordId, remainGalaxyCoin, remainGalaxyCoin, true);
|
|
|
|
|
+ if (update == 1) {
|
|
|
|
|
+ userFinalUseGalaxyCoin = userFinalUseGalaxyCoin.subtract(remainGalaxyCoin);
|
|
|
|
|
+ }
|
|
|
|
|
+ } else if (thisRemainGalaxyCoin.compareTo(userFinalUseGalaxyCoin) > 0) {
|
|
|
|
|
+ //足以抵扣
|
|
|
|
|
+ Integer update = deductUserGalaxyCoin(galaxyCoinRecordId, userFinalUseGalaxyCoin, remainGalaxyCoin, false);
|
|
|
|
|
+ if (update == 1) {
|
|
|
|
|
+ userFinalUseGalaxyCoin = BigDecimal.ZERO;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
sendGalaxyCoinHandle(userGalaxyCoinRecord.getUserId(), orderId, galaxyCoin.negate().intValue(), PointsRecordConst.ORDER_REFUND_SUB, true, false, source);
|
|
sendGalaxyCoinHandle(userGalaxyCoinRecord.getUserId(), orderId, galaxyCoin.negate().intValue(), PointsRecordConst.ORDER_REFUND_SUB, true, false, source);
|
|
|
userGalaxyCoinRecord.setIsUsed(Boolean.TRUE);
|
|
userGalaxyCoinRecord.setIsUsed(Boolean.TRUE);
|
|
|
userGalaxyCoinRecordMapper.updateById(userGalaxyCoinRecord);
|
|
userGalaxyCoinRecordMapper.updateById(userGalaxyCoinRecord);
|
|
@@ -181,4 +221,17 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
|
|
|
public void sendOrderGalaxyCloseOrder(Long orderId, Long userId, BigDecimal galaxyCoin, OrderDonGalaxyCoinRecord.Source source) {
|
|
public void sendOrderGalaxyCloseOrder(Long orderId, Long userId, BigDecimal galaxyCoin, OrderDonGalaxyCoinRecord.Source source) {
|
|
|
sendGalaxyCoinHandle(userId, orderId, galaxyCoin.intValue(), PointsRecordConst.ORDER_CLOSE, true, true, source);
|
|
sendGalaxyCoinHandle(userId, orderId, galaxyCoin.intValue(), PointsRecordConst.ORDER_CLOSE, true, true, source);
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private Integer deductUserGalaxyCoin(Long galaxyCoinRecordId, BigDecimal deductGalaxyCoin, BigDecimal remainGalaxyCoin, boolean isUsed) {
|
|
|
|
|
+ Integer update = userGalaxyCoinRecordMapper.update(null, Wrappers.lambdaUpdate(UserGalaxyCoinRecord.class)
|
|
|
|
|
+ .set(UserGalaxyCoinRecord::getRemainGalaxyCoin, remainGalaxyCoin.subtract(deductGalaxyCoin))
|
|
|
|
|
+ .set(isUsed, UserGalaxyCoinRecord::getIsUsed, isUsed)
|
|
|
|
|
+ .eq(UserGalaxyCoinRecord::getId, galaxyCoinRecordId)
|
|
|
|
|
+ .eq(UserGalaxyCoinRecord::getIsUsed, Boolean.FALSE)
|
|
|
|
|
+ .eq(UserGalaxyCoinRecord::getRemainGalaxyCoin, remainGalaxyCoin));
|
|
|
|
|
+ if (update == 0) {
|
|
|
|
|
+ log.info("此次扣除银河币错误,继续扣除");
|
|
|
|
|
+ }
|
|
|
|
|
+ return update;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|