|
@@ -12,9 +12,12 @@ 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.enums.MarketingStatusEnum;
|
|
|
+import com.qs.mp.common.enums.UserTypeEnum;
|
|
|
import com.qs.mp.common.utils.DateUtils;
|
|
|
+import com.qs.mp.common.utils.StringUtils;
|
|
|
import com.qs.mp.user.domain.MarketingHitPrize;
|
|
|
import com.qs.mp.user.domain.MarketingUserCode;
|
|
|
+import com.qs.mp.user.domain.param.MarketingHelpParam;
|
|
|
import com.qs.mp.user.domain.param.UserMarketingQueryParam;
|
|
|
import com.qs.mp.user.domain.vo.UserMarketingDetailVO;
|
|
|
import com.qs.mp.user.domain.vo.UserMarketingListVO;
|
|
@@ -27,6 +30,7 @@ import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import io.swagger.annotations.ApiResponse;
|
|
|
import io.swagger.annotations.ApiResponses;
|
|
|
+import org.aspectj.weaver.loadtime.Aj;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
@@ -62,11 +66,79 @@ public class MarketingController extends BaseApiController {
|
|
|
@Autowired
|
|
|
private IMarketingUserCodeService marketingUserCodeService;
|
|
|
|
|
|
+ @PostMapping("/help")
|
|
|
+ @ApiOperation("活动助力")
|
|
|
+ public AjaxResult help(@RequestBody MarketingHelpParam marketingHelpParam) {
|
|
|
+ Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
+ if (Objects.isNull(userId)) {
|
|
|
+ return AjaxResult.error("用户未登录");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ String inviteCode = marketingHelpParam.getInviteCode();
|
|
|
+ if (StringUtils.isBlank(inviteCode)) {
|
|
|
+ return AjaxResult.error("邀请码不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ Marketing marketing = marketingService.getById(marketingHelpParam.getMarketingId());
|
|
|
+ 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("活动未开始~");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ // 判断是否已经助力过
|
|
|
+ int count = marketingUserCodeService.count(new LambdaQueryWrapper<MarketingUserCode>()
|
|
|
+ .eq(MarketingUserCode::getUserId, userId)
|
|
|
+ .eq(MarketingUserCode::getMarketingId, marketingHelpParam.getMarketingId()));
|
|
|
+ if (count > 0) {
|
|
|
+ return AjaxResult.error("您已经助力过了");
|
|
|
+ }
|
|
|
+
|
|
|
+ // 邀请码解码,被助力人id
|
|
|
+ Long helpedUserId = MarketingUtils.decodeInviteCode(inviteCode);
|
|
|
+
|
|
|
+ // 生成抽奖码
|
|
|
+ String code = "";
|
|
|
+ while (true) {
|
|
|
+ code = MarketingUtils.generatePrizeCode();
|
|
|
+ // 判断抽奖码是否已经存在
|
|
|
+ int codeCount = marketingUserCodeService.count(new LambdaQueryWrapper<MarketingUserCode>()
|
|
|
+ .eq(MarketingUserCode::getCode, code));
|
|
|
+ if (codeCount > 0) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ break;
|
|
|
+ }
|
|
|
+
|
|
|
+ MarketingUserCode marketingUserCode = new MarketingUserCode();
|
|
|
+ marketingUserCode.setMarketingId(marketingHelpParam.getMarketingId());
|
|
|
+ marketingUserCode.setCode(code);
|
|
|
+ // 设置被助力人
|
|
|
+ marketingUserCode.setUserId(helpedUserId);
|
|
|
+ // 设置助力人
|
|
|
+ marketingUserCode.setHelpUserId(userId);
|
|
|
+ marketingUserCode.setUserType(UserTypeEnum.ORDINARY.getValue());
|
|
|
+
|
|
|
+ marketingUserCodeService.save(marketingUserCode);
|
|
|
+ return AjaxResult.success("助力成功");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
@PostMapping("/inviteCode")
|
|
|
@ApiOperation(value = "邀请码生成", notes = "邀请码生成")
|
|
|
- @ApiResponses({
|
|
|
- @ApiResponse(code = 200, message = "成功", response = String.class)
|
|
|
- })
|
|
|
public AjaxResult inviteCode() {
|
|
|
Long userId = SecurityUtils.getLoginUser().getUserId();
|
|
|
if (Objects.isNull(userId)) {
|