优惠券
This commit is contained in:
parent
a5f67b1eac
commit
f9a8a5f20e
@ -0,0 +1,9 @@
|
|||||||
|
package com.ycwl.basic.controller.mobile;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/mobile/controller/v1")
|
||||||
|
public class AppCouponController {
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
package com.ycwl.basic.controller.pc;
|
||||||
|
import com.github.pagehelper.PageHelper;
|
||||||
|
import com.github.pagehelper.PageInfo;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO;
|
||||||
|
import com.ycwl.basic.service.pc.CouponService;
|
||||||
|
import com.ycwl.basic.utils.ApiResponse;
|
||||||
|
import io.swagger.annotations.Api;
|
||||||
|
import io.swagger.annotations.ApiOperation;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/coupon/v1")
|
||||||
|
@Api(tags = "优惠券管理")
|
||||||
|
public class CouponController {
|
||||||
|
@Autowired
|
||||||
|
private CouponService couponService;
|
||||||
|
|
||||||
|
@ApiOperation("新增优惠券")
|
||||||
|
@PostMapping("/add")
|
||||||
|
public ApiResponse<Integer> add(@RequestBody CouponEntity coupon) {
|
||||||
|
return ApiResponse.success(couponService.add(coupon));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("更新优惠券")
|
||||||
|
@PostMapping("/update/{id}")
|
||||||
|
public ApiResponse<Boolean> update(@PathVariable Integer id, @RequestBody CouponEntity coupon) {
|
||||||
|
coupon.setId(id);
|
||||||
|
return ApiResponse.success(couponService.update(coupon));
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/updateStatus/{id}")
|
||||||
|
public ApiResponse<Boolean> updateStatus(@PathVariable Integer id) {
|
||||||
|
return ApiResponse.success(couponService.updateStatus(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("删除优惠券")
|
||||||
|
@DeleteMapping("/delete/{id}")
|
||||||
|
public ApiResponse<Boolean> delete(@PathVariable Integer id) {
|
||||||
|
return ApiResponse.success(couponService.delete(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("根据ID查询优惠券")
|
||||||
|
@GetMapping("/get/{id}")
|
||||||
|
public ApiResponse<CouponEntity> getById(@PathVariable Integer id) {
|
||||||
|
return ApiResponse.success(couponService.getById(id));
|
||||||
|
}
|
||||||
|
|
||||||
|
@ApiOperation("分页查询优惠券列表")
|
||||||
|
@PostMapping("/page")
|
||||||
|
public ApiResponse<PageInfo<CouponRespVO>> list(@RequestBody CouponQueryReq couponQuery) {
|
||||||
|
PageHelper.startPage(couponQuery.getPageNum(), couponQuery.getPageSize());
|
||||||
|
List<CouponRespVO> list = couponService.list(couponQuery);
|
||||||
|
PageInfo<CouponRespVO> pageInfo = new PageInfo<>(list);
|
||||||
|
return ApiResponse.success(pageInfo);
|
||||||
|
}
|
||||||
|
}
|
15
src/main/java/com/ycwl/basic/mapper/CouponMapper.java
Normal file
15
src/main/java/com/ycwl/basic/mapper/CouponMapper.java
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package com.ycwl.basic.mapper;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
|
||||||
|
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO;
|
||||||
|
import org.apache.ibatis.annotations.Mapper;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Mapper
|
||||||
|
public interface CouponMapper extends BaseMapper<CouponEntity> {
|
||||||
|
List<CouponRespVO> selectByQuery(CouponQueryReq query);
|
||||||
|
|
||||||
|
int updateStatus(Integer id);
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package com.ycwl.basic.model.pc.coupon.entity;
|
||||||
|
|
||||||
|
import com.baomidou.mybatisplus.annotation.IdType;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableId;
|
||||||
|
import com.baomidou.mybatisplus.annotation.TableName;
|
||||||
|
import lombok.Data;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
@TableName("coupon")
|
||||||
|
public class CouponEntity {
|
||||||
|
@TableId(value = "id", type = IdType.AUTO)
|
||||||
|
private Integer id;
|
||||||
|
private Long scenicId;
|
||||||
|
|
||||||
|
// 新增优惠券名称字段
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券类别,0:普通优惠券;1:第一次推送;2:第二次;3:第三次
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
/**
|
||||||
|
* 价格配置ID,逗号分隔字符串
|
||||||
|
*/
|
||||||
|
private String configIds;
|
||||||
|
/**
|
||||||
|
* 0降价,1打折
|
||||||
|
*/
|
||||||
|
private Integer discountType;
|
||||||
|
private BigDecimal discountPrice;
|
||||||
|
/**
|
||||||
|
* 状态:0不开启;1开启
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
private Date createAt;
|
||||||
|
}
|
@ -0,0 +1,33 @@
|
|||||||
|
package com.ycwl.basic.model.pc.coupon.req;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
import lombok.Data;
|
||||||
|
import com.ycwl.basic.model.common.BaseQueryParameterReq;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@EqualsAndHashCode(callSuper = true)
|
||||||
|
@Data
|
||||||
|
@ApiModel("优惠券查询请求参数")
|
||||||
|
public class CouponQueryReq extends BaseQueryParameterReq {
|
||||||
|
@ApiModelProperty("景区ID")
|
||||||
|
private Long scenicId;
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
@ApiModelProperty("优惠券类型:0普通/1首次推送/2二次/3三次")
|
||||||
|
private Integer type;
|
||||||
|
|
||||||
|
@ApiModelProperty("折扣类型:0降价/1打折")
|
||||||
|
private Integer discountType;
|
||||||
|
|
||||||
|
@ApiModelProperty("状态:0关闭/1开启")
|
||||||
|
private Integer status;
|
||||||
|
|
||||||
|
@ApiModelProperty("创建时间起始")
|
||||||
|
private Date createAtStart;
|
||||||
|
|
||||||
|
@ApiModelProperty("创建时间结束")
|
||||||
|
private Date createAtEnd;
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package com.ycwl.basic.model.pc.coupon.resp;
|
||||||
|
|
||||||
|
import lombok.Data;
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
@Data
|
||||||
|
public class CouponRespVO {
|
||||||
|
private Integer id;
|
||||||
|
private Long scenicId;
|
||||||
|
private String scenicName;
|
||||||
|
|
||||||
|
// 新增优惠券名称字段
|
||||||
|
private String name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 优惠券类别,0:普通优惠券;1:第一次推送;2:第二次;3:第三次
|
||||||
|
*/
|
||||||
|
private Integer type;
|
||||||
|
/**
|
||||||
|
* 价格配置ID,逗号分隔字符串
|
||||||
|
*/
|
||||||
|
private String configIds;
|
||||||
|
/**
|
||||||
|
* 0降价,1打折
|
||||||
|
*/
|
||||||
|
private Integer discountType;
|
||||||
|
private BigDecimal discountPrice;
|
||||||
|
/**
|
||||||
|
* 状态:0不开启;1开启
|
||||||
|
*/
|
||||||
|
private Integer status;
|
||||||
|
private Date createAt;
|
||||||
|
}
|
@ -0,0 +1,49 @@
|
|||||||
|
package com.ycwl.basic.service.impl.pc;
|
||||||
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
||||||
|
import com.ycwl.basic.mapper.CouponMapper;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO;
|
||||||
|
import com.ycwl.basic.service.pc.CouponService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class CouponServiceImpl extends ServiceImpl<CouponMapper, CouponEntity> implements CouponService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private CouponMapper couponMapper;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Integer add(CouponEntity coupon) {
|
||||||
|
return couponMapper.insert(coupon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean update(CouponEntity coupon) {
|
||||||
|
return couponMapper.updateById(coupon) > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean delete(Integer id) {
|
||||||
|
return removeById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public CouponEntity getById(Integer id) {
|
||||||
|
return couponMapper.selectById(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<CouponRespVO> list(CouponQueryReq query) {
|
||||||
|
List<CouponRespVO> list = couponMapper.selectByQuery(query);
|
||||||
|
return list;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Boolean updateStatus(Integer id) {
|
||||||
|
return couponMapper.updateStatus(id) > 0;
|
||||||
|
}
|
||||||
|
}
|
17
src/main/java/com/ycwl/basic/service/pc/CouponService.java
Normal file
17
src/main/java/com/ycwl/basic/service/pc/CouponService.java
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
package com.ycwl.basic.service.pc;
|
||||||
|
|
||||||
|
import com.ycwl.basic.model.pc.coupon.entity.CouponEntity;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.req.CouponQueryReq;
|
||||||
|
import com.ycwl.basic.model.pc.coupon.resp.CouponRespVO;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface CouponService {
|
||||||
|
Integer add(CouponEntity coupon);
|
||||||
|
Boolean update(CouponEntity coupon);
|
||||||
|
Boolean delete(Integer id);
|
||||||
|
CouponEntity getById(Integer id);
|
||||||
|
List<CouponRespVO> list(CouponQueryReq query);
|
||||||
|
|
||||||
|
Boolean updateStatus(Integer id);
|
||||||
|
}
|
32
src/main/resources/mapper/CouponMapper.xml
Normal file
32
src/main/resources/mapper/CouponMapper.xml
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8" ?>
|
||||||
|
<!DOCTYPE mapper
|
||||||
|
PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN"
|
||||||
|
"http://mybatis.org/dtd/mybatis-3-mapper.dtd">
|
||||||
|
<mapper namespace="com.ycwl.basic.mapper.CouponMapper">
|
||||||
|
<update id="updateStatus">
|
||||||
|
UPDATE coupon
|
||||||
|
SET status = IF(status = 1, 0, 1)
|
||||||
|
WHERE id = #{id}
|
||||||
|
</update>
|
||||||
|
<select id="selectByQuery" resultType="com.ycwl.basic.model.pc.coupon.resp.CouponRespVO">
|
||||||
|
SELECT
|
||||||
|
c.id, scenic_id AS scenicId, s.name as scenicName,
|
||||||
|
c.name AS name,
|
||||||
|
config_ids AS configIds, discount_price AS discountPrice,
|
||||||
|
type, discount_type AS discountType,
|
||||||
|
c.status, c.create_at
|
||||||
|
FROM coupon c
|
||||||
|
LEFT JOIN scenic s ON c.scenic_id = s.id
|
||||||
|
<where>
|
||||||
|
<if test="scenicId != null">AND scenic_id = #{scenicId}</if>
|
||||||
|
<if test="name != null and name != ''">AND c.name = concat('%',#{name},'%')</if>
|
||||||
|
<if test="type != null">AND type = #{type}</if>
|
||||||
|
<if test="discountType != null">AND discount_type = #{discountType}</if>
|
||||||
|
<if test="status != null">AND c.status = #{status}</if>
|
||||||
|
<if test="createAtStart != null">AND create_time >= #{createAtStart}</if>
|
||||||
|
<if test="createAtEnd != null">AND create_time <= #{createAtEnd}
|
||||||
|
</if>
|
||||||
|
</where>
|
||||||
|
ORDER BY create_time DESC
|
||||||
|
</select>
|
||||||
|
</mapper>
|
Loading…
x
Reference in New Issue
Block a user