diff --git a/cash-api/market-server/src/main/java/com/czg/controller/user/UShopCouponController.java b/cash-api/market-server/src/main/java/com/czg/controller/user/UShopCouponController.java index 6c48f3f7..a3528295 100644 --- a/cash-api/market-server/src/main/java/com/czg/controller/user/UShopCouponController.java +++ b/cash-api/market-server/src/main/java/com/czg/controller/user/UShopCouponController.java @@ -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> 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 receivePopUp(String getMode) { + Long shopId = StpKit.USER.getShopId(); + couponService.receivePopUp(shopId, StpKit.USER.getLoginIdAsLong(), getMode); + return CzgResult.success(); + } + /** * 获取当前店铺会员信息 diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkShopCouponRecord.java b/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkShopCouponRecord.java index 185dae9e..0649b711 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkShopCouponRecord.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/entity/MkShopCouponRecord.java @@ -56,6 +56,10 @@ public class MkShopCouponRecord implements Serializable { * 卷Id (校验是否可用) */ private Long couponId; + /** + * 优惠券同步id + */ + private Long couponSyncId; /** * 卷描述 满10减2/商品卷 diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopCouponService.java b/cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopCouponService.java index 1ffa6465..a9ac5047 100644 --- a/cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopCouponService.java +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/service/ShopCouponService.java @@ -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 { Page getCouponPage(ShopCouponDTO param); + List getPopUp(Long shopId, Long userId, String getMode); + + void receivePopUp(Long shopId, Long userId, String getMode); + ShopCouponDTO getCouponById(Long id); void addCoupon(ShopCouponDTO param); diff --git a/cash-common/cash-common-service/src/main/java/com/czg/market/vo/ShopCouponPopUp.java b/cash-common/cash-common-service/src/main/java/com/czg/market/vo/ShopCouponPopUp.java new file mode 100644 index 00000000..048ccee5 --- /dev/null +++ b/cash-common/cash-common-service/src/main/java/com/czg/market/vo/ShopCouponPopUp.java @@ -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; +} diff --git a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopCouponRecordServiceImpl.java b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopCouponRecordServiceImpl.java index 85c1b362..1f30ac18 100644 --- a/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopCouponRecordServiceImpl.java +++ b/cash-service/market-service/src/main/java/com/czg/service/market/service/impl/MkShopCouponRecordServiceImpl.java @@ -177,6 +177,7 @@ public class MkShopCouponRecordServiceImpl extends ServiceImpl getCouponPage(ShopCouponDTO param) { @@ -77,6 +86,86 @@ public class ShopCouponServiceImpl extends ServiceImpl getPopUp(Long shopId, Long userId, String getMode) { + ShopUser shopUser = shopUserService.getShopUserInfo(shopId, userId); + AssertUtil.isNull(shopUser, "用户不存在"); + List result = new ArrayList<>(); + List 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 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不能为空");