Search in sources :

Example 1 with Coupon

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);
}
Also used : Coupon(com.whoiszxl.entity.Coupon) MemberCoupon(com.whoiszxl.entity.MemberCoupon) CouponReceivedRecord(com.whoiszxl.entity.CouponReceivedRecord) SaCheckLogin(cn.dev33.satoken.annotation.SaCheckLogin) ApiOperation(io.swagger.annotations.ApiOperation)

Example 2 with Coupon

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();
}
Also used : Coupon(com.whoiszxl.entity.Coupon) MemberCoupon(com.whoiszxl.entity.MemberCoupon) SaCheckPermission(cn.dev33.satoken.annotation.SaCheckPermission) ApiOperation(io.swagger.annotations.ApiOperation)

Example 3 with Coupon

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);
}
Also used : Coupon(com.whoiszxl.entity.Coupon) SaCheckLogin(cn.dev33.satoken.annotation.SaCheckLogin) ApiOperation(io.swagger.annotations.ApiOperation)

Example 4 with Coupon

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);
}
Also used : ActivityCoupon(com.whoiszxl.entity.ActivityCoupon) Coupon(com.whoiszxl.entity.Coupon) ActivityCoupon(com.whoiszxl.entity.ActivityCoupon) CouponApiVO(com.whoiszxl.cqrs.vo.CouponApiVO) Activity(com.whoiszxl.entity.Activity) ActivityApiResponse(com.whoiszxl.cqrs.response.ActivityApiResponse)

Example 5 with Coupon

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);
}
Also used : Coupon(com.whoiszxl.entity.Coupon) MemberCoupon(com.whoiszxl.entity.MemberCoupon) CouponCategory(com.whoiszxl.entity.CouponCategory) CouponFeignDTO(com.whoiszxl.dto.CouponFeignDTO)

Aggregations

Coupon (com.whoiszxl.entity.Coupon)8 MemberCoupon (com.whoiszxl.entity.MemberCoupon)5 ApiOperation (io.swagger.annotations.ApiOperation)4 SaCheckLogin (cn.dev33.satoken.annotation.SaCheckLogin)3 CouponApiVO (com.whoiszxl.cqrs.vo.CouponApiVO)2 SaCheckPermission (cn.dev33.satoken.annotation.SaCheckPermission)1 ActivityApiResponse (com.whoiszxl.cqrs.response.ActivityApiResponse)1 CouponFeignDTO (com.whoiszxl.dto.CouponFeignDTO)1 Activity (com.whoiszxl.entity.Activity)1 ActivityCoupon (com.whoiszxl.entity.ActivityCoupon)1 CouponCategory (com.whoiszxl.entity.CouponCategory)1 CouponReceivedRecord (com.whoiszxl.entity.CouponReceivedRecord)1 Type (java.lang.reflect.Type)1 LocalDateTime (java.time.LocalDateTime)1 List (java.util.List)1