From 622df03a6e65f2509f1fd70d196140a3c3e8cff5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=AE=B8=E5=85=81=E6=9E=9E?= <3422692813@qq.com> Date: Fri, 11 Oct 2024 15:13:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B010.11?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../mapper/xml/ActiveAppletMapper.xml | 1 + .../controller/CardCouponController.java | 9 +++ .../cardCoupon/service/CardCouponService.java | 7 +++ .../service/impl/CardCouponServiceImpl.java | 63 +++++++++++++++++++ 4 files changed, 80 insertions(+) diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeApplet/mapper/xml/ActiveAppletMapper.xml b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeApplet/mapper/xml/ActiveAppletMapper.xml index 2bfd0af56..5c53a6157 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeApplet/mapper/xml/ActiveAppletMapper.xml +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/activeApplet/mapper/xml/ActiveAppletMapper.xml @@ -32,6 +32,7 @@ FROM active_applet aa LEFT JOIN t_account ta on aa.create_by = ta.acct_id + type != '1' and type != '2' AND aa.name like concat('%', #{entity.name}, '%') diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/controller/CardCouponController.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/controller/CardCouponController.java index d5844c370..6df640942 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/controller/CardCouponController.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/controller/CardCouponController.java @@ -223,6 +223,15 @@ public class CardCouponController extends BaseController { return getSuccessResult(cardCouponService.sendCoupon(cardCouponUser)); } + /** + * 用户领取优惠券 + * @return + */ + @GetMapping("userGetCoupon") + public ResponseObject userGetCoupon(Integer couponId){ + return getSuccessResult(cardCouponService.userGetCoupon(couponId)); + } + // @GetMapping("getCouponOne") // public ResponseObject getCouponOne(Integer id) { // return getSuccessResult(cardCouponService.getCouponOne(id)); diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/CardCouponService.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/CardCouponService.java index df9fa1dd6..ace58dbe1 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/CardCouponService.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/CardCouponService.java @@ -31,6 +31,13 @@ public interface CardCouponService extends IService { int sendCoupon(CardCouponUser cardCouponUser); CardCoupon selectOneBuId(Integer id); + + /** + * 用户领取卡券 + * @param couponId + * @return + */ + int userGetCoupon(Integer couponId); /** * 卡券详情(小程序) * @param id diff --git a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/impl/CardCouponServiceImpl.java b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/impl/CardCouponServiceImpl.java index 4686b702f..c418d2828 100644 --- a/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/impl/CardCouponServiceImpl.java +++ b/fuintBackend/fuint-application/src/main/java/com/fuint/business/marketingActivity/cardCoupon/service/impl/CardCouponServiceImpl.java @@ -147,6 +147,69 @@ public class CardCouponServiceImpl extends ServiceImpl() + .eq(CardCoupon::getId, couponId)); + + //判断优惠券是否在线 + if (cardCoupon.getStatus().equals("0")) { + return 2; + } + + //判断是否有库存 + int count = cardCoupon.getTfTotal() - cardCoupon.getGiftCardTotal(); + if (count == 0) { + return 0; + } + //判断用户是否已经领取上限 + Integer getCount = cardCouponUserMapper.selectCount(new LambdaQueryWrapper() + .eq(CardCouponUser::getMtUserId, nowAccountInfo.getId()) + .eq(CardCouponUser::getCardCouponId, couponId)); + if (getCount >= cardCoupon.getGetNumLimit()) { + return 1; + } + Integer validityDay = 0; + //优惠券的有效期 + Date effectiveDateStart = new Date(); + Date effectiveDateEnd = new Date(); + if (cardCoupon.getTimeType().equals("1")) { + validityDay = cardCoupon.getValidityDay(); + DateTime now = DateUtil.date(); + effectiveDateStart = now; + effectiveDateEnd = DateUtil.offsetDay(now, validityDay); + }else { + effectiveDateStart = cardCoupon.getEffectiveDateStart(); + effectiveDateEnd = cardCoupon.getEffectiveDateEnd(); + } + + //添加到用户优惠券表 + CardCouponUser cardCouponUser = new CardCouponUser(); + cardCouponUser.setStatus("0"); + cardCouponUser.setChainStoreId(cardCoupon.getChainStorId()); + cardCouponUser.setStoreId(cardCoupon.getStoreId()); + cardCouponUser.setMtUserId(nowAccountInfo.getId()); + cardCouponUser.setFromType("6"); + cardCouponUser.setCardCouponId(cardCoupon.getId()); + cardCouponUser.setStartTime(effectiveDateStart); + cardCouponUser.setEndTime(effectiveDateEnd); + cardCouponUser.setCreateTime(new Date()); + cardCouponUser.setCreateBy(TokenUtil.getNowAccountInfo().getId().toString()); + cardCouponUserMapper.insert(cardCouponUser); + + //更新优惠券表 + cardCoupon.setTfGetNum(cardCoupon.getTfGetNum() + 1); + return baseMapper.updateById(cardCoupon); + } + /** * 卡券详情(小程序) *