| | |
| | | package com.ruoyi.account.controller; |
| | | import java.math.BigDecimal; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.account.api.model.AppUser; |
| | | import com.ruoyi.account.api.model.UserCoupon; |
| | | import com.ruoyi.account.api.model.UserPoint; |
| | | import com.ruoyi.account.api.vo.CouponInfoVo; |
| | | import com.ruoyi.account.service.AppUserService; |
| | | import com.ruoyi.account.service.UserCouponService; |
| | | import com.ruoyi.account.service.UserPointService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.utils.bean.BeanUtils; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | |
| | | |
| | | @Resource |
| | | private CouponClient couponClient; |
| | | @Resource |
| | | private AppUserService appUserService; |
| | | |
| | | @Resource |
| | | private UserPointService userPointService; |
| | | |
| | | |
| | | |
| | | |
| | | @PostMapping("/mine/list") |
| | | @ApiOperation(value = "已领取列表", tags = {"小程序-首页-优惠劵"}) |
| | | @ApiOperation(value = "已领取列表", tags = {"小程序-个人中心-优惠劵"}) |
| | | public R<Page<UserCoupon>> minelist(@RequestParam Integer pageNum, @RequestParam Integer pageSize, @ApiParam("1未使用2已使用3已过期") Integer status) { |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | Page<UserCoupon> page = userCouponService.lambdaQuery() |
| | |
| | | } |
| | | |
| | | |
| | | @PostMapping("/get") |
| | | @ApiOperation(value = "领取或者兑换优惠券", tags = {"小程序-个人中心-优惠劵"}) |
| | | public R<Page<UserCoupon>> get(@RequestParam Integer couponId) { |
| | | |
| | | Long userid = tokenService.getLoginUserApplet().getUserid(); |
| | | AppUser byId = appUserService.getById(userid); |
| | | |
| | | CouponInfo data = couponClient.detail(couponId).getData(); |
| | | //检验当前优惠券是否存在 |
| | | if (data==null){ |
| | | return R.fail("当前优惠券不存在,请刷新后重试"); |
| | | } |
| | | if (data.getSendType()!=1&&byId.getLavePoint().compareTo(data.getNeedPoint())==-1){ |
| | | return R.fail("当前积分不足,兑换失败"); |
| | | } |
| | | //检验发放时间 |
| | | LocalDateTime now = LocalDateTime.now(); |
| | | if (now.isBefore(data.getSendStartTime())||now.isAfter(data.getSendEndTime())){ |
| | | return R.fail("领取失败,不在发放有效期"); |
| | | } |
| | | //如果是积分兑换,增加积分的历史记录 |
| | | if (data.getSendType()!=1){ |
| | | UserPoint userPoint = new UserPoint(); |
| | | userPoint.setType(4); |
| | | userPoint.setHistoricalPoint(byId.getLavePoint()); |
| | | userPoint.setVariablePoint(data.getNeedPoint()); |
| | | userPoint.setAppUserId(userid); |
| | | userPoint.setObjectId(Long.valueOf(data.getId())); |
| | | userPointService.save(userPoint); |
| | | //扣除积分 |
| | | byId.setLavePoint(byId.getLavePoint().subtract(userPoint.getVariablePoint())); |
| | | appUserService.updateById(byId); |
| | | } |
| | | //增加优惠券记录,根据时间类型设置开始结束时间 |
| | | UserCoupon userCoupon = new UserCoupon(); |
| | | userCoupon.setAppUserId(userid); |
| | | if (data.getPeriodType()==1) { |
| | | userCoupon.setStartTime(data.getPeriodStartTime()); |
| | | userCoupon.setEndTime(data.getPeriodEndTime()); |
| | | }else { |
| | | userCoupon.setStartTime(now); |
| | | userCoupon.setEndTime(now.plusDays(data.getPeriodDays())); |
| | | } |
| | | userCoupon.setCouponId(data.getId()); |
| | | userCouponService.save(userCoupon); |
| | | return R.ok(); |
| | | |
| | | |
| | | } |
| | | |
| | | |
| | | |
| | | |
| | | |