Commit bc8ffd75 by caiyt

增加优惠券部分接口

parent 6cd2da43
......@@ -22,7 +22,8 @@
<kaptcha.version>2.3.2</kaptcha.version>
<mybatis-spring-boot.version>2.2.2</mybatis-spring-boot.version>
<pagehelper.boot.version>1.4.1</pagehelper.boot.version>
<fastjson.version>1.2.79</fastjson.version>
<log4j2.version>2.17.2</log4j2.version>
<fastjson.version>1.2.83</fastjson.version>
<oshi.version>6.1.2</oshi.version>
<jna.version>5.10.0</jna.version>
<commons.io.version>2.11.0</commons.io.version>
......@@ -31,6 +32,8 @@
<poi.version>4.1.2</poi.version>
<velocity.version>2.3</velocity.version>
<jwt.version>0.9.1</jwt.version>
<io.springfox.version>3.0.0</io.springfox.version>
<io.swagger.version>1.5.23</io.swagger.version>
</properties>
<!-- 依赖声明 -->
......
......@@ -4,6 +4,7 @@ package com.soss.web.controller.coupon;
import com.soss.common.annotation.Log;
import com.soss.common.core.controller.BaseController;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.core.page.TableDataInfo;
import com.soss.common.enums.BusinessType;
import com.soss.system.domain.CouponCategory;
import com.soss.system.service.ICouponCategoryService;
......@@ -25,7 +26,7 @@ import java.util.List;
*/
@RestController
@RequestMapping("/coupon-category")
@Api("优惠券类别服务类")
@Api(tags = "优惠券类别服务类")
public class CouponCategoryController extends BaseController {
@Autowired
private ICouponCategoryService couponCategoryService;
......@@ -49,20 +50,45 @@ public class CouponCategoryController extends BaseController {
@Log(title = "查询优惠券类别列表", businessType = BusinessType.INSERT)
@GetMapping
@ApiOperation("查询优惠券类别列表")
public AjaxResult listCouponCategory(@RequestBody CouponCategory couponCategory) {
public TableDataInfo listCouponCategory(@RequestBody CouponCategory couponCategory) {
startPage();
List<CouponCategory> couponCategories = couponCategoryService.listCouponCategory(couponCategory);
return AjaxResult.success(couponCategories);
return getDataTable(couponCategories);
}
/**
* 变更优惠券类别状态
* 上架优惠券类别状态
*/
@PreAuthorize("@ss.hasPermi('coupon:category:state-switch')")
@Log(title = "变更优惠券类别状态", businessType = BusinessType.INSERT)
@GetMapping("/{id}/{state}")
@ApiOperation(value = "变更优惠券类别状态", notes = "state: 状态 0 默认 1 生效 2 下线 3删除")
public AjaxResult switchState(@PathVariable Integer id, @PathVariable Integer state) {
int updateCnt = couponCategoryService.switchState(id, state);
@PreAuthorize("@ss.hasPermi('coupon:category:online')")
@Log(title = "上架优惠券类别", businessType = BusinessType.INSERT)
@GetMapping("/online/{id}")
@ApiOperation("上架优惠券类别状态")
public AjaxResult switchState(@PathVariable Integer id) {
int updateCnt = couponCategoryService.onlineCouponCategory(id);
return toAjax(updateCnt);
}
/**
* 下架优惠券类别状态
*/
@PreAuthorize("@ss.hasPermi('coupon:category:offline')")
@Log(title = "下架优惠券类别", businessType = BusinessType.INSERT)
@GetMapping("/offline/{id}")
@ApiOperation("下架优惠券类别状态")
public AjaxResult offlineCouponCategory(@PathVariable Integer id) {
int updateCnt = couponCategoryService.offlineCouponCategory(id);
return toAjax(updateCnt);
}
/**
* 删除优惠券类别状态
*/
@PreAuthorize("@ss.hasPermi('coupon:category:delete')")
@Log(title = "删除优惠券类别", businessType = BusinessType.INSERT)
@DeleteMapping("/{id}")
@ApiOperation("删除优惠券类别状态")
public AjaxResult deleteCouponCategory(@PathVariable Integer id) {
int updateCnt = couponCategoryService.deleteCouponCategory(id);
return toAjax(updateCnt);
}
}
package com.soss.web.controller.coupon;
import com.soss.common.annotation.Log;
import com.soss.common.core.domain.AjaxResult;
import com.soss.common.enums.BusinessType;
import com.soss.system.domain.po.CouponPo;
import com.soss.system.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
......@@ -13,7 +24,20 @@ import org.springframework.web.bind.annotation.RestController;
* @since 2022-07-21
*/
@RestController
@Api(tags = "优惠券服务类")
@RequestMapping("/coupon")
public class CouponController {
@Autowired
private ICouponService couponService;
/**
* 新增优惠券
*/
@PreAuthorize("@ss.hasPermi('coupon:add')")
@Log(title = "新增优惠券", businessType = BusinessType.INSERT)
@PutMapping
@ApiOperation("新增优惠券")
public AjaxResult save(@RequestBody CouponPo couponPo) {
return AjaxResult.success();
}
}
package com.soss.web.controller.coupon;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
/**
* <p>
* 优惠券规则 前端控制器
* </p>
*
* @author caiyt
* @since 2022-07-21
*/
@RestController
@RequestMapping("/coupon-rule")
public class CouponRuleController {
}
......@@ -92,8 +92,32 @@
<version>4.1.0</version>
</dependency>
<!-- swagger相关 -->
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-boot-starter</artifactId>
<version>${io.springfox.version}</version>
<exclusions>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
</exclusion>
<exclusion>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>${io.swagger.version}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-models</artifactId>
<version>${io.swagger.version}</version>
</dependency>
</dependencies>
......
......@@ -92,6 +92,11 @@ public class CouponRule extends BaseEntity {
private Integer relativeTime;
/**
* 价格扣减(当券类型为抵扣时单位为'元',当券类型为折扣时,单位为'折')
*/
private BigDecimal priceDiscount;
/**
* 价格门槛
*/
private BigDecimal priceLimit;
......
package com.soss.system.domain.po;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.soss.common.exception.ServiceException;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;
@Data
@ApiModel("优惠券请求类")
public class CouponPo {
@ApiModelProperty("主键")
private Integer id;
@ApiModelProperty("优惠劵名")
private String name;
@ApiModelProperty("优惠券编码")
private String serialNo;
@ApiModelProperty("优惠券类别ID")
private Integer categoryId;
@ApiModelProperty("优惠券类别名")
private String categoryName;
@ApiModelProperty("优惠券规则id")
private Integer ruleId;
@ApiModelProperty("优惠券类型 1 抵扣 2 折扣 3 免单")
private Integer type;
@ApiModelProperty("优惠劵规则描述")
private String desc;
@ApiModelProperty("可用商品类别列表")
private List<Integer> categoryIds;
@ApiModelProperty("可用商品id列表")
private List<Integer> goodsIds;
@ApiModelProperty("可用省份列表 可存code列表")
private List<String> province;
@ApiModelProperty("可用城市列表")
private List<String> city;
@ApiModelProperty("可用区域列表")
private List<String> area;
@ApiModelProperty("可用店铺ID列表")
private List<Integer> shopIds;
@ApiModelProperty("领取开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime startTime;
@ApiModelProperty("领取截止时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime endTime;
@ApiModelProperty("使用绝对开始时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime useStartTime;
@ApiModelProperty("使用绝对截止时间")
@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
private LocalDateTime useEndTime;
@ApiModelProperty("领取后相对有效天数")
private Integer relativeTime;
@ApiModelProperty("价格扣减(当券类型为抵扣时单位为'元',当券类型为折扣时,单位为'折')")
private BigDecimal priceDiscount;
@ApiModelProperty("价格门槛,为0表示无门槛")
private BigDecimal priceLimit;
@ApiModelProperty("订单限制 false 整单 true 单杯")
private Boolean orderLimit;
@ApiModelProperty("周几限制 1,2,3")
private List<Integer> weekLimit;
@ApiModelProperty("用户可领取次数之次数限制0无限制,即每N天M次对应的次数")
private Integer userLimit;
@ApiModelProperty("用户可领取次数之天数限制0无限制,即每N天M次对应的天数")
private Integer daysLimit;
@ApiModelProperty("是否发送短信 false 不 true 发")
private Boolean sendMsg;
@ApiModelProperty("短信模板ID")
private Integer msgId;
public void couponUseLimitCheck() {
int limitDim = 0;
if (!CollectionUtils.isEmpty(province)) {
limitDim += 1;
}
if (!CollectionUtils.isEmpty(city)) {
limitDim += 1;
}
if (!CollectionUtils.isEmpty(area)) {
limitDim += 1;
}
if (!CollectionUtils.isEmpty(shopIds)) {
limitDim += 1;
}
if (limitDim > 1) {
throw new ServiceException("适用范围之地区/门店不能跨级");
}
}
}
package com.soss.system.domain.vo;
import com.soss.system.domain.po.CouponPo;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
@ApiModel
@Data
public class CouponVo extends CouponPo {
@ApiModelProperty("优惠劵规则名称")
private String ruleName;
}
......@@ -30,6 +30,14 @@ public interface CouponCategoryMapper {
List<CouponCategory> listCouponCategory(CouponCategory couponCategory);
/**
* 根据id查询优惠券类别
*
* @param id 优惠券类别ID
* @return 优惠券类别
*/
CouponCategory selectCouponCategoryById(Integer id);
/**
* 更新优惠券类别
*
* @param couponCategory 优惠券类别
......
......@@ -18,5 +18,9 @@ public interface ICouponCategoryService {
List<CouponCategory> listCouponCategory(CouponCategory couponCategory);
int switchState(Integer id, Integer state);
int onlineCouponCategory(Integer id);
int offlineCouponCategory(Integer id);
int deleteCouponCategory(Integer id);
}
package com.soss.system.service.impl;
import com.soss.common.enums.CouponCategoryType;
import com.soss.common.enums.CouponState;
import com.soss.system.domain.CouponCategory;
import com.soss.system.mapper.CouponCategoryMapper;
import com.soss.system.mapper.CouponMapper;
......@@ -69,17 +70,46 @@ public class CouponCategoryServiceImpl implements ICouponCategoryService {
}
/**
* 更新优惠券类别状态
* 上架优惠券类别
*
* @param id
* @param state
* @return
*/
@Override
@Transactional
public int switchState(Integer id, Integer state) {
CouponCategory online = new CouponCategory(id, state);
public int onlineCouponCategory(Integer id) {
CouponCategory online = new CouponCategory(id, CouponState.ONLINE.getState());
int updateCnt = couponCategoryMapper.updateCouponCategory(online);
return updateCnt;
}
/**
* 下架优惠券类别
*
* @param id
* @return
*/
@Override
@Transactional
public int offlineCouponCategory(Integer id) {
CouponCategory online = new CouponCategory(id, CouponState.OFFLINE.getState());
int updateCnt = couponCategoryMapper.updateCouponCategory(online);
// offline logic todo
return updateCnt;
}
/**
* 删除优惠券类别
*
* @param id
* @return
*/
@Override
@Transactional
public int deleteCouponCategory(Integer id) {
CouponCategory online = new CouponCategory(id, CouponState.DELETE.getState());
int updateCnt = couponCategoryMapper.updateCouponCategory(online);
// delete logic todo
return updateCnt;
}
}
package com.soss.system.service.impl;
import com.soss.common.enums.CouponCategoryType;
import com.soss.common.utils.GenerateCode;
import com.soss.system.domain.Coupon;
import com.soss.system.domain.CouponCategory;
import com.soss.system.domain.CouponRule;
import com.soss.system.domain.po.CouponPo;
import com.soss.system.mapper.CouponCategoryMapper;
import com.soss.system.mapper.CouponMapper;
import com.soss.system.service.ICouponService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.stream.Collectors;
/**
* <p>
......@@ -13,5 +29,70 @@ import org.springframework.stereotype.Service;
*/
@Service
public class CouponServiceImpl implements ICouponService {
@Autowired
private CouponCategoryMapper couponCategoryMapper;
@Autowired
private CouponMapper couponMapper;
public void save(CouponPo couponPo) {
Assert.notNull(couponPo.getName(), "优惠券名称还未填写");
Assert.notNull(couponPo.getCategoryId(), "优惠券类别还未选择");
CouponCategory couponCategory = couponCategoryMapper.selectCouponCategoryById(couponPo.getCategoryId());
Assert.notNull(couponCategory, "未查询到匹配的优惠券类别[id=" + couponPo.getCategoryId() + "]");
StringBuilder ruleName = new StringBuilder(16);
if (CouponCategoryType.DEDUCTION.getType().equals(couponCategory.getType())) {
Assert.notNull(couponPo.getPriceDiscount(), "满减价还未设置");
Assert.notNull(couponPo.getPriceLimit(), "价格门槛还未设置");
Assert.notNull(couponPo.getDaysLimit(), "用户可领取次数还未设置");
if (couponPo.getPriceLimit().compareTo(BigDecimal.ZERO) == 0) {
ruleName.append("无门槛");
} else {
ruleName.append("满").append(couponPo.getPriceLimit()).append("元");
}
ruleName.append("立减").append(couponPo.getPriceDiscount()).append("元");
} else if (CouponCategoryType.DISCOUNT.getType().equals(couponCategory.getType())) {
Assert.notNull(couponPo.getPriceDiscount(), "打折数还未设置");
Assert.notNull(couponPo.getOrderLimit(), "订单限制还未设置");
ruleName.append(couponPo.getOrderLimit() ? "单杯" : "整单").append(couponPo.getOrderLimit()).append("折");
} else {
Assert.notNull(couponPo.getPriceLimit(), "价格门槛还未设置");
Assert.notNull(couponPo.getOrderLimit(), "订单限制还未设置");
if (couponPo.getPriceLimit().compareTo(BigDecimal.ZERO) == 0) {
ruleName.append("无门槛");
} else {
ruleName.append("满").append(couponPo.getPriceLimit()).append("元");
}
ruleName.append("免单");
}
Assert.notNull(couponPo.getUseStartTime(), "优惠券的绝对有效时间还未设置");
Assert.notNull(couponPo.getUseEndTime(), "优惠券的绝对有效时间还未设置");
Assert.isTrue(!CollectionUtils.isEmpty(couponPo.getCategoryIds())
&& !CollectionUtils.isEmpty(couponPo.getGoodsIds()), "商品范围还未设置");
Assert.notNull(couponPo.getSendMsg(), "是否短信通知还未设置");
Assert.isTrue(couponPo.getSendMsg() && couponPo.getMsgId() != null, "短信模板还未选择");
Coupon coupon = new Coupon();
coupon.setName(couponPo.getName());
coupon.setSerialNo(GenerateCode.getCode("CP", "%06d"));
coupon.setCategoryId(couponCategory.getId());
coupon.setCategoryName(couponCategory.getName());
// coupon.setRuleId(); todo
coupon.setType(couponCategory.getType());
LocalDateTime now = LocalDateTime.now();
coupon.setCreatedAt(now);
coupon.setUpdatedAt(now);
CouponRule couponRule = new CouponRule();
BeanUtils.copyProperties(couponPo, couponRule);
couponRule.setName(ruleName.toString());
couponRule.setDesc(""); // todo
couponRule.setCategoryIds(couponPo.getCategoryIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
couponRule.setGoodsIds(couponPo.getGoodsIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
couponRule.setProvince(String.join(",", couponPo.getProvince()));
couponRule.setCity(String.join(",", couponPo.getCity()));
couponRule.setArea(String.join(",", couponPo.getArea()));
couponRule.setShopIds(couponPo.getShopIds().stream().map(String::valueOf).collect(Collectors.joining(",")));
couponRule.setCreatedAt(now);
couponRule.setUpdatedAt(now);
}
}
......@@ -16,13 +16,18 @@
select id, name, state, `desc`, type, created_at, updated_at from coupon_category
</sql>
<select id="listCouponCategory" parameterType="CouponCategory" resultMap="BaseResultMap">
<select id="selectCouponCategoryById" resultMap="BaseResultMap">
<include refid="selectCouponCategory"/>
where id = #{id} and state = ${@com.soss.common.enums.CouponState @ONLINE.getState}
</select>
<select id="listCouponCategory" parameterType="com.soss.system.domain.CouponCategory" resultMap="BaseResultMap">
<include refid="selectCouponCategory"/>
<where>
<if test="type != null"> and type = #{type}</if>
<if test="state != null and state != ''"> and state = #{state}</if>
</where>
order by turn
order by updated_at desc, id desc
</select>
<insert id="insertCouponCategory" parameterType="com.soss.system.domain.CouponCategory" useGeneratedKeys="true" keyProperty="id">
......
......@@ -16,7 +16,7 @@
</resultMap>
<select id="getCouponCategoryTypeStat" resultType="com.soss.system.domain.CouponCategory">
select category_id id, count(*) couponCnt from coupon
select category_id id, count(*) couponCnt from coupon where category_id in
<foreach collection="categoryIds" item="categoryId" open="(" close=")" separator=",">#{categoryId}</foreach>
group by category_id
</select>
......
......@@ -17,6 +17,7 @@
<result column="use_start_time" property="useStartTime" />
<result column="use_end_time" property="useEndTime" />
<result column="relative_time" property="relativeTime" />
<result column="price_discount" property="priceDiscount" />
<result column="price_limit" property="priceLimit" />
<result column="order_limit" property="orderLimit" />
<result column="week_limit" property="weekLimit" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment