...
|
...
|
@@ -122,9 +122,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ |
|
|
@Override
|
|
|
public ApiResponse saveOrUpdateCoupon(CouponSaveUpdateReq req) {
|
|
|
LOGGER.info("enter saveOrUpdateCoupon,param is {}",req);
|
|
|
if(!checkSaveOrUpdateCouponParam(req)){
|
|
|
return new ApiResponse.ApiResponseBuilder().code(500).message("参数有误").build();
|
|
|
}
|
|
|
checkSaveOrUpdateCouponParam(req);
|
|
|
int productLimitType = req.getProductLimitType().intValue();
|
|
|
List<Integer> productIds = getProductIdsAndCheckProductLimitParam(productLimitType,req.getProductLimitValue());
|
|
|
|
...
|
...
|
@@ -140,6 +138,10 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ |
|
|
if (Objects.isNull(coupon)) {
|
|
|
throw new ServiceException(400, "错误:优惠券信息不存在");
|
|
|
}
|
|
|
if (coupon.getSendNum() > 0) {
|
|
|
LOGGER.info("checkUpdateCouponParam failed! coupon is using! sendNum is {}", coupon.getSendNum());
|
|
|
throw new ServiceException(500, "修改失败,优惠券已发放");
|
|
|
}
|
|
|
} else {
|
|
|
coupon = null;
|
|
|
}
|
...
|
...
|
@@ -218,56 +220,51 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ |
|
|
return new ApiResponse.ApiResponseBuilder().data(jsonObject).build();
|
|
|
}
|
|
|
|
|
|
private boolean checkSaveOrUpdateCouponParam(CouponSaveUpdateReq req) {
|
|
|
private void checkSaveOrUpdateCouponParam(CouponSaveUpdateReq req) {
|
|
|
if(req == null){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! req is null");
|
|
|
return false;
|
|
|
}
|
|
|
if(req.getId()!=null){
|
|
|
return checkUpdateCouponParam(req);
|
|
|
throw new ServiceException(400, "错误:参数有误");
|
|
|
}
|
|
|
if(StringUtils.isBlank(req.getCouponName())){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! couponName is blank");
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:优惠券名称为空");
|
|
|
}
|
|
|
if(null == req.getUseLimitType()){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! useLimitType error! useLimitType is {}",req.getUseLimitType());
|
|
|
throw new ServiceException(400, "错误:优惠条件为空");
|
|
|
}
|
|
|
if(null == req.getCouponAmount() || req.getCouponAmount()<0){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! couponAmount error! couponAmount is {}",req.getCouponAmount());
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:优惠金额为空");
|
|
|
}
|
|
|
if(null == req.getCouponNum() || req.getCouponNum()<0){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! couponNum error! couponNum is {}",req.getCouponNum());
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:数量为空");
|
|
|
}
|
|
|
if(null == req.getUseNum() || req.getUseNum()<0){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! useNum error! useNum is {}",req.getUseNum());
|
|
|
return false;
|
|
|
}
|
|
|
if(null == req.getUseLimitType()){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! useLimitType error! useLimitType is {}",req.getUseLimitType());
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:使用次数无效");
|
|
|
}
|
|
|
if(null == req.getStartTime() || req.getStartTime()<0){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! startTime error! startTime is {}",req.getStartTime());
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:使用期限无效");
|
|
|
}
|
|
|
if(null == req.getEndTime() || req.getEndTime()<0){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! endTime error! endTime is {}",req.getEndTime());
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:使用期限无效");
|
|
|
}
|
|
|
if(req.getEndTime()<req.getStartTime()){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! endTime < startTime!endTime is {},startTime is {}"
|
|
|
,req.getEndTime(),req.getStartTime());
|
|
|
return false;
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! endTime < startTime!endTime is {},startTime is {}" ,req.getEndTime(),req.getStartTime());
|
|
|
throw new ServiceException(400, "错误:使用期限无效");
|
|
|
}
|
|
|
if(StringUtils.isBlank(req.getRemark())){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! remark is blank.");
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:优惠券说明为空");
|
|
|
}
|
|
|
if(Objects.isNull(req.getProductLimitType())){
|
|
|
LOGGER.info("checkSaveOrUpdateCouponParam failed! productLimitType is blank.");
|
|
|
return false;
|
|
|
throw new ServiceException(400, "错误:适用范围为空");
|
|
|
}
|
|
|
return true;
|
|
|
}
|
|
|
|
|
|
private boolean checkUpdateCouponParam(CouponSaveUpdateReq req) {
|
...
|
...
|
@@ -276,10 +273,7 @@ public class CouponServiceImpl implements ICouponService,IBusinessExportService{ |
|
|
LOGGER.info("checkUpdateCouponParam failed! coupon is null.id is {}",req.getId());
|
|
|
throw new ServiceException(500,"修改失败,优惠券不存在");
|
|
|
}
|
|
|
if(coupon.getSendNum()>0){
|
|
|
LOGGER.info("checkUpdateCouponParam failed! coupon is using! sendNum is {}",coupon.getSendNum());
|
|
|
throw new ServiceException(500,"修改失败,优惠券已发放");
|
|
|
}
|
|
|
|
|
|
return true;
|
|
|
}
|
|
|
|
...
|
...
|
|