zoujiajian 1 ano atrás
pai
commit
6541bd6301

+ 2 - 0
netflix-common/src/main/java/com/cyksj/common/constant/PointsRecordConst.java

@@ -16,4 +16,6 @@ public interface PointsRecordConst {
 	String ORDER_REFUND = "订单退款";
 
 	String ORDER_CLOSE = "订单关闭";
+
+	String ORDER_REFUND_SUB = "订单退款扣除返现";
 }

+ 3 - 1
netflix-service/src/main/java/com/cyksj/service/coin/UserGalaxyCoinService.java

@@ -12,7 +12,9 @@ public interface UserGalaxyCoinService {
 
 	void sendGalaxyCoinRecord(Long userId, Integer galaxyCoin, String remark, Boolean isLottery);
 
-	void recordUseRecord(Long orderId, Long userId, BigDecimal galaxyCoin, String remark);
+	void recordUseRecord(Long orderId, Long userId, BigDecimal galaxyCoin, String remark, Boolean available);
 
 	void recordOrderRefundGalaxyCoinIfValid(Long orderId, Long userId, BigDecimal galaxyCoin);
+
+	void subOrderGenerateGalaxyCoin(Long orderId);
 }

+ 32 - 6
netflix-service/src/main/java/com/cyksj/service/coin/impl/UserGalaxyCoinServiceImpl.java

@@ -33,11 +33,20 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
 	@Override
 	public void sendGalaxyCoinRecord(Long userId, Integer galaxyCoin, String remark, Boolean isLottery) {
 		if (!isLottery) {
-			sendGalaxyCoinHandle(userId, null, galaxyCoin, remark, true);
+			sendGalaxyCoinHandle(userId, null, galaxyCoin, remark, true, true);
 		}
 	}
 
-	public void sendGalaxyCoinHandle(Long userId, Long orderId, Integer galaxyCoin, String remark, Boolean isRecord) {
+	/**
+	 *
+	 * @param userId
+	 * @param orderId
+	 * @param galaxyCoin
+	 * @param remark
+	 * @param isRecord 是否记录
+	 * @param available 该笔银河币是否可用
+	 */
+	public void sendGalaxyCoinHandle(Long userId, Long orderId, Integer galaxyCoin, String remark, Boolean isRecord, Boolean available) {
 		if (galaxyCoin <= 0) {
 			return;
 		}
@@ -54,7 +63,7 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
 					.eq(User::getGalaxyCoin, userGalaxyCoin));
 			if (update == 1) {
 				if (isRecord) {
-					recordUseRecord(userId, orderId, BigDecimal.valueOf(galaxyCoin), remark);
+					recordUseRecord(userId, orderId, BigDecimal.valueOf(galaxyCoin), remark, available);
 				}
 				break;
 			}
@@ -65,7 +74,7 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
 	 * 记录银河币详情
 	 */
 	@Override
-	public void recordUseRecord(Long orderId, Long userId, BigDecimal galaxyCoin, String remark) {
+	public void recordUseRecord(Long orderId, Long userId, BigDecimal galaxyCoin, String remark, Boolean available) {
 		UserGalaxyCoinRecord userGalaxyCoinRecord = new UserGalaxyCoinRecord();
 		userGalaxyCoinRecord.setOrderId(orderId);
 		userGalaxyCoinRecord.setUserId(userId);
@@ -80,7 +89,8 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
 			userGalaxyCoinRecord.setExpiryTime(DateUtil.endOfYear(DateTime.now()));
 		}
 		//下单 标记该笔银河币记录为已使用
-		if (StrUtil.equals(PointsRecordConst.ORDER, remark)) {
+		//该银河币是否可用
+		if (!available) {
 			userGalaxyCoinRecord.setIsUsed(Boolean.TRUE);
 			//下单时,剩余是0
 			userGalaxyCoinRecord.setRemainGalaxyCoin(BigDecimal.ZERO);
@@ -104,7 +114,23 @@ public class UserGalaxyCoinServiceImpl implements UserGalaxyCoinService {
 			return;
 		}
 		//发送银河币
-		sendGalaxyCoinHandle(userId, orderId, galaxyCoin.intValue(), PointsRecordConst.ORDER_REFUND, true);
+		sendGalaxyCoinHandle(userId, orderId, galaxyCoin.intValue(), PointsRecordConst.ORDER_REFUND, true, true);
 	}
 
+	@Override
+	public void subOrderGenerateGalaxyCoin(Long orderId) {
+		UserGalaxyCoinRecord userGalaxyCoinRecord = userGalaxyCoinRecordMapper.selectOne(Wrappers.lambdaQuery(UserGalaxyCoinRecord.class)
+				.eq(UserGalaxyCoinRecord::getOrderId, orderId)
+				.last("limit 1"));
+		if (userGalaxyCoinRecord != null) {
+			BigDecimal remainGalaxyCoin = userGalaxyCoinRecord.getRemainGalaxyCoin();
+			if (remainGalaxyCoin.compareTo(BigDecimal.ZERO) > 0) {
+				//扣除记录 对应的银河币不可用
+				sendGalaxyCoinHandle(userGalaxyCoinRecord.getUserId(), orderId, remainGalaxyCoin.negate().intValue(), PointsRecordConst.ORDER_REFUND_SUB, true, false);
+				userGalaxyCoinRecord.setRemainGalaxyCoin(BigDecimal.ZERO);
+				userGalaxyCoinRecord.setIsUsed(Boolean.TRUE);
+				userGalaxyCoinRecordMapper.updateById(userGalaxyCoinRecord);
+			}
+		}
+	}
 }

+ 4 - 0
netflix-service/src/main/java/com/cyksj/service/mange/impl/CmsOrderDonServiceImpl.java

@@ -1060,6 +1060,10 @@ public class CmsOrderDonServiceImpl extends ServiceImpl<OrderDonMapper,OrderDon>
             if (orderDonGalaxyCoinRecord != null) {
                 //有效时,返还银河币 并记录
                 userGalaxyCoinService.recordOrderRefundGalaxyCoinIfValid(orderDon.getId(), orderDonGalaxyCoinRecord.getUserId(), orderDonGalaxyCoinRecord.getGalaxyCoin());
+                //扣除 该笔订单产生的返现银河币
+                if (orderDon.getMoney().compareTo(BigDecimal.ZERO) > 0) {
+                    userGalaxyCoinService.subOrderGenerateGalaxyCoin(orderDon.getId());
+                }
             }
         }
 

+ 1 - 1
netflix-service/src/main/java/com/cyksj/service/order/impl/OrderDonServiceImpl.java

@@ -2965,7 +2965,7 @@ public class OrderDonServiceImpl extends ServiceImpl<OrderDonMapper, OrderDon> i
 				.last("limit 1"));
 		if (orderDonGalaxyCoinRecord != null) {
 			//使用记录
-			userGalaxyCoinService.recordUseRecord(orderDon.getId(), orderDon.getUserId(), orderDonGalaxyCoinRecord.getGalaxyCoin(), PointsRecordConst.ORDER);
+			userGalaxyCoinService.recordUseRecord(orderDon.getId(), orderDon.getUserId(), orderDonGalaxyCoinRecord.getGalaxyCoin(), PointsRecordConst.ORDER, false);
 			orderDonGalaxyCoinRecord.setRefundGalaxyCoin(orderDonGalaxyCoinRecord.getGalaxyCoin());
 			orderDonGalaxyCoinRecord.setOrderId(orderDon.getId());
 			orderDonGalaxyCoinRecordMapper.updateById(orderDonGalaxyCoinRecord);