From d39d882a8a56d84b76bb407c3b99b82d6d2e4f40 Mon Sep 17 00:00:00 2001 From: Pu Zhibing <393733352@qq.com> Date: 星期五, 27 十二月 2024 11:38:54 +0800 Subject: [PATCH] 修改分佣逻辑 --- ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java | 47 +++++++++++++++++++++++++++++++++++------------ 1 files changed, 35 insertions(+), 12 deletions(-) diff --git a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java index 671074d..da4254c 100644 --- a/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java +++ b/ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java @@ -14,7 +14,9 @@ import com.ruoyi.common.core.utils.bean.BeanUtils; import com.ruoyi.account.api.vo.PaymentUserCoupon; import com.ruoyi.other.api.domain.Goods; +import com.ruoyi.other.api.domain.PointSetting; import com.ruoyi.other.api.feignClient.GoodsClient; +import com.ruoyi.other.api.feignClient.PointSettingClient; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; @@ -54,11 +56,14 @@ private UserPointService userPointService; @Resource private GoodsClient goodsClient; + + @Resource + private PointSettingClient pointSettingClient; - @PostMapping("/mine/list") + @GetMapping("/mine/list") @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(); @@ -66,7 +71,7 @@ .isNull(status!=null&&(status==1||status==3),UserCoupon::getUseTime) .isNotNull(status!=null&&status==2,UserCoupon::getUseTime) .lt(status!=null&&status==3,UserCoupon::getEndTime, LocalDateTime.now()) - .eq(UserCoupon::getAppUserId, userid).page(Page.of(pageNum, pageSize)); + .eq(UserCoupon::getAppUserId, userid).page(Page.of(pageNum-1, pageSize)); for (UserCoupon record : page.getRecords()) { CouponInfo data = couponClient.detail(record.getCouponId()).getData(); CouponInfoVo vo = new CouponInfoVo(); @@ -99,24 +104,30 @@ }else { record.setStatus(2); } + + + AppUser appUser = appUserService.getById(record.getAppUserId()); + record.setUserName(appUser.getName()); + record.setPhone(appUser.getPhone()); } return R.ok(page); } - @PostMapping("/get") + @GetMapping("/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(); + R<CouponInfo> detail = couponClient.detail(couponId); + CouponInfo data = detail.getData(); //检验当前优惠券是否存在 if (data==null){ return R.fail("当前优惠券不存在,请刷新后重试"); } - if (data.getSendType()!=1&&byId.getLavePoint().compareTo(data.getNeedPoint().intValue())==-1){ + if (data.getSendType()!=1&& byId.getLavePoint().compareTo(data.getNeedPoint().intValue()) < 0){ return R.fail("当前积分不足,兑换失败"); } //检验发放时间 @@ -126,23 +137,27 @@ } //如果是积分兑换,增加积分的历史记录 if (data.getSendType()!=1){ + int point = data.getNeedPoint().intValue(); + Integer lavePoint = byId.getLavePoint(); + //扣除积分 + byId.setLavePoint(byId.getLavePoint() - point); + appUserService.updateById(byId); + UserPoint userPoint = new UserPoint(); userPoint.setType(4); - userPoint.setHistoricalPoint(byId.getLavePoint()); - userPoint.setVariablePoint(data.getNeedPoint().intValue()); + userPoint.setHistoricalPoint(lavePoint); + userPoint.setVariablePoint(point); + userPoint.setBalance(byId.getLavePoint()); userPoint.setAppUserId(userid); userPoint.setObjectId(Long.valueOf(data.getId())); userPointService.save(userPoint); - //扣除积分 - byId.setLavePoint(byId.getLavePoint() - userPoint.getVariablePoint()); - appUserService.updateById(byId); } //增加优惠券记录,根据时间类型设置开始结束时间 UserCoupon userCoupon = new UserCoupon(); userCoupon.setAppUserId(userid); if (data.getPeriodType()==1) { - userCoupon.setStartTime(data.getPeriodStartTime()); - userCoupon.setEndTime(data.getPeriodEndTime()); + userCoupon.setStartTime(data.getPeriodStartTime().atTime(0,0,0)); + userCoupon.setEndTime(data.getPeriodEndTime().atTime(0,0,0)); }else { userCoupon.setStartTime(now); userCoupon.setEndTime(now.plusDays(data.getPeriodDays())); @@ -183,5 +198,13 @@ BeanUtils.copyProperties(data, couponInfoVo); return R.ok(couponInfoVo); } + + /** + * 获取优惠券发放数量 + */ + @GetMapping("/getCouponCount") + public R<Long> getCouponCount(@RequestParam Integer couponId){ + return R.ok(userCouponService.lambdaQuery().eq(UserCoupon::getCouponId, couponId).count()); + } } -- Gitblit v1.7.1