后端 + 前端:优惠劵模板添加(未完成)
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
package cn.iocoder.mall.promotion.biz.convert;
|
||||
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
|
||||
import cn.iocoder.mall.promotion.api.dto.CouponCardTemplateAddDTO;
|
||||
import cn.iocoder.mall.promotion.api.dto.CouponCodeTemplateAddDTO;
|
||||
import cn.iocoder.mall.promotion.biz.dataobject.CouponTemplateDO;
|
||||
import org.mapstruct.Mapper;
|
||||
import org.mapstruct.Mappings;
|
||||
import org.mapstruct.factory.Mappers;
|
||||
|
||||
@Mapper
|
||||
public interface CouponTemplateConvert {
|
||||
|
||||
CouponTemplateConvert INSTANCE = Mappers.getMapper(CouponTemplateConvert.class);
|
||||
|
||||
// @Mappings({})
|
||||
// CouponTemplateBO convertToBO(CouponTemplateDO banner);
|
||||
//
|
||||
// @Mappings({})
|
||||
// List<CouponTemplateBO> convertToBO(List<CouponTemplateDO> bannerList);
|
||||
|
||||
@Mappings({})
|
||||
CouponTemplateDO convert(CouponCodeTemplateAddDTO template);
|
||||
|
||||
@Mappings({})
|
||||
CouponTemplateDO convert(CouponCardTemplateAddDTO template);
|
||||
|
||||
@Mappings({})
|
||||
CouponTemplateBO convert(CouponTemplateDO template);
|
||||
|
||||
}
|
||||
@@ -195,7 +195,7 @@ public class CouponTemplateDO extends BaseDO {
|
||||
private Integer discountPriceLimit;
|
||||
// ========== 使用效果 END ==========
|
||||
|
||||
// // ========== 统计信息 BEGIN ==========
|
||||
// ========== 统计信息 BEGIN ==========
|
||||
// /**
|
||||
// * 领取优惠券的人数
|
||||
// */
|
||||
@@ -208,6 +208,186 @@ public class CouponTemplateDO extends BaseDO {
|
||||
// * 使用优惠券的次数
|
||||
// */
|
||||
// private Integer statUseNum;
|
||||
// // ========== 统计信息 END ==========
|
||||
// ========== 统计信息 END ==========
|
||||
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setId(Integer id) {
|
||||
this.id = id;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setTitle(String title) {
|
||||
this.title = title;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setDescription(String description) {
|
||||
this.description = description;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getType() {
|
||||
return type;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setType(Integer type) {
|
||||
this.type = type;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getCodeType() {
|
||||
return codeType;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setCodeType(Integer codeType) {
|
||||
this.codeType = codeType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getStatus() {
|
||||
return status;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setStatus(Integer status) {
|
||||
this.status = status;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getQuota() {
|
||||
return quota;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setQuota(Integer quota) {
|
||||
this.quota = quota;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setStock(Integer stock) {
|
||||
this.stock = stock;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPriceAvailable() {
|
||||
return priceAvailable;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setPriceAvailable(Integer priceAvailable) {
|
||||
this.priceAvailable = priceAvailable;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getRangeType() {
|
||||
return rangeType;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setRangeType(Integer rangeType) {
|
||||
this.rangeType = rangeType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public String getRangeValues() {
|
||||
return rangeValues;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setRangeValues(String rangeValues) {
|
||||
this.rangeValues = rangeValues;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getDateType() {
|
||||
return dateType;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setDateType(Integer dateType) {
|
||||
this.dateType = dateType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getValidStartTime() {
|
||||
return validStartTime;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setValidStartTime(Date validStartTime) {
|
||||
this.validStartTime = validStartTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Date getValidEndTime() {
|
||||
return validEndTime;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setValidEndTime(Date validEndTime) {
|
||||
this.validEndTime = validEndTime;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getFixedTerm() {
|
||||
return fixedTerm;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setFixedTerm(Integer fixedTerm) {
|
||||
this.fixedTerm = fixedTerm;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPreferentialType() {
|
||||
return preferentialType;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setPreferentialType(Integer preferentialType) {
|
||||
this.preferentialType = preferentialType;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPercentOff() {
|
||||
return percentOff;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setPercentOff(Integer percentOff) {
|
||||
this.percentOff = percentOff;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPriceOff() {
|
||||
return priceOff;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setPriceOff(Integer priceOff) {
|
||||
this.priceOff = priceOff;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getDiscountPriceLimit() {
|
||||
return discountPriceLimit;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setDiscountPriceLimit(Integer discountPriceLimit) {
|
||||
this.discountPriceLimit = discountPriceLimit;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getStatFetchNum() {
|
||||
return statFetchNum;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setStatFetchNum(Integer statFetchNum) {
|
||||
this.statFetchNum = statFetchNum;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package cn.iocoder.mall.promotion.biz.dataobject;
|
||||
|
||||
import cn.iocoder.common.framework.dataobject.DeletableDO;
|
||||
import cn.iocoder.mall.promotion.api.constant.ProductRecommendTypeEnum;
|
||||
|
||||
/**
|
||||
* 商品推荐 DO
|
||||
@@ -14,7 +15,7 @@ public class ProductRecommendDO extends DeletableDO {
|
||||
/**
|
||||
* 类型
|
||||
*
|
||||
* {@link cn.iocoder.mall.promotion.api.constant.ProductRecommendType}
|
||||
* {@link ProductRecommendTypeEnum}
|
||||
*/
|
||||
private Integer type;
|
||||
/**
|
||||
@@ -91,4 +92,4 @@ public class ProductRecommendDO extends DeletableDO {
|
||||
return this;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,137 @@
|
||||
package cn.iocoder.mall.promotion.biz.service;
|
||||
|
||||
public class CouponServiceImpl {
|
||||
import cn.iocoder.common.framework.constant.SysErrorCodeEnum;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.CouponService;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponCardBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplatePageBO;
|
||||
import cn.iocoder.mall.promotion.api.constant.CouponTemplateDateTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.constant.CouponTemplatePreferentialTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.constant.CouponTemplateStatusEnum;
|
||||
import cn.iocoder.mall.promotion.api.constant.CouponTemplateTypeEnum;
|
||||
import cn.iocoder.mall.promotion.api.dto.*;
|
||||
import cn.iocoder.mall.promotion.biz.convert.CouponTemplateConvert;
|
||||
import cn.iocoder.mall.promotion.biz.dao.CouponTemplateMapper;
|
||||
import cn.iocoder.mall.promotion.biz.dataobject.CouponTemplateDO;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@Service // 实际上不用添加。添加的原因是,必须 Spring 报错提示
|
||||
@com.alibaba.dubbo.config.annotation.Service(validation = "true")
|
||||
public class CouponServiceImpl implements CouponService {
|
||||
|
||||
@Autowired
|
||||
private CouponTemplateMapper couponTemplateMapper;
|
||||
|
||||
@Override
|
||||
public CommonResult<CouponTemplatePageBO> getCouponTemplatePage(CouponTemplatePageDTO couponTemplatePageDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<CouponTemplateBO> addCouponCodeTemplate(CouponCodeTemplateAddDTO couponCodeTemplateAddDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<CouponTemplateBO> addCouponCardTemplate(CouponCardTemplateAddDTO couponCardTemplateAddDTO) {
|
||||
// 校验生效日期相关
|
||||
CommonResult<Boolean> checkCouponCodeTemplateDateTypeResult = this.checkCouponTemplateDateType(
|
||||
couponCardTemplateAddDTO.getDateType(),
|
||||
couponCardTemplateAddDTO.getValidStartTime(), couponCardTemplateAddDTO.getValidEndTime(),
|
||||
couponCardTemplateAddDTO.getFixedBeginTerm(), couponCardTemplateAddDTO.getFixedEndTerm());
|
||||
if (checkCouponCodeTemplateDateTypeResult.isError()) {
|
||||
return CommonResult.error(checkCouponCodeTemplateDateTypeResult);
|
||||
}
|
||||
// 校验优惠类型
|
||||
CommonResult<Boolean> checkCouponTemplateDateTypeResult = this.checkCouponTemplatePreferentialType(
|
||||
couponCardTemplateAddDTO.getPreferentialType(), couponCardTemplateAddDTO.getPercentOff(),
|
||||
couponCardTemplateAddDTO.getPriceOff());
|
||||
if (checkCouponCodeTemplateDateTypeResult.isError()) {
|
||||
return CommonResult.error(checkCouponTemplateDateTypeResult);
|
||||
}
|
||||
// 保存优惠劵模板到数据库
|
||||
CouponTemplateDO template = CouponTemplateConvert.INSTANCE.convert(couponCardTemplateAddDTO)
|
||||
.setType(CouponTemplateTypeEnum.CARD.getValue())
|
||||
.setStatus(CouponTemplateStatusEnum.ENABLE.getValue())
|
||||
.setStatFetchNum(0);
|
||||
couponTemplateMapper.insert(template);
|
||||
// 返回成功
|
||||
return CommonResult.success(CouponTemplateConvert.INSTANCE.convert(template));
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateCouponCodeTemplate(CouponCodeTemplateUpdateDTO couponCodeTemplateUpdateDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateCouponCardTemplate(CouponCardTemplateUpdateDTO couponCardTemplateUpdateDTO) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> updateCouponTemplateStatus(Integer adminId, Integer couponTemplateId, Integer status) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<CouponCardBO> addCouponCard(Integer userId, Integer couponTemplateId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> useCouponCard(Integer userId, Integer couponCardId, Integer usedOrderId, Integer usedPrice) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<Boolean> cancelUseCouponCard(Integer userId, Integer couponCardId) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public CommonResult<CouponCardBO> useCouponCode(Integer userId, String code) {
|
||||
return null;
|
||||
}
|
||||
|
||||
private CommonResult<Boolean> checkCouponTemplateDateType(Integer dateType, Date validStartTime, Date validEndTime, Integer fixedBeginTerm, Integer fixedEndTerm) {
|
||||
if (CouponTemplateDateTypeEnum.FIXED_DATE.getValue().equals(dateType)) { // 固定日期
|
||||
if (validStartTime == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "生效开始时间不能为空");
|
||||
}
|
||||
if (validEndTime == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "生效结束时间不能为空");
|
||||
}
|
||||
} else if (CouponTemplateDateTypeEnum.FIXED_TERM.getValue().equals(dateType)) { // 领取日期
|
||||
if (fixedBeginTerm == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "领取日期开始时间不能为空");
|
||||
}
|
||||
if (fixedEndTerm == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "领取日期结束时间不能为空");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("未知的生效日期类型:" + dateType);
|
||||
}
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
private CommonResult<Boolean> checkCouponTemplatePreferentialType(Integer preferentialType, Integer percentOff, Integer priceOff) {
|
||||
if (CouponTemplatePreferentialTypeEnum.PRICE.getValue().equals(preferentialType)) {
|
||||
if (priceOff == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "优惠金额不能为空");
|
||||
}
|
||||
} else if (CouponTemplatePreferentialTypeEnum.DISCOUNT.getValue().equals(preferentialType)) {
|
||||
if (percentOff == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "折扣百分比不能为空");
|
||||
}
|
||||
} else {
|
||||
throw new IllegalArgumentException("未知的优惠类型:" + preferentialType);
|
||||
}
|
||||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -72,15 +72,15 @@
|
||||
<insert id="insert" parameterType="CouponTemplateDO" useGeneratedKeys="true" keyColumn="id" keyProperty="id">
|
||||
INSERT INTO coupon_template (
|
||||
title, description, type, code_type,
|
||||
status, quota, stock, price_available, range_type,
|
||||
status, quota, total, price_available, range_type,
|
||||
range_values, date_type, valid_start_time, valid_end_time, fixed_term,
|
||||
preferential_type, percent_off, price_off, discount_price_limit, stat_fetch_num,
|
||||
create_time
|
||||
) VALUES (
|
||||
#{title}, #{description, #{type, #{code_type},
|
||||
#{status}, #{quota, #{stock}, #{priceAvailable}, #{rangeType},
|
||||
#{rangeValues}, #{dateType}, #{validStartTime}, #{validEndTime, #{fixedTerm},
|
||||
#{preferentialType, #{percentOff}, #{priceOff}, #{discountPriceLimit}, #{statFetchNum},
|
||||
#{title}, #{description}, #{type}, #{codeType},
|
||||
#{status}, #{quota}, #{total}, #{priceAvailable}, #{rangeType},
|
||||
#{rangeValues}, #{dateType}, #{validStartTime}, #{validEndTime}, #{fixedTerm},
|
||||
#{preferentialType}, #{percentOff}, #{priceOff}, #{discountPriceLimit}, #{statFetchNum},
|
||||
#{createTime}
|
||||
)
|
||||
</insert>
|
||||
@@ -104,37 +104,37 @@
|
||||
stock = #{stock},
|
||||
</if>
|
||||
<if test="priceAvailable != null">
|
||||
price_available = #{priceAvailable}
|
||||
price_available = #{priceAvailable},
|
||||
</if>
|
||||
<if test="rangeType != null">
|
||||
range_type = #{rangeType}
|
||||
range_type = #{rangeType},
|
||||
</if>
|
||||
<if test="rangeValues != null">
|
||||
range_values = #{rangeValues}
|
||||
range_values = #{rangeValues},
|
||||
</if>
|
||||
<if test="dateType != null">
|
||||
date_type = #{dateType}
|
||||
date_type = #{dateType},
|
||||
</if>
|
||||
<if test="validStartTime != null">
|
||||
valid_start_time = #{validStartTime}
|
||||
valid_start_time = #{validStartTime},
|
||||
</if>
|
||||
<if test="validEndTime != null">
|
||||
valid_end_time = #{validEndTime}
|
||||
valid_end_time = #{validEndTime},
|
||||
</if>
|
||||
<if test="fixedTerm != null">
|
||||
fixed_term = #{fixedTerm}
|
||||
fixed_term = #{fixedTerm},
|
||||
</if>
|
||||
<if test="preferentialType != null">
|
||||
preferential_type = #{preferentialType}
|
||||
preferential_type = #{preferentialType},
|
||||
</if>
|
||||
<if test="percentOff != null">
|
||||
percent_off = #{percentOff}
|
||||
percent_off = #{percentOff},
|
||||
</if>
|
||||
<if test="priceOff != null">
|
||||
price_off = #{priceOff}
|
||||
price_off = #{priceOff},
|
||||
</if>
|
||||
<if test="discountPriceLimit != null">
|
||||
discount_price_limit = #{discountPriceLimit}
|
||||
discount_price_limit = #{discountPriceLimit},
|
||||
</if>
|
||||
</set>
|
||||
WHERE id = #{id}
|
||||
|
||||
Reference in New Issue
Block a user