promotion:实现部分优惠劵模板的前端列表
parent
3c10058dbd
commit
dc51a93533
|
@ -15,8 +15,8 @@ import java.util.Arrays;
|
||||||
@AllArgsConstructor
|
@AllArgsConstructor
|
||||||
public enum PromotionDiscountTypeEnum implements IntArrayValuable {
|
public enum PromotionDiscountTypeEnum implements IntArrayValuable {
|
||||||
|
|
||||||
PRICE(1, "减价"), // 具体金额
|
PRICE(1, "满减"), // 具体金额
|
||||||
PERCENT(2, "打折"), // 百分比
|
PERCENT(2, "折扣"), // 百分比
|
||||||
;
|
;
|
||||||
|
|
||||||
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionDiscountTypeEnum::getType).toArray();
|
public static final int[] ARRAYS = Arrays.stream(values()).mapToInt(PromotionDiscountTypeEnum::getType).toArray();
|
||||||
|
|
|
@ -24,7 +24,7 @@ public class CouponTemplateRespVO extends CouponTemplateBaseVO {
|
||||||
private Integer status;
|
private Integer status;
|
||||||
|
|
||||||
@ApiModelProperty(value = "领取优惠券的数量", required = true, example = "1024")
|
@ApiModelProperty(value = "领取优惠券的数量", required = true, example = "1024")
|
||||||
private Integer takeNum;
|
private Integer takeCount;
|
||||||
|
|
||||||
@ApiModelProperty(value = "使用优惠券的次数", required = true, example = "2048")
|
@ApiModelProperty(value = "使用优惠券的次数", required = true, example = "2048")
|
||||||
private Integer useCount;
|
private Integer useCount;
|
||||||
|
|
|
@ -105,6 +105,12 @@ public class CouponTemplateDO extends BaseDO {
|
||||||
* 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#DATE}
|
* 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#DATE}
|
||||||
*/
|
*/
|
||||||
private Date validEndTime;
|
private Date validEndTime;
|
||||||
|
/**
|
||||||
|
* 领取日期 - 开始天数
|
||||||
|
*
|
||||||
|
* 当 {@link #validityType} 为 {@link CouponTemplateValidityTypeEnum#TERM}
|
||||||
|
*/
|
||||||
|
private Integer fixedStartTerm;
|
||||||
/**
|
/**
|
||||||
* 领取日期 - 结束天数
|
* 领取日期 - 结束天数
|
||||||
*
|
*
|
||||||
|
|
|
@ -1,30 +1,26 @@
|
||||||
package cn.iocoder.yudao.module.promotion.service.coupon;
|
package cn.iocoder.yudao.module.promotion.service.coupon;
|
||||||
|
|
||||||
import org.junit.jupiter.api.Disabled;
|
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
||||||
import org.junit.jupiter.api.Test;
|
|
||||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
|
||||||
|
|
||||||
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
import cn.iocoder.yudao.framework.test.core.ut.BaseDbUnitTest;
|
||||||
|
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateCreateReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.*;
|
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplatePageReqVO;
|
||||||
|
import cn.iocoder.yudao.module.promotion.controller.admin.coupon.vo.CouponTemplateUpdateReqVO;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
|
import cn.iocoder.yudao.module.promotion.dal.dataobject.coupon.CouponTemplateDO;
|
||||||
import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper;
|
import cn.iocoder.yudao.module.promotion.dal.mysql.coupon.CouponTemplateMapper;
|
||||||
import cn.iocoder.yudao.framework.common.pojo.PageResult;
|
import org.junit.jupiter.api.Disabled;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.springframework.context.annotation.Import;
|
||||||
|
|
||||||
import javax.annotation.Resource;
|
import javax.annotation.Resource;
|
||||||
import org.springframework.context.annotation.Import;
|
import java.util.Date;
|
||||||
import java.util.*;
|
|
||||||
|
|
||||||
import static cn.hutool.core.util.RandomUtil.*;
|
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.cloneIgnoreId;
|
||||||
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.*;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertPojoEquals;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.*;
|
import static cn.iocoder.yudao.framework.test.core.util.AssertUtils.assertServiceException;
|
||||||
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*;
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomLongId;
|
||||||
import static cn.iocoder.yudao.framework.common.util.object.ObjectUtils.*;
|
import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.randomPojo;
|
||||||
import static cn.iocoder.yudao.framework.common.util.date.DateUtils.*;
|
import static cn.iocoder.yudao.module.promotion.enums.ErrorCodeConstants.COUPON_TEMPLATE_NOT_EXISTS;
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.mockito.Mockito.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link CouponTemplateServiceImpl} 的单元测试类
|
* {@link CouponTemplateServiceImpl} 的单元测试类
|
||||||
|
@ -110,7 +106,7 @@ public class CouponTemplateServiceImplTest extends BaseDbUnitTest {
|
||||||
CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class, o -> { // 等会查询到
|
CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class, o -> { // 等会查询到
|
||||||
o.setName(null);
|
o.setName(null);
|
||||||
o.setStatus(null);
|
o.setStatus(null);
|
||||||
o.setType(null);
|
o.setDiscountType(null);
|
||||||
o.setCreateTime(null);
|
o.setCreateTime(null);
|
||||||
});
|
});
|
||||||
couponTemplateMapper.insert(dbCouponTemplate);
|
couponTemplateMapper.insert(dbCouponTemplate);
|
||||||
|
@ -119,14 +115,14 @@ public class CouponTemplateServiceImplTest extends BaseDbUnitTest {
|
||||||
// 测试 status 不匹配
|
// 测试 status 不匹配
|
||||||
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setStatus(null)));
|
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setStatus(null)));
|
||||||
// 测试 type 不匹配
|
// 测试 type 不匹配
|
||||||
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setType(null)));
|
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setDiscountType(null)));
|
||||||
// 测试 createTime 不匹配
|
// 测试 createTime 不匹配
|
||||||
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setCreateTime(null)));
|
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setCreateTime(null)));
|
||||||
// 准备参数
|
// 准备参数
|
||||||
CouponTemplatePageReqVO reqVO = new CouponTemplatePageReqVO();
|
CouponTemplatePageReqVO reqVO = new CouponTemplatePageReqVO();
|
||||||
reqVO.setName(null);
|
reqVO.setName(null);
|
||||||
reqVO.setStatus(null);
|
reqVO.setStatus(null);
|
||||||
reqVO.setType(null);
|
reqVO.setDiscountType(null);
|
||||||
reqVO.setCreateTime((new Date[]{}));
|
reqVO.setCreateTime((new Date[]{}));
|
||||||
|
|
||||||
// 调用
|
// 调用
|
||||||
|
@ -137,37 +133,4 @@ public class CouponTemplateServiceImplTest extends BaseDbUnitTest {
|
||||||
assertPojoEquals(dbCouponTemplate, pageResult.getList().get(0));
|
assertPojoEquals(dbCouponTemplate, pageResult.getList().get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
@Disabled // TODO 请修改 null 为需要的值,然后删除 @Disabled 注解
|
|
||||||
public void testGetCouponTemplateList() {
|
|
||||||
// mock 数据
|
|
||||||
CouponTemplateDO dbCouponTemplate = randomPojo(CouponTemplateDO.class, o -> { // 等会查询到
|
|
||||||
o.setName(null);
|
|
||||||
o.setStatus(null);
|
|
||||||
o.setType(null);
|
|
||||||
o.setCreateTime(null);
|
|
||||||
});
|
|
||||||
couponTemplateMapper.insert(dbCouponTemplate);
|
|
||||||
// 测试 name 不匹配
|
|
||||||
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setName(null)));
|
|
||||||
// 测试 status 不匹配
|
|
||||||
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setStatus(null)));
|
|
||||||
// 测试 type 不匹配
|
|
||||||
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setType(null)));
|
|
||||||
// 测试 createTime 不匹配
|
|
||||||
couponTemplateMapper.insert(cloneIgnoreId(dbCouponTemplate, o -> o.setCreateTime(null)));
|
|
||||||
// 准备参数
|
|
||||||
CouponTemplateExportReqVO reqVO = new CouponTemplateExportReqVO();
|
|
||||||
reqVO.setName(null);
|
|
||||||
reqVO.setStatus(null);
|
|
||||||
reqVO.setType(null);
|
|
||||||
reqVO.setCreateTime((new Date[]{}));
|
|
||||||
|
|
||||||
// 调用
|
|
||||||
List<CouponTemplateDO> list = couponTemplateService.getCouponTemplateList(reqVO);
|
|
||||||
// 断言
|
|
||||||
assertEquals(1, list.size());
|
|
||||||
assertPojoEquals(dbCouponTemplate, list.get(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -236,3 +236,31 @@ export const ProductSpuStatusEnum = {
|
||||||
name: '上架'
|
name: '上架'
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠类型枚举
|
||||||
|
*/
|
||||||
|
export const PromotionDiscountTypeEnum = {
|
||||||
|
PRICE: {
|
||||||
|
type: 1,
|
||||||
|
name: '满减'
|
||||||
|
},
|
||||||
|
PERCENT: {
|
||||||
|
type: 2,
|
||||||
|
name: '折扣'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠劵模板的有限期类型的枚举
|
||||||
|
*/
|
||||||
|
export const CouponTemplateValidityTypeEnum = {
|
||||||
|
DATE: {
|
||||||
|
type: 1,
|
||||||
|
name: '固定日期可用'
|
||||||
|
},
|
||||||
|
TERM: {
|
||||||
|
type: 2,
|
||||||
|
name: '领取之后可用'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -59,6 +59,9 @@ export const DICT_TYPE = {
|
||||||
|
|
||||||
// ========== MALL - PRODUCT 模块 ==========
|
// ========== MALL - PRODUCT 模块 ==========
|
||||||
PRODUCT_SPU_STATUS: 'product_spu_status', // 商品 SPU 状态
|
PRODUCT_SPU_STATUS: 'product_spu_status', // 商品 SPU 状态
|
||||||
|
|
||||||
|
// ========== MALL - PROMOTION 模块 ==========
|
||||||
|
PROMOTION_DISCOUNT_TYPE: 'promotion_discount_type', // 优惠类型
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -2,25 +2,19 @@
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
|
|
||||||
<!-- 搜索工作栏 -->
|
<!-- 搜索工作栏 -->
|
||||||
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
|
<el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="82px">
|
||||||
<el-form-item label="优惠劵名" prop="name">
|
<el-form-item label="优惠券名称" prop="name">
|
||||||
<el-input v-model="queryParams.name" placeholder="请输入优惠劵名" clearable @keyup.enter.native="handleQuery"/>
|
<el-input v-model="queryParams.name" placeholder="请输入优惠劵名" clearable @keyup.enter.native="handleQuery"/>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="状态" prop="status">
|
<el-form-item label="优惠券类型" prop="discountType">
|
||||||
<el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
|
<el-select v-model="queryParams.discountType" placeholder="请选择优惠券类型" clearable size="small">
|
||||||
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
|
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.PROMOTION_DISCOUNT_TYPE)"
|
||||||
:key="dict.value" :label="dict.label" :value="dict.value"/>
|
:key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
<el-form-item label="类型
|
<el-form-item label="优惠券状态" prop="status">
|
||||||
*
|
<el-select v-model="queryParams.status" placeholder="请选择优惠券状态" clearable size="small">
|
||||||
* 1-优惠劵
|
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.COMMON_STATUS)"
|
||||||
* 2-优惠码" prop="type">
|
|
||||||
<el-select v-model="queryParams.type" placeholder="请选择类型
|
|
||||||
*
|
|
||||||
* 1-优惠劵
|
|
||||||
* 2-优惠码" clearable size="small">
|
|
||||||
<el-option v-for="dict in this.getDictDatas(DICT_TYPE.PRODUCT_SPU_STATUS)"
|
|
||||||
:key="dict.value" :label="dict.label" :value="dict.value"/>
|
:key="dict.value" :label="dict.label" :value="dict.value"/>
|
||||||
</el-select>
|
</el-select>
|
||||||
</el-form-item>
|
</el-form-item>
|
||||||
|
@ -48,45 +42,24 @@
|
||||||
<el-table-column label="优惠券名称" align="center" prop="name" />
|
<el-table-column label="优惠券名称" align="center" prop="name" />
|
||||||
<el-table-column label="优惠券类型" align="center" prop="discountType">
|
<el-table-column label="优惠券类型" align="center" prop="discountType">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<dict-tag :type="DICT_TYPE.PRODUCT_SPU_STATUS" :value="scope.row.type" />
|
<dict-tag :type="DICT_TYPE.PROMOTION_DISCOUNT_TYPE" :value="scope.row.discountType" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="发行总量" align="center" prop="totalCount" />
|
<el-table-column label="优惠金额 / 折扣" align="center" prop="discount" :formatter="discountFormat" />
|
||||||
<el-table-column label="每人限领个数
|
<el-table-column label="发放数量" align="center" prop="totalCount" />
|
||||||
*
|
<el-table-column label="剩余数量" align="center" prop="totalCount" :formatter="row => (row.totalCount - row.takeCount)" />
|
||||||
* null - 则表示不限制" align="center" prop="takeLimitCount" />
|
<el-table-column label="领取上限" align="center" prop="takeLimitCount" :formatter="takeLimitCountFormat" />
|
||||||
<el-table-column label="领取方式" align="center" prop="takeType" />
|
<el-table-column label="有效期限" align="center" prop="validityType" width="180" :formatter="validityTypeFormat" />
|
||||||
<el-table-column label="是否设置满多少金额可用,单位:分" align="center" prop="usePrice" />
|
<el-table-column label="状态" align="center" prop="status">
|
||||||
<el-table-column label="商品范围" align="center" prop="productScope" />
|
|
||||||
<el-table-column label="商品 SPU 编号的数组" align="center" prop="productSpuIds" />
|
|
||||||
<el-table-column label="生效日期类型" align="center" prop="validityType" />
|
|
||||||
<el-table-column label="固定日期-生效开始时间" align="center" prop="validStartTime" width="180">
|
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.validStartTime) }}</span>
|
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="固定日期-生效结束时间" align="center" prop="validEndTime" width="180">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<span>{{ parseTime(scope.row.validEndTime) }}</span>
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="领取日期-开始天数" align="center" prop="fixedStartTerm" />
|
|
||||||
<el-table-column label="领取日期-结束天数" align="center" prop="fixedEndTerm" />
|
|
||||||
<el-table-column label="折扣百分比" align="center" prop="discountPercent" />
|
|
||||||
<el-table-column label="优惠金额,单位:分" align="center" prop="discountPrice" />
|
|
||||||
<el-table-column label="折扣上限" />
|
|
||||||
<el-table-column label="领取优惠券的数量" align="center" prop="takeNum" />
|
|
||||||
<el-table-column label="使用优惠券的次数" align="center" prop="useCount" />
|
|
||||||
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
<el-table-column label="创建时间" align="center" prop="createTime" width="180">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<span>{{ parseTime(scope.row.createTime) }}</span>
|
<span>{{ parseTime(scope.row.createTime) }}</span>
|
||||||
</template>
|
</template>
|
||||||
</el-table-column>
|
</el-table-column>
|
||||||
<el-table-column label="优惠券类型" align="center" prop="status">
|
|
||||||
<template slot-scope="scope">
|
|
||||||
<dict-tag :type="DICT_TYPE.COMMON_STATUS" :value="scope.row.status" />
|
|
||||||
</template>
|
|
||||||
</el-table-column>
|
|
||||||
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
<el-table-column label="操作" align="center" class-name="small-padding fixed-width">
|
||||||
<template slot-scope="scope">
|
<template slot-scope="scope">
|
||||||
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
|
<el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)"
|
||||||
|
@ -185,7 +158,8 @@
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { createCouponTemplate, updateCouponTemplate, deleteCouponTemplate, getCouponTemplate, getCouponTemplatePage, exportCouponTemplateExcel } from "@/api/promotion/couponTemplate";
|
import { createCouponTemplate, updateCouponTemplate, deleteCouponTemplate, getCouponTemplate, getCouponTemplatePage } from "@/api/promotion/couponTemplate";
|
||||||
|
import {CouponTemplateValidityTypeEnum, PromotionDiscountTypeEnum} from "@/utils/constants";
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
name: "CouponTemplate",
|
name: "CouponTemplate",
|
||||||
|
@ -340,6 +314,33 @@ export default {
|
||||||
this.$modal.msgSuccess("删除成功");
|
this.$modal.msgSuccess("删除成功");
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
},
|
},
|
||||||
|
// 格式化【优惠金额/折扣】
|
||||||
|
discountFormat(row, column) {
|
||||||
|
if (row.discountType === PromotionDiscountTypeEnum.PRICE.type) {
|
||||||
|
return `¥${(row.discountPrice / 100.0).toFixed(2)}`;
|
||||||
|
}
|
||||||
|
if (row.discountType === PromotionDiscountTypeEnum.PERCENT.type) {
|
||||||
|
return `¥${(row.discountPrice / 100.0).toFixed(2)}`;
|
||||||
|
}
|
||||||
|
return '未知【' + row.discountType + '】';
|
||||||
|
},
|
||||||
|
// 格式化【领取上限】
|
||||||
|
takeLimitCountFormat(row, column) {
|
||||||
|
if (row.takeLimitCount === -1) {
|
||||||
|
return '无领取限制';
|
||||||
|
}
|
||||||
|
return `${row.takeLimitCount} 张/人`
|
||||||
|
},
|
||||||
|
// 格式化【有效期限】
|
||||||
|
validityTypeFormat(row, column) {
|
||||||
|
if (row.validityType === CouponTemplateValidityTypeEnum.DATE.type) {
|
||||||
|
return `${parseTime(row.validStartTime)} 至 ${parseTime(row.validEndTime)}`
|
||||||
|
}
|
||||||
|
if (row.validityType === CouponTemplateValidityTypeEnum.TERM.type) {
|
||||||
|
return `领取后第 ${row.fixedStartTerm} - ${row.fixedEndTerm} 天内可用`
|
||||||
|
}
|
||||||
|
return '未知【' + row.validityType + '】';
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
</script>
|
</script>
|
||||||
|
|
Loading…
Reference in New Issue