优惠券弹窗

This commit is contained in:
wangw 2025-09-25 17:15:58 +08:00
parent 31005bd6c7
commit 5c41fb8d67
6 changed files with 245 additions and 0 deletions

View File

@ -2,12 +2,15 @@ package com.czg.controller.user;
import com.czg.account.vo.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.entity.ShopCoupon;
import com.czg.market.service.ShopCouponService;
import com.czg.market.vo.ShopCouponPopUp;
import com.czg.market.vo.UserCouponVO;
import com.czg.resp.CzgResult;
import com.czg.sa.StpKit;
import com.czg.utils.AssertUtil;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.query.QueryWrapper;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;
@ -23,6 +26,30 @@ public class UShopCouponController {
@Resource
private ShopCouponService couponService;
/**
* 优惠券弹窗
*
* @param getMode 首页home/用餐eat/订单order
* @return
*/
@GetMapping("/popUp")
public CzgResult<List<ShopCouponPopUp>> getPopUp(String getMode) {
Long shopId = StpKit.USER.getShopId();
return CzgResult.success(couponService.getPopUp(shopId, StpKit.USER.getLoginIdAsLong(), getMode));
}
/**
* 优惠券弹窗领取
*
* @param getMode 首页home/用餐eat/订单order
*/
@GetMapping("/receivePopUp")
public CzgResult<Void> receivePopUp(String getMode) {
Long shopId = StpKit.USER.getShopId();
couponService.receivePopUp(shopId, StpKit.USER.getLoginIdAsLong(), getMode);
return CzgResult.success();
}
/**
* 获取当前店铺会员信息

View File

@ -56,6 +56,10 @@ public class MkShopCouponRecord implements Serializable {
* 卷Id (校验是否可用)
*/
private Long couponId;
/**
* 优惠券同步id
*/
private Long couponSyncId;
/**
* 卷描述 满10减2/商品卷

View File

@ -4,6 +4,7 @@ import com.czg.account.vo.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.dto.ShopCouponDTO;
import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.vo.ShopCouponPopUp;
import com.czg.market.vo.UserCouponVO;
import com.mybatisflex.core.paginate.Page;
import com.mybatisflex.core.service.IService;
@ -20,6 +21,10 @@ import java.util.List;
public interface ShopCouponService extends IService<ShopCoupon> {
Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param);
List<ShopCouponPopUp> getPopUp(Long shopId, Long userId, String getMode);
void receivePopUp(Long shopId, Long userId, String getMode);
ShopCouponDTO getCouponById(Long id);
void addCoupon(ShopCouponDTO param);

View File

@ -0,0 +1,119 @@
package com.czg.market.vo;
import com.mybatisflex.annotation.Column;
import com.mybatisflex.annotation.Id;
import com.mybatisflex.annotation.KeyType;
import com.mybatisflex.annotation.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;
import java.io.Serial;
import java.io.Serializable;
import java.math.BigDecimal;
import java.sql.Time;
import java.time.LocalDateTime;
/**
* 优惠券信息表 实体类
*
* @author ww
* @since 2025-09-11
*/
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class ShopCouponPopUp implements Serializable {
@Serial
private static final long serialVersionUID = 1L;
/**
* 自增主键
*/
@Id(keyType = KeyType.Auto)
private Long id;
/**
* 优惠券类型1-满减券2-商品兑换券3-折扣券4-第二件半价券5-消费送券6-买一送一券7-固定价格券8-免配送费券
*/
private Integer couponType;
/**
* 券名称
*/
private String title;
/**
* 可使用类型dine堂食/pickup自取/deliv配送/express快递
*/
private String useType;
/**
* 有效期类型fixed固定时间custom自定义时间
*/
private String validType;
/**
* 有效期()
*/
private Integer validDays;
/**
* 有效期开始时间
*/
private LocalDateTime validStartTime;
/**
* 有效期结束时间
*/
private LocalDateTime validEndTime;
/**
* 隔天生效
*/
private Integer daysToTakeEffect;
/**
* 总发放数量-10086为不限量
*/
private Integer giveNum;
/**
* 已发放数量
*/
private Integer giftNum;
/**
* 附加规则说明
*/
private String ruleDetails;
/**
* 使用门槛满多少金额
*/
private BigDecimal fullAmount;
/**
* 使用门槛减多少金额
*/
private BigDecimal discountAmount;
/**
* 折扣%
*/
private Integer discountRate;
/**
* 可抵扣最大金额
*/
private BigDecimal maxDiscountAmount;
/**
* 抵扣数量
*/
private Integer discountNum;
}

View File

@ -177,6 +177,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl<MkShopCouponRecor
record.setShopUserId(giftDTO.getShopUserId());
record.setUserId(shopUser.getUserId());
record.setCouponId(giftDTO.getCouponId());
record.setCouponSyncId(coupon.getSyncId());
record.setSourceId(giftDTO.getSourceId());
record.setSourceFlowId(giftDTO.getSourceFlowId());
record.setSource(giftDTO.getSource());

View File

@ -16,15 +16,21 @@ import com.czg.account.service.ShopUserService;
import com.czg.account.vo.ShopInfoCouponVO;
import com.czg.account.vo.UserCouponFoodVo;
import com.czg.account.vo.UserCouponVo;
import com.czg.market.dto.MkShopCouponGiftDTO;
import com.czg.market.dto.ShopCouponDTO;
import com.czg.market.entity.MkShopCouponRecord;
import com.czg.market.entity.ShopCoupon;
import com.czg.market.service.MkCouponGiftService;
import com.czg.market.service.MkShopCouponRecordService;
import com.czg.market.service.ShopCouponService;
import com.czg.market.vo.ShopCouponPopUp;
import com.czg.market.vo.UserCouponVO;
import com.czg.order.entity.OrderInfo;
import com.czg.order.service.OrderInfoService;
import com.czg.product.entity.Product;
import com.czg.product.service.ProductService;
import com.czg.sa.StpKit;
import com.czg.service.market.enums.OrderStatusEnums;
import com.czg.service.market.mapper.MkShopCouponRecordMapper;
import com.czg.service.market.mapper.ShopCouponMapper;
import com.czg.utils.AssertUtil;
@ -40,6 +46,7 @@ import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.config.annotation.DubboService;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.util.*;
@ -66,6 +73,8 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
private ShopUserService shopUserService;
@DubboReference
private ProductService productService;
@DubboReference
private OrderInfoService orderInfoService;
@Override
public Page<ShopCouponDTO> getCouponPage(ShopCouponDTO param) {
@ -77,6 +86,86 @@ public class ShopCouponServiceImpl extends ServiceImpl<ShopCouponMapper, ShopCou
return pageAs(PageUtil.buildPage(), queryWrapper, ShopCouponDTO.class);
}
@Override
public List<ShopCouponPopUp> getPopUp(Long shopId, Long userId, String getMode) {
ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId);
AssertUtil.isNull(shopUser, "用户不存在");
List<ShopCouponPopUp> result = new ArrayList<>();
List<ShopCoupon> coupons = list(new QueryWrapper()
.eq(ShopCoupon::getShopId, StpKit.USER.getShopId())
.eq(ShopCoupon::getGetType, "yes")
.eq(ShopCoupon::getGetMode, getMode)
.eq(ShopCoupon::getStatus, 1)
.eq(ShopCoupon::getIsDel, 0)
);
for (ShopCoupon coupon : coupons) {
if ("custom".equals(coupon.getValidType()) && coupon.getValidEndTime() != null && coupon.getValidEndTime().isBefore(LocalDateTime.now())) {
continue;
}
if (coupon.getGiveNum() != -10086 && coupon.getLeftNum() <= 0) {
continue;
}
boolean isNotNewUser = true;
if (!"all".equals(coupon.getGetUserType())) {
if ("new".equals(coupon.getGetUserType())) {
isNotNewUser = false;
long count = orderInfoService.count(new QueryWrapper().eq(OrderInfo::getUserId, userId)
.eq(OrderInfo::getShopId, shopId).eq(OrderInfo::getStatus, OrderStatusEnums.DONE));
if (count > 0) {
continue;
}
long count1 = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getCouponSyncId, coupon.getSyncId()));
if (count1 > 0) {
continue;
}
} else if ("vip".equals(coupon.getGetUserType()) && shopUser.getIsVip() != 1) {
continue;
}
}
if (isNotNewUser && coupon.getGetLimit() != -10086) {
if (coupon.getSyncId() != null) {
long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getCouponSyncId, coupon.getSyncId()));
if (count >= coupon.getGetLimit()) {
continue;
}
} else {
long count = recordService.count(new QueryWrapper().eq(MkShopCouponRecord::getCouponSyncId, coupon.getId()));
if (count >= coupon.getGetLimit()) {
continue;
}
}
}
result.add(BeanUtil.copyProperties(coupon, ShopCouponPopUp.class));
}
return result;
}
@Override
public void receivePopUp(Long shopId, Long userId, String getMode) {
ShopUser shopUser = null;
List<ShopCouponPopUp> popUps = getPopUp(shopId, userId, getMode);
if ("home".equals(getMode)) {
getMode = "首页";
} else if ("eat".equals(getMode)) {
getMode = "用餐";
} else if ("order".equals(getMode)) {
getMode = "订单";
}
for (ShopCouponPopUp popUp : popUps) {
MkShopCouponGiftDTO giftDTO = new MkShopCouponGiftDTO();
giftDTO.setShopId(shopId);
if (shopUser == null) {
shopUser = shopUserService.getShopUserInfo(shopId, userId);
}
giftDTO.setShopUserId(shopUser.getId());
giftDTO.setCouponId(popUp.getId());
giftDTO.setSourceId(-1L);
giftDTO.setSource(getMode + "弹窗领取");
recordService.receiveCoupon(giftDTO, 1, true);
}
}
@Override
public ShopCouponDTO getCouponById(Long id) {
AssertUtil.isNull(id, "优惠券ID不能为空");