From d341be8242db41136119a842e29194af4902a9b7 Mon Sep 17 00:00:00 2001
From: Pu Zhibing <393733352@qq.com>
Date: 星期二, 10 十二月 2024 18:35:14 +0800
Subject: [PATCH] 同步代码

---
 ruoyi-service/ruoyi-account/src/main/java/com/ruoyi/account/controller/UserCouponController.java |   56 +++++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 45 insertions(+), 11 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..a86426a 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
@@ -13,9 +13,15 @@
 import com.ruoyi.common.core.domain.R;
 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;
+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;
@@ -48,23 +54,47 @@
 
     @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));
+                .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-1, pageSize));
         for (UserCoupon record : page.getRecords()) {
             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);
@@ -79,7 +109,7 @@
     }
 
 
-    @PostMapping("/get")
+    @GetMapping("/get")
     @ApiOperation(value = "领取或者兑换优惠券", tags = {"小程序-个人中心-优惠劵"})
     public R<Page<UserCoupon>> get(@RequestParam Integer couponId) {
 
@@ -101,16 +131,20 @@
         }
         //如果是积分兑换,增加积分的历史记录
         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();

--
Gitblit v1.7.1