| | |
| | | import cn.lili.common.security.context.UserContext; |
| | | import cn.lili.common.vo.PageVO; |
| | | import cn.lili.common.vo.ResultMessage; |
| | | import cn.lili.modules.promotion.entity.dos.Coupon; |
| | | import cn.lili.modules.promotion.entity.dos.MemberCoupon; |
| | | import cn.lili.modules.promotion.entity.dto.CouponActivityTrigger; |
| | | import cn.lili.modules.promotion.entity.dto.search.CouponSearchParams; |
| | |
| | | import cn.lili.modules.promotion.service.CouponService; |
| | | import cn.lili.modules.promotion.service.MemberCouponService; |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | | import io.swagger.annotations.ApiImplicitParams; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.BeanUtils; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.GetMapping; |
| | | import org.springframework.web.bind.annotation.PathVariable; |
| | |
| | | @GetMapping |
| | | @ApiOperation(value = "获取可领取优惠券列表") |
| | | public ResultMessage<IPage<CouponVO>> getCouponList(CouponSearchParams queryParam, PageVO page) { |
| | | System.out.println("------------------------------------"); |
| | | System.out.println(queryParam); |
| | | queryParam.setPromotionStatus(PromotionsStatusEnum.START.name()); |
| | | queryParam.setGetType(CouponGetEnum.FREE.name()); |
| | | IPage<CouponVO> canUseCoupons = couponService.pageVOFindAll(queryParam, page); |
| | | // 查询原始分页数据 |
| | | IPage<CouponVO> originalPage = couponService.pageVOFindAll(queryParam, page); |
| | | List<CouponVO> originalRecords = originalPage.getRecords(); |
| | | |
| | | List<CouponVO> list = canUseCoupons.getRecords(); |
| | | couponService.getUserCouponsStatus(list); |
| | | //更具用户id |
| | | return ResultUtil.data(canUseCoupons); |
| | | // // 获取用户优惠券状态 |
| | | // couponService.getUserCouponsStatus(originalRecords); |
| | | |
| | | // |
| | | originalRecords.forEach(couponVO -> { |
| | | couponVO.setOwned(Boolean.FALSE); |
| | | // 发行数量为0表示不限制,只检查用户领取限制 |
| | | if (couponVO.getPublishNum() == 0) { |
| | | if(shouldRemoveCoupon(couponVO)){ |
| | | couponVO.setOwned(Boolean.TRUE); |
| | | } |
| | | |
| | | } else { |
| | | // 计算剩余数量 |
| | | int residueNum = couponVO.getPublishNum() - couponVO.getReceivedNum(); |
| | | // 剩余数量为0或用户达到领取限制,都需要删除 |
| | | if(residueNum == 0 || shouldRemoveCoupon(couponVO)){ |
| | | couponVO.setOwned(Boolean.TRUE); |
| | | } |
| | | } |
| | | }); |
| | | |
| | | |
| | | |
| | | return ResultUtil.data(originalPage); |
| | | } |
| | | |
| | | /** |
| | | * 判断是否需要标记优惠券不可领取 |
| | | * 用户领取数量达到限制时返回true |
| | | */ |
| | | private boolean shouldRemoveCoupon(CouponVO couponVO) { |
| | | if (couponVO == null || couponVO.getCouponLimitNum() == null) { |
| | | return false; |
| | | } |
| | | |
| | | Long userCouponCount = couponService.getCouponsCountByIdAndMemberId(couponVO.getId()); |
| | | |
| | | if (userCouponCount == null) { |
| | | return false; |
| | | } |
| | | |
| | | // 用户领取数量 >= 限制数量时,需要移除 |
| | | return userCouponCount >= couponVO.getCouponLimitNum(); |
| | | } |
| | | |
| | | @ApiOperation(value = "获取当前会员的优惠券列表") |
| | | @GetMapping("/getCoupons") |
| | | public ResultMessage<IPage<MemberCoupon>> getCoupons(MemberCouponSearchParams param, PageVO pageVo) { |
| | | System.out.println("------------------------------------"); |
| | | System.out.println(param); |
| | | AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); |
| | | param.setMemberId(currentUser.getId()); |
| | |
| | | @GetMapping("/receive/{couponId}") |
| | | public ResultMessage<Object> receiveCoupon(@NotNull(message = "优惠券ID不能为空") @PathVariable("couponId") String couponId) { |
| | | AuthUser currentUser = Objects.requireNonNull(UserContext.getCurrentUser()); |
| | | //在这里判断领取 |
| | | memberCouponService.receiveBuyerCoupon(couponId, currentUser.getId(), currentUser.getNickName()); |
| | | return ResultUtil.success(); |
| | | |
| | | Coupon coupon = couponService.getById(couponId); |
| | | CouponVO couponVO = new CouponVO(); |
| | | BeanUtils.copyProperties(coupon,couponVO); |
| | | System.out.println(couponVO); |
| | | couponVO.setOwned(Boolean.FALSE); |
| | | // 发行数量为0表示不限制,只检查用户领取限制 |
| | | if (couponVO.getPublishNum() == 0) { |
| | | if(shouldRemoveCoupon(couponVO)){ |
| | | couponVO.setOwned(Boolean.TRUE); |
| | | } |
| | | |
| | | } else { |
| | | // 计算剩余数量 |
| | | int residueNum = couponVO.getPublishNum() - couponVO.getReceivedNum(); |
| | | // 剩余数量为0或用户达到领取限制,都需要删除 |
| | | if(residueNum == 0 || shouldRemoveCoupon(couponVO)){ |
| | | couponVO.setOwned(Boolean.TRUE); |
| | | } |
| | | } |
| | | |
| | | return ResultUtil.data(couponVO); |
| | | } |
| | | |
| | | @ApiOperation(value = "通过id获取") |