| | |
| | | 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.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.*; |
| | | |
| | |
| | | |
| | | 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; |
| | | } |
| | | |
| | | /** |
| | |
| | | public AjaxResult<String> add(@RequestBody TShopDTO dto) { |
| | | shopService.save(dto); |
| | | // 添加账号 |
| | | userService.addAccount(dto); |
| | | Long userId = userService.addAccount(dto); |
| | | dto.setUserId(userId); |
| | | shopService.updateById(dto); |
| | | return AjaxResult.success(); |
| | | } |
| | | |
| | |
| | | */ |
| | | @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 AjaxResult.error("该用户不是商家账号"); |
| | | } |
| | | return AjaxResult.success(shopService.getOne(Wrappers.<TShop>lambdaQuery().eq(TShop::getUserId, tokenService.getLoginUser().getUserId()) |
| | | .last("LIMIT 1"))); |
| | | } |
| | | |
| | | /** |