| | |
| | | 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; |
| | | import com.ruoyi.system.api.model.LoginUserInfo; |
| | | import com.ruoyi.user.entity.Region; |
| | | import com.ruoyi.user.entity.UserRecipient; |
| | | import com.ruoyi.user.service.RegionService; |
| | | import com.ruoyi.user.service.UserRecipientService; |
| | | import io.swagger.annotations.Api; |
| | | import io.swagger.annotations.ApiImplicitParam; |
| | |
| | | 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))); |
| | | } |
| | | |
| | | /** |
| | |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | Region one = regionService.lambdaQuery().eq(Region::getCode, userRecipient.getCityCode()).one(); |
| | | userRecipient.setCity(one.getName()); |
| | | |
| | | userRecipient.setUserId(loginUser.getUserid()); |
| | | // 当前新增收货地址为默认地址时 |
| | | boolean result = recipientService.updateBatchAddress(userRecipient, loginUser.getUserid()); |
| | | return result && recipientService.save(userRecipient) ? R.ok() : R.fail(); |
| | | } |
| | | |
| | | /** |
| | | * 设置默认收货地址 |
| | | * |
| | | * @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(); |
| | | } |
| | | |
| | | |
| | | @Resource |
| | | private RegionService regionService; |
| | | /** |
| | | * 修改收货地址 |
| | | * |
| | |
| | | if (null == loginUser) { |
| | | return R.loginExpire("登录失效!"); |
| | | } |
| | | Region one = regionService.lambdaQuery().eq(Region::getCode, userRecipient.getCityCode()).one(); |
| | | userRecipient.setCity(one.getName()); |
| | | // 当前修改收货地址为默认地址时 |
| | | boolean result = recipientService.updateBatchAddress(userRecipient, loginUser.getUserid()); |
| | | return result && recipientService.updateById(userRecipient) ? R.ok() : R.fail(); |