| | |
| | | import com.ruoyi.account.service.TAppUserAddressService; |
| | | import com.ruoyi.common.core.domain.R; |
| | | import com.ruoyi.common.core.web.domain.AjaxResult; |
| | | import com.ruoyi.common.log.annotation.Log; |
| | | import com.ruoyi.common.log.enums.BusinessType; |
| | | import com.ruoyi.common.log.enums.OperatorType; |
| | | import com.ruoyi.common.security.service.TokenService; |
| | | import io.swagger.annotations.ApiOperation; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.web.bind.annotation.*; |
| | | |
| | | import java.util.List; |
| | | import java.util.Objects; |
| | | |
| | | /** |
| | | * <p> |
| | |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TAppUserAddress appUserAddress = appUserAddressService.getOne(Wrappers.<TAppUserAddress>lambdaQuery().eq(TAppUserAddress::getAppUserId, userId) |
| | | .eq(TAppUserAddress::getDefaultAddress, 1)); |
| | | if(Objects.isNull(appUserAddress)){ |
| | | return AjaxResult.success(); |
| | | } |
| | | appUserAddress.setUid(appUserAddress.getId().toString()); |
| | | return AjaxResult.ok(appUserAddress); |
| | | return AjaxResult.success(appUserAddress); |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 添加用户地址管理 |
| | | */ |
| | | @Log(title = "【我的】添加用户地址", businessType = BusinessType.INSERT,operatorType = OperatorType.MOBILE) |
| | | @ApiOperation(tags = {"小程序-用户地址"},value = "添加用户地址") |
| | | @PostMapping(value = "/add") |
| | | public AjaxResult<Boolean> add(@RequestBody TAppUserAddress dto) { |
| | |
| | | /** |
| | | * 修改用户地址 |
| | | */ |
| | | @Log(title = "【我的】设置默认地址", businessType = BusinessType.UPDATE,operatorType = OperatorType.MOBILE) |
| | | @ApiOperation(tags = {"小程序-用户地址"},value = "设置默认地址") |
| | | @GetMapping(value = "/setDefaultAddress") |
| | | public AjaxResult<String> setDefaultAddress(@RequestParam(value = "id") Long id) { |
| | | TAppUserAddress appUserAddress = appUserAddressService.getById(id); |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | if(!appUserAddress.getAppUserId().equals(userId)){ |
| | | return AjaxResult.error("权限不足"); |
| | | } |
| | | // 修改用户默认地址 |
| | | appUserAddressService.updateDefaultAddress(1,tokenService.getLoginUserApplet().getUserId()); |
| | | TAppUserAddress appUserAddress = appUserAddressService.getById(id); |
| | | appUserAddress.setDefaultAddress(1); |
| | | appUserAddressService.updateById(appUserAddress); |
| | | return AjaxResult.success(); |
| | |
| | | /** |
| | | * 修改用户地址 |
| | | */ |
| | | @Log(title = "【我的】修改用户地址", businessType = BusinessType.UPDATE,operatorType = OperatorType.MOBILE) |
| | | @ApiOperation(tags = {"小程序-用户地址"},value = "修改用户地址") |
| | | @PostMapping(value = "/update") |
| | | public AjaxResult<Boolean> update(@RequestBody TAppUserAddress dto) { |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | TAppUserAddress userAddress = appUserAddressService.getById(dto.getId()); |
| | | if(!userAddress.getAppUserId().equals(userId)){ |
| | | return AjaxResult.error("权限不足"); |
| | | } |
| | | // 用户id |
| | | dto.setAppUserId(tokenService.getLoginUserApplet().getUserId()); |
| | | dto.setAppUserId(userId); |
| | | // 修改用户默认地址 |
| | | appUserAddressService.updateDefaultAddress(dto.getDefaultAddress(),dto.getAppUserId()); |
| | | return AjaxResult.ok(appUserAddressService.updateById(dto)); |
| | |
| | | @ApiOperation(tags = {"小程序-用户地址"},value = "查询用户地址详情") |
| | | @GetMapping(value = "/getDetailById") |
| | | public R<TAppUserAddress> getDetailById(@RequestParam(value = "id")Long id) { |
| | | return R.ok(appUserAddressService.getById(id)); |
| | | TAppUserAddress appUserAddress = appUserAddressService.getById(id); |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | if(!appUserAddress.getAppUserId().equals(userId)){ |
| | | return R.fail("权限不足"); |
| | | } |
| | | appUserAddress.setUid(appUserAddress.getId().toString()); |
| | | return R.ok(appUserAddress); |
| | | } |
| | | |
| | | /** |
| | | * 删除用户地址 |
| | | */ |
| | | @Log(title = "【我的】删除用户地址", businessType = BusinessType.DELETE,operatorType = OperatorType.MOBILE) |
| | | @ApiOperation(tags = {"小程序-用户地址"},value = "删除用户地址") |
| | | @DeleteMapping(value = "/deleteById") |
| | | public AjaxResult<Boolean> deleteById(@RequestParam("id") Integer id) { |
| | | public AjaxResult<Boolean> deleteById(@RequestParam("id") Long id) { |
| | | TAppUserAddress appUserAddress = appUserAddressService.getById(id); |
| | | Long userId = tokenService.getLoginUserApplet().getUserId(); |
| | | if(!appUserAddress.getAppUserId().equals(userId)){ |
| | | return AjaxResult.error("权限不足"); |
| | | } |
| | | return AjaxResult.ok(appUserAddressService.removeById(id)); |
| | | } |
| | | |