Skip to content

Commit

Permalink
'优惠券功能改版'
Browse files Browse the repository at this point in the history
  • Loading branch information
chopper711 committed Dec 23, 2022
1 parent 602678e commit 8543a22
Show file tree
Hide file tree
Showing 21 changed files with 387 additions and 124 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,14 @@
import cn.lili.common.vo.PageVO;
import cn.lili.common.vo.ResultMessage;
import cn.lili.modules.promotion.entity.dos.MemberCoupon;
import cn.lili.modules.promotion.entity.dto.CouponActivityTrigger;
import cn.lili.modules.promotion.entity.dto.search.CouponSearchParams;
import cn.lili.modules.promotion.entity.dto.search.MemberCouponSearchParams;
import cn.lili.modules.promotion.entity.enums.CouponActivityTypeEnum;
import cn.lili.modules.promotion.entity.enums.CouponGetEnum;
import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum;
import cn.lili.modules.promotion.entity.vos.CouponVO;
import cn.lili.modules.promotion.service.CouponActivityService;
import cn.lili.modules.promotion.service.CouponService;
import cn.lili.modules.promotion.service.MemberCouponService;
import com.baomidou.mybatisplus.core.metadata.IPage;
Expand All @@ -26,6 +29,7 @@
import org.springframework.web.bind.annotation.RestController;

import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;

/**
Expand All @@ -45,12 +49,30 @@ public class CouponBuyerController {
@Autowired
private CouponService couponService;

/**
* 优惠券活动
*/
@Autowired
private CouponActivityService couponActivityService;

/**
* 会员优惠券
*/
@Autowired
private MemberCouponService memberCouponService;

@GetMapping("/activity")
@ApiOperation(value = "自动领取优惠券")
public ResultMessage<List<MemberCoupon>> activity() {
return ResultUtil.data(couponActivityService.trigger(
CouponActivityTrigger.builder()
.couponActivityTypeEnum(CouponActivityTypeEnum.AUTO_COUPON)
.nickName(UserContext.getCurrentUser().getNickName())
.userId(UserContext.getCurrentUser().getId())
.build())
);
}

@GetMapping
@ApiOperation(value = "获取可领取优惠券列表")
public ResultMessage<IPage<CouponVO>> getCouponList(CouponSearchParams queryParam, PageVO page) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
package cn.lili.event.impl;

import cn.lili.cache.Cache;
import cn.lili.cache.CachePrefix;
import cn.lili.common.utils.StringUtils;
import cn.lili.event.MemberRegisterEvent;
import cn.lili.modules.member.entity.dos.Member;
import cn.lili.modules.promotion.entity.dos.CouponActivity;
import cn.lili.modules.member.service.MemberService;
import cn.lili.modules.promotion.entity.dto.CouponActivityTrigger;
import cn.lili.modules.promotion.entity.enums.CouponActivityTypeEnum;
import cn.lili.modules.promotion.entity.enums.PromotionsStatusEnum;
import cn.lili.modules.promotion.service.CouponActivityService;
import cn.lili.modules.promotion.tools.PromotionTools;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
* 注册赠券活动
*
Expand All @@ -25,6 +24,12 @@ public class RegisteredCouponActivityExecute implements MemberRegisterEvent {
@Autowired
private CouponActivityService couponActivityService;


@Autowired
private MemberService memberService;
@Autowired
private Cache cache;

/**
* 获取进行中的注册赠券的优惠券活动
* 发送注册赠券
Expand All @@ -33,9 +38,22 @@ public class RegisteredCouponActivityExecute implements MemberRegisterEvent {
*/
@Override
public void memberRegister(Member member) {
List<CouponActivity> couponActivities = couponActivityService.list(new QueryWrapper<CouponActivity>()
.eq("coupon_activity_type", CouponActivityTypeEnum.REGISTERED.name())
.and(PromotionTools.queryPromotionStatus(PromotionsStatusEnum.START)));
couponActivityService.registered(couponActivities, member);
//用户注册赠券
couponActivityService.trigger(CouponActivityTrigger.builder()
.nickName(member.getNickName())
.userId(member.getId())
.couponActivityTypeEnum(CouponActivityTypeEnum.REGISTERED)
.build());
//邀请人赠券
String memberId = (String) cache.get(CachePrefix.INVITER.getPrefix() + member.getId());
if (StringUtils.isNotEmpty(memberId)) {
//邀请人
Member inviter = memberService.getById(memberId);
couponActivityService.trigger(CouponActivityTrigger.builder()
.nickName(inviter.getNickName())
.userId(inviter.getId())
.couponActivityTypeEnum(CouponActivityTypeEnum.INVITE_NEW)
.build());
}
}
}
13 changes: 10 additions & 3 deletions framework/src/main/java/cn/lili/cache/CachePrefix.java
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ public enum CachePrefix {
* 促销活动
*/
PROMOTION,
/**
* 当前优惠券活动
*/
CURRENT_COUPON_ACTIVITY,
/**
* 促销活动
*/
Expand Down Expand Up @@ -441,6 +445,10 @@ public enum CachePrefix {
* 分销员
*/
DISTRIBUTION,
/**
* 邀请人
*/
INVITER,

/**
* 找回手机
Expand Down Expand Up @@ -503,12 +511,11 @@ public enum CachePrefix {

/**
* 扫码登录
*
* @param str
* @return
*/
QR_CODE_LOGIN_SESSION

;
QR_CODE_LOGIN_SESSION;


public static String removePrefix(String str) {
Expand Down
5 changes: 4 additions & 1 deletion framework/src/main/java/cn/lili/common/enums/ResultCode.java
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ public enum ResultCode {
PROMOTION_ACTIVITY_GOODS_ERROR(40009, "当前活动已经开始无法添加商品"),
PROMOTION_ACTIVITY_ERROR(400010, "当前促销活动不存在"),
PROMOTION_LOG_EXIST(40011, "活动已参加,已发重复参加"),
APPLY_END_TIME_ERROR(40012, "参与截至时间不能小于当前时间,不能大于活动开始时间"),

/**
* 优惠券
Expand All @@ -301,14 +302,15 @@ public enum ResultCode {
COUPON_SCOPE_ERROR(41014, "指定商品范围关联id无效!"),
COUPON_MEMBER_NOT_EXIST(41015, "没有当前会员优惠券"),
COUPON_MEMBER_STATUS_ERROR(41016, "当前会员优惠券已过期/作废无法变更状态!"),
COUPON_RANGE_ERROR(41017, "优惠券使用时间范围错误"),

SPECIAL_CANT_USE(41019, "特殊商品不能使用优惠券,不能使用"),

COUPON_SAVE_ERROR(41020, "保存优惠券失败"),
COUPON_DELETE_ERROR(41021, "删除优惠券失败"),
COUPON_ACTIVITY_NOT_EXIST(41022, "当前优惠券活动不存在"),
COUPON_ACTIVITY_SAVE_ERROR(41023, "保存优惠券活动失败"),
COUPON_ACTIVITY_MAX_NUM(41024, "优惠券活动赠券数量最多为3"),
COUPON_ACTIVITY_MAX_NUM(41024, "优惠券活动赠券数量最多为5"),

COUPON_DO_NOT_RECEIVER(41030, "当前优惠券不允许主动领取"),

Expand Down Expand Up @@ -373,6 +375,7 @@ public enum ResultCode {
COUPON_ACTIVITY_ITEM_ERROR(46003, "优惠券活动必须指定优惠券,不能为空"),
COUPON_ACTIVITY_ITEM_MUST_NUM_ERROR(46004, "优惠券活动最多指定10个优惠券"),
COUPON_ACTIVITY_ITEM_NUM_ERROR(46005, "赠券数量必须大于0"),
COUPON_ACTIVITY_ITEM_NUM_MAX_VALUE_2(46006, "赠券数量最大为2"),

/**
* 其他促销
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import cn.lili.common.security.enums.UserEnums;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

/**
* @author Chopper
*/
@Data
@NoArgsConstructor
@AllArgsConstructor
public class AuthUser implements Serializable {

Expand Down Expand Up @@ -85,7 +87,7 @@ public AuthUser(String username, String id, String face, UserEnums manager, Stri
this.nickName = nickName;
}

public AuthUser(String username, String id, UserEnums manager, String nickName, Boolean isSuper, String clerkId,String face) {
public AuthUser(String username, String id, UserEnums manager, String nickName, Boolean isSuper, String clerkId, String face) {
this.username = username;
this.id = id;
this.role = manager;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import cn.lili.common.security.AuthUser;
import cn.lili.common.security.enums.SecurityEnum;
import cn.lili.common.security.token.SecretKeyUtil;
import cn.lili.common.utils.StringUtils;
import com.google.gson.Gson;
import io.jsonwebtoken.Claims;
import io.jsonwebtoken.Jwts;
Expand Down Expand Up @@ -101,4 +102,21 @@ public static AuthUser getAuthUser(String accessToken) {
return null;
}
}


/**
* 写入邀请人信息
*/
public static void settingInviter(String memberId, Cache cache) {
if (RequestContextHolder.getRequestAttributes() != null) {
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
//邀请人id
String inviterId = request.getHeader(SecurityEnum.INVITER.getValue());
if (StringUtils.isNotEmpty(inviterId)) {
cache.put(CachePrefix.INVITER.getPrefix() + memberId, inviterId);
}
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public enum SecurityEnum {
/**
* 存在与header中的token参数头 名
*/
HEADER_TOKEN("accessToken"), USER_CONTEXT("userContext"), JWT_SECRET("secret"), UUID("uuid");
HEADER_TOKEN("accessToken"), USER_CONTEXT("userContext"), JWT_SECRET("secret"), UUID("uuid"), INVITER("inviter");

String value;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,17 @@ public Token phoneMpBindAndLogin(String sessionKey, WechatMPLoginParams params,
Member newMember = new Member("m" + phone, "111111", phone, params.getNickName(), params.getImage());
memberService.save(newMember);
newMember = memberService.findByUsername(newMember.getUsername());

//判定有没有邀请人并且写入
UserContext.settingInviter(newMember.getId(), cache);

bindMpMember(openId, unionId, newMember);


//判定有没有邀请人并且写入
UserContext.settingInviter(newMember.getId(), cache);


// 发送会员注册信息
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("new member register", rocketmqCustomProperties.getMemberTopic(), MemberTagsEnum.MEMBER_REGISTER.name(), newMember));
return memberTokenGenerate.createToken(newMember, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,7 @@ public void updateCategory(Category category) {
}
}
UpdateWrapper<Category> updateWrapper = new UpdateWrapper<>();
updateWrapper.eq("id", category.getId())
.set("name", category.getName())
.set("image", category.getImage())
.set("sort_order", category.getSortOrder())
.set(DELETE_FLAG_COLUMN, category.getDeleteFlag())
.set("commission_rate", category.getCommissionRate());
updateWrapper.eq("id", category.getId());
this.baseMapper.update(category, updateWrapper);
removeCache();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ public void registerHandler(Member member) {
member.setId(SnowFlake.getIdStr());
//保存会员
this.save(member);


// 发送会员注册信息
applicationEventPublisher.publishEvent(new TransactionCommitSendMQEvent("new member register", rocketmqCustomProperties.getMemberTopic(), MemberTagsEnum.MEMBER_REGISTER.name(), member));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ public class PriceDetailDTO implements Serializable {
@ApiModelProperty(value = "优惠金额")
private Double discountPrice;

@ApiModelProperty(value = "优惠金额")
private String discountPriceDetail;

@ApiModelProperty(value = "优惠券金额")
private Double couponPrice;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,13 @@ public class CouponActivity extends BasePromotions {
* @see CouponActivityTypeEnum
*/
@NotNull(message = "优惠券活动类型不能为空")
@ApiModelProperty(value = "优惠券活动类型", allowableValues = "REGISTERED:新人赠券,SPECIFY:精确发券")
@ApiModelProperty(value = "优惠券活动类型", allowableValues = "REGISTERED:新人赠券,INVITE_NEW:邀新赠券,AUTO_COUPON:自动赠券,SPECIFY:精确发券")
private String couponActivityType;

/**
* @see CouponActivitySendTypeEnum
*/
//目前仅在自动赠券模式下该参数会生效,日后如果完善发送测略则调整这里即可
@NotNull(message = "请选择活动范围")
@ApiModelProperty(value = "活动范围", allowableValues = "ALL:全部会员,DESIGNATED:指定会员")
private String activityScope;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package cn.lili.modules.promotion.entity.dto;

import cn.lili.modules.promotion.entity.enums.CouponActivityTypeEnum;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;


/**
* 优惠券活动触发
*
* @author paulG
* @since 2020/10/9
**/
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
public class CouponActivityTrigger {


@ApiModelProperty(value = "用户ID")
private String userId;

@ApiModelProperty(value = "用户昵称")
private String nickName;

@ApiModelProperty(value = "优惠券活动类型")
private CouponActivityTypeEnum couponActivityTypeEnum;
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,15 @@ public enum CouponActivityTypeEnum {
*/
REGISTERED("新人赠券"),
/**
* "精确发券"
* "邀新赠券"
*/
INVITE_NEW("邀新赠券"),
/**
* "自动赠券"
*/
AUTO_COUPON("自动赠券"),
/**
* "定向发券"
*/
SPECIFY("精确发券");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,14 @@ public String description() {
return description;
}

public static boolean exist(String name) {
try {
CouponRangeDayEnum.valueOf(name);
} catch (IllegalArgumentException e) {
return false;
}
return true;
}


}
Loading

0 comments on commit 8543a22

Please sign in to comment.