Parcourir la source

优惠券新增相关字段及服务

zhangchen il y a 1 jour
Parent
commit
7767633188

+ 19 - 0
alien-entity/src/main/java/shop/alien/entity/store/LifeDiscountCoupon.java

@@ -106,6 +106,25 @@ public class LifeDiscountCoupon extends Model<LifeDiscountCoupon> {
     @TableField(value = "updated_user_id", fill = FieldFill.INSERT_UPDATE)
     private Integer updatedUserId;
 
+    @ApiModelProperty(value = "指定天数")
+    @TableField("specified_day")
+    private Integer specifiedDay;
+
+    @ApiModelProperty(value = "是否可以叠加其他优惠券使用")
+    @TableField("is_overlay")
+    private Integer isOverlay;
+
+    @ApiModelProperty(value = "是否通用")
+    @TableField("is_common")
+    private Integer isCommon;
+
+    @ApiModelProperty(value = "适用范围,0,适用,1不适用")
+    @TableField("application_scope")
+    private Integer applicationScope;
+
+    @ApiModelProperty(value = "适用范围内容")
+    @TableField("application_scope_value")
+    private String applicationScopeValue;
 
     @Override
     protected Serializable pkVal() {

+ 75 - 0
alien-entity/src/main/java/shop/alien/entity/store/LifeDiscountCouponQuantumRules.java

@@ -0,0 +1,75 @@
+package shop.alien.entity.store;
+
+import com.baomidou.mybatisplus.annotation.*;
+import com.baomidou.mybatisplus.extension.activerecord.Model;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+
+import java.io.Serializable;
+import java.util.Date;
+
+/**
+ * <p>
+ * 优惠券时间段规则表
+ * </p>
+ *
+ * @author zhangchen
+ * @since 2025-08-04
+ */
+@Data
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "LifeDiscountCouponQuantumRules对象", description = "优惠券时间段规则表")
+public class LifeDiscountCouponQuantumRules extends Model<LifeDiscountCouponQuantumRules> {
+
+    private static final long serialVersionUID = 1L;
+
+    @ApiModelProperty(value = "主键")
+    @TableId(value = "id", type = IdType.AUTO)
+    private Integer id;
+
+    @ApiModelProperty(value = "优惠券id")
+    @TableField("discount_coupon_id")
+    private Integer discountCouponId;
+
+    @ApiModelProperty(value = "时间段规则类型(可用时间段:available_time_quantum,不可用时间段:unavailable_time_quantum)")
+    @TableField("time_quantum_type")
+    private String timeQuantumType;
+
+    @ApiModelProperty(value = "删除状态")
+    @TableField("delete_flag")
+    @TableLogic
+    private Integer deleteFlag;
+
+    @ApiModelProperty(value = "创建时间")
+    @TableField(value = "created_time", fill = FieldFill.INSERT)
+    private Date createdTime;
+
+    @ApiModelProperty(value = "更新时间")
+    @TableField(value = "updated_time", fill = FieldFill.INSERT_UPDATE)
+    private Date updatedTime;
+
+    @ApiModelProperty(value = "创建人ID")
+    @TableField(value = "created_user_id", fill = FieldFill.INSERT)
+    private Integer createdUserId;
+
+    @ApiModelProperty(value = "修改人ID")
+    @TableField(value = "updated_user_id", fill = FieldFill.INSERT_UPDATE)
+    private Integer updatedUserId;
+
+    @ApiModelProperty(value = "开始时间段")
+    @TableField(value = "begin_time_quantum", fill = FieldFill.INSERT)
+    private Date beginTimeQuantum;
+
+    @ApiModelProperty(value = "结束时间段")
+    @TableField(value = "end_time_quantum", fill = FieldFill.INSERT)
+    private Date endTimeQuantum;
+    @Override
+    protected Serializable pkVal() {
+        return this.id;
+    }
+
+}

+ 3 - 0
alien-entity/src/main/java/shop/alien/entity/store/LifeDiscountCouponUnavailableRules.java

@@ -64,6 +64,9 @@ public class LifeDiscountCouponUnavailableRules extends Model<LifeDiscountCoupon
     @TableField(value = "updated_user_id", fill = FieldFill.INSERT_UPDATE)
     private Integer updatedUserId;
 
+    @ApiModelProperty(value = "自定义领取规则数量")
+    @TableField("customize_value")
+    private Integer customizeValue;
 
     @Override
     protected Serializable pkVal() {

+ 27 - 1
alien-entity/src/main/java/shop/alien/entity/store/dto/LifeDiscountCouponDto.java

@@ -1,10 +1,12 @@
 package shop.alien.entity.store.dto;
 
+import com.baomidou.mybatisplus.annotation.TableField;
 import io.swagger.annotations.ApiModel;
 import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import shop.alien.entity.store.LifeDiscountCouponQuantumRules;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -74,6 +76,30 @@ public class LifeDiscountCouponDto {
     @ApiModelProperty(value = "节假日禁用规则")
     private List<String> holidayDisabledList;
 
-    @ApiModelProperty(value = "优惠券领取规则  每日一领:day,每周一领:week,每月一领:month,每年一领:year")
+    @ApiModelProperty(value = "指定天数")
+    private Integer specifiedDay;
+
+    @ApiModelProperty(value = "是否可以叠加其他优惠券使用,0,是,1否")
+    private Integer isOverlay;
+
+    @ApiModelProperty(value = "是否通用,0,是,1否")
+    private Integer isCommon;
+
+    @ApiModelProperty(value = "指定时间段可用")
+    private List<LifeDiscountCouponQuantumRules> availableTimeQuantum;
+
+    @ApiModelProperty(value = "自定义时间段不可用")
+    private List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantum;
+
+    @ApiModelProperty(value = "优惠券领取规则  每日一领:day,每周一领:week,每月一领:month,每年一领:year,自定义:customize")
     private String claimRule;
+
+    @ApiModelProperty(value = "自定义领取规则数量")
+    private Integer claimRuleCustomizeValue;
+
+    @ApiModelProperty(value = "适用范围,0,适用,1不适用")
+    private Integer applicationScope;
+
+    @ApiModelProperty(value = "适用范围内容")
+    private String applicationScopeValue;
 }

+ 27 - 1
alien-entity/src/main/java/shop/alien/entity/store/vo/LifeDiscountCouponVo.java

@@ -5,6 +5,7 @@ import io.swagger.annotations.ApiModelProperty;
 import lombok.Data;
 import lombok.EqualsAndHashCode;
 import lombok.experimental.Accessors;
+import shop.alien.entity.store.LifeDiscountCouponQuantumRules;
 
 import java.math.BigDecimal;
 import java.time.LocalDate;
@@ -95,7 +96,7 @@ public class LifeDiscountCouponVo {
     @ApiModelProperty(value = "节假日禁用规则")
     private List<String> holidayDisabledList;
 
-    @ApiModelProperty(value = "优惠券领取规则  每日一领:day,每周一领:week,每月一领:month,每年一领:year")
+    @ApiModelProperty(value = "优惠券领取规则  每日一领:day,每周一领:week,每月一领:month,每年一领:year,自定义:customize")
     private String claimRule;
 
     @ApiModelProperty(value = "店铺名称")
@@ -112,4 +113,29 @@ public class LifeDiscountCouponVo {
 
     @ApiModelProperty(value = "经营板块id(词典表 键为 business_section)")
     private Integer businessSection;
+
+    @ApiModelProperty(value = "自定义领取规则数量")
+    private Integer claimRuleCustomizeValue;
+
+    @ApiModelProperty(value = "适用范围,0,适用,1不适用")
+    private Integer applicationScope;
+
+    @ApiModelProperty(value = "适用范围内容")
+    private String applicationScopeValue;
+
+    @ApiModelProperty(value = "指定天数")
+    private Integer specifiedDay;
+
+    @ApiModelProperty(value = "是否可以叠加其他优惠券使用,0,是,1否")
+    private Integer isOverlay;
+
+    @ApiModelProperty(value = "是否通用,0,是,1否")
+    private Integer isCommon;
+
+    @ApiModelProperty(value = "指定时间段可用")
+    private List<LifeDiscountCouponQuantumRules> availableTimeQuantum;
+
+    @ApiModelProperty(value = "自定义时间段不可用")
+    private List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantum;
+
 }

+ 16 - 0
alien-entity/src/main/java/shop/alien/mapper/LifeDiscountCouponQuantumRulesMapper.java

@@ -0,0 +1,16 @@
+package shop.alien.mapper;
+
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+import shop.alien.entity.store.LifeDiscountCouponQuantumRules;
+
+/**
+ * <p>
+ * 优惠券时间段规则表 Mapper 接口
+ * </p>
+ *
+ * @author zhangchen
+ * @since 2025-02-08
+ */
+public interface LifeDiscountCouponQuantumRulesMapper extends BaseMapper<LifeDiscountCouponQuantumRules> {
+
+}

+ 16 - 0
alien-store/src/main/java/shop/alien/store/service/LifeDiscountCouponQuantumRulesService.java

@@ -0,0 +1,16 @@
+package shop.alien.store.service;
+
+import com.baomidou.mybatisplus.extension.service.IService;
+import shop.alien.entity.store.LifeDiscountCouponQuantumRules;
+
+/**
+ * <p>
+ * 优惠券时间段规则表 服务类
+ * </p>
+ *
+ * @author zhangchen
+ * @since 2025-02-08
+ */
+public interface LifeDiscountCouponQuantumRulesService extends IService<LifeDiscountCouponQuantumRules> {
+
+}

+ 20 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponQuantumRulesServiceImpl.java

@@ -0,0 +1,20 @@
+package shop.alien.store.service.impl;
+
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+import shop.alien.entity.store.LifeDiscountCouponQuantumRules;
+import shop.alien.mapper.LifeDiscountCouponQuantumRulesMapper;
+import shop.alien.store.service.LifeDiscountCouponQuantumRulesService;
+
+/**
+ * <p>
+ * 优惠券禁用规则表 服务实现类
+ * </p>
+ *
+ * @author ssk
+ * @since 2025-02-08
+ */
+@Service
+public class LifeDiscountCouponQuantumRulesServiceImpl extends ServiceImpl<LifeDiscountCouponQuantumRulesMapper, LifeDiscountCouponQuantumRules> implements LifeDiscountCouponQuantumRulesService {
+
+}

+ 67 - 0
alien-store/src/main/java/shop/alien/store/service/impl/LifeDiscountCouponServiceImpl.java

@@ -1,5 +1,6 @@
 package shop.alien.store.service.impl;
 
+import com.alibaba.nacos.common.utils.CollectionUtils;
 import com.aliyun.tea.utils.StringUtils;
 import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
 import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
@@ -16,6 +17,7 @@ import shop.alien.entity.store.vo.LifeCouponStatusVo;
 import shop.alien.entity.store.vo.LifeDiscountCouponStoreFriendVo;
 import shop.alien.entity.store.vo.LifeDiscountCouponVo;
 import shop.alien.mapper.*;
+import shop.alien.store.service.LifeDiscountCouponQuantumRulesService;
 import shop.alien.store.service.LifeDiscountCouponService;
 import shop.alien.util.common.constant.DiscountCouponEnum;
 
@@ -50,6 +52,8 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
 
     private final LifeDiscountCouponUnavailableRulesMapper lifeDiscountCouponUnavailableRulesMapper;
 
+    private final LifeDiscountCouponQuantumRulesMapper lifeDiscountCouponQuantumRulesMapper;
+
     private final LifeDiscountCouponUserMapper lifeDiscountCouponUserMapper;
 
     private final EssentialHolidayComparisonMapper essentialHolidayComparisonMapper;
@@ -60,6 +64,9 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
 
     private final StoreInfoMapper storeInfoMapper;
 
+    private final LifeDiscountCouponQuantumRulesService lifeDiscountCouponQuantumRulesService;
+
+
     @Override
     public boolean addDiscountCoupon(LifeDiscountCouponDto lifeDiscountCouponDto) {
 
@@ -96,8 +103,29 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             });
             //领取规则
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.CLAIM_RULE.getValue());
+            String claimRule = lifeDiscountCouponDto.getClaimRule();
+            //领取规则为自定义时,获取自定义数量
+            if (claimRule != null && claimRule.equals(DiscountCouponEnum.CUSTOMIZE.getValue())){
+                lifeDiscountCouponUnavailableRules.setCustomizeValue(lifeDiscountCouponDto.getClaimRuleCustomizeValue());
+            }
             lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(lifeDiscountCouponDto.getClaimRule());
             lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
+            //指定时间段可用规则
+            List<LifeDiscountCouponQuantumRules> availableTimeQuantumList =  lifeDiscountCouponDto.getAvailableTimeQuantum();
+            if(CollectionUtils.isNotEmpty(availableTimeQuantumList)){
+                availableTimeQuantumList.forEach(availableTimeQuantum->{
+                    availableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
+                });
+                lifeDiscountCouponQuantumRulesService.saveBatch(availableTimeQuantumList);
+            }
+            //自定义时间段不可用规则
+            List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantumList =  lifeDiscountCouponDto.getCustomizeUnavailableTimeQuantum();
+            if(CollectionUtils.isNotEmpty(customizeUnavailableTimeQuantumList)) {
+                customizeUnavailableTimeQuantumList.forEach(customizeUnavailableTimeQuantum->{
+                    customizeUnavailableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
+                });
+                lifeDiscountCouponQuantumRulesService.saveBatch(customizeUnavailableTimeQuantumList);
+            }
         } catch (BeansException e) {
             e.printStackTrace();
             return false;
@@ -137,6 +165,29 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
             lifeDiscountCouponUnavailableRules.setUnavailableRuleType(DiscountCouponEnum.CLAIM_RULE.getValue());
             lifeDiscountCouponUnavailableRules.setUnavailableRuleValue(lifeDiscountCouponDto.getClaimRule());
             lifeDiscountCouponUnavailableRulesMapper.insert(lifeDiscountCouponUnavailableRules);
+
+            // 删除时间段规则信息
+            LambdaQueryWrapper<LifeDiscountCouponQuantumRules> lifeDiscountCouponQuantumRulesLambdaQueryWrapper = new LambdaQueryWrapper<>();
+            lifeDiscountCouponQuantumRulesLambdaQueryWrapper.eq(LifeDiscountCouponQuantumRules::getDiscountCouponId, lifeDiscountCoupon.getId());
+            lifeDiscountCouponUnavailableRulesMapper.delete(queryWrapper);
+
+            //指定时间段可用规则
+            List<LifeDiscountCouponQuantumRules> availableTimeQuantumList =  lifeDiscountCouponDto.getAvailableTimeQuantum();
+            if(CollectionUtils.isNotEmpty(availableTimeQuantumList)){
+                availableTimeQuantumList.forEach(availableTimeQuantum->{
+                    availableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
+                });
+                lifeDiscountCouponQuantumRulesService.saveBatch(availableTimeQuantumList);
+            }
+            //自定义时间段不可用规则
+            List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantumList =  lifeDiscountCouponDto.getCustomizeUnavailableTimeQuantum();
+            if(CollectionUtils.isNotEmpty(customizeUnavailableTimeQuantumList)) {
+                customizeUnavailableTimeQuantumList.forEach(customizeUnavailableTimeQuantum->{
+                    customizeUnavailableTimeQuantum.setDiscountCouponId(lifeDiscountCoupon.getId());
+                });
+                lifeDiscountCouponQuantumRulesService.saveBatch(customizeUnavailableTimeQuantumList);
+            }
+
         } catch (BeansException e) {
             e.printStackTrace();
             return false;
@@ -200,6 +251,22 @@ public class LifeDiscountCouponServiceImpl extends ServiceImpl<LifeDiscountCoupo
         lifeDiscountCouponVo.setHolidayDisabledList(holidayDisabledList);
         lifeDiscountCouponVo.setClaimRule(claimRule);
 
+        // 查询时间段规则信息
+        LambdaQueryWrapper<LifeDiscountCouponQuantumRules> quantumRulesLambdaQueryWrapper = new LambdaQueryWrapper<>();
+        quantumRulesLambdaQueryWrapper.eq(LifeDiscountCouponQuantumRules::getDiscountCouponId, counponId);
+        List<LifeDiscountCouponQuantumRules> lifeDiscountCouponQuantumRulesList = lifeDiscountCouponQuantumRulesMapper.selectList(quantumRulesLambdaQueryWrapper);
+        List<LifeDiscountCouponQuantumRules> availableTimeQuantumList = new ArrayList<>();
+        List<LifeDiscountCouponQuantumRules> customizeUnavailableTimeQuantumList = new ArrayList<>();
+        for(LifeDiscountCouponQuantumRules lifeDiscountCouponQuantumRules : lifeDiscountCouponQuantumRulesList) {
+            if(lifeDiscountCouponQuantumRules.getTimeQuantumType().equals(DiscountCouponEnum.AVAILABLE_TIME_QUANTUM.getValue())) {
+                availableTimeQuantumList.add(lifeDiscountCouponQuantumRules);
+            }
+            if(lifeDiscountCouponQuantumRules.getTimeQuantumType().equals(DiscountCouponEnum.UNAVAILABLE_TIME_QUANTUM.getValue())) {
+                customizeUnavailableTimeQuantumList.add(lifeDiscountCouponQuantumRules);
+            }
+        }
+        lifeDiscountCouponVo.setAvailableTimeQuantum(availableTimeQuantumList);
+        lifeDiscountCouponVo.setCustomizeUnavailableTimeQuantum(customizeUnavailableTimeQuantumList);
         return lifeDiscountCouponVo;
     }
 

+ 8 - 0
alien-util/src/main/java/shop/alien/util/common/constant/DiscountCouponEnum.java

@@ -40,6 +40,14 @@ public enum DiscountCouponEnum {
     MONTH("MONTH"),
     //每年一领
     YEAR("year"),
+    //自定义
+    CUSTOMIZE("customize"),
+
+    /**时间段规则*/
+    //可用时间段
+    AVAILABLE_TIME_QUANTUM("available_time_quantum"),
+    //不可用时间段
+    UNAVAILABLE_TIME_QUANTUM("unavailable_time_quantum"),
 
     /**条件类型*/
     //所有