|
|
@@ -4,7 +4,6 @@ import cn.hutool.core.date.DateTime;
|
|
|
import cn.hutool.core.date.DateUtil;
|
|
|
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
|
|
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
|
|
-import com.cyksj.common.annotation.NoSubmit;
|
|
|
import com.cyksj.common.exception.BusinessRuntimeException;
|
|
|
import com.cyksj.common.i18n.I18nMessageUtil;
|
|
|
import com.cyksj.common.util.Jsons;
|
|
|
@@ -12,14 +11,12 @@ import com.cyksj.dto.Result;
|
|
|
import com.cyksj.enums.GatewayResponse;
|
|
|
import com.cyksj.mapper.UserMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponMapper;
|
|
|
-import com.cyksj.mapper.manage.coupon.CouponRecommendMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponSkuMapper;
|
|
|
import com.cyksj.mapper.manage.coupon.CouponUserMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeMapper;
|
|
|
import com.cyksj.mapper.manage.distribute.UserDistributeSharedMapper;
|
|
|
import com.cyksj.model.dto.CouponPopularizeDto;
|
|
|
import com.cyksj.model.entity.*;
|
|
|
-import com.cyksj.model.request.ChannelPopularizeCouponReq;
|
|
|
import com.cyksj.model.request.CouponCollectReq;
|
|
|
import com.cyksj.model.views.*;
|
|
|
import com.cyksj.redis.RedisService;
|
|
|
@@ -29,9 +26,9 @@ import com.ejlchina.searcher.BeanSearcher;
|
|
|
import com.ejlchina.searcher.param.Operator;
|
|
|
import com.ejlchina.searcher.util.MapUtils;
|
|
|
import lombok.RequiredArgsConstructor;
|
|
|
-import org.springframework.validation.annotation.Validated;
|
|
|
import org.springframework.web.bind.annotation.*;
|
|
|
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.stream.Collectors;
|
|
|
@@ -60,47 +57,25 @@ public class CouponFrontController {
|
|
|
|
|
|
private final UserDistributeMapper userDistributeMapper;
|
|
|
|
|
|
- private final CouponRecommendMapper couponRecommendMapper;
|
|
|
+ private final HttpServletRequest request;
|
|
|
|
|
|
private final UserDistributeSharedMapper userDistributeSharedMapper;
|
|
|
|
|
|
private final UserMapper userMapper;
|
|
|
-
|
|
|
- /**
|
|
|
- * 优惠券领取中心列表
|
|
|
- */
|
|
|
- @GetMapping("/center/list")
|
|
|
- public Result<Page<CouponActiveView>> couponCenterList(@RequestParam(defaultValue = "1") Long start, @RequestParam(defaultValue = "5") Long limit) {
|
|
|
- Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- Page<CouponActiveView> page = couponUserMapper.couponCenterList(userId, new Page<>(start, limit));
|
|
|
- page.getRecords().forEach(data -> {
|
|
|
- String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
|
|
|
- data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
- List<CouponSkuView> couponSkus = couponSkuMapper.getGoodsSkuByCouponId(data.getCouponId());
|
|
|
- try {
|
|
|
- data.setGoodsSkuIds(Jsons.toJson(couponSkus));
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(page);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 个人优惠券列表
|
|
|
*/
|
|
|
@GetMapping("/personal/list")
|
|
|
- public Result<Page<CouponUserView>> couponPersonalList(@RequestParam(defaultValue = "1") Long start, @RequestParam(defaultValue = "5") Long limit) {
|
|
|
+ public Result<Page<CouponUserView>> couponPersonalList(@RequestParam(defaultValue = "1") Long start, @RequestParam(defaultValue = "5") Long limit, Long couponId) {
|
|
|
+ String lang = request.getHeader("lang");
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- Page<CouponUserView> page = couponUserMapper.couponPersonalList(userId, new Page<>(start, limit));
|
|
|
+ Page<CouponUserView> page = couponUserMapper.couponPersonalList(userId, new Page<>(start, limit), couponId);
|
|
|
page.getRecords().forEach(data -> {
|
|
|
- String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
|
|
|
- data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
+ data.setGoodsSkuStr(couponFontService.setCouponSkuLanguage(data.getCouponId(), lang));
|
|
|
List<CouponSkuView> couponSkus = couponSkuMapper.getGoodsSkuByCouponId(data.getCouponId());
|
|
|
try {
|
|
|
data.setGoodsSkuIds(Jsons.toJson(couponSkus));
|
|
|
} catch (Exception e) {
|
|
|
-
|
|
|
}
|
|
|
});
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(page);
|
|
|
@@ -138,65 +113,12 @@ public class CouponFrontController {
|
|
|
|
|
|
@GetMapping("/available/list")
|
|
|
public Result<Page<CouponUserView>> availableCouponList(Long skuId, Long couponId, Boolean isRenew, @RequestParam(defaultValue = "1") Long start, @RequestParam(defaultValue = "5") Long limit) {
|
|
|
+ String lang = request.getHeader("lang");
|
|
|
Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- Page<CouponUserView> couponActiveViewList = couponFontService.getAvailableCouponList(skuId, couponId, userId, isRenew, start, limit);
|
|
|
+ Page<CouponUserView> couponActiveViewList = couponFontService.getAvailableCouponList(skuId, couponId, userId, isRenew, start, limit, lang);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponActiveViewList);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 推荐优惠券列表
|
|
|
- */
|
|
|
- @GetMapping("/recommend/list")
|
|
|
- public Result<Page<CouponRecommendView>> getRecommendList(@RequestParam(defaultValue = "1") Long start, @RequestParam(defaultValue = "5") Long limit) {
|
|
|
- Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- CouponNewUserView couponNewUserView = beanSearcher.searchFirst(CouponNewUserView.class, MapUtils.builder().field(CouponNewUserView::getUserId, userId).op(Operator.Equal).build());
|
|
|
- Boolean isNewUser = true;
|
|
|
- if (couponNewUserView != null) {
|
|
|
- isNewUser = false;
|
|
|
- }
|
|
|
- Page<CouponRecommendView> page = couponRecommendMapper.getRecommendCouponViewList(userId, isNewUser, new Page<>(start, limit));
|
|
|
- page.getRecords().forEach(data -> {
|
|
|
- if (data.getCouponStatus() == CouponActiveView.CouponStatus.received) {
|
|
|
- data.setValidStartTime(data.getUserValidStartTime());
|
|
|
- data.setValidEndTime(data.getUserValidEndTime());
|
|
|
- }
|
|
|
- String str = couponSkuMapper.selectGoodsSkuStr(data.getCouponId());
|
|
|
- data.setGoodsSkuStr(str.replaceAll(",", "/").replaceAll(";", ""));
|
|
|
- List<CouponSkuView> couponSkus = couponSkuMapper.getGoodsSkuByCouponId(data.getCouponId());
|
|
|
- try {
|
|
|
- data.setGoodsSkuIds(Jsons.toJson(couponSkus));
|
|
|
- } catch (Exception e) {
|
|
|
-
|
|
|
- }
|
|
|
- });
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(page);
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 一键领取推荐优惠券
|
|
|
- */
|
|
|
- @PostMapping("/collect/recommend/whole")
|
|
|
- @NoSubmit
|
|
|
- public Result<String> collectWholeRecommendCoupon() {
|
|
|
- Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- couponFontService.collectWholeRecommendCoupon(userId);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 今日推荐优惠券弹窗已弹
|
|
|
- */
|
|
|
- @GetMapping("/get/recommend/appear")
|
|
|
- public Result<Boolean> recommendIsAppear() {
|
|
|
- Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- String zero = DateUtil.beginOfDay(DateTime.now()).toString();
|
|
|
- Object exists = redisService.get(RedisService.key.RECOMMEND_COUPON_DAY.getNameFormat(String.format("%s-%s", zero, userId)));
|
|
|
- if (exists == null) {
|
|
|
- redisService.set(RedisService.key.RECOMMEND_COUPON_DAY.getNameFormat(String.format("%s-%s", zero, userId)), userId, RedisService.key.RECOMMEND_COUPON_DAY.getTimeout());
|
|
|
- }
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(exists == null ? false : true);
|
|
|
- }
|
|
|
-
|
|
|
/**
|
|
|
* 领取优惠券
|
|
|
*/
|
|
|
@@ -207,31 +129,6 @@ public class CouponFrontController {
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 领取推荐优惠券
|
|
|
- */
|
|
|
- @PostMapping("/recommend/collect")
|
|
|
- public Result<String> collectRecommendCoupon(@RequestBody CouponCollectReq couponCollectReq) {
|
|
|
- Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- couponFontService.collectRecommendCoupon(couponCollectReq, userId);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 查询有可以领取的推荐优惠券
|
|
|
- */
|
|
|
- @GetMapping("/recommend/collect/num")
|
|
|
- public Result<Integer> collectRecommendCouponNum() {
|
|
|
- Long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- CouponNewUserView couponNewUserView = beanSearcher.searchFirst(CouponNewUserView.class, MapUtils.builder().field(CouponNewUserView::getUserId, userId).op(Operator.Equal).build());
|
|
|
- Boolean isNewUser = true;
|
|
|
- if (couponNewUserView != null) {
|
|
|
- isNewUser = false;
|
|
|
- }
|
|
|
- Integer num = couponFontService.collectRecommendCouponNum(userId, isNewUser);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult(num);
|
|
|
- }
|
|
|
-
|
|
|
|
|
|
/**
|
|
|
* 优惠码详情
|
|
|
@@ -245,7 +142,7 @@ public class CouponFrontController {
|
|
|
}
|
|
|
BigDecimal skuMoney = goodsDonSkuView.getMoney();
|
|
|
if (goodsDonSkuView.getType() == 2) {
|
|
|
- throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_sku_not_available_error"));
|
|
|
+ throw BusinessRuntimeException.getInstance("");
|
|
|
}
|
|
|
CouponPopularizeDto dto = couponMapper.checkExCode(exCode);
|
|
|
if (dto == null) {
|
|
|
@@ -272,10 +169,10 @@ public class CouponFrontController {
|
|
|
throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_code_new_user_error"));
|
|
|
}
|
|
|
CouponNewUserView couponNewUserView = beanSearcher.searchFirst(CouponNewUserView.class, MapUtils.builder().field(CouponNewUserView::getUserId, userId).op(Operator.Equal).build());
|
|
|
- if (couponNewUserView != null) throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_code_new_user_error"));
|
|
|
+ if (couponNewUserView != null) throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_code_new_user_error"));;
|
|
|
}
|
|
|
if (userDistributeShared != null && !userDistributeShared.getSharedId().equals(dto.getUserId())) {
|
|
|
- throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_code_popularize_repeat_use_error"));
|
|
|
+ throw BusinessRuntimeException.getInstance("");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -288,13 +185,13 @@ public class CouponFrontController {
|
|
|
if (isRenew != null && isRenew) {
|
|
|
Coupon.UseScope useScope = dto.getUseScope();
|
|
|
if (useScope == Coupon.UseScope.orders) {
|
|
|
- throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_code_only_order_error"));
|
|
|
+ throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_only_order_error"));
|
|
|
}
|
|
|
}
|
|
|
if (isRenew == null || !isRenew) {
|
|
|
Coupon.UseScope useScope = dto.getUseScope();
|
|
|
if (useScope == Coupon.UseScope.renew) {
|
|
|
- throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_code_only_renew_order_error"));
|
|
|
+ throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_only_renew_error"));
|
|
|
}
|
|
|
}
|
|
|
if (dto.getIsValidTime() && dto.getValidStartTime().after(DateTime.now())) {
|
|
|
@@ -308,12 +205,7 @@ public class CouponFrontController {
|
|
|
.eq(CouponSku::getCouponId, dto.getCouponId())
|
|
|
.select(CouponSku::getId).last("limit 1"));
|
|
|
if (couponSku == null) {
|
|
|
- throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_sku_not_available_error"));
|
|
|
- }
|
|
|
- if (goodsDonSkuView.getType() == 2) {
|
|
|
- if (dto.getType() == Coupon.Type.reduce && skuMoney.compareTo(dto.getReduceCondition()) < 0) {
|
|
|
- throw BusinessRuntimeException.getInstance(I18nMessageUtil.getI18nMsg("coupon_reduce_money_not_available_error"));
|
|
|
- }
|
|
|
+ throw BusinessRuntimeException.getInstance("");
|
|
|
}
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(dto);
|
|
|
}
|
|
|
@@ -328,40 +220,27 @@ public class CouponFrontController {
|
|
|
}
|
|
|
List<CouponView> couponViews = beanSearcher.searchAll(CouponView.class, MapUtils.builder()
|
|
|
.field(CouponView::getId, couponIds).op(Operator.InList)
|
|
|
- .orderBy(CouponView ::getId).desc()
|
|
|
+ .orderBy(CouponView::getId).desc()
|
|
|
.build());
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponViews);
|
|
|
}
|
|
|
|
|
|
- /**
|
|
|
- * 渠道推广用户领取优惠券
|
|
|
- */
|
|
|
- @PostMapping("/channel/popularize/receive")
|
|
|
- public Result<String> receiveChannelPopularizeCoupon(@RequestBody @Validated ChannelPopularizeCouponReq req) {
|
|
|
+ @GetMapping("/get/coupon/detail/{couponId}")
|
|
|
+ public Result<CouponUserView> getCouponDetailById(@PathVariable Long couponId) {
|
|
|
+ String lang = request.getHeader("lang");
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- req.setUserId(userId);
|
|
|
- couponFontService.receiveChannelPopularizeCoupon(req);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 渠道推广一键领取优惠券
|
|
|
- */
|
|
|
- @PostMapping("/channel/popularize/collectAll/{popularizeId}")
|
|
|
- public Result<String> collectAllChannelCoupons(@PathVariable Long popularizeId) {
|
|
|
- long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- couponFontService.collectAllChannelCoupons(userId, popularizeId);
|
|
|
- return GatewayResponse.SUCCESS.newBuilder().toResult();
|
|
|
+ CouponUserView couponUserView = couponFontService.getCouponDetailById(userId, couponId, lang);
|
|
|
+ return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 新用户福利 优惠券详情展示
|
|
|
+ * 领取优惠券
|
|
|
*/
|
|
|
- @GetMapping("/get/newUser/welfare")
|
|
|
- public Result<CouponUserView> getNewUserWelfare() {
|
|
|
+ @PostMapping("/receive/coupon/{couponId}")
|
|
|
+ public Result<CouponUserView> receiveCoupon(@PathVariable Long couponId) {
|
|
|
+ String lang = request.getHeader("lang");
|
|
|
long userId = StpUserUtil.getLoginIdAsLong();
|
|
|
- DateTime now = DateTime.now();
|
|
|
- CouponUserView couponUserView = couponFontService.getNewUserWelfareCoupons(userId, now);
|
|
|
+ CouponUserView couponUserView = couponFontService.receiveCoupon(userId, couponId, lang);
|
|
|
return GatewayResponse.SUCCESS.newBuilder().toResult(couponUserView);
|
|
|
}
|
|
|
}
|