| | |
| | | package com.ruoyi.user.controller; |
| | | |
| | | |
| | | import com.baomidou.mybatisplus.core.metadata.IPage; |
| | | import com.baomidou.mybatisplus.extension.plugins.pagination.Page; |
| | | import com.ruoyi.common.core.constant.Constants; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | |
| | | private TokenService tokenService; |
| | | |
| | | /** |
| | | * 用户端首页回收分类推荐 |
| | | * 收货地址列表 |
| | | */ |
| | | @GetMapping(value = "/list") |
| | | @ApiOperation(value = "收货地址列表", tags = {"用户端-收货地址管理"}) |
| | |
| | | .eq(UserRecipient::getIsDelete, Constants.ZERO) |
| | | .orderByDesc(UserRecipient::getIsDefault) |
| | | .orderByDesc(UserRecipient::getCreateTime).list()); |
| | | } |
| | | |
| | | /** |
| | | * 收货地址列表 |
| | | */ |
| | | @GetMapping(value = "/page") |
| | | @ApiOperation(value = "收货地址分页列表", tags = {"用户端-收货地址管理"}) |
| | | public R<IPage<UserRecipient>> page(@RequestParam(name = "pageNum", defaultValue = "1") Integer pageNum, |
| | | @RequestParam(name = "pageSize", defaultValue = "10") Integer pageSize) { |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | return R.ok(recipientService.lambdaQuery().eq(UserRecipient::getUserId, loginUser.getUserid()) |
| | | .eq(UserRecipient::getIsDelete, Constants.ZERO) |
| | | .orderByDesc(UserRecipient::getIsDefault) |
| | | .orderByDesc(UserRecipient::getCreateTime).page(Page.of(pageNum, pageSize))); |
| | | } |
| | | |
| | | /** |
| | |
| | | } |
| | | |
| | | /** |
| | | * 设置默认收货地址 |
| | | * |
| | | * @param id 收货地址id |
| | | */ |
| | | @ApiOperation(value = "设置默认收货地址", tags = {"用户端-收货地址管理"}) |
| | | @PostMapping(value = "/defaultAddress") |
| | | public R<String> defaultAddress(@RequestParam Integer id) { |
| | | LoginUserInfo loginUser = tokenService.getLoginUserByUser(); |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | // 修改所有收货地址 |
| | | boolean update = recipientService.lambdaUpdate() |
| | | .set(UserRecipient::getIsDefault, Constants.ZERO) |
| | | .eq(UserRecipient::getUserId, loginUser.getUserid()) |
| | | .eq(UserRecipient::getIsDelete, Constants.ZERO).update(); |
| | | update = update && recipientService.lambdaUpdate() |
| | | .eq(UserRecipient::getId, id) |
| | | .set(UserRecipient::getIsDefault, Constants.ONE).update(); |
| | | return update ? R.ok() : R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 修改收货地址 |
| | | * |
| | | * @param userRecipient 收货地址信息 |