From ffb13ddfb98ddc0f360caa313a93b5dc8d6483f5 Mon Sep 17 00:00:00 2001 From: hjl <1657978663@qq.com> Date: 星期二, 21 五月 2024 17:42:53 +0800 Subject: [PATCH] feat: 接口返回更改;微信分享接口提供 --- ruoyi-service/ruoyi-goods/src/main/java/com/ruoyi/goods/controller/TGoodsController.java | 73 +++++++++++++++++++++++------------- 1 files changed, 46 insertions(+), 27 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 20988ac..7ee95af 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 @@ -6,14 +6,14 @@ import com.ruoyi.common.core.web.domain.AjaxResult; import com.ruoyi.common.core.web.page.PageInfo; import com.ruoyi.common.security.service.TokenService; -import com.ruoyi.common.security.utils.SecurityUtils; import com.ruoyi.goods.domain.*; import com.ruoyi.goods.dto.GoodExchangeDTO; import com.ruoyi.goods.dto.GoodQueryDTO; import com.ruoyi.goods.dto.GoodsTypeQuery; import com.ruoyi.goods.service.*; import com.ruoyi.goods.vo.TGoodsVO; -import com.ruoyi.system.api.model.LoginUserParent; +import io.swagger.annotations.ApiImplicitParam; +import io.swagger.annotations.ApiImplicitParams; import io.swagger.annotations.ApiOperation; import org.springframework.beans.BeanUtils; import org.springframework.beans.factory.annotation.Autowired; @@ -47,6 +47,8 @@ private IRecipientService recipientService; @Resource private IRegionService regionService; + @Resource + private TokenService tokenService; @PostMapping("/listType") @ApiOperation(value = "列表查询", tags = {"后台-商品类型管理"}) @@ -164,10 +166,11 @@ */ @GetMapping("/exchangeRecord") @ApiOperation(value = "兑换记录", tags = {"兑换记录"}) - public R<List<TOrder>> exchangeRecord() { - return R.ok(orderService.lambdaQuery().eq(TOrder::getUserId, SecurityUtils.getUserId()) + public AjaxResult<List<TOrder>> exchangeRecord() { + return AjaxResult.success(orderService.lambdaQuery().eq(TOrder::getUserId, tokenService.getLoginUserStudy().getUserid()) .orderByDesc(TOrder::getCreateTime).list()); } + /** * 兑换记录 */ @@ -184,9 +187,9 @@ */ @GetMapping("/shopAddress") @ApiOperation(value = "获取用户收货地址", tags = {"获取用户收货地址"}) - public R<List<Recipient>> shopAddress() { - return R.ok(recipientService.lambdaQuery().eq(Recipient::getUserId, - SecurityUtils.getUserId()).list()); + public AjaxResult<List<Recipient>> shopAddress() { + return AjaxResult.success(recipientService.lambdaQuery().eq(Recipient::getUserId, + tokenService.getLoginUserStudy().getUserid()).list()); } /** @@ -194,9 +197,9 @@ */ @PostMapping("/addressSaveOrUpdate") @ApiOperation(value = "新增收货地址/修改收货地址", tags = {"新增收货地址/修改收货地址"}) - public R<String> addressSave(@RequestBody Recipient recipient) { - recipient.setUserId(SecurityUtils.getUserId().intValue()); - return R.ok(recipientService.addressSaveOrUpdate(recipient)); + public AjaxResult<String> addressSave(@RequestBody Recipient recipient) { + recipient.setUserId(tokenService.getLoginUserStudy().getUserid()); + return AjaxResult.success(recipientService.addressSaveOrUpdate(recipient)); } /** @@ -204,8 +207,11 @@ */ @GetMapping("/addressDelete") @ApiOperation(value = "删除收货地址", tags = {"删除收货地址"}) - public R<String> addressDelete(@RequestParam String id) { - return R.ok(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); + @ApiImplicitParams({ + @ApiImplicitParam(value = "地址信息id", name = "id", dataType = "String", required = true) + }) + public AjaxResult<String> addressDelete(@RequestParam String id) { + return AjaxResult.success(recipientService.removeById(id) ? "删除成功!" : "删除失败!"); } /** @@ -215,8 +221,12 @@ */ @GetMapping("/updateOrderAddress") @ApiOperation(value = "修改订单收货地址", tags = {"修改订单收货地址"}) - public R<Boolean> updateOrderAddress(@RequestParam String orderId, @RequestParam String address) { - return R.ok(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address) + @ApiImplicitParams({ + @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true), + @ApiImplicitParam(value = "完整收货地址", name = "address", dataType = "String", required = true) + }) + public AjaxResult<Boolean> updateOrderAddress(@RequestParam String orderId, @RequestParam String address) { + return AjaxResult.success(orderService.lambdaUpdate().set(TOrder::getConsigneeAddress, address) .eq(TOrder::getId, orderId).eq(TOrder::getState, 1).update()); } @@ -225,8 +235,8 @@ */ @GetMapping("/addressTree") @ApiOperation(value = "收货地址省市区三级联动", tags = {"收货地址省市区三级联动"}) - public R<List<Region>> addressTree() { - return R.ok(regionService.addressTree()); + public AjaxResult<List<Region>> addressTree() { + return AjaxResult.success(regionService.addressTree()); } /** @@ -234,8 +244,11 @@ */ @GetMapping("/goodRecommend") @ApiOperation(value = "可兑换商品推荐", tags = {"可兑换商品推荐"}) - public R<List<TGoodsVO>> goodRecommend(String userId) { - return R.ok(goodsService.goodRecommend(userId)); + @ApiImplicitParams({ + @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) + }) + public R<List<TGoodsVO>> goodRecommend() { + return R.ok(goodsService.goodRecommend(tokenService.getLoginUserStudy().getUserid())); } /** @@ -245,7 +258,10 @@ */ @GetMapping("/goodDetail") @ApiOperation(value = "商品详情", tags = {"商品详情"}) - public R<Map<String, Object>> goodDetail(@RequestParam String goodId) { + @ApiImplicitParams({ + @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) + }) + public AjaxResult<Map<String, Object>> goodDetail(@RequestParam String goodId) { Map<String, Object> result = new HashMap<>(8); // 商品详情 TGoods goods = goodsService.lambdaQuery().eq(TGoods::getId, goodId).one(); @@ -255,11 +271,11 @@ // 已兑换人数 result.put("number", goods.getBasicCount() + orderService.getGoodBuyNumber(goods.getId())); // 用户收货地址 - if (SecurityUtils.getUserId() != null) { + if (tokenService.getLoginUserStudy().getUserid() != null) { result.put("address", recipientService.lambdaQuery() - .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one()); + .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()).eq(Recipient::getIsDefault, 1).one()); } - return R.ok(result); + return AjaxResult.success(result); } /** @@ -267,10 +283,13 @@ */ @GetMapping("/redeemNow") @ApiOperation(value = "商城-立即兑换", tags = {"立即兑换"}) - public R<Map<String, Object>> redeemNow(@RequestParam String goodId) { + @ApiImplicitParams({ + @ApiImplicitParam(value = "商品id", name = "goodId", dataType = "String", required = true) + }) + public AjaxResult<Map<String, Object>> redeemNow(@RequestParam String goodId) { Recipient recipient = recipientService.lambdaQuery() - .eq(Recipient::getUserId, SecurityUtils.getUserId()).eq(Recipient::getIsDefault, 1).one(); - return R.ok(goodsService.redeemNow(goodId, recipient)); + .eq(Recipient::getUserId, tokenService.getLoginUserStudy().getUserid()).eq(Recipient::getIsDefault, 1).one(); + return AjaxResult.success(goodsService.redeemNow(goodId, recipient)); } /** @@ -280,9 +299,9 @@ */ @PostMapping("/goodExchange") @ApiOperation(value = "商品兑换-确认", tags = {"商品兑换-确认"}) - public R<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { + public AjaxResult<Object> goodExchange(@RequestBody GoodExchangeDTO goodExchange) { Recipient recipient = recipientService.getById(goodExchange.getRecipientId()); - return R.ok(goodsService.goodExchange(goodExchange, recipient)); + return AjaxResult.success(goodsService.goodExchange(goodExchange, recipient)); } } -- Gitblit v1.7.1