|
@@ -13,11 +13,13 @@ import com.qs.mp.admin.service.IMarketingService;
|
|
|
import com.qs.mp.common.core.domain.AjaxResult;
|
|
|
import com.qs.mp.common.core.page.TableDataInfo;
|
|
|
import com.qs.mp.common.core.redis.DistributedLocker;
|
|
|
+import com.qs.mp.common.enums.MarketingCodeTypeEnum;
|
|
|
import com.qs.mp.common.enums.MarketingStatusEnum;
|
|
|
import com.qs.mp.common.enums.UserTypeEnum;
|
|
|
import com.qs.mp.common.exception.ServiceException;
|
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
|
import com.qs.mp.common.utils.StringUtils;
|
|
|
+import com.qs.mp.framework.redis.RedisLockKey;
|
|
|
import com.qs.mp.framework.security.handle.HostHolder;
|
|
|
import com.qs.mp.system.domain.SysUser;
|
|
|
import com.qs.mp.system.service.ISysUserService;
|
|
@@ -84,6 +86,52 @@ public class MarketingController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private ISysUserService sysUserService;
|
|
|
|
|
|
+ @PostMapping("/generateCode/{marketingId}")
|
|
|
+ @ApiOperation("立即获取抽奖码")
|
|
|
+ public AjaxResult generateCode(@PathVariable("marketingId") Long marketingId) {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ if (Objects.isNull(userId)) {
|
|
|
+ return AjaxResult.error("用户未登录");
|
|
|
+ }
|
|
|
+
|
|
|
+ Marketing marketing = marketingService.getById(marketingId);
|
|
|
+ if (Objects.isNull(marketing)) {
|
|
|
+ return AjaxResult.error("活动不存在");
|
|
|
+ }
|
|
|
+ // 未开启的活动不能获取抽奖码
|
|
|
+ if (!MarketingStatusEnum.ON.getValue().equals(marketing.getIsOn())) {
|
|
|
+ return AjaxResult.error("活动未开启~");
|
|
|
+ }
|
|
|
+ Date now = DateUtils.getNowDate();
|
|
|
+ // 结束的活动不支持获取抽奖码
|
|
|
+ if (marketing.getTriggerStatus() == 1 || marketing.getEndTime().before(now)) {
|
|
|
+ return AjaxResult.error("活动已过期~");
|
|
|
+ }
|
|
|
+ // 未开始的活动不能获取抽奖码
|
|
|
+ if (marketing.getStartTime().after(now)) {
|
|
|
+ return AjaxResult.error("活动未开始~");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!marketing.getCodeType().equals(MarketingCodeTypeEnum.INSTANT.getValue())) {
|
|
|
+ return AjaxResult.error("错误请求");
|
|
|
+ }
|
|
|
+
|
|
|
+ String lockKey = RedisLockKey.build(RedisLockKey.MARKETING_REAL_NUM_LOCK, marketingId);
|
|
|
+ if (!distributedLocker.tryLock(lockKey)) {
|
|
|
+ return AjaxResult.error("活动太火爆了,请稍后重试!");
|
|
|
+ }
|
|
|
+
|
|
|
+ try {
|
|
|
+ marketingService.generateCode(marketingId, userId);
|
|
|
+ }finally {
|
|
|
+ distributedLocker.unlock(lockKey);
|
|
|
+ }
|
|
|
+
|
|
|
+ return AjaxResult.success("获取成功");
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@PostMapping("/recent")
|
|
|
@ApiOperation("获取已开始且最近要开奖的营销活动")
|
|
|
@ApiResponses(
|
|
@@ -163,7 +211,7 @@ public class MarketingController extends BaseApiController {
|
|
|
return AjaxResult.error("不能助力自己哦");
|
|
|
}
|
|
|
|
|
|
- String lockKey = String.format(MARKETING_REAL_NUM_LOCK, marketing.getId());
|
|
|
+ String lockKey = RedisLockKey.build(RedisLockKey.MARKETING_REAL_NUM_LOCK, marketingHelpParam.getMarketingId());
|
|
|
|
|
|
if (!distributedLocker.tryLock(lockKey)) {
|
|
|
return AjaxResult.error("活动太火爆了,请稍后重试!");
|