From 93eae706828ce693db00bbb9c128a335ca6d4e6d Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期五, 17 一月 2025 15:26:37 +0800
Subject: [PATCH] 修改bug
---
ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java | 282 ++++++++++++++++++++++++++++++++++++++++++++++++++++---
1 files changed, 263 insertions(+), 19 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 8f6e789..6dfc084 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
@@ -1,6 +1,10 @@
package com.ruoyi.account.controller;
+import com.alibaba.fastjson2.JSON;
+import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
+import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
+import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruoyi.account.api.model.AppUser;
import com.ruoyi.account.api.model.UserCoupon;
@@ -11,11 +15,19 @@
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.StringUtils;
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.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
+import java.util.ArrayList;
+import java.util.Arrays;
import java.util.List;
import com.ruoyi.common.security.service.TokenService;
import com.ruoyi.other.api.domain.CouponInfo;
@@ -24,6 +36,7 @@
import io.swagger.annotations.ApiParam;
import java.time.LocalDateTime;
+import java.util.stream.Collectors;
/**
* <p>
@@ -48,23 +61,130 @@
@Resource
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();
- Page<UserCoupon> page = userCouponService.lambdaQuery()
- .isNull(status==1||status==3,UserCoupon::getUseTime)
- .isNotNull(status == 2,UserCoupon::getUseTime)
- .lt(status == 3,UserCoupon::getEndTime, LocalDateTime.now())
- .eq(UserCoupon::getAppUserId, userid).page(Page.of(pageNum, pageSize));
+ LambdaQueryChainWrapper<UserCoupon> chainWrapper = userCouponService.lambdaQuery()
+ .eq(UserCoupon::getAppUserId, userid);
+ if(null != status && 1 == status){
+ chainWrapper.isNull(UserCoupon::getUseTime).gt(UserCoupon::getEndTime, LocalDateTime.now());
+ }
+ if(null != status && 2 == status){
+ chainWrapper.isNotNull(UserCoupon::getUseTime);
+ }
+ if(null != status && 3 == status){
+ chainWrapper.isNull(UserCoupon::getUseTime).lt(UserCoupon::getEndTime, LocalDateTime.now());
+ }
+ Page<UserCoupon> page = chainWrapper.page(Page.of(pageNum-1, pageSize));
for (UserCoupon record : page.getRecords()) {
+ record.setIdStr(record.getId().toString());
CouponInfo data = couponClient.detail(record.getCouponId()).getData();
CouponInfoVo vo = new CouponInfoVo();
BeanUtils.copyProperties(data,vo);
+ //如果是商品券,将商品名称返回
+ if (vo.getCouponType()==4){
+ List<String> goodNames = new ArrayList<>();
+ if (vo.getForGoodIds().equals("-1")){
+ List<Goods> data1 = goodsClient.getAllGoods().getData();
+ List<String> collect = data1.stream().map(Goods::getName).collect(Collectors.toList());
+ goodNames.addAll(collect);
+ }else if(StringUtils.isEmpty(data.getForGoodIds())){
+ goodNames.addAll(JSON.parseArray(data.getGoodsNameJson(), String.class));
+ }else {
+ String[] split = vo.getForGoodIds().split(",");
+ R<List<Goods>> goodsById = goodsClient.getGoodsById(split);
+ if (goodsById.getData()!=null){
+ for (Goods datum : goodsById.getData()) {
+ goodNames.add(datum.getName());
+ }
+ }
+ }
+ vo.setGoodNames(goodNames);
+ }
+
+ record.setCouponInfoVo(vo);
+ if(null != record.getUseTime()){
+ record.setStatus(2);
+ }else{
+ if(record.getEndTime().isBefore(LocalDateTime.now())){
+ record.setStatus(3);
+ }else{
+ record.setStatus(1);
+ }
+ }
+ AppUser appUser = appUserService.getById(record.getAppUserId());
+ record.setUserName(appUser.getName());
+ record.setPhone(appUser.getPhone());
+ }
+ return R.ok(page);
+ }
+
+
+ @GetMapping("/mine/list1")
+ @ApiOperation(value = "已领取列表", tags = {"管理后台-优惠劵"})
+ public R<Page<UserCoupon>> list1(@RequestParam Integer pageNum,
+ @RequestParam Integer pageSize,
+ String userName,
+ @ApiParam("1未使用2已使用3已过期") Integer status,
+ String phone,
+ Integer id) {
+
+ LambdaQueryWrapper<AppUser> queryWrapper = new LambdaQueryWrapper<>();
+
+ if (!StringUtils.isEmpty(phone)) {
+ queryWrapper.like(AppUser::getPhone, phone);
+ }
+ if (!StringUtils.isEmpty(userName)) {
+ queryWrapper.like(AppUser::getName, userName);
+ }
+
+ List<AppUser> appUserList = appUserService.list(queryWrapper);
+
+ if (CollectionUtils.isEmpty(appUserList)) {
+ return R.ok(Page.of(pageNum, pageSize));
+ }
+
+ List<Long> appUserIds = appUserList.stream().map(AppUser::getId).distinct().collect(Collectors.toList());
+
+
+ Page<UserCoupon> page = userCouponService.lambdaQuery()
+ .isNull(status!=null&&(status==1||status==3),UserCoupon::getUseTime)
+ .isNotNull(status!=null&&status==2,UserCoupon::getUseTime)
+ .eq(UserCoupon::getCouponId, id)
+ .in(!CollectionUtils.isEmpty(appUserIds),UserCoupon::getAppUserId, appUserIds)
+ .lt(status!=null&&status==3,UserCoupon::getEndTime, LocalDateTime.now()).page(Page.of(pageNum-1, pageSize));
+ for (UserCoupon record : page.getRecords()) {
+ record.setIdStr(record.getId().toString());
+ CouponInfo data = couponClient.detail(record.getCouponId()).getData();
+ CouponInfoVo vo = new CouponInfoVo();
+ BeanUtils.copyProperties(data,vo);
+ //如果是商品券,将商品名称返回
+ if (vo.getCouponType()==4){
+ List<String> goodNames = new ArrayList<>();
+ if (vo.getForGoodIds().equals("-1")){
+ goodNames.add("全部商品");
+ }else{
+ String[] split = vo.getForGoodIds().split(",");
+ R<List<Goods>> goodsById = goodsClient.getGoodsById(split);
+ if (goodsById.getData()!=null){
+ for (Goods datum : goodsById.getData()) {
+ goodNames.add(datum.getName());
+ }
+ }
+ vo.setGoodNames(goodNames);
+ }
+ }
+
record.setCouponInfoVo(vo);
if (record.getUseTime()==null){
record.setStatus(1);
@@ -74,24 +194,40 @@
}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){
+ long count = userCouponService.count(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getCouponId, couponId).eq(UserCoupon::getDelFlag, 0));
+ if(data.getSendNum() <= count){
+ return R.fail("当前优惠券已全部领取完毕");
+ }
+ count = userCouponService.count(new LambdaQueryWrapper<UserCoupon>().eq(UserCoupon::getCouponId, couponId)
+ .eq(UserCoupon::getAppUserId, userid).eq(UserCoupon::getDelFlag, 0));
+ if(data.getMaxNum() <= count){
+ return R.fail("当前优惠券已达到最大领取限制");
+ }
+
+ if (data.getSendType()!=1&& byId.getLavePoint().compareTo(data.getNeedPoint().intValue()) < 0){
return R.fail("当前积分不足,兑换失败");
}
//检验发放时间
@@ -101,23 +237,30 @@
}
//如果是积分兑换,增加积分的历史记录
if (data.getSendType()!=1){
- UserPoint userPoint = new UserPoint();
- userPoint.setType(4);
- userPoint.setHistoricalPoint(byId.getLavePoint());
- userPoint.setVariablePoint(data.getNeedPoint().intValue());
- userPoint.setAppUserId(userid);
- userPoint.setObjectId(Long.valueOf(data.getId()));
- userPointService.save(userPoint);
+ int point = data.getNeedPoint().intValue();
+ Integer lavePoint = byId.getLavePoint();
//扣除积分
- byId.setLavePoint(byId.getLavePoint() - userPoint.getVariablePoint());
+ byId.setLavePoint(byId.getLavePoint() - point);
appUserService.updateById(byId);
+
+ if(point > 0){
+ UserPoint userPoint = new UserPoint();
+ userPoint.setType(15);
+ userPoint.setHistoricalPoint(lavePoint);
+ userPoint.setVariablePoint(point);
+ userPoint.setBalance(byId.getLavePoint());
+ userPoint.setAppUserId(userid);
+ userPoint.setObjectId(Long.valueOf(data.getId()));
+ userPoint.setCreateTime(LocalDateTime.now());
+ userPointService.save(userPoint);
+ }
}
//增加优惠券记录,根据时间类型设置开始结束时间
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(23, 59, 59));
}else {
userCoupon.setStartTime(now);
userCoupon.setEndTime(now.plusDays(data.getPeriodDays()));
@@ -158,5 +301,106 @@
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());
+ }
+
+
+
+
+ @ResponseBody
+ @GetMapping("/getCouponInfoInfo")
+ @ApiOperation(value = "获取核销商品券详情", tags = {"小程序-个人中心-门店管理"})
+ public R<UserCoupon> getCouponInfoInfo(String id){
+ UserCoupon userCoupon = userCouponService.getById(id);
+ CouponInfo couponInfo = couponClient.detail(userCoupon.getCouponId()).getData();
+ List<String> goodNames = new ArrayList<>();
+ if(!"null".equals(couponInfo.getGoodsNameJson()) && StringUtils.isNotEmpty(couponInfo.getGoodsNameJson())){
+ goodNames = JSON.parseArray(couponInfo.getGoodsNameJson(), String.class);
+ }else{
+ List<Goods> goods = null;
+ if("-1".equals(couponInfo.getForGoodIds())){
+ goods = goodsClient.getGoodsByType(2).getData();
+ }else{
+ goods = goodsClient.getGoodsById(couponInfo.getForGoodIds().split(",")).getData();
+ }
+ goodNames = goods.stream().map(Goods::getName).collect(Collectors.toList());
+ }
+
+ CouponInfoVo couponInfoVo = new CouponInfoVo();
+ BeanUtils.copyProperties(couponInfo, couponInfoVo);
+ couponInfoVo.setGoodNames(goodNames);
+ userCoupon.setCouponInfoVo(couponInfoVo);
+ if (userCoupon.getUseTime()==null){
+ userCoupon.setStatus(1);
+ if (userCoupon.getEndTime().isBefore(LocalDateTime.now())){
+ userCoupon.setStatus(3);
+ }
+ }else {
+ userCoupon.setStatus(2);
+ }
+ return R.ok(userCoupon);
+ }
+
+ @ResponseBody
+ @PutMapping("/useCoupon/{id}")
+ @ApiOperation(value = "核销商品优惠券", tags = {"小程序-个人中心-门店管理"})
+ public R useCoupon(@PathVariable("id") String id){
+ UserCoupon userCoupon = userCouponService.getById(id);
+ if(null == userCoupon){
+ return R.ok("核销码错误");
+ }
+ if(userCoupon.getUseTime() != null){
+ return R.ok("优惠券已使用");
+ }
+ if(LocalDateTime.now().isAfter(userCoupon.getEndTime())){
+ return R.ok("优惠券已过期");
+ }
+ userCoupon.setStatus(2);
+ userCoupon.setUseTime(LocalDateTime.now());
+ userCouponService.updateById(userCoupon);
+ return R.ok();
+ }
+
+
+ /**
+ * 获取用户优惠券详情
+ * @param id
+ * @return
+ */
+ @PostMapping("/getUserCoupon")
+ public R<UserCoupon> getUserCoupon(@RequestParam("id") Long id){
+ UserCoupon userCoupon = userCouponService.getById(id);
+ return R.ok(userCoupon);
+ }
+
+
+ /**
+ * 编辑用户优惠券
+ * @return
+ */
+ @PostMapping("/editUserCoupon")
+ public R editUserCoupon(@RequestBody UserCoupon userCoupon){
+ userCouponService.updateById(userCoupon);
+ return R.ok();
+ }
+
+
+ /**
+ * 编辑用户优惠券使用时间
+ * @param userCoupon
+ * @return
+ */
+ @PostMapping("/editReturnUse")
+ public R editReturnUse(@RequestBody UserCoupon userCoupon){
+ userCouponService.update(new LambdaUpdateWrapper<UserCoupon>().eq(UserCoupon::getId, userCoupon.getId())
+ .set(UserCoupon::getUseTime, userCoupon.getUseTime()));
+ return R.ok();
+ }
}
--
Gitblit v1.7.1