Kaynağa Gözat

修改道具兑换BUG

silent 4 yıl önce
ebeveyn
işleme
70521d64ee

+ 17 - 9
src/main/java/org/springblade/sing/goods/wrapper/HelpGoodsWrapper.java

@@ -43,7 +43,7 @@ import java.util.Objects;
  * @since 2021-11-09
  */
 @AllArgsConstructor
-public class HelpGoodsWrapper extends BaseEntityWrapper<HelpGoods, HelpGoodsVO>  {
+public class HelpGoodsWrapper extends BaseEntityWrapper<HelpGoods, HelpGoodsVO> {
 
 	private final static AppHelpGoodsService appHelpGoodsService = SpringContextHolder.getBean(AppHelpGoodsService.class);
 
@@ -53,19 +53,22 @@ public class HelpGoodsWrapper extends BaseEntityWrapper<HelpGoods, HelpGoodsVO>
 
 	private final Long productId;
 
-	public static HelpGoodsWrapper build(Long userId,Long productId) {
-		return new HelpGoodsWrapper(userId,productId);
- 	}
+	public static HelpGoodsWrapper build(Long userId, Long productId) {
+		return new HelpGoodsWrapper(userId, productId);
+	}
 
 	@Override
 	public HelpGoodsVO entityVO(HelpGoods helpGoods) {
 		HelpGoodsVO helpGoodsVO = Objects.requireNonNull(BeanUtil.copy(helpGoods, HelpGoodsVO.class));
 
 		//查询用户剩余道具次数
-		if(ObjectUtils.isNotEmpty(userId) && ObjectUtils.isNotEmpty(productId)){
-			//判断次数
+		if (ObjectUtils.isNotEmpty(userId) && ObjectUtils.isNotEmpty(productId)) {
+			//判断该活动商品兑换剩余次数
 			long total = helpGoodsVO.getTotal() - appHelpGoodsService.userHelpGoodsExchangeCount(userId, helpGoodsVO.getId());
-			if(0L <= total){
+			//判断该用户对该活动投票剩余次数
+			if (Long.valueOf(-1).equals(helpGoodsVO.getTotal()) && Long.valueOf(-1).equals(helpGoodsVO.getActiveVote())) {
+				helpGoodsVO.setRemainCount(999L);
+			} else if (0L < total || Long.valueOf(-1).equals(helpGoodsVO.getTotal())) {
 				Map<String, Object> map = activeHelpRecordService.getMap(Wrappers.<ActiveHelpRecord>query().select(new StringBuilder("ifnull(sum(")
 						.append(BeanPropertyUtil.getFieldNameToUnder(ActiveHelpRecord::getVoteCount))
 						.append("),0) as count")
@@ -83,9 +86,14 @@ public class HelpGoodsWrapper extends BaseEntityWrapper<HelpGoods, HelpGoodsVO>
 					.divide(helpGoodsVO.getVotePointRate())
 					.subtract(BigDecimal.valueOf(MapUtil.getLong(map, "count"))
 						.divide(helpGoodsVO.getVotePointRate())).longValue();
-				helpGoodsVO.setRemainCount(count<0L?0L:count);
 
-			}else{
+				//判断道具兑换剩余次数和活动投票剩余次数
+				if (Long.valueOf(-1).equals(helpGoodsVO.getTotal())) {
+					helpGoodsVO.setRemainCount(count < 0L ? 0L : count);
+				}else{
+					helpGoodsVO.setRemainCount(total - count < 0 ? 0L : total - count);
+				}
+			} else {
 				helpGoodsVO.setRemainCount(0L);
 			}
 		}