[feat] 优惠券删除前占用情况判断,新增满减和抹零
| | |
| | | } |
| | | |
| | | |
| | | @GetMapping("/logan/inner/appUserCoupon/holding") |
| | | @ApiOperation(value = "查询优惠券是否已有用户使用", tags = {"管理后台-优惠券是否占用"}) |
| | | public R<Boolean> holding(@RequestParam Long couponId) { |
| | | |
| | | return R.ok(xpAppUserCouponService.holding(couponId)); |
| | | } |
| | | |
| | | |
| | | |
| | | /** |
| | | * 1.0获取用户可用优惠券数量 |
| | | */ |
| | |
| | | * @return |
| | | */ |
| | | Integer getUserCouponNum(String uid); |
| | | |
| | | Boolean holding(Long couponId); |
| | | } |
| | |
| | | return num.intValue(); |
| | | } |
| | | |
| | | @Override |
| | | public Boolean holding(Long couponId) { |
| | | return baseMapper.selectCount(new LambdaQueryWrapper<XpAppUserCoupon>().eq(XpAppUserCoupon::getCouponId, couponId).ne(XpAppUserCoupon::getStatus, 0)) > 0; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 是否在运营内 |
| | |
| | | |
| | | <!-- 通用查询结果列 --> |
| | | <sql id="Base_Column_List"> |
| | | id, full_money, money, expiration_time, status, coupon_type, app_user_id, coupon_id, activity_id, activity_type, is_deleted, create_time, update_time, create_by, update_by |
| | | id, full_money, money, money2, money3 , expiration_time, status, coupon_type, app_user_id, coupon_id, activity_id, activity_type, is_deleted, create_time, update_time, create_by, update_by |
| | | </sql> |
| | | |
| | | <select id="pageList" resultType="com.xiaopeng.account.model.vo.XpAppUserCouponListVo"> |
| | |
| | | <if test="query.status != null"> |
| | | and a.status = #{query.status} |
| | | </if> |
| | | <if test="query.couponType != null"> |
| | | and a.coupon_type = #{query.couponType} |
| | | </if> |
| | | <if test="query.acticityIds != null"> |
| | | and a.activity_id in |
| | | <foreach item="item" collection="query.acticityIds" separator="," open="(" close=")" index=""> |
| | |
| | | return null; |
| | | } |
| | | |
| | | @Override |
| | | public boolean isHolding(Long id) { |
| | | log.error("优惠券服务繁忙,原因: {}", cause.getMessage()); |
| | | return false; |
| | | } |
| | | |
| | | }; |
| | | } |
| | | } |
| | |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.dto.ServiceNameConstantsEnum; |
| | | import org.springframework.cloud.openfeign.FeignClient; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | |
| | |
| | | R<BigDecimal> backUserCoupon(@RequestBody UseUserCouponDto dto); |
| | | |
| | | |
| | | @GetMapping("/logan/inner/appUserCoupon/holding") |
| | | boolean isHolding(Long id); |
| | | } |
| | |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | | |
| | | import javax.validation.constraints.DecimalMax; |
| | | import javax.validation.constraints.DecimalMin; |
| | | import javax.validation.constraints.Max; |
| | | import javax.validation.constraints.Min; |
| | | import java.math.BigDecimal; |
| | | import java.time.LocalDateTime; |
| | | |
| | |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "满减金额") |
| | | @Min(0)@Max(9999) |
| | | private BigDecimal fullMoney; |
| | | |
| | | @ApiModelProperty(value = "金额") |
| | | @ApiModelProperty(value = "满减面额,对应couponType=1") |
| | | @Min(0)@Max(9999) |
| | | private BigDecimal money; |
| | | |
| | | @ApiModelProperty(value = "抹零后金额,对应couponType=3") |
| | | @Min(0)@Max(9999) |
| | | private BigDecimal money3; |
| | | |
| | | @ApiModelProperty(value = "折扣,对应couponType=2") |
| | | @DecimalMin(value = "0.1", inclusive = true) |
| | | @DecimalMax(value = "10", inclusive = true) |
| | | private BigDecimal money2; |
| | | |
| | | @ApiModelProperty(value = "过期时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | |
| | | @ApiModelProperty(value = "状态(1=未使用,2=已使用,3=已过期 0=待领取 4=占用中)") |
| | | private Integer status; |
| | | |
| | | @ApiModelProperty(value = "优惠券类型(1=抵扣,2=满减)") |
| | | @ApiModelProperty(value = "优惠券类型(1=抵扣,2=满减,3=抹零)") |
| | | private Integer couponType; |
| | | |
| | | @ApiModelProperty(value = "用户id") |
| | |
| | | package com.xiaopeng.api.model.operation; |
| | | |
| | | import java.io.IOException; |
| | | import java.math.BigDecimal; |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import java.time.LocalDateTime; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import java.io.Serializable; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.TableName; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.fasterxml.jackson.core.JsonGenerator; |
| | | import com.fasterxml.jackson.core.JsonParser; |
| | | import com.fasterxml.jackson.databind.DeserializationContext; |
| | | import com.fasterxml.jackson.databind.JsonDeserializer; |
| | | import com.fasterxml.jackson.databind.JsonSerializer; |
| | | import com.fasterxml.jackson.databind.SerializerProvider; |
| | | import com.fasterxml.jackson.databind.annotation.JsonDeserialize; |
| | | import com.fasterxml.jackson.databind.annotation.JsonSerialize; |
| | | import com.xiaopeng.common.core.web.domain.BaseModel; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | | import org.apache.commons.lang3.StringEscapeUtils; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.validation.constraints.DecimalMax; |
| | | import javax.validation.constraints.DecimalMin; |
| | | import javax.validation.constraints.Max; |
| | | import javax.validation.constraints.Min; |
| | | import java.math.BigDecimal; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | @ApiModelProperty(value = "优惠券") |
| | | private String couponName; |
| | | |
| | | @ApiModelProperty(value = "类型 1=抵扣 2=满减") |
| | | @ApiModelProperty(value = "类型 1=抵扣 2=满减 3=抹零") |
| | | private Integer couponType; |
| | | |
| | | @ApiModelProperty(value = "条件金额") |
| | |
| | | @ApiModelProperty(value = "金额") |
| | | private BigDecimal amount; |
| | | |
| | | @ApiModelProperty(value = "抹零后金额,对应couponType=3") |
| | | @Min(0)@Max(9999) |
| | | private BigDecimal amount2; |
| | | |
| | | @ApiModelProperty(value = "折扣,对应couponType=2") |
| | | @DecimalMin(value = "0.1", inclusive = true) |
| | | @DecimalMax(value = "10", inclusive = true) |
| | | private BigDecimal amount3; |
| | | |
| | | @ApiModelProperty(value = "描述") |
| | | private String couponDescription; |
| | | |
| | |
| | | @ApiModelProperty(value = "活动名称") |
| | | private String acticityName; |
| | | |
| | | @ApiModelProperty(value = "优惠券类型") |
| | | private Integer couponType; |
| | | |
| | | @ApiModelProperty(value = "领取时间开始") |
| | | @JsonFormat(pattern = "yyyy-MM-dd", timezone = "GMT+8") |
| | | private LocalDateTime createTimeStart; |
| New file |
| | |
| | | package com.xiaopeng.api.query.operation; |
| | | |
| | | import com.baomidou.mybatisplus.annotation.IdType; |
| | | import com.baomidou.mybatisplus.annotation.TableId; |
| | | import com.fasterxml.jackson.annotation.JsonFormat; |
| | | import com.xiaopeng.common.core.web.page.BasePage; |
| | | import io.swagger.annotations.ApiModel; |
| | | import io.swagger.annotations.ApiModelProperty; |
| | | import lombok.Data; |
| | | import lombok.EqualsAndHashCode; |
| | | import lombok.experimental.Accessors; |
| | | |
| | | import java.time.LocalDateTime; |
| | | |
| | | /** |
| | | * <p> |
| | | * 活动管理 |
| | | * </p> |
| | | * |
| | | * @author mitao |
| | | * @since 2026-02-03 |
| | | */ |
| | | @Data |
| | | @EqualsAndHashCode(callSuper = false) |
| | | @Accessors(chain = true) |
| | | @ApiModel(value="XpActicity对象", description="活动管理") |
| | | public class XpActivityPageListQuery extends BasePage { |
| | | |
| | | @TableId(value = "id", type = IdType.AUTO) |
| | | private Long id; |
| | | |
| | | @ApiModelProperty(value = "活动名称") |
| | | private String acticityName; |
| | | |
| | | @ApiModelProperty(value = "开始时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private LocalDateTime startTime; |
| | | |
| | | @ApiModelProperty(value = "结束时间") |
| | | @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8") |
| | | private LocalDateTime endTime; |
| | | |
| | | @ApiModelProperty(value = "状态 1=未开始 2=进行中 3=已结束 4=暂停") |
| | | private Integer status; |
| | | |
| | | @ApiModelProperty(value = "备注") |
| | | private String remarks; |
| | | |
| | | @ApiModelProperty(value = "注册启用 1=是 0=否") |
| | | private Boolean registerEnable; |
| | | |
| | | @ApiModelProperty(value = "邀请启用 1=是 0=否") |
| | | private Boolean inviteEnable; |
| | | |
| | | @ApiModelProperty(value = "是否删除") |
| | | private String deleted; |
| | | |
| | | @ApiModelProperty(value = "图片") |
| | | private String img; |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | import com.xiaopeng.api.model.operation.XpActivity; |
| | | import com.xiaopeng.api.query.operation.XpActivityPageListQuery; |
| | | import com.xiaopeng.api.vo.operation.XpActivityVo; |
| | | import com.xiaopeng.common.core.constant.CacheConstants; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.common.core.utils.bean.BeanUtils; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.operation.service.IXpActicityService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiOperation; |
| | |
| | | import org.springframework.data.redis.core.RedisTemplate; |
| | | import org.springframework.data.redis.core.ValueOperations; |
| | | import org.springframework.web.bind.annotation.PostMapping; |
| | | import org.springframework.web.bind.annotation.RequestBody; |
| | | import org.springframework.web.bind.annotation.RequestParam; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | public class XpActicityController { |
| | | |
| | | @Resource |
| | | private IXpActicityService xpActicityService; |
| | | private IXpActicityService service; |
| | | |
| | | |
| | | /** |
| | |
| | | if(acticityName == null){ |
| | | return R.ok(); |
| | | } |
| | | return R.ok(xpActicityService.findListToIds(acticityName)); |
| | | return R.ok(service.findListToIds(acticityName)); |
| | | } |
| | | |
| | | |
| | |
| | | |
| | | String uid = request.getHeader("XP-Uid"); |
| | | ValueOperations<String, String> ops = redisTemplate.opsForValue(); |
| | | XpActivity activity = xpActicityService.activiting(); |
| | | XpActivity activity = service.activiting(); |
| | | XpActivityVo ret = new XpActivityVo(); |
| | | if (activity !=null) { |
| | | BeanUtils.copyBeanProp(ret, activity); |
| | |
| | | |
| | | } |
| | | |
| | | |
| | | @PostMapping("/v1/api/appUserCoupon/pageList") |
| | | @ApiOperation(value = "活动列表",tags = {"管理后台-活动列表"},response = XpActivity.class) |
| | | public R<PageInfo<XpActivity>> pageList(@RequestBody XpActivityPageListQuery query) { |
| | | PageInfo<XpActivity> pageList = service.pageList(query); |
| | | return R.ok(pageList); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.xiaopeng.api.feignClient.account.XpAppUserCouponClient; |
| | | import com.xiaopeng.api.model.operation.XpCoupon; |
| | | import com.xiaopeng.common.core.domain.R; |
| | | import com.xiaopeng.operation.query.XpCouponListQuery; |
| | | import com.xiaopeng.operation.service.IXpCouponService; |
| | | import com.xiaopeng.operation.vo.XpBannerListVo; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import org.springframework.stereotype.Controller; |
| | | |
| | | import java.util.List; |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | } |
| | | |
| | | |
| | | |
| | | @Resource XpAppUserCouponClient xpAppUserCouponClient; |
| | | |
| | | /** |
| | | * 删除优惠券 |
| | | */ |
| | | @DeleteMapping("/v1/api/xp-coupon/deleteById") |
| | | @ApiOperation(value = "删除优惠券",tags = {"管理后台-优惠券"},response = XpCoupon.class) |
| | | public R<?> deleteById(@RequestParam Long id){ |
| | | xpCouponService.removeById(id); |
| | | return R.ok(); |
| | | |
| | | if (!xpAppUserCouponClient.isHolding(id)){ |
| | | xpCouponService.removeById(id); |
| | | return R.ok(); |
| | | } |
| | | else{ |
| | | return R.fail("该优惠券已有用户使用,无法作废 / 删除"); |
| | | } |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.mapper.BaseMapper; |
| | | import com.xiaopeng.api.model.operation.XpActivity; |
| | | import com.xiaopeng.api.query.operation.XpActivityPageListQuery; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | |
| | | import java.util.List; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | */ |
| | | public interface XpActicityMapper extends BaseMapper<XpActivity> { |
| | | |
| | | List<XpActivity> pageList(PageInfo<XpActivity> pageInfo, XpActivityPageListQuery query); |
| | | } |
| | |
| | | |
| | | import com.baomidou.mybatisplus.extension.service.IService; |
| | | import com.xiaopeng.api.model.operation.XpActivity; |
| | | import com.xiaopeng.api.query.operation.XpActivityPageListQuery; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | |
| | | import java.util.List; |
| | | |
| | |
| | | */ |
| | | public interface IXpActicityService extends IService<XpActivity> { |
| | | |
| | | PageInfo<XpActivity> pageList(XpActivityPageListQuery query); |
| | | |
| | | List<String> findListToIds(String acticityName); |
| | | |
| | |
| | | |
| | | import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper; |
| | | import com.xiaopeng.api.model.operation.XpActivity; |
| | | import com.xiaopeng.api.query.operation.XpActivityPageListQuery; |
| | | import com.xiaopeng.common.core.web.page.PageInfo; |
| | | import com.xiaopeng.operation.mapper.XpActicityMapper; |
| | | import com.xiaopeng.operation.service.IXpActicityService; |
| | | import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl; |
| | |
| | | public class XpActicityServiceImpl extends ServiceImpl<XpActicityMapper, XpActivity> implements IXpActicityService { |
| | | |
| | | |
| | | @Override |
| | | public PageInfo<XpActivity> pageList(XpActivityPageListQuery query) { |
| | | PageInfo<XpActivity> pageInfo = new PageInfo<>(query.getPageNum(),query.getPageSize()); |
| | | List<XpActivity> list = this.baseMapper.pageList(pageInfo,query); |
| | | pageInfo.setRecords(list); |
| | | return pageInfo; |
| | | } |
| | | |
| | | @Override |
| | | public List<String> findListToIds(String acticityName){ |
| | |
| | | <mapper namespace="com.xiaopeng.operation.mapper.XpActicityMapper"> |
| | | |
| | | |
| | | <select id="pageList" resultType="com.xiaopeng.api.model.operation.XpActivity"> |
| | | select a.* |
| | | from xp_acticity as a |
| | | where a.is_deleted = 0 and a.app_user_id = #{appUserId} |
| | | <if test="query.createTimeStart != null "> |
| | | a.create_time >= #{query.createTimeStart} |
| | | </if> |
| | | <if test="query.createTimeEnd != null "> |
| | | a.create_time <= #{query.createTimeEnd} |
| | | </if> |
| | | <if test="query.status != null"> |
| | | and a.status = #{query.status} |
| | | </if> |
| | | <if test="query.couponType != null"> |
| | | and a.coupon_type = #{query.couponType} |
| | | </if> |
| | | <if test="query.acticityIds != null"> |
| | | and a.activity_id in |
| | | <foreach item="item" collection="query.acticityIds" separator="," open="(" close=")" index=""> |
| | | #{item} |
| | | </foreach> |
| | | </if> |
| | | order by a.create_time desc |
| | | |
| | | </select> |
| | | </mapper> |