From 6aa659f6cb7d3c86c87c4ab58be4220820c7326b Mon Sep 17 00:00:00 2001
From: xuhy <3313886187@qq.com>
Date: 星期五, 25 十月 2024 19:37:07 +0800
Subject: [PATCH] 修改

---
 ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java |   57 +++++++++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 53 insertions(+), 4 deletions(-)

diff --git a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java
index 220d113..3acfe2d 100644
--- a/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java
+++ b/ruoyi-admin/src/main/java/com/ruoyi/web/controller/api/TShopController.java
@@ -1,22 +1,30 @@
 package com.ruoyi.web.controller.api;
 
 
+import com.baomidou.mybatisplus.core.toolkit.Wrappers;
 import com.ruoyi.common.basic.PageInfo;
 import com.ruoyi.common.core.domain.AjaxResult;
 import com.ruoyi.common.core.domain.entity.SysUser;
+import com.ruoyi.common.utils.StringUtils;
+import com.ruoyi.framework.web.service.TokenService;
+import com.ruoyi.system.domain.TBoard;
 import com.ruoyi.system.domain.TShop;
 import com.ruoyi.system.dto.TShopDTO;
 import com.ruoyi.system.query.TShopQuery;
 import com.ruoyi.system.service.ISysUserService;
+import com.ruoyi.system.service.TBoardService;
 import com.ruoyi.system.service.TShopService;
 import com.ruoyi.system.vo.TShopVO;
 import io.swagger.annotations.Api;
 import io.swagger.annotations.ApiOperation;
+import org.springframework.beans.BeanUtils;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.web.bind.annotation.*;
 
 import java.util.List;
 import java.util.Objects;
+
+import static com.ruoyi.common.core.domain.AjaxResult.error;
 
 /**
  * <p>
@@ -33,11 +41,15 @@
 
     private final TShopService shopService;
     private final ISysUserService userService;
+    private final TBoardService boardService;
+    private final TokenService tokenService;
 
     @Autowired
-    public TShopController(TShopService shopService, ISysUserService userService) {
+    public TShopController(TShopService shopService, ISysUserService userService, TBoardService boardService, TokenService tokenService) {
         this.shopService = shopService;
         this.userService = userService;
+        this.boardService = boardService;
+        this.tokenService = tokenService;
     }
 
     /**
@@ -55,9 +67,18 @@
     @ApiOperation( value = "添加店铺信息")
     @PostMapping(value = "/add")
     public AjaxResult<String> add(@RequestBody TShopDTO dto) {
+        SysUser user = new SysUser();
+        user.setUserName(dto.getAccount());
+        user.setPhonenumber(dto.getAccount());
+        if (!userService.checkUserNameUnique(user))
+        {
+            return error("添加用户'" + user.getUserName() + "'失败,登录账号已存在");
+        }
         shopService.save(dto);
         // 添加账号
-        userService.addAccount(dto);
+        Long userId = userService.addAccount(dto);
+        dto.setUserId(userId);
+        shopService.updateById(dto);
         return AjaxResult.success();
     }
 
@@ -67,6 +88,14 @@
     @ApiOperation( value = "编辑店铺信息")
     @PostMapping(value = "/edit")
     public AjaxResult<String> edit(@RequestBody TShopDTO dto) {
+        SysUser user = new SysUser();
+        user.setUserName(dto.getAccount());
+        user.setPhonenumber(dto.getAccount());
+        user.setUserId(dto.getUserId());
+        if (!userService.checkUserNameUnique(user))
+        {
+            return error("修改用户'" + user.getUserName() + "'失败,登录账号已存在");
+        }
         shopService.updateById(dto);
         userService.updateAccount(dto);
         return AjaxResult.success();
@@ -77,8 +106,28 @@
      */
     @ApiOperation( value = "查看店铺信息详情")
     @GetMapping(value = "/getDetailById")
-    public AjaxResult<TShop> getDetailById(@RequestParam("id") Long id) {
-        return AjaxResult.success(shopService.getById(id));
+    public AjaxResult<TShopVO> getDetailById(@RequestParam("id") Long id) {
+        TShop shop = shopService.getById(id);
+        TShopVO shopVO = new TShopVO();
+        BeanUtils.copyProperties(shop,shopVO);
+        List<TBoard> list = boardService.list(Wrappers.lambdaQuery(TBoard.class)
+                .eq(TBoard::getShopId, id));
+        shopVO.setBoards(list);
+        return AjaxResult.success(shopVO);
+    }
+
+    /**
+     * 用户查看店铺信息详情
+     */
+    @ApiOperation( value = "用户查看店铺信息详情")
+    @GetMapping(value = "/getDetailByUserId")
+    public AjaxResult<TShop> getDetailByUserId() {
+        Integer roleType = tokenService.getLoginUser().getRoleType();
+        if(roleType == 1){
+            return error("该用户不是商家账号");
+        }
+        return AjaxResult.success(shopService.getOne(Wrappers.<TShop>lambdaQuery().eq(TShop::getUserId, tokenService.getLoginUser().getUserId())
+                .last("LIMIT 1")));
     }
 
     /**

--
Gitblit v1.7.1