diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java index a8d8fe2..46d906d 100644 --- a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/constant/RedisKeyConstant.java @@ -94,10 +94,15 @@ public class RedisKeyConstant { public static final String VERIFY_PROFIT_LOCK_KEY = "bnyer.img.profit.lock:"; /** - * 平台用户下载键 + * 平台用户下载图片广告键 */ public static final String PLATFORM_USER_DOWNLOAD_KEY = "bnyer.img.user.download:"; + /** + * 平台用户绘画奖励广告键 + */ + public static final String PLATFORM_USER_PAINT_REWARD_KEY = "bnyer.img.user.paint.reward:"; + /** * 平台用户ai绘画键 */ diff --git a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/checkUserCanDownloadDto.java b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/checkUserCanDownloadDto.java index 612d71f..c84fb0c 100644 --- a/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/checkUserCanDownloadDto.java +++ b/bnyer-common/bnyer-common-core/src/main/java/com/bnyer/common/core/dto/checkUserCanDownloadDto.java @@ -24,4 +24,8 @@ public class checkUserCanDownloadDto implements Serializable { @NotNull(message = "应用不能为空!") @ApiModelProperty(value="应用") private String appType; + + @NotNull(message = "广告类型不能为空!") + @ApiModelProperty(value="广告类型(0->下载图片;1->绘画奖励)") + private String adType; } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java index a0df054..c8e9316 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/FhMiniController.java @@ -458,4 +458,10 @@ public class FhMiniController extends BaseController { public AjaxResult queryGoldNum(@PathVariable @ApiParam("主键id") Long id){ return AjaxResult.success(fhUserService.getUserGoldNum(id)); } + + @ApiOperation(value="获取某平台用户当日下载/绘画奖励剩余次数") + @PostMapping(value = "/getRestNum") + public AjaxResult getUserDownloadNumOrRewardNum(@Validated @RequestBody @ApiParam("检查超标对象") checkUserCanDownloadDto dto){ + return AjaxResult.success(fhUserService.getUserDownloadNumOrRewardNum(dto.getUserId(),dto.getPlatform(),dto.getAppType(),dto.getAdType())); + } } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java index a728633..3e52a9c 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/TiktokMiniController.java @@ -240,11 +240,11 @@ public class TiktokMiniController extends BaseController { } - @ApiOperation(value="检查某平台用户当日下载次数是否超标") + @ApiOperation(value="检查某平台用户当日下载/绘画奖励次数是否超标") @PostMapping(value = "/checkUserCanDownload") public AjaxResult checkUserCanDownload(@Validated @RequestBody @ApiParam("检查超标对象") checkUserCanDownloadDto dto){ log.debug("【抖音图文小程序】检查某平台用户当日下载次数是否超标参数为:{}", JSON.toJSONString(dto)); - return AjaxResult.success(tiktokUserService.checkUserCanDownload(dto.getUserId(),dto.getPlatform(),dto.getAppType())); + return AjaxResult.success(tiktokUserService.checkUserCanDownload(dto.getUserId(),dto.getPlatform(),dto.getAppType(),dto.getAdType())); } @ApiOperation(value="检查某平台用户当日ai绘画次数是否超标") @@ -490,8 +490,15 @@ public class TiktokMiniController extends BaseController { } @ApiOperation(value="获取用户画意值") - @GetMapping(value = "/queryGoldNum/{id}") - public AjaxResult queryGoldNum(@PathVariable @ApiParam("主键id") Long id){ - return AjaxResult.success(tiktokUserService.getUserGoldNum(id)); + @GetMapping(value = "/queryGoldNum/{userId}") + public AjaxResult queryGoldNum(@PathVariable @ApiParam("用户id") Long userId){ + return AjaxResult.success(tiktokUserService.getUserGoldNum(userId)); } + + @ApiOperation(value="获取某平台用户当日下载/绘画奖励剩余次数") + @PostMapping(value = "/getRestNum") + public AjaxResult getUserDownloadNumOrRewardNum(@Validated @RequestBody @ApiParam("检查超标对象") checkUserCanDownloadDto dto){ + return AjaxResult.success(tiktokUserService.getUserDownloadNumOrRewardNum(dto.getUserId(),dto.getPlatform(),dto.getAppType(),dto.getAdType())); + } + } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java index e366e6a..46e8d28 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/controller/WxMiniController.java @@ -484,4 +484,11 @@ public class WxMiniController extends BaseController { public AjaxResult queryGoldNum(@PathVariable @ApiParam("主键id") Long id){ return AjaxResult.success(wxUserService.getUserGoldNum(id)); } + + @ApiOperation(value="获取某平台用户当日下载/绘画奖励剩余次数") + @PostMapping(value = "/getRestNum") + public AjaxResult getUserDownloadNumOrRewardNum(@Validated @RequestBody @ApiParam("检查超标对象") checkUserCanDownloadDto dto){ + return AjaxResult.success(wxUserService.getUserDownloadNumOrRewardNum(dto.getUserId(),dto.getPlatform(),dto.getAppType(),dto.getAdType())); + } + } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/FhUserService.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/FhUserService.java index cb0d4e3..98af7ed 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/FhUserService.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/FhUserService.java @@ -52,4 +52,14 @@ public interface FhUserService { * @return - */ int getUserGoldNum(Long id); + + /** + * 获取某平台用户剩余可下载图片/获取画意值奖励次数 + * @param userId 用户id + * @param platform 平台 + * @param appType 应用 + * @param adType 广告类型 + * @return - + */ + int getUserDownloadNumOrRewardNum(Long userId,String platform,String appType,String adType); } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/TiktokUserService.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/TiktokUserService.java index de8bf07..f4d00ff 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/TiktokUserService.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/TiktokUserService.java @@ -12,9 +12,10 @@ public interface TiktokUserService { * @param userId 用户id * @param platform 平台 * @param appType 应用 + * @param adType 广告类型 * @return - */ - boolean checkUserCanDownload(Long userId,String platform,String appType); + boolean checkUserCanDownload(Long userId,String platform,String appType,String adType); /** * 检查某平台用户当日ai绘画次数是否超标 @@ -51,4 +52,14 @@ public interface TiktokUserService { * @return - */ int getUserGoldNum(Long id); + + /** + * 获取某平台用户剩余可下载图片/获取画意值奖励次数 + * @param userId 用户id + * @param platform 平台 + * @param appType 应用 + * @param adType 广告类型 + * @return - + */ + int getUserDownloadNumOrRewardNum(Long userId,String platform,String appType,String adType); } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/WxUserService.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/WxUserService.java index 7f068ae..33b8a5d 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/WxUserService.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/WxUserService.java @@ -51,4 +51,14 @@ public interface WxUserService { * @return - */ int getUserGoldNum(Long id); + + /** + * 获取某平台用户剩余可下载图片/获取画意值奖励次数 + * @param userId 用户id + * @param platform 平台 + * @param appType 应用 + * @param adType 广告类型 + * @return - + */ + int getUserDownloadNumOrRewardNum(Long userId,String platform,String appType,String adType); } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/FhUserServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/FhUserServiceImpl.java index bff264e..5d39406 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/FhUserServiceImpl.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/FhUserServiceImpl.java @@ -195,4 +195,34 @@ public class FhUserServiceImpl implements FhUserService { public int getUserGoldNum(Long id) { return fhUserMapper.queryGoldNum(id); } + + @Override + public int getUserDownloadNumOrRewardNum(Long userId, String platform, String appType, String adType) { + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + String date = df.format(new Date()); + String hashKey = appType+":"+platform+":"+userId; + if(adType.equals("0")){ + //下载图片广告最多每天5次 + String downloadKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; + if(redisService.hasHashKey(downloadKey,hashKey)){ + //存在键,判断次数,次数达标则不可下载 + Integer downloadNum = redisService.getCacheMapValue(downloadKey, hashKey); + return 5 - downloadNum; + }else{ + //不存在键则可下载次数为最大值 + return 5; + } + }else{ + //看广告获取绘画奖励广告最多每天3次 + String rewardKey = RedisKeyConstant.PLATFORM_USER_PAINT_REWARD_KEY + date; + if(redisService.hasHashKey(rewardKey,hashKey)){ + //存在键,判断次数,次数达标则不可再获取奖励 + Integer rewardNum = redisService.getCacheMapValue(rewardKey, hashKey); + return 3 - rewardNum; + }else{ + //不存在键则可得到获取奖励最大值 + return 3; + } + } + } } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokUserServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokUserServiceImpl.java index b70ea0a..7ef3027 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokUserServiceImpl.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/TiktokUserServiceImpl.java @@ -129,23 +129,42 @@ public class TiktokUserServiceImpl implements TiktokUserService { } @Override - public boolean checkUserCanDownload(Long userId, String platform, String appType) { + public boolean checkUserCanDownload(Long userId, String platform, String appType,String adType) { SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); String date = df.format(new Date()); String hashKey = appType+":"+platform+":"+userId; - String redisKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; - if(redisService.hasHashKey(redisKey,hashKey)){ - //存在键,判断次数,次数达标则不可下载 - Integer downloadNum = redisService.getCacheMapValue(redisKey, hashKey); - if(downloadNum >= 10){ - return true; + if(adType.equals("0")){ + //下载图片广告最多每天5次 + String downloadKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; + if(redisService.hasHashKey(downloadKey,hashKey)){ + //存在键,判断次数,次数达标则不可下载 + Integer downloadNum = redisService.getCacheMapValue(downloadKey, hashKey); + if(downloadNum >= 5){ + return true; + }else{ + return false; + } }else{ + //不存在键则可下载 return false; } }else{ - //不存在键则可下载 - return false; + //看广告获取绘画奖励广告最多每天3次 + String rewardKey = RedisKeyConstant.PLATFORM_USER_PAINT_REWARD_KEY + date; + if(redisService.hasHashKey(rewardKey,hashKey)){ + //存在键,判断次数,次数达标则不可再获取奖励 + Integer rewardNum = redisService.getCacheMapValue(rewardKey, hashKey); + if(rewardNum >= 3){ + return true; + }else{ + return false; + } + }else{ + //不存在键则可获取奖励 + return false; + } } + } @Override @@ -201,4 +220,34 @@ public class TiktokUserServiceImpl implements TiktokUserService { public int getUserGoldNum(Long id) { return tiktokUserMapper.queryGoldNum(id); } + + @Override + public int getUserDownloadNumOrRewardNum(Long userId, String platform, String appType, String adType) { + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + String date = df.format(new Date()); + String hashKey = appType+":"+platform+":"+userId; + if(adType.equals("0")){ + //下载图片广告最多每天5次 + String downloadKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; + if(redisService.hasHashKey(downloadKey,hashKey)){ + //存在键,判断次数,次数达标则不可下载 + Integer downloadNum = redisService.getCacheMapValue(downloadKey, hashKey); + return 5 - downloadNum; + }else{ + //不存在键则可下载次数为最大值 + return 5; + } + }else{ + //看广告获取绘画奖励广告最多每天3次 + String rewardKey = RedisKeyConstant.PLATFORM_USER_PAINT_REWARD_KEY + date; + if(redisService.hasHashKey(rewardKey,hashKey)){ + //存在键,判断次数,次数达标则不可再获取奖励 + Integer rewardNum = redisService.getCacheMapValue(rewardKey, hashKey); + return 3 - rewardNum; + }else{ + //不存在键则可得到获取奖励最大值 + return 3; + } + } + } } diff --git a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/WxUserServiceImpl.java b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/WxUserServiceImpl.java index b593946..e78239c 100644 --- a/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/WxUserServiceImpl.java +++ b/bnyer-services/bnyer-img/src/main/java/com/bnyer/img/service/impl/WxUserServiceImpl.java @@ -197,4 +197,34 @@ public class WxUserServiceImpl implements WxUserService { public int getUserGoldNum(Long id) { return wxUserMapper.queryGoldNum(id); } + + @Override + public int getUserDownloadNumOrRewardNum(Long userId, String platform, String appType, String adType) { + SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd"); + String date = df.format(new Date()); + String hashKey = appType+":"+platform+":"+userId; + if(adType.equals("0")){ + //下载图片广告最多每天5次 + String downloadKey = RedisKeyConstant.PLATFORM_USER_DOWNLOAD_KEY + date; + if(redisService.hasHashKey(downloadKey,hashKey)){ + //存在键,判断次数,次数达标则不可下载 + Integer downloadNum = redisService.getCacheMapValue(downloadKey, hashKey); + return 5 - downloadNum; + }else{ + //不存在键则可下载次数为最大值 + return 5; + } + }else{ + //看广告获取绘画奖励广告最多每天3次 + String rewardKey = RedisKeyConstant.PLATFORM_USER_PAINT_REWARD_KEY + date; + if(redisService.hasHashKey(rewardKey,hashKey)){ + //存在键,判断次数,次数达标则不可再获取奖励 + Integer rewardNum = redisService.getCacheMapValue(rewardKey, hashKey); + return 3 - rewardNum; + }else{ + //不存在键则可得到获取奖励最大值 + return 3; + } + } + } }