|
@@ -2,9 +2,11 @@ package com.cyksj.web.controller.coupon;
|
|
|
|
|
|
|
|
import cn.hutool.core.date.DateTime;
|
|
import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
import com.cyksj.common.annotation.NoSubmit;
|
|
|
|
|
+import com.cyksj.common.constant.Constant;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
import com.cyksj.common.util.Jsons;
|
|
|
import com.cyksj.dto.Result;
|
|
import com.cyksj.dto.Result;
|
|
@@ -23,6 +25,7 @@ import com.cyksj.model.request.CouponCollectReq;
|
|
|
import com.cyksj.model.views.*;
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
import com.cyksj.redis.RedisService;
|
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
import com.cyksj.service.coupon.CouponFontService;
|
|
|
|
|
+import com.cyksj.service.sys.SysConfigService;
|
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
import com.cyksj.web.util.StpUserUtil;
|
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
import com.ejlchina.searcher.param.Operator;
|
|
@@ -31,6 +34,7 @@ import lombok.RequiredArgsConstructor;
|
|
|
import org.springframework.validation.annotation.Validated;
|
|
import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
import java.util.stream.Collectors;
|
|
@@ -65,6 +69,10 @@ public class CouponFrontController {
|
|
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
private final UserMapper userMapper;
|
|
|
|
|
|
|
|
|
|
+ private final HttpServletRequest request;
|
|
|
|
|
+
|
|
|
|
|
+ private final SysConfigService sysConfigService;
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 优惠券领取中心列表
|
|
* 优惠券领取中心列表
|
|
|
*/
|
|
*/
|
|
@@ -357,10 +365,20 @@ public class CouponFrontController {
|
|
|
* 新用户福利 优惠券详情展示
|
|
* 新用户福利 优惠券详情展示
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/get/newUser/welfare")
|
|
@GetMapping("/get/newUser/welfare")
|
|
|
- public Result<CouponUserView> getNewUserWelfare() {
|
|
|
|
|
|
|
+ public Result<Object> getNewUserWelfare() {
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- DateTime now = DateTime.now();
|
|
|
|
|
- CouponUserView couponUserView = couponFontService.getNewUserWelfareCoupons(userId, now);
|
|
|
|
|
|
|
+ SysConfig one = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
|
|
+ .eq(SysConfig::getSysKey, Constant.YL_NEW_WELFARE_COUPON_ID)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (one == null || StrUtil.isEmpty(one.getSysValue())) {
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+ String couponId = one.getSysValue();
|
|
|
|
|
+ CouponUserView couponUserView = couponFontService.getNewUserWelfareCoupons(userId, Long.valueOf(couponId));
|
|
|
|
|
+ if (couponUserView == null) {
|
|
|
|
|
+ CouponDetailView couponDetailView = beanSearcher.searchFirst(CouponDetailView.class, MapUtils.flatBuilder(request.getParameterMap()).field(CouponDetailView::getCouponId, couponId).build());
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(couponDetailView);
|
|
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -377,7 +395,71 @@ public class CouponFrontController {
|
|
|
@PostMapping("/receive/coupon/{couponId}")
|
|
@PostMapping("/receive/coupon/{couponId}")
|
|
|
public Result<CouponUserView> receiveCoupon(@PathVariable Long couponId) {
|
|
public Result<CouponUserView> receiveCoupon(@PathVariable Long couponId) {
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- CouponUserView couponUserView = couponFontService.receiveCoupon(userId, couponId);
|
|
|
|
|
|
|
+ CouponUserView couponUserView = couponFontService.receiveCoupon(userId, couponId, CouponUser.Channel.manual);
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 优惠券详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/detail/{couponId}")
|
|
|
|
|
+ public Result<CouponDetailView> getCouponDetail(@PathVariable Long couponId) {
|
|
|
|
|
+ CouponDetailView couponDetailView = beanSearcher.searchFirst(CouponDetailView.class, MapUtils.flatBuilder(request.getParameterMap()).field(CouponDetailView::getCouponId, couponId).build());
|
|
|
|
|
+ String str = couponSkuMapper.selectGoodsSkuStr(couponDetailView.getCouponId());
|
|
|
|
|
+ couponDetailView.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
|
|
+ List<CouponSkuView> couponSkus = couponSkuMapper.getGoodsSkuByCouponId(couponDetailView.getCouponId());
|
|
|
|
|
+ try {
|
|
|
|
|
+ couponDetailView.setGoodsSkuIds(Jsons.toJson(couponSkus));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(couponDetailView);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 引流新人优惠券详情
|
|
|
|
|
+ */
|
|
|
|
|
+ @GetMapping("/get/yl/welfare/coupon/detail")
|
|
|
|
|
+ @Deprecated
|
|
|
|
|
+ public Result<CouponDetailView> getYlWelfareCouponDetail() {
|
|
|
|
|
+ SysConfig one = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
|
|
+ .eq(SysConfig::getSysKey, Constant.YL_NEW_WELFARE_COUPON_ID)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (one == null || StrUtil.isEmpty(one.getSysValue())) {
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
|
|
+ }
|
|
|
|
|
+ String couponId = one.getSysValue();
|
|
|
|
|
+ CouponDetailView couponDetailView = beanSearcher.searchFirst(CouponDetailView.class, MapUtils.flatBuilder(request.getParameterMap()).field(CouponDetailView::getCouponId, couponId).build());
|
|
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(couponDetailView);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 领取新人优惠券
|
|
|
|
|
+ */
|
|
|
|
|
+ @PostMapping("/receive/newWelfare")
|
|
|
|
|
+ public Result<CouponUserView> receiveNewWelfareCoupon() {
|
|
|
|
|
+ long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
|
|
+ SysConfig one = sysConfigService.getOne(Wrappers.lambdaQuery(SysConfig.class)
|
|
|
|
|
+ .eq(SysConfig::getSysKey, Constant.YL_NEW_WELFARE_COUPON_ID)
|
|
|
|
|
+ .last("limit 1"));
|
|
|
|
|
+ if (one == null || StrUtil.isEmpty(one.getSysValue())) {
|
|
|
|
|
+ throw BusinessRuntimeException.getInstance("暂无新人优惠券活动");
|
|
|
|
|
+ }
|
|
|
|
|
+ String couponId = one.getSysValue();
|
|
|
|
|
+ CouponUserView couponUserView = couponFontService.receiveCoupon(userId, Long.valueOf(couponId), CouponUser.Channel.new_welfare);
|
|
|
|
|
+ if (couponUserView == null) {
|
|
|
|
|
+ couponUserView = beanSearcher.searchFirst(CouponUserView.class, MapUtils.flatBuilder(request.getParameterMap()).field(CouponNewUserView::getUserId, userId).field(CouponUserView::getCouponId, couponId).build());
|
|
|
|
|
+ }
|
|
|
|
|
+ if (couponUserView != null) {
|
|
|
|
|
+ String str = couponSkuMapper.selectGoodsSkuStr(couponUserView.getCouponId());
|
|
|
|
|
+ couponUserView.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
|
|
+ List<CouponSkuView> couponSkus = couponSkuMapper.getGoodsSkuByCouponId(couponUserView.getCouponId());
|
|
|
|
|
+ try {
|
|
|
|
|
+ couponUserView.setGoodsSkuIds(Jsons.toJson(couponSkus));
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|