From c630d74cbb57be7f8345981bae99a11182a2ec26 Mon Sep 17 00:00:00 2001
From: 无关风月 <443237572@qq.com>
Date: 星期三, 19 六月 2024 15:15:49 +0800
Subject: [PATCH] bug修改

---
 ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java |   33 ++++++++++++++++++++++++++-------
 1 files changed, 26 insertions(+), 7 deletions(-)

diff --git a/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java b/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
index 428d9d4..325b9b5 100644
--- a/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
+++ b/ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java
@@ -25,6 +25,7 @@
 import io.swagger.annotations.ApiOperationSupport;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.util.StringUtils;
+import org.springframework.validation.annotation.Validated;
 import org.springframework.web.bind.annotation.*;
 
 import javax.annotation.Resource;
@@ -163,6 +164,11 @@
     @PostMapping("/addGoods")
     @ApiOperation(value = "添加", tags = {"后台-商品管理"})
     public R addGoods(@RequestBody TGoods dto) {
+        if (dto.getTotal()!=null){
+            dto.setSurplus(dto.getTotal());
+        }else{
+            dto.setSurplus(0);
+        }
         goodsService.save(dto);
         return R.ok("添加成功");
     }
@@ -178,6 +184,11 @@
     @PostMapping("/updateGoods")
     @ApiOperation(value = "修改", tags = {"后台-商品管理"})
     public R updateGoods(@RequestBody TGoods dto) {
+        if (dto.getTotal()!=null){
+            dto.setSurplus(dto.getTotal());
+        }else{
+            dto.setSurplus(0);
+        }
         goodsService.updateById(dto);
         return R.ok("修改成功");
     }
@@ -287,6 +298,7 @@
         }
         TOrder byId = orderService.getById(id);
         byId.setState(3);
+        byId.setCompleteTime(new Date());
         return R.ok(orderService.updateById(byId));
     }
 
@@ -615,6 +627,9 @@
             @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
     })
     public R<GoodDetailVO> goodDetail(@RequestParam String goodId) {
+        if (tokenService.getLoginUserStudy() == null) {
+            return R.tokenError("登录失效!");
+        }
         // 商品详情
         TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one();
         if (null == goods) {
@@ -643,9 +658,9 @@
             @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true)
     })
     public R<GoodDetailVO> goodDetailParent(@RequestParam String goodId) {
-        if (tokenService.getLoginUser1() == null) {
-            return R.tokenError("登录失效");
-        }
+//        if (tokenService.getLoginUser1() == null) {
+//            return R.tokenError("登录失效");
+//        }
         // 商品详情
         TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one();
         if (null == goods) {
@@ -673,7 +688,8 @@
         }
         Recipient recipient = recipientService.lambdaQuery()
                 .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid())
-                .eq(Recipient::getIsDefault, 1).one();
+                .eq(Recipient::getIsDefault, 1)
+                .eq(Recipient::getDisabled, 0).one();
         GoodDetailVO goodDetailVO = goodsService.redeemNow(goodId, recipient);
         LocalDateTime currentDateTime = LocalDateTime.now();
         // 格式化日期和时间信息
@@ -683,10 +699,11 @@
         Random random = new Random();
         StringBuilder randomPart = new StringBuilder();
         for (int i = 0; i < 3; i++) {
-            randomPart.append((char) (random.nextInt(26) + 'A')); // 大写字母
+            // 大写字母
+            randomPart.append((char) (random.nextInt(26) + 'A'));
         }
         // 组合订单编号
-        String orderNumber = formattedDateTime + randomPart.toString();
+        String orderNumber = formattedDateTime + randomPart;
         goodDetailVO.setOrderNumber(orderNumber);
         return R.ok(goodDetailVO);
     }
@@ -743,6 +760,7 @@
     @PostMapping("/goodExchange")
     @ApiOperation(value = "家长端-商品兑换确认", tags = {"家长端-商品兑换确认"})
     public R goodExchange(@RequestBody GoodExchangeDTO goodExchange) {
+        System.err.println("家长兑换:");
         Recipient recipient = recipientService.getById(Integer.valueOf(goodExchange.getRecipientId()));
         return goodsService.goodExchange1(goodExchange, recipient);
     }
@@ -750,7 +768,8 @@
     @PostMapping("/goodExchangeStudy")
     @ApiOperation(value = "商品兑换确认", tags = {"学习端-商城"})
     @ApiOperationSupport(order = 42)
-    public R goodExchangeStudy(@RequestBody GoodExchangeDTO goodExchange) {
+    public R<String> goodExchangeStudy(@RequestBody @Validated GoodExchangeDTO goodExchange) {
+        System.err.println("学习兑换:");
         Recipient recipient = recipientService.getById(goodExchange.getRecipientId());
         return goodsService.goodExchange(goodExchange, recipient);
     }

--
Gitblit v1.7.1