Commit 6f3ddcc5 by ping.wu

Merge branches 'feature/20210901_积分商城兑换券校验券有效期_wuping' and 'master' of…

Merge branches 'feature/20210901_积分商城兑换券校验券有效期_wuping' and 'master' of http://gitlab.freemud.com/order-group-application/order-group

# Conflicts:
#	shopping-cart-application-service/src/main/java/cn/freemud/service/impl/MemberDiscountServiceImpl.java
parents e44d7cbe 5604e2c3
package cn.freemud.entities;
import com.alibaba.fastjson.annotation.JSONField;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
import java.math.BigDecimal;
import java.util.Date;
import java.util.List;
@Data
public class Active {
@JSONField(
name = "ActiveId"
)
private Integer ActiveId;
@JSONField(
name = "EBCode"
)
private String EBCode;
@JSONField(
name = "Type"
)
private Integer Type;
@JSONField(
name = "PartnerID"
)
private Integer PartnerID;
@JSONField(
name = "PlatformItemId"
)
private String PlatformItemId;
@JSONField(
name = "State"
)
private Integer State;
@JSONField(
name = "CreateUser"
)
private String CreateUser;
@JSONField(
name = "CreateDate"
)
private String CreateDate;
@JSONField(
name = "LastEditUser"
)
private String LastEditUser;
@JSONField(
name = "LastEditDate"
)
private String LastEditDate;
@JSONField(
name = "ActiveCode"
)
private String ActiveCode;
@JSONField(
name = "ActiveName"
)
private String ActiveName;
@JSONField(
name = "StartDate"
)
private String StartDate;
@JSONField(
name = "EndDate"
)
private String EndDate;
@JSONField(
name = "ShouldRedeemAll"
)
private Boolean ShouldRedeemAll;
@JSONField(
name = "PromotionType"
)
private String PromotionType;
@JSONField(
name = "Exclusive"
)
private Boolean Exclusive;
@JSONField(
name = "MinAmount"
)
private BigDecimal MinAmount;
@JSONField(
name = "MaxRedeemTimes"
)
private Integer MaxRedeemTimes;
@JSONField(
name = "MaxSendOut"
)
private Integer MaxSendOut;
@JSONField(
name = "Cost"
)
private BigDecimal Cost;
@JSONField(
name = "BusinessID"
)
private Integer BusinessID;
@JSONField(
name = "ActiveDesc"
)
private String ActiveDesc;
@JSONField(
name = "Percentage"
)
private Double percentage;
@JSONField(
name = "Inventory"
)
@JsonProperty("EBCode")
private String ebCode;
private Integer type;
private Integer partnerId;
private String platformItemid;
private String activeCode;
private Integer state;
private String activeName;
private String activeDesc;
private String createUser;
private Date createDate;
private Date startDate;
private Date endDate;
private String lasteditUser;
private Date lasteditDate;
private Boolean shouldRedeemall;
private String promotionType;
private Boolean exclusive;
private BigDecimal minAmount;
private Integer maxRedeemTimes;
private BigDecimal cost;
private Integer businessId;
private BigDecimal percentDiscount;
private BigDecimal maxDiscount;
private BigDecimal originalPrice;
private BigDecimal salePrice;
private Integer timeLimit;
private Integer dailyRedeemTimes;
private Integer stationEnable;
private String redeemChannel;
private String appId;
private Integer fromDayEffective;
private Integer effective;
private Date effectiveStart;
private Date effectiveEnd;
private Date effectiveStartTime;
private Date effectiveEndTime;
private BigDecimal amountDiscount;
private BigDecimal merchantDiscountPrice;
private BigDecimal platformDiscountPrice;
private BigDecimal supplierDiscountPrice;
private String thirdpartyActiveCode;
private Integer storeLimitType;
private Integer limitType;
private String logo;
private String productScopeDesc;
private String storeScopeDesc;
private Integer createType;
private Integer promotionSharing;
private String remark;
private List<String> labelNames;
private List<Integer> labels;
private String cornerIcon;
private String cornerPosition;
private Integer isMarketingTransfer;
private Integer isDonate;
private Integer prestoreCodeNumber;
private Integer inventory;
@JSONField(
name = "PercentDiscount"
)
private BigDecimal PercentDiscount;
@JSONField(
name = "MaxDiscount"
)
private Integer MaxDiscount;
@JSONField(
name = "AppId"
)
private String AppId;
@JSONField(
name = "FromDayEffective"
)
private Integer FromDayEffective;
@JSONField(
name = "Effective"
)
private Integer Effective;
@JSONField(
name = "EffectiveStart"
)
private Date EffectiveStart;
@JSONField(
name = "EffectiveEnd"
)
private Date EffectiveEnd;
@JSONField(
name = "RedeemChannel"
)
private String RedeemChannel;
@JSONField(
name = "MerchantDiscountPrice"
)
private BigDecimal MerchantDiscountPrice;
@JSONField(
name = "PlatformDiscountPrice"
)
private BigDecimal PlatformDiscountPrice;
@JSONField(
name = "OtherDiscountPrice"
)
private BigDecimal OtherDiscountPrice;
private Integer leftInventory;
@JSONField(
name = "salePrice"
)
private Integer salePrice;
@JSONField(
name = "voucherFaceValue"
)
private Integer voucherFaceValue;
/**
* 限购份数, 仅商品兑换券可用
*/
@JSONField(
name = "accountSendOutNum"
)
private Integer accountSendOutNum;
/**
* 每份购买张数, 仅商品兑换券可用
*/
@JSONField(
name = "accountSendOutAmount"
)
private Integer accountSendOutAmount;
// @JSONField(
// name = "ActiveId"
// )
// private Integer ActiveId;
// @JSONField(
// name = "EBCode"
// )
// private String EBCode;
// @JSONField(
// name = "Type"
// )
// private Integer Type;
// @JSONField(
// name = "PartnerID"
// )
// private Integer PartnerID;
// @JSONField(
// name = "PlatformItemId"
// )
// private String PlatformItemId;
// @JSONField(
// name = "State"
// )
// private Integer State;
// @JSONField(
// name = "CreateUser"
// )
// private String CreateUser;
// @JSONField(
// name = "CreateDate"
// )
// private String CreateDate;
// @JSONField(
// name = "LastEditUser"
// )
// private String LastEditUser;
// @JSONField(
// name = "LastEditDate"
// )
// private String LastEditDate;
// @JSONField(
// name = "ActiveCode"
// )
// private String ActiveCode;
// @JSONField(
// name = "ActiveName"
// )
// private String ActiveName;
// @JSONField(
// name = "StartDate"
// )
// private String StartDate;
// @JSONField(
// name = "EndDate"
// )
// private String EndDate;
// @JSONField(
// name = "ShouldRedeemAll"
// )
// private Boolean ShouldRedeemAll;
// @JSONField(
// name = "PromotionType"
// )
// private String PromotionType;
// @JSONField(
// name = "Exclusive"
// )
// private Boolean Exclusive;
// @JSONField(
// name = "MinAmount"
// )
// private BigDecimal MinAmount;
// @JSONField(
// name = "MaxRedeemTimes"
// )
// private Integer MaxRedeemTimes;
// @JSONField(
// name = "MaxSendOut"
// )
// private Integer MaxSendOut;
// @JSONField(
// name = "Cost"
// )
// private BigDecimal Cost;
// @JSONField(
// name = "BusinessID"
// )
// private Integer BusinessID;
// @JSONField(
// name = "ActiveDesc"
// )
// private String ActiveDesc;
// @JSONField(
// name = "Percentage"
// )
// private Double percentage;
// @JSONField(
// name = "Inventory"
// )
// private Integer inventory;
// @JSONField(
// name = "PercentDiscount"
// )
// private BigDecimal PercentDiscount;
// @JSONField(
// name = "MaxDiscount"
// )
// private Integer MaxDiscount;
// @JSONField(
// name = "AppId"
// )
// private String AppId;
// @JSONField(
// name = "FromDayEffective"
// )
// private Integer FromDayEffective;
// @JSONField(
// name = "Effective"
// )
// private Integer Effective;
// @JSONField(
// name = "EffectiveStart"
// )
// private Date EffectiveStart;
// @JSONField(
// name = "EffectiveEnd"
// )
// private Date EffectiveEnd;
// @JSONField(
// name = "RedeemChannel"
// )
// private String RedeemChannel;
// @JSONField(
// name = "MerchantDiscountPrice"
// )
// private BigDecimal MerchantDiscountPrice;
// @JSONField(
// name = "PlatformDiscountPrice"
// )
// private BigDecimal PlatformDiscountPrice;
// @JSONField(
// name = "OtherDiscountPrice"
// )
// private BigDecimal OtherDiscountPrice;
//
// @JSONField(
// name = "salePrice"
// )
// private Integer salePrice;
// @JSONField(
// name = "voucherFaceValue"
// )
// private Integer voucherFaceValue;
// /**
// * 限购份数, 仅商品兑换券可用
// */
// @JSONField(
// name = "accountSendOutNum"
// )
// private Integer accountSendOutNum;
// /**
// * 每份购买张数, 仅商品兑换券可用
// */
// @JSONField(
// name = "accountSendOutAmount"
// )
// private Integer accountSendOutAmount;
}
package cn.freemud.entities;
import java.util.List;
public class BatchQueryActivityInfoResponse {
/**
* 状态码
*/
private String statusCode;
/**
* 状态码描述
*/
private String msg;
private List<Active> activities;
}
//package cn.freemud.entities;
//
//import java.util.List;
//
//public class BatchQueryActivityInfoResponse {
//
// /**
// * 状态码
// */
// private String statusCode;
//
// /**
// * 状态码描述
// */
// private String msg;
//
// private List<Active> activities;
//
//}
package cn.freemud.enums;
public enum CouponActiveStateEnum {
/**
* 只有1和2能发,一般没有2
*/
STATE_0(0, "未启用"),
STATE_1(1, "启用"),
STATE_2(2, "开始"),
STATE_3(3, "结束"),
STATE_4(4, "暂停"),
STATE_5(5, "作废"),
STATE_6(6, "禁用")
;
private Integer code;
private String desc;
CouponActiveStateEnum(Integer code, String desc) {
this.code = code;
this.desc = desc;
}
public static CouponActiveStateEnum getByCode(Integer code) {
for (CouponActiveStateEnum type : values()) {
if (type.getCode().equals(code)) {
return type;
}
}
return null;
}
public Integer getCode() {
return code;
}
public void setCode(Integer code) {
this.code = code;
}
public String getDesc() {
return desc;
}
public void setDesc(String desc) {
this.desc = desc;
}
}
......@@ -14,6 +14,7 @@ import cn.freemud.entities.dto.user.StatislScoreResponse;
import cn.freemud.entities.dto.user.StatisticalScoreRequestVo;
import cn.freemud.entities.dto.user.UseScoreRequest;
import cn.freemud.entities.vo.*;
import cn.freemud.enums.CouponActiveStateEnum;
import cn.freemud.enums.ResponseResult;
import cn.freemud.enums.integralproduct.IntegralProductStatusEnum;
import cn.freemud.service.CouponService;
......@@ -121,16 +122,26 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
Active active = null;
if (isCoupon) {
String activityCode = integralProductType.getCouponCode();
//券商品查询券活动信息校验券有效 
BatchQueryActivityInfoRequestDto queryActivityInfoRequestDto = new BatchQueryActivityInfoRequestDto();
queryActivityInfoRequestDto.setActiveCode(Arrays.asList(activityCode));
// queryActivityInfoRequestDto.setActiveCode(Arrays.asList("V1628760321931083"));
queryActivityInfoRequestDto.setPartnerId(Integer.valueOf(partnerId));
BatchQueryActivityInfoResponseDto batchQueryActivityInfoResponseDto = couponService.batchQueryActivityInfo(queryActivityInfoRequestDto);
if (!Objects.equals("0", batchQueryActivityInfoResponseDto.getStatusCode())) {
return ResponseUtil.error(batchQueryActivityInfoResponseDto.getStatusCode(), "优惠券异常");
}
active = batchQueryActivityInfoResponseDto.getActivities().get(0);
Date couponValidEnd = getCouponValidEnd(active);
//券商品查询券活动信息校验券有效
//只有1和2能发,一般没有2
List<Integer> canSendCoupon = Arrays.asList(CouponActiveStateEnum.STATE_1.getCode(),CouponActiveStateEnum.STATE_2.getCode());
if(!canSendCoupon.contains(active.getState()) || couponValidEnd == null){
return ResponseUtil.error(ResponseCodeConstant.RESPONSE_ERROR_STR, "优惠券异常");
}
//券已过期
if(getCouponValidEnd(active).before(new Date())){
return ResponseUtil.error(ResponseCodeConstant.RESPONSE_ERROR_STR, "优惠券已过期,无法兑换");
}
}
if (exchangeType != 2) {
......@@ -538,5 +549,37 @@ public class PointsMallOrderServiceImpl implements PointsMallOrderService {
}
/**
* 获取券的有效结束时间
*/
private Date getCouponValidEnd(Active activeInfo){
Date returnDate = null;
if (activeInfo.getEffective() != null && activeInfo.getEffective() > 0) { // 根据固定时长来计算 天来计算
int delayTimes = activeInfo.getFromDayEffective() != null ? activeInfo.getFromDayEffective() : 0;
int validityPeriod = activeInfo.getEffective() != null ? activeInfo.getEffective() : 1;
if (activeInfo.getEffectiveStart() != null && activeInfo.getEffectiveEnd() != null) {
// 有效期为0 默认传1天,做兼容处理
Date effectiveStart = activeInfo.getEffectiveStart();
Date effectiveEnd = activeInfo.getEffectiveEnd();
Date date = new Date();
Date startDate = cn.freemud.base.util.DateUtil.addDays(date, delayTimes);
Date endDate = cn.freemud.base.util.DateUtil.addDays(date, (delayTimes + validityPeriod));
if (startDate.before(effectiveStart)) {
startDate = effectiveStart;
}
if (endDate.after(effectiveEnd)) {
endDate = effectiveEnd;
}
returnDate = endDate;
} else {
// 有效期为0 默认传1天,做兼容处理
returnDate = DateUtil.addDays(new Date(), (delayTimes + validityPeriod - 1));
}
} else {
returnDate = activeInfo.getEffectiveEndTime();
}
return returnDate;
}
}
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