use of com.whoiszxl.entity.Coupon in project shopzz by whoiszxl.
the class CouponController method receive.
@SaCheckLogin
@PostMapping("/receive/{couponId}")
@ApiOperation(value = "用户领取优惠券", notes = "用户领取优惠券", response = Boolean.class)
public ResponseResult<Boolean> receive(@PathVariable Long couponId) {
// 1. 校验优惠券是否能被领取
Coupon coupon = couponService.getById(couponId);
if (coupon.getGiveType().equals(CouponConstants.Status.GIVING) || coupon.getAllCount() - coupon.getReceivedCount() == 0) {
return ResponseResult.buildError("当前优惠券不能被领取");
}
Long memberId = StpUtil.getLoginIdAsLong();
// 2. 判断用户是否领取过
CouponReceivedRecord couponReceivedRecord = couponReceivedRecordService.getByCouponIdAndMemberId(couponId, memberId);
if (couponReceivedRecord != null) {
return ResponseResult.buildError("你已经领取过了此优惠券");
}
// 3. 发放优惠券
Boolean giveFlag = couponService.giveCouponToMember(StpUtil.getLoginIdAsLong(), couponId);
return ResponseResult.buildByFlag(giveFlag);
}
use of com.whoiszxl.entity.Coupon in project shopzz by whoiszxl.
the class AdminCouponController method give.
@SaCheckPermission("admin")
@PostMapping("/{memberId}/{couponId}")
@ApiOperation(value = "后台单独给用户发放优惠券", notes = "后台单独给用户发放优惠券", response = Boolean.class)
public ResponseResult<Boolean> give(@PathVariable Long memberId, @PathVariable Long couponId) {
// 1. 校验优惠券是否支持后台发放
Coupon coupon = couponService.getById(couponId);
if (coupon.getType().equals(CouponConstants.GiveType.ONLY_RECEIVE) || !coupon.getStatus().equals(CouponConstants.Status.GIVING)) {
return ResponseResult.buildError("当前优惠券不支持后台发放");
}
// 2. 发放优惠券
couponService.giveCouponToMember(memberId, couponId);
return ResponseResult.buildSuccess();
}
use of com.whoiszxl.entity.Coupon in project shopzz by whoiszxl.
the class CouponAdminController method save.
@SaCheckLogin
@PostMapping
@ApiOperation(value = "新增优惠券", notes = "新增优惠券", response = ResponseResult.class)
public ResponseResult<Boolean> save(@RequestBody CouponSaveCommand bannerSaveCommand) {
Coupon banner = dozerUtils.map(bannerSaveCommand, Coupon.class);
boolean saveFlag = couponService.save(banner);
return ResponseResult.buildByFlag(saveFlag);
}
use of com.whoiszxl.entity.Coupon in project shopzz by whoiszxl.
the class ActivityServiceImpl method detail.
@Override
public ActivityApiResponse detail(Long id) {
String redisKey = RedisKeyPrefixConstants.ACTIVITY_DETAIL + id;
String activityJson = redisUtils.get(redisKey);
if (StringUtils.isBlank(activityJson)) {
synchronized (this) {
activityJson = redisUtils.get(redisKey);
if (StringUtils.isBlank(activityJson)) {
// 从数据库拿数据
ActivityApiResponse response = new ActivityApiResponse();
Activity activity = super.getById(id);
dozerUtils.map(activity, response);
List<ActivityCoupon> activityCouponList = activityCouponService.list(Wrappers.<ActivityCoupon>lambdaQuery().eq(ActivityCoupon::getActivityId, id));
List<Long> couponIdList = activityCouponList.stream().map(ActivityCoupon::getCouponId).collect(Collectors.toList());
List<Coupon> couponList = couponService.listByIds(couponIdList);
List<CouponApiVO> couponApiVOList = dozerUtils.mapList(couponList, CouponApiVO.class);
response.setCouponList(couponApiVOList);
activityJson = JsonUtil.toJson(response);
redisUtils.set(redisKey, activityJson);
}
}
}
return JsonUtil.fromJson(activityJson, ActivityApiResponse.class);
}
use of com.whoiszxl.entity.Coupon in project shopzz by whoiszxl.
the class PromotionFeignClientImpl method getCoupon.
@Override
public ResponseResult<CouponFeignDTO> getCoupon(Long couponId) {
Coupon coupon = couponService.getById(couponId);
CouponFeignDTO couponFeignDTO = dozerUtils.map(coupon, CouponFeignDTO.class);
List<CouponCategory> couponCategoryList = couponCategoryService.list(Wrappers.<CouponCategory>lambdaQuery().eq(CouponCategory::getCouponId, couponId));
List<Long> categoryIdList = couponCategoryList.stream().map(CouponCategory::getCategoryId).collect(Collectors.toList());
couponFeignDTO.setCategoryIdList(categoryIdList);
return ResponseResult.buildSuccess(couponFeignDTO);
}
Aggregations