后端 + 前端:优惠劵模板添加
This commit is contained in:
parent
f6c847d104
commit
8418641731
|
@ -105,7 +105,7 @@ export default class BaseMenu extends PureComponent {
|
|||
onClick={
|
||||
isMobile
|
||||
? () => {
|
||||
onCollapse(true);
|
||||
onCollapsetrue;
|
||||
}
|
||||
: undefined
|
||||
}
|
||||
|
|
|
@ -220,11 +220,12 @@ const AddOrUpdateForm = Form.create()(props => {
|
|||
if (err) return;
|
||||
let newFileds = {
|
||||
...fields,
|
||||
priceAvailable: fields['priceAvailable'] ? parseInt(fields.priceAvailable * 100) : undefined,
|
||||
priceOff: fields['priceOff'] ? parseInt(fields.priceOff * 100) : undefined,
|
||||
discountPriceLimit: fields['discountPriceLimit'] ? parseInt(fields.discountPriceLimit * 100) : undefined,
|
||||
}
|
||||
debugger;
|
||||
priceAvailable: fields.priceAvailable ? parseInt(fields.priceAvailable * 100) : undefined,
|
||||
priceOff: fields.priceOff ? parseInt(fields.priceOff * 100) : undefined,
|
||||
discountPriceLimit: fields.discountPriceLimit ? parseInt(fields.discountPriceLimit * 100) : undefined,
|
||||
validStartTime: fields.validStartTime ? fields.validStartTime.format('YYYY-MM-DD') : undefined,
|
||||
validEndTime: fields.validEndTime ? fields.validEndTime.format('YYYY-MM-DD') : undefined
|
||||
};
|
||||
// 添加表单
|
||||
if (modalType === 'add') {
|
||||
dispatch({
|
||||
|
@ -291,7 +292,8 @@ const AddOrUpdateForm = Form.create()(props => {
|
|||
>
|
||||
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="标题">
|
||||
{form.getFieldDecorator('title', {
|
||||
rules: [{ required: true, message: '请输入标题!' }],
|
||||
rules: [{ required: true, message: '请输入标题!' },
|
||||
{max: 16, min:2, message: '长度为 2-16 位'},],
|
||||
initialValue: formVals.title,
|
||||
})(<Input placeholder="请输入" />)}
|
||||
</FormItem>
|
||||
|
@ -310,7 +312,6 @@ const AddOrUpdateForm = Form.create()(props => {
|
|||
initialValue: formVals.quota,
|
||||
})(
|
||||
<Select placeholder="请选择" style={{ maxWidth: 200, width: '100%' }}>
|
||||
<SelectOption value="">不限次数</SelectOption>
|
||||
<SelectOption value="1">1 次</SelectOption>
|
||||
<SelectOption value="2">2 次</SelectOption>
|
||||
<SelectOption value="3">3 次</SelectOption>
|
||||
|
@ -391,12 +392,14 @@ const AddOrUpdateForm = Form.create()(props => {
|
|||
formVals.dateType == 2 ?
|
||||
<FormItem labelCol={{ span: 5 }} wrapperCol={{ span: 15 }} label="领取日期">
|
||||
{form.getFieldDecorator('fixedBeginTerm', {
|
||||
rules: [{ required: true, message: '请输入固定日期!' },],
|
||||
rules: [{ required: true, message: '请输入固定日期!' },
|
||||
{min: 1, type: 'number', message: '最小值为 1'}],
|
||||
initialValue: formVals.fixedBeginTerm,
|
||||
})(<InputNumber placeholder="请输入" />)}
|
||||
-
|
||||
{form.getFieldDecorator('fixedEndTerm', {
|
||||
rules: [{ required: false, message: '请输入固定日期!' },],
|
||||
rules: [{ required: true, message: '请输入固定日期!' },
|
||||
{min: 1, type: 'number', message: '最小值为 1'}],
|
||||
initialValue: formVals.fixedEndTerm,
|
||||
})(<InputNumber placeholder="请输入" />)} 天
|
||||
</FormItem> : ''
|
||||
|
|
|
@ -43,7 +43,74 @@ public class DateUtil {
|
|||
if (date == null) {
|
||||
return "";
|
||||
}
|
||||
// TODO 芋艿,后面改成缓存
|
||||
return new SimpleDateFormat(pattern).format(date);
|
||||
}
|
||||
|
||||
}
|
||||
/**
|
||||
* 获取指定天结束时间
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 获得该日期的开始
|
||||
*/
|
||||
public static Date getDayBegin(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
setCalender(calendar, 0, 0, 0, 0);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天开始时间
|
||||
*
|
||||
* @return 获得该日期的开始
|
||||
*/
|
||||
public static Date getDayBegin() {
|
||||
return getDayBegin(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取指定天结束时间
|
||||
*
|
||||
* @param date 日期
|
||||
* @return 获得该日期的结束
|
||||
*/
|
||||
public static Date getDayEnd(Date date) {
|
||||
if (date == null) {
|
||||
return null;
|
||||
}
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTime(date);
|
||||
setCalender(calendar, 23, 59, 59, 999);
|
||||
return calendar.getTime();
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取当天结束时间
|
||||
*
|
||||
* @return 获得该日期的开始
|
||||
*/
|
||||
public static Date getDayEnd() {
|
||||
return getDayEnd(new Date());
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置Calendar的小时、分钟、秒、毫秒
|
||||
*
|
||||
* @param calendar 日历
|
||||
* @param hour 小时
|
||||
* @param minute 分钟
|
||||
* @param second 秒
|
||||
* @param milliSecond 毫秒
|
||||
*/
|
||||
public static void setCalender(Calendar calendar, int hour, int minute, int second, int milliSecond) {
|
||||
calendar.set(Calendar.HOUR_OF_DAY, hour);
|
||||
calendar.set(Calendar.MINUTE, minute);
|
||||
calendar.set(Calendar.SECOND, second);
|
||||
calendar.set(Calendar.MILLISECOND, milliSecond);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package cn.iocoder.mall.promotion.application.controller.admins;
|
||||
|
||||
import cn.iocoder.common.framework.util.DateUtil;
|
||||
import cn.iocoder.common.framework.vo.CommonResult;
|
||||
import cn.iocoder.mall.promotion.api.CouponService;
|
||||
import cn.iocoder.mall.promotion.api.bo.CouponTemplateBO;
|
||||
|
@ -11,6 +12,7 @@ import io.swagger.annotations.Api;
|
|||
import io.swagger.annotations.ApiImplicitParam;
|
||||
import io.swagger.annotations.ApiImplicitParams;
|
||||
import io.swagger.annotations.ApiOperation;
|
||||
import org.springframework.format.annotation.DateTimeFormat;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
|
@ -19,7 +21,7 @@ import org.springframework.web.bind.annotation.RestController;
|
|||
import java.util.Date;
|
||||
|
||||
@RestController
|
||||
@RequestMapping("admins/product_recommend")
|
||||
@RequestMapping("admins/coupon")
|
||||
@Api("优惠劵(码)模块")
|
||||
public class AdminsCouponTemplateController {
|
||||
|
||||
|
@ -33,8 +35,8 @@ public class AdminsCouponTemplateController {
|
|||
@ApiImplicitParams({
|
||||
@ApiImplicitParam(name = "title", value = "标题", required = true, example = "优惠劵牛逼"),
|
||||
@ApiImplicitParam(name = "description", value = "使用说明", example = "我只是描述"),
|
||||
@ApiImplicitParam(name = "quota", value = "每人限领个数", example = "null - 则表示不限制"),
|
||||
@ApiImplicitParam(name = "stock", value = "剩余可用库存", example = "null - 则表示无限库存"),
|
||||
@ApiImplicitParam(name = "quota", value = "每人限领个数", required = true),
|
||||
@ApiImplicitParam(name = "total", value = "发行总量"),
|
||||
@ApiImplicitParam(name = "priceAvailable", value = "是否设置满多少金额可用,单位:分", example = "0-不限制;大于0-多少金额可用"),
|
||||
@ApiImplicitParam(name = "rangeType", value = "可用范围的类型", required = true, example = "参见 CouponTemplateRangeTypeEnum 枚举"),
|
||||
@ApiImplicitParam(name = "rangeValues", value = "指定商品 / 分类列表,使用逗号分隔商品编号"),
|
||||
|
@ -50,13 +52,15 @@ public class AdminsCouponTemplateController {
|
|||
})
|
||||
public CommonResult<AdminsCouponTemplateVO> add(@RequestParam(value = "title") String title,
|
||||
@RequestParam(value = "description", required = false) String description,
|
||||
@RequestParam(value = "quota", required = false) Integer quota,
|
||||
@RequestParam(value = "stock", required = false) Integer stock,
|
||||
@RequestParam(value = "quota") Integer quota,
|
||||
@RequestParam(value = "total", required = false) Integer total,
|
||||
@RequestParam(value = "priceAvailable") Integer priceAvailable,
|
||||
@RequestParam(value = "rangeType") Integer rangeType,
|
||||
@RequestParam(value = "rangeType", required = false) String rangeValues,
|
||||
@RequestParam(value = "dateType") Integer dateType,
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@RequestParam(value = "validStartTime", required = false) Date validStartTime,
|
||||
@DateTimeFormat(pattern = "yyyy-MM-dd")
|
||||
@RequestParam(value = "validEndTime", required = false) Date validEndTime,
|
||||
@RequestParam(value = "fixedBeginTerm", required = false) Integer fixedBeginTerm,
|
||||
@RequestParam(value = "fixedEndTerm", required = false) Integer fixedEndTerm,
|
||||
|
@ -65,9 +69,11 @@ public class AdminsCouponTemplateController {
|
|||
@RequestParam(value = "percentOff", required = false) Integer percentOff,
|
||||
@RequestParam(value = "discountPriceLimit", required = false) Integer discountPriceLimit) {
|
||||
// 创建 CouponCardTemplateAddDTO 对象
|
||||
validStartTime = DateUtil.getDayBegin(validStartTime); // 开始时间,以当前 00:00:00 为准
|
||||
validEndTime = DateUtil.getDayBegin(validEndTime); // 结束时间,以当前 25:59:59 为准
|
||||
CouponCardTemplateAddDTO couponCardTemplateAddDTO = new CouponCardTemplateAddDTO()
|
||||
.setTitle(title).setDescription(description)
|
||||
.setQuota(quota).setStock(stock)
|
||||
.setQuota(quota).setTotal(total)
|
||||
.setPriceAvailable(priceAvailable).setRangeType(rangeType).setRangeValues(rangeValues)
|
||||
.setDateType(dateType).setValidStartTime(validStartTime).setValidEndTime(validEndTime)
|
||||
.setFixedBeginTerm(fixedBeginTerm).setFixedEndTerm(fixedEndTerm)
|
||||
|
|
|
@ -136,15 +136,6 @@ public class AdminsCouponTemplateVO {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Integer getStock() {
|
||||
return stock;
|
||||
}
|
||||
|
||||
public AdminsCouponTemplateVO setStock(Integer stock) {
|
||||
this.stock = stock;
|
||||
return this;
|
||||
}
|
||||
|
||||
public Integer getPriceAvailable() {
|
||||
return priceAvailable;
|
||||
}
|
||||
|
|
|
@ -19,7 +19,7 @@ public class CouponCardTemplateAddDTO {
|
|||
* 标题
|
||||
*/
|
||||
@NotEmpty(message = "标题不能为空")
|
||||
@Length(min = 6, max = 16, message = "标题长度为 {min}-{max} 位")
|
||||
@Length(min = 2, max = 16, message = "标题长度为 {min}-{max} 位")
|
||||
private String title;
|
||||
/**
|
||||
* 使用说明
|
||||
|
@ -31,9 +31,8 @@ public class CouponCardTemplateAddDTO {
|
|||
// ========== 领取规则 BEGIN ==========
|
||||
/**
|
||||
* 每人限领个数
|
||||
*
|
||||
* null - 则表示不限制
|
||||
*/
|
||||
@NotNull(message = "每人限领个数不能为空")
|
||||
@Min(value = 1, message = "每人限领个数最小为 {value}")
|
||||
private Integer quota;
|
||||
/**
|
||||
|
|
|
@ -82,11 +82,9 @@ public class CouponTemplateDO extends BaseDO {
|
|||
*/
|
||||
private Integer quota;
|
||||
/**
|
||||
* 剩余可用库存
|
||||
*
|
||||
* null - 则表示无限库存
|
||||
* 发行总量
|
||||
*/
|
||||
private Integer stock;
|
||||
private Integer total;
|
||||
// ========== 领取规则 END ==========
|
||||
|
||||
// ========== 使用规则 BEGIN ==========
|
||||
|
@ -274,12 +272,12 @@ public class CouponTemplateDO extends BaseDO {
|
|||
return this;
|
||||
}
|
||||
|
||||
public Integer getStock() {
|
||||
return stock;
|
||||
public Integer getTotal() {
|
||||
return total;
|
||||
}
|
||||
|
||||
public CouponTemplateDO setStock(Integer stock) {
|
||||
this.stock = stock;
|
||||
public CouponTemplateDO setTotal(Integer total) {
|
||||
this.total = total;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public class CouponServiceImpl implements CouponService {
|
|||
// 校验优惠类型
|
||||
CommonResult<Boolean> checkCouponTemplateDateTypeResult = this.checkCouponTemplatePreferentialType(
|
||||
couponCardTemplateAddDTO.getPreferentialType(), couponCardTemplateAddDTO.getPercentOff(),
|
||||
couponCardTemplateAddDTO.getPriceOff());
|
||||
if (checkCouponCodeTemplateDateTypeResult.isError()) {
|
||||
couponCardTemplateAddDTO.getPriceOff(), couponCardTemplateAddDTO.getPriceAvailable());
|
||||
if (checkCouponTemplateDateTypeResult.isError()) {
|
||||
return CommonResult.error(checkCouponTemplateDateTypeResult);
|
||||
}
|
||||
// 保存优惠劵模板到数据库
|
||||
|
@ -58,6 +58,7 @@ public class CouponServiceImpl implements CouponService {
|
|||
.setType(CouponTemplateTypeEnum.CARD.getValue())
|
||||
.setStatus(CouponTemplateStatusEnum.ENABLE.getValue())
|
||||
.setStatFetchNum(0);
|
||||
template.setCreateTime(new Date());
|
||||
couponTemplateMapper.insert(template);
|
||||
// 返回成功
|
||||
return CommonResult.success(CouponTemplateConvert.INSTANCE.convert(template));
|
||||
|
@ -106,6 +107,9 @@ public class CouponServiceImpl implements CouponService {
|
|||
if (validEndTime == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "生效结束时间不能为空");
|
||||
}
|
||||
if (validStartTime.after(validEndTime)) {
|
||||
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(), "领取日期开始时间不能为空");
|
||||
|
@ -119,11 +123,15 @@ public class CouponServiceImpl implements CouponService {
|
|||
return CommonResult.success(true);
|
||||
}
|
||||
|
||||
private CommonResult<Boolean> checkCouponTemplatePreferentialType(Integer preferentialType, Integer percentOff, Integer priceOff) {
|
||||
private CommonResult<Boolean> checkCouponTemplatePreferentialType(Integer preferentialType, Integer percentOff,
|
||||
Integer priceOff, Integer priceAvailable) {
|
||||
if (CouponTemplatePreferentialTypeEnum.PRICE.getValue().equals(preferentialType)) {
|
||||
if (priceOff == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "优惠金额不能为空");
|
||||
}
|
||||
if (priceOff >= priceAvailable) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "优惠金额不能d大于等于使用金额门槛");
|
||||
}
|
||||
} else if (CouponTemplatePreferentialTypeEnum.DISCOUNT.getValue().equals(preferentialType)) {
|
||||
if (percentOff == null) {
|
||||
return CommonResult.error(SysErrorCodeEnum.VALIDATION_REQUEST_PARAM_ERROR.getCode(), "折扣百分比不能为空");
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
<sql id="FIELDS">
|
||||
id, 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
|
||||
|
@ -100,8 +100,8 @@
|
|||
<if test="quota != null">
|
||||
quota = #{quota},
|
||||
</if>
|
||||
<if test="stock != null">
|
||||
stock = #{stock},
|
||||
<if test="total != null">
|
||||
total = #{total},
|
||||
</if>
|
||||
<if test="priceAvailable != null">
|
||||
price_available = #{priceAvailable},
|
||||
|
|
Loading…
Reference in New Issue