Authored by tanling

可用优惠券类型

@@ -189,7 +189,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ @@ -189,7 +189,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
189 if (!couponTypeEnum.isPresent()){ 189 if (!couponTypeEnum.isPresent()){
190 throw new ServiceException(400, "错误:不合法的优惠券类型"); 190 throw new ServiceException(400, "错误:不合法的优惠券类型");
191 } 191 }
192 - parseSkupForbidType(req); 192 + parseSkupAllowType(req);
193 193
194 int productLimitType = req.getProductLimitType().intValue(); 194 int productLimitType = req.getProductLimitType().intValue();
195 List<Integer> productIds = getProductIdsAndCheckProductLimitParam(productLimitType,req.getProductLimitValue()); 195 List<Integer> productIds = getProductIdsAndCheckProductLimitParam(productLimitType,req.getProductLimitValue());
@@ -256,26 +256,36 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ @@ -256,26 +256,36 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{
256 return new ApiResponse.ApiResponseBuilder().build(); 256 return new ApiResponse.ApiResponseBuilder().build();
257 } 257 }
258 258
259 - private void parseSkupForbidType(CouponSaveUpdateReq req) {  
260 - if (StringUtils.isBlank(req.getSkupForbidType())) {  
261 - req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);  
262 - return;  
263 - }  
264 - List<String> limitTypes = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(req.getSkupForbidType());  
265 - if (CollectionUtils.isEmpty(limitTypes)) {  
266 - req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);  
267 - return;  
268 - }  
269 - for (String limitType : limitTypes) {  
270 - if (!limitType.matches("\\d+")) {  
271 - throw new ServiceException(400, "错误:不合法的限制类型");  
272 - }  
273 - if (!SkupType.of(Integer.parseInt(limitType)).isPresent() && !SKUP_FORBID_TYPE_NONE.equals(limitType)) {  
274 - throw new ServiceException(401, "错误:不合法的限制类型");  
275 - }  
276 - }  
277 - req.setSkupForbidType(Joiner.on(",").join(limitTypes));  
278 - } 259 +
  260 + private void parseSkupAllowType(CouponSaveUpdateReq req) {
  261 + if (StringUtils.isBlank(req.getSkupAllowType())) {
  262 + throw new ServiceException(403, "可使用该优惠券的商品属性不能为空");
  263 + }
  264 + List<String> allowAttributeTypes = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(req.getSkupAllowType());
  265 + req.setSkupAllowType(Joiner.on(",").join(allowAttributeTypes));
  266 + }
  267 +
  268 +
  269 +// private void parseSkupForbidType(CouponSaveUpdateReq req) {
  270 +// if (StringUtils.isBlank(req.getSkupForbidType())) {
  271 +// req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);
  272 +// return;
  273 +// }
  274 +// List<String> limitTypes = Splitter.on(",").omitEmptyStrings().trimResults().splitToList(req.getSkupForbidType());
  275 +// if (CollectionUtils.isEmpty(limitTypes)) {
  276 +// req.setSkupForbidType(SKUP_FORBID_TYPE_NONE);
  277 +// return;
  278 +// }
  279 +// for (String limitType : limitTypes) {
  280 +// if (!limitType.matches("\\d+")) {
  281 +// throw new ServiceException(400, "错误:不合法的限制类型");
  282 +// }
  283 +// if (!SkupType.of(Integer.parseInt(limitType)).isPresent() && !SKUP_FORBID_TYPE_NONE.equals(limitType)) {
  284 +// throw new ServiceException(401, "错误:不合法的限制类型");
  285 +// }
  286 +// }
  287 +// req.setSkupForbidType(Joiner.on(",").join(limitTypes));
  288 +// }
279 289
280 private void saveProductLimitItems(CouponSaveUpdateReq req, int productLimitType, List<Integer> productIds) { 290 private void saveProductLimitItems(CouponSaveUpdateReq req, int productLimitType, List<Integer> productIds) {
281 if(req.getProductLimitType() == Coupon.PRODUCTLIMITTYPE_SPECIALPRODUCT || req.getProductLimitType() == Coupon.PRODUCTLIMITTYPE_EXCLUDE){ 291 if(req.getProductLimitType() == Coupon.PRODUCTLIMITTYPE_SPECIALPRODUCT || req.getProductLimitType() == Coupon.PRODUCTLIMITTYPE_EXCLUDE){
@@ -32,6 +32,12 @@ public class Coupon implements Serializable { @@ -32,6 +32,12 @@ public class Coupon implements Serializable {
32 * 禁止商品类型 32 * 禁止商品类型
33 */ 33 */
34 private String skupForbidType; 34 private String skupForbidType;
  35 +
  36 + /**
  37 + * 可用商品类型
  38 + */
  39 + private String skupAllowType;
  40 +
35 /**商品限制条件-特定商品*/ 41 /**商品限制条件-特定商品*/
36 public static final int PRODUCTLIMITTYPE_SPECIALPRODUCT = 1; 42 public static final int PRODUCTLIMITTYPE_SPECIALPRODUCT = 1;
37 /**商品限制条件-无限制*/ 43 /**商品限制条件-无限制*/
@@ -21,12 +21,13 @@ @@ -21,12 +21,13 @@
21 <result column="pid" property="pid" jdbcType="INTEGER" /> 21 <result column="pid" property="pid" jdbcType="INTEGER" />
22 <result column="remark" property="remark" jdbcType="VARCHAR" /> 22 <result column="remark" property="remark" jdbcType="VARCHAR" />
23 <result column="skup_forbid_type" property="skupForbidType" jdbcType="VARCHAR" /> 23 <result column="skup_forbid_type" property="skupForbidType" jdbcType="VARCHAR" />
  24 + <result column="skup_allow_type" property="skupAllowType" jdbcType="VARCHAR" />
24 </resultMap> 25 </resultMap>
25 26
26 <sql id="Base_Column_List"> 27 <sql id="Base_Column_List">
27 id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num, 28 id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num,
28 use_limit_type,use_limit_value,product_limit_type,product_limit_value,start_time, 29 use_limit_type,use_limit_value,product_limit_type,product_limit_value,start_time,
29 - end_time,status,create_time,pid,remark,skup_forbid_type 30 + end_time,status,create_time,pid,remark,skup_forbid_type,skup_forbid_type
30 </sql> 31 </sql>
31 <insert id="insertOrUpdate" useGeneratedKeys="true" keyProperty="param.id"> 32 <insert id="insertOrUpdate" useGeneratedKeys="true" keyProperty="param.id">
32 insert into coupon(id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num, 33 insert into coupon(id,coupon_token,coupon_name,coupon_amount,coupon_type,coupon_num,use_num,send_num,
@@ -129,8 +130,8 @@ @@ -129,8 +130,8 @@
129 <if test="param.remark != null"> 130 <if test="param.remark != null">
130 remark=#{param.remark}, 131 remark=#{param.remark},
131 </if> 132 </if>
132 - <if test="param.skupForbidType != null">  
133 - skup_forbid_type=#{param.skupForbidType}, 133 + <if test="param.skupAllowType != null">
  134 + skup_allow_type=#{param.skupAllowType},
134 </if> 135 </if>
135 </set> 136 </set>
136 where id = #{param.id} 137 where id = #{param.id}