Authored by tanling

可用优惠券类型

... ... @@ -189,7 +189,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
if (!couponTypeEnum.isPresent()){
throw new ServiceException(400, "错误:不合法的优惠券类型");
}
parseSkupForbidType(req);
parseSkupAllowType(req);
int productLimitType = req.getProductLimitType().intValue();
List<Integer> productIds = getProductIdsAndCheckProductLimitParam(productLimitType,req.getProductLimitValue());
... ... @@ -256,27 +256,37 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
return new ApiResponse.ApiResponseBuilder().build();
}
private void parseSkupForbidType(CouponSaveUpdateReq req) {
if (StringUtils.isBlank(req.getSkupForbidType())) {
req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);
return;
}
List<String> limitTypes = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(req.getSkupForbidType());
if (CollectionUtils.isEmpty(limitTypes)) {
req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);
return;
}
for (String limitType : limitTypes) {
if (!limitType.matches("\\d+")) {
throw new ServiceException(400, "错误:不合法的限制类型");
}
if (!SkupType.of(Integer.parseInt(limitType)).isPresent() && !SKUP_FORBID_TYPE_NONE.equals(limitType)) {
throw new ServiceException(401, "错误:不合法的限制类型");
}
private void parseSkupAllowType(CouponSaveUpdateReq req) {
if (StringUtils.isBlank(req.getSkupAllowType())) {
throw new ServiceException(403, "可使用该优惠券的商品属性不能为空");
}
req.setSkupForbidType(Joiner.on(",").join(limitTypes));
List<String> allowAttributeTypes = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(req.getSkupAllowType());
req.setSkupAllowType(Joiner.on(",").join(allowAttributeTypes));
}
// private void parseSkupForbidType(CouponSaveUpdateReq req) {
// if (StringUtils.isBlank(req.getSkupForbidType())) {
// req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);
// return;
// }
// List<String> limitTypes = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(req.getSkupForbidType());
// if (CollectionUtils.isEmpty(limitTypes)) {
// req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);
// return;
// }
// for (String limitType : limitTypes) {
// if (!limitType.matches("\\d+")) {
// throw new ServiceException(400, "错误:不合法的限制类型");
// }
// if (!SkupType.of(Integer.parseInt(limitType)).isPresent() && !SKUP_FORBID_TYPE_NONE.equals(limitType)) {
// throw new ServiceException(401, "错误:不合法的限制类型");
// }
// }
// req.setSkupForbidType(Joiner.on(",").join(limitTypes));
// }
private void saveProductLimitItems(CouponSaveUpdateReq req, int productLimitType, List<Integer> productIds) {
if(req.getProductLimitType() == Coupon.PRODUCTLIMITTYPE_SPECIALPRODUCT || req.getProductLimitType() == Coupon.PRODUCTLIMITTYPE_EXCLUDE){
// 清理之前的记录
... ...
... ... @@ -32,6 +32,12 @@ public class Coupon implements Serializable {
* 禁止商品类型
*/
private String skupForbidType;
/**
* 可用商品类型
*/
private String skupAllowType;
/**商品限制条件-特定商品*/
public static final int PRODUCTLIMITTYPE_SPECIALPRODUCT = 1;
/**商品限制条件-无限制*/
... ...
... ... @@ -21,12 +21,13 @@
<result column="pid" property="pid" jdbcType="INTEGER" />
<result column="remark" property="remark" jdbcType="VARCHAR" />
<result column="skup_forbid_type" property="skupForbidType" jdbcType="VARCHAR" />
<result column="skup_allow_type" property="skupAllowType" jdbcType="VARCHAR" />
</resultMap>
<sql id="Base_Column_List">
id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num,
use_limit_type,use_limit_value,product_limit_type,product_limit_value,start_time,
end_time,status,create_time,pid,remark,skup_forbid_type
end_time,status,create_time,pid,remark,skup_forbid_type,skup_forbid_type
</sql>
<insert id="insertOrUpdate" useGeneratedKeys="true" keyProperty="param.id">
insert into coupon(id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num,
... ... @@ -129,8 +130,8 @@
<if test="param.remark != null">
remark=#{param.remark},
</if>
<if test="param.skupForbidType != null">
skup_forbid_type=#{param.skupForbidType},
<if test="param.skupAllowType != null">
skup_allow_type=#{param.skupAllowType},
</if>
</set>
where id = #{param.id}
... ...