Authored by tanling

优惠券

... ... @@ -46,8 +46,8 @@ public class CouponProxyService implements Compensator {
userCouponsBo.setProductLimitType("1");
userCouponsBo.setProductIdInclude(Lists.newArrayList(88888900));
userCouponsBo.setUseRule("满299可用");
userCouponsBo.setStartTime(1514739661L);
userCouponsBo.setEndTime(1546275661L);
userCouponsBo.setStartTime(1514739661);
userCouponsBo.setEndTime(1546275661);
UserCouponsBo userCouponsBo1 = new UserCouponsBo();
userCouponsBo1.setCouponCode("a200");
... ... @@ -56,8 +56,8 @@ public class CouponProxyService implements Compensator {
userCouponsBo1.setUseLimitValue("");
userCouponsBo1.setProductLimitType("1");
userCouponsBo1.setProductIdInclude(Lists.newArrayList(88888900));
userCouponsBo1.setStartTime(1514739661L);
userCouponsBo1.setEndTime(1546275661L);
userCouponsBo1.setStartTime(1514739661);
userCouponsBo1.setEndTime(1546275661);
return Lists.newArrayList(userCouponsBo, userCouponsBo1);
}
... ... @@ -69,8 +69,8 @@ public class CouponProxyService implements Compensator {
userCouponsBo.setUseLimitValue("299");
userCouponsBo.setProductLimitType("1");
userCouponsBo.setProductIdInclude(Lists.newArrayList(88888900));
userCouponsBo.setStartTime(1514739661L);
userCouponsBo.setEndTime(1546275661L);
userCouponsBo.setStartTime(1514739661);
userCouponsBo.setEndTime(1546275661);
return Lists.newArrayList(userCouponsBo);
}
... ...
package com.yohoufo.promotion.common;
public enum CouponUseStatusEnum {
NOT_USED(0, "未使用"),
USED(1, "已使用"),
/**
* 已作废
*
* @使用场景 1、生日礼包最多使用一张其它会作废
* 2、新客礼包最多使用一张它会作废
*/
INVALID(2, "已作废");
/**
* 编码
*/
private int code;
/**
* 描述
*/
private String desc;
CouponUseStatusEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
}
\ No newline at end of file
package com.yohoufo.promotion.common;
public enum CouponsStatusEnum {
//ERP中老的状态为: 0:未启用 1:启用 3:作废
/**
待审核:通过、驳回、查看详情
通过:查看详情、作废
驳回:修改
作废:查看详情
*/
/**
* 新建之后是待审核
*/
NEED_REVIEW(0, "待审核"),
/**
* 审核通过之后是有效的(对应原来的启用状态)
*/
VALID(1, "有效"),
/**
* 审核通过之后可作废
*/
INVALID(3, "作废"),
/**
* 审批未通过的是驳回状态,驳回状态可编辑,编辑之后变成待审核
*/
REJECT(2, "审核驳回");
/**
* 编码
*/
private int code;
/**
* 描述
*/
private String desc;
/**
* 操作列表
*
* @param code
* @param desc
* @return
*/
CouponsStatusEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
}
package com.yohoufo.promotion.common;
public enum ProductLimitType {
PRODUCT(1, "特定商品", "限特定商品");
int code ;
String desc;
/**
* 显示给前端的文案
*/
String text;
ProductLimitType(int code, String desc, String text) {
this.code = code;
this.desc = desc;
this.text = text;
}
public int getCode() {
return code;
}
public String getText() {
return text;
}
}
\ No newline at end of file
package com.yohoufo.promotion.common;
public enum UseLimitType {
NO_LIMIT(0, "无限制", ""),
AMOUNT_LIMIT(1, "金额", "满{0}可用");
int code ;
String desc;
/**
* 给前端的显示文案
*/
String text;
UseLimitType(int code, String desc, String text) {
this.code = code;
this.desc = desc;
this.text = text;
}
public String getText() {
return text;
}
public int getCode() {
return code;
}
}
package com.yohoufo.promotion.common;
public enum UserCouponsStatusEnum {
NO_USE(0, "未使用"),
USED(1, "已使用");
/**
* 编码
*/
private int code;
/**
* 描述
*/
private String desc;
/**
* 操作列表
*
* @param code
* @param desc
* @return
*/
UserCouponsStatusEnum(int code, String desc) {
this.code = code;
this.desc = desc;
}
public int getCode() {
return code;
}
public String getDesc() {
return desc;
}
}
package com.yohoufo.promotion.controller;
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.promotion.model.response.CouponInfo;
import com.yohoufo.promotion.service.ICouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ...
package com.yohoufo.promotion.controller;
import com.yohobuy.ufo.model.promotion.UserCouponsListBo;
import com.yohoufo.common.ApiResponse;
import com.yohoufo.promotion.model.response.CouponBo;
import com.yohoufo.promotion.model.response.CouponInfo;
import com.yohoufo.promotion.service.ICouponService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
... ... @@ -78,8 +77,8 @@ public class OrderCouponController {
public ApiResponse queryUserNoUsedCoupons(@RequestParam(value = "uid") Integer uid) {
logger.info("use coupons, uid: {}", uid);
List<CouponBo> couponBoList = couponService.queryUserNoUsedCoupons(uid);
logger.info("use coupons, uid: {}, size:{}, success", uid, couponBoList.size());
UserCouponsListBo couponBoList = couponService.queryUserNoUsedCoupons(uid);
logger.info("use coupons, uid: {}, success", uid);
return new ApiResponse.ApiResponseBuilder().code(200).data(couponBoList).build();
}
... ...
package com.yohoufo.promotion.convert;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum;
import com.yohobuy.ufo.model.promotion.constant.CouponUseLimitTypeEnum;
import com.yohobuy.ufo.model.promotion.constant.UserCouponsStatusEnum;
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.promotion.model.*;
import com.yohoufo.promotion.common.ProductLimitType;
import com.yohoufo.promotion.common.UseLimitType;
import com.yohoufo.promotion.common.UserCouponsStatusEnum;
import com.yohoufo.promotion.model.response.CouponInfo;
import com.yohoufo.promotion.model.response.CouponBo;
import java.text.MessageFormat;
import java.util.Arrays;
public class CouponConvert {
public static CouponBo covertCouponBo(UserCoupon userCoupon, Coupon coupon){
public static UserCouponsBo covertCouponBo(UserCoupon userCoupon, Coupon coupon){
CouponBo couponBo = new CouponBo();
UserCouponsBo couponBo = new UserCouponsBo();
couponBo.setUid(userCoupon.getUid());
couponBo.setCouponId(userCoupon.getCouponId());
couponBo.setCouponCode(userCoupon.getCouponCode());
couponBo.setCouponToken(userCoupon.getCouponToken());
couponBo.setCouponType(userCoupon.getCouponType());
couponBo.setCouponAmount(coupon.getCouponAmount());
couponBo.setCouponName(coupon.getCouponName());
couponBo.setProductLimitType(coupon.getProductLimitType());
couponBo.setProductLimitValue(coupon.getProductLimitValue());
couponBo.setUseLimitType(coupon.getUseLimitType());
couponBo.setUseLimitValue(coupon.getUseLimitValue());
couponBo.setProductLimitType(coupon.getProductLimitType()!=null ? String.valueOf(coupon.getProductLimitType()):"");
couponBo.setUseLimitType(coupon.getUseLimitType()!=null ? String.valueOf(coupon.getUseLimitType()) : "");
couponBo.setUseLimitValue(coupon.getUseLimitValue()!=null ? String.valueOf(coupon.getUseLimitValue()) : "");
couponBo.setStartTime(userCoupon.getStartTime());
couponBo.setEndTime(userCoupon.getEndTime());
couponBo.setStatus(userCoupon.getStatus());
// use_limit_type use_limit_value 满多少元可用
if (coupon.getUseLimitType()!=null){
couponBo.setUseRule(MessageFormat.format(CouponUseLimitTypeEnum.of(String.valueOf(coupon.getUseLimitType())).get().getText(),coupon.getUseLimitValue().intValue()));
}
return couponBo;
}
... ... @@ -62,13 +65,13 @@ public class CouponConvert {
couponInfo.setCoupon_value(coupon.getCouponAmount());
// use_limit_type use_limit_value 满多少元可用
if (coupon.getUseLimitType()!=null && coupon.getUseLimitType().intValue() == UseLimitType.AMOUNT_LIMIT.getCode()){
couponInfo.setUse_rule(MessageFormat.format(UseLimitType.AMOUNT_LIMIT.getText(),coupon.getUseLimitValue().intValue()));
if (coupon.getUseLimitType()!=null){
couponInfo.setUse_rule(MessageFormat.format(CouponUseLimitTypeEnum.of(String.valueOf(coupon.getUseLimitType())).get().getText(),coupon.getUseLimitValue().intValue()));
}
// product_limit_type product_limit_value 特定商品
if (coupon.getProductLimitType()!=null && coupon.getProductLimitType().intValue() == ProductLimitType.PRODUCT.getCode()){
couponInfo.setNotes(Arrays.asList(ProductLimitType.PRODUCT.getText()));
if (coupon.getProductLimitType()!=null){
couponInfo.setNotes(Arrays.asList(CouponProductLimitTypeEnum.of(String.valueOf(coupon.getProductLimitType())).get().getText()));
}
}
... ... @@ -97,7 +100,6 @@ public class CouponConvert {
userCoupon.setCouponCode(couponCode);
int now = DateUtil.getCurrentTimeSecond();
userCoupon.setStartTime(now);
// TODO
userCoupon.setEndTime(couponAndType.getCoupon().getEndTime());
userCoupon.setCreateTime(now);
userCoupon.setOrderCode(0l);
... ...
package com.yohoufo.promotion.model.response;
import lombok.Data;
import java.math.BigDecimal;
import java.util.List;
@Data
public class CouponBo {
private Integer uid;
private Integer couponId;
private String couponCode;
private String couponToken;
private String couponName;
private BigDecimal couponAmount;
private Integer couponType;
private Byte useLimitType;
private Short useLimitValue;
private Byte productLimitType;
private String productLimitValue;
private List<Integer> matchProducts;
}
package com.yohoufo.promotion.model.response;
import java.math.BigDecimal;
import java.util.List;
import lombok.Data;
@Data
public class CouponInfo {
private String coupon_token;
private String coupon_name;
private String coupon_code;
private BigDecimal coupon_value;
private String use_rule;
private String coupon_validity;
private Integer coupon_type; //大类
private String coupon_type_name;
List<String> notes;
}
package com.yohoufo.promotion.service;
import com.yohoufo.promotion.model.response.CouponBo;
import com.yohoufo.promotion.model.response.CouponInfo;
import com.yohobuy.ufo.model.promotion.UserCouponsListBo;
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
import java.util.List;
... ... @@ -44,7 +45,7 @@ public interface ICouponService {
* @param uid
* @return
*/
public List<CouponBo> queryUserNoUsedCoupons(Integer uid);
public UserCouponsListBo queryUserNoUsedCoupons(Integer uid);
}
... ...
... ... @@ -3,17 +3,17 @@ package com.yohoufo.promotion.service.impl;
import com.google.common.collect.Lists;
import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohobuy.ufo.model.promotion.UserCouponsListBo;
import com.yohobuy.ufo.model.promotion.constant.CouponProductLimitTypeEnum;
import com.yohobuy.ufo.model.promotion.constant.CouponUseStatusEnum;
import com.yohobuy.ufo.model.promotion.constant.CouponsStatusEnum;
import com.yohobuy.ufo.model.promotion.response.CouponInfo;
import com.yohoufo.common.utils.DateUtil;
import com.yohoufo.dal.promotion.CouponMapper;
import com.yohoufo.dal.promotion.CouponProductLimitMapper;
import com.yohoufo.dal.promotion.UserCouponMapper;
import com.yohoufo.dal.promotion.model.*;
import com.yohoufo.promotion.common.CouponUseStatusEnum;
import com.yohoufo.promotion.common.CouponsStatusEnum;
import com.yohoufo.promotion.common.ProductLimitType;
import com.yohoufo.promotion.convert.CouponConvert;
import com.yohoufo.promotion.model.response.CouponInfo;
import com.yohoufo.promotion.model.response.CouponBo;
import com.yohoufo.promotion.service.*;
import org.apache.commons.collections.CollectionUtils;
import org.slf4j.Logger;
... ... @@ -206,7 +206,7 @@ public class CouponServiceImpl implements ICouponService {
* @param uid
* @return
*/
public List<CouponBo> queryUserNoUsedCoupons(Integer uid){
public UserCouponsListBo queryUserNoUsedCoupons(Integer uid){
if (uid == null || uid <=0){
logger.warn("query coupon list param invalidate");
... ... @@ -217,7 +217,7 @@ public class CouponServiceImpl implements ICouponService {
List<UserCoupon> list = userCouponMapper.selectUsableCouponByUid(uid, DateUtil.getCurrentTimeSecond());
if (CollectionUtils.isEmpty(list)){
return Lists.newArrayList();
return UserCouponsListBo.builder().build();
}
// 批量获取coupon
... ... @@ -228,24 +228,25 @@ public class CouponServiceImpl implements ICouponService {
// 优惠券商品限制 key=couponId, value=ProductId集合
Map<Integer, List<Integer>> couponProductIdMap = getProductIdListMap(couponList);
List<CouponBo> couponBoList = list.stream().map(userCoupon -> {
List<UserCouponsBo> couponBoList = list.stream().map(userCoupon -> {
Coupon coupon = couponMap.get(userCoupon.getCouponId());
List<Integer> productIds = couponProductIdMap.get(userCoupon.getCouponId());
CouponBo couponBo = CouponConvert.covertCouponBo(userCoupon, coupon);
couponBo.setMatchProducts(productIds);
UserCouponsBo couponBo = CouponConvert.covertCouponBo(userCoupon, coupon);
couponBo.setProductIdInclude(productIds);
return couponBo;
}).collect(Collectors.toList());
return couponBoList;
return UserCouponsListBo.builder().coupons(couponBoList).build();
}
private Map<Integer, List<Integer>> getProductIdListMap(List<Coupon> couponList) {
// 批量获取 coupon_product_limt 过滤出商品限制的优惠券id
List<Integer> productLimitCouponIds = couponList.stream().filter(coupon -> {
if (coupon.getProductLimitType()!=null && ProductLimitType.PRODUCT.getCode() == coupon.getProductLimitType().intValue()){
if (coupon.getProductLimitType()!=null && CouponProductLimitTypeEnum.SPECIFIC_PRODUCT.getLimitType().equals(String.valueOf(coupon.getProductLimitType()))){
return true;
}else{
return false;
... ...