|
|
@@ -3,6 +3,7 @@ package com.cyksj.web.controller.coupon;
|
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import cn.hutool.core.util.StrUtil;
|
|
|
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
|
@@ -11,6 +12,7 @@ import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
+import com.cyksj.mapper.CouponUserPopupsRecordMapper;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponRecommendMapper;
|
|
|
@@ -73,6 +75,8 @@ public class CouponFrontController {
|
|
|
|
|
|
private final SysConfigService sysConfigService;
|
|
|
|
|
|
+ private final CouponUserPopupsRecordMapper couponUserPopupsRecordMapper;
|
|
|
+
|
|
|
/**
|
|
|
* 优惠券领取中心列表
|
|
|
*/
|
|
|
@@ -461,5 +465,68 @@ public class CouponFrontController {
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
|
}
|
|
|
+
|
|
|
+ //==================================================优惠券弹窗======================================================================================
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户存在弹窗列表
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @GetMapping("/get/popups")
|
|
|
+ public Result<List<CouponUserPopupsView>> getCouponPopups() {
|
|
|
+ long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
+ DateTime now = DateTime.now();
|
|
|
+ List<CouponUserPopupsView> couponUserPopups = beanSearcher.searchAll(CouponUserPopupsView.class, MapUtils.flatBuilder(request.getParameterMap())
|
|
|
+ .field(CouponUserPopupsView::getStartTime, now).op(Operator.LessEqual)
|
|
|
+ .field(CouponUserPopupsView::getEndTime, now).op(Operator.GreaterThan)
|
|
|
+ .build());
|
|
|
+ couponUserPopups = couponUserPopups.stream().filter(cu -> {
|
|
|
+ try {
|
|
|
+ List<Long> couponIds = Jsons.parseList(cu.getCouponIds(), Long.class);
|
|
|
+ Integer selectCount = couponUserMapper.selectCount(Wrappers.lambdaQuery(CouponUser.class)
|
|
|
+ .eq(CouponUser::getUserId, userId)
|
|
|
+ .in(CouponUser::getCouponId, couponIds)
|
|
|
+ .le(CouponUser::getValidStartTime, now)
|
|
|
+ .gt(CouponUser::getValidEndTime, now)
|
|
|
+ .eq(CouponUser::getStatus, CouponUser.Status.unused));
|
|
|
+ //是否符合条件
|
|
|
+ if (selectCount > 0) {
|
|
|
+ Integer frequency = cu.getFrequency();
|
|
|
+ LambdaQueryWrapper<CouponUserPopupsRecord> wrapper = Wrappers.lambdaQuery(CouponUserPopupsRecord.class);
|
|
|
+ if (frequency != 0) {
|
|
|
+ wrapper.between(CouponUserPopupsRecord::getCreatedTime, DateUtil.beginOfDay(now), DateUtil.endOfDay(now));
|
|
|
+ }
|
|
|
+ Integer popupsRecordCount = couponUserPopupsRecordMapper.selectCount(wrapper.eq(CouponUserPopupsRecord::getUserId, userId).eq(CouponUserPopupsRecord::getPopupsId, cu.getPopupsId()));
|
|
|
+ //未有弹窗记录
|
|
|
+ if (popupsRecordCount == 0) {
|
|
|
+ List<CouponUserView> couponUserViews = beanSearcher.searchAll(CouponUserView.class, MapUtils.builder().field(CouponUserView::getUserId, userId)
|
|
|
+ .field(CouponUserView::getCouponId, couponIds).op(Operator.InList)
|
|
|
+ .orderBy(CouponUserView::getDiscount).asc()
|
|
|
+ .build());
|
|
|
+ cu.setCouponUserViews(couponUserViews);
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ } catch (Exception e) {
|
|
|
+
|
|
|
+ }
|
|
|
+ return false;
|
|
|
+ }).collect(Collectors.toList());
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserPopups);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 优惠弹窗记录
|
|
|
+ */
|
|
|
+ @PostMapping("/record/popups/{popupsId}")
|
|
|
+ public Result<String> recordPopups(@PathVariable Long popupsId) {
|
|
|
+ long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
+ CouponUserPopupsRecord couponUserPopupsRecord = new CouponUserPopupsRecord();
|
|
|
+ couponUserPopupsRecord.setPopupsId(popupsId);
|
|
|
+ couponUserPopupsRecord.setUserId(userId);
|
|
|
+ couponUserPopupsRecordMapper.insert(couponUserPopupsRecord);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ }
|
|
|
}
|
|
|
|