|
@@ -157,15 +157,18 @@ public class CouponIssueServiceImp extends ServiceImpl<CouponIssueMapper, Coupon
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
- public void issueCoupon(Long couponId, List<UserParam> userParam, Long issuer, String reason,Boolean sendMessage) {
|
|
|
+ public Boolean issueCoupon(Long couponId, List<UserParam> userParam, Long issuer, String reason, Boolean sendMessage, Boolean throwE) {
|
|
|
CouponInfo couponInfo = couponInfoService.queryCouponInfoById(couponId);
|
|
|
if (couponInfo == null) {
|
|
|
+ if (!throwE) return false;
|
|
|
throw new BizException("未找到优惠券信息");
|
|
|
}
|
|
|
if (couponInfo.getInventory() < userParam.size()) {
|
|
|
+ if (!throwE) return false;
|
|
|
throw new BizException("库存不足");
|
|
|
}
|
|
|
if (couponInfo.getStatus() == EStatus.DISABLE.getValue()) {
|
|
|
+ if (!throwE) return false;
|
|
|
throw new BizException("优惠券已被禁用");
|
|
|
}
|
|
|
// 判断优惠券类型 设置优惠券时间
|
|
@@ -182,9 +185,11 @@ public class CouponIssueServiceImp extends ServiceImpl<CouponIssueMapper, Coupon
|
|
|
List<CouponIssue> couponIssueList = new ArrayList<>();
|
|
|
for (UserParam param : userParam) {
|
|
|
if (param.getUserId() == null) {
|
|
|
+ if (!throwE) return false;
|
|
|
throw new BizException("发放用户id不能为空");
|
|
|
}
|
|
|
if (param.getClientType() == null) {
|
|
|
+ if (!throwE) return false;
|
|
|
throw new BizException("发放客户端不能为空");
|
|
|
}
|
|
|
CouponIssue couponIssue = new CouponIssue();
|
|
@@ -206,6 +211,7 @@ public class CouponIssueServiceImp extends ServiceImpl<CouponIssueMapper, Coupon
|
|
|
// 优惠券扣减库存
|
|
|
int i = couponInfoService.updateStock(couponId, userParam.size(), InOrOutEnum.OUT);
|
|
|
if (i == 0) {
|
|
|
+ if (!throwE) return false;
|
|
|
throw new BizException("库存不足");
|
|
|
}
|
|
|
|
|
@@ -213,6 +219,7 @@ public class CouponIssueServiceImp extends ServiceImpl<CouponIssueMapper, Coupon
|
|
|
if (sendMessage) {
|
|
|
sendMessage(couponInfo.getName(), userParam);
|
|
|
}
|
|
|
+ return true;
|
|
|
}
|
|
|
|
|
|
private void sendMessage(String couponName,List<UserParam> userParams) {
|