修改地址逻辑

This commit is contained in:
muhua 2024-07-13 15:45:52 +08:00
parent 753903b388
commit 126b8bff39
5 changed files with 33 additions and 10 deletions

View File

@ -65,4 +65,10 @@ public class UserController {
public R<String> addAddress(@RequestHeader String token, @RequestBody AddressDTO addressDTO){ public R<String> addAddress(@RequestHeader String token, @RequestBody AddressDTO addressDTO){
return userService.addAddress(token, addressDTO); return userService.addAddress(token, addressDTO);
} }
@PostMapping("update-addr")
@ApiOperation(value = "更新用户地址")
public R<String> updateAddr(@RequestHeader String token, @RequestParam("address")String addr){
return userService.updateAddress(token, addr);
}
} }

View File

@ -44,6 +44,11 @@ public class User implements Serializable {
*/ */
private Integer status; private Integer status;
/**
* 用户地址
*/
private String address;
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
@Override @Override

View File

@ -64,4 +64,12 @@ public interface UserService extends IService<User> {
* @return 添加信息 * @return 添加信息
*/ */
R<String> addAddress(String token, AddressDTO addressDTO); R<String> addAddress(String token, AddressDTO addressDTO);
/**
* 修改用户地址
* @param token 用户token
* @param address 地址
* @return 更新信息
*/
R<String> updateAddress(String token, String address);
} }

View File

@ -56,12 +56,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderList>
if (shoppingCarts == null || shoppingCarts.isEmpty()){ if (shoppingCarts == null || shoppingCarts.isEmpty()){
return R.fail(CommonStatusConstant.SHOPPINGCART_ERROR); return R.fail(CommonStatusConstant.SHOPPINGCART_ERROR);
} }
System.out.println(order);
User user = userService.getById(id); User user = userService.getById(id);
Integer addressId = order.getAddressId(); Integer addressId = order.getAddressId();
Address address = addressService.getById(addressId); String address = user.getAddress();
System.out.println(address);
if (address == null){ if (address == null){
return R.fail(CommonStatusConstant.ADDRESS_ERROR); return R.fail(CommonStatusConstant.ADDRESS_ERROR);
} }
@ -81,21 +79,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderList>
order.setId(orderId); order.setId(orderId);
order.setUserId(id); order.setUserId(id);
order.setAddress((address.getProvince() == null ? "" : address.getProvince()) order.setAddress(address);
+ (address.getCity() == null ? "" : address.getCity())
+ (address.getDistrict() == null ? "" : address.getDistrict())
+ (address.getDetail() == null ? "" : address.getDetail()));
System.out.println(order);
boolean save = this.save(order); boolean save = this.save(order);
if (!save){ if (!save){
return R.fail(CommonStatusConstant.INSERT_ERROR); return R.fail(CommonStatusConstant.INSERT_ERROR);
} }
boolean b = orderItemService.saveBatch(orderItems); boolean b = orderItemService.saveBatch(orderItems);
if (!b){ if (!b){
return R.fail(CommonStatusConstant.INSERT_ERROR); return R.fail(CommonStatusConstant.INSERT_ERROR);
} }
shoppingCartService.remove(wrapper); shoppingCartService.remove(wrapper);
return R.ok("添加成功"); return R.ok("添加成功");

View File

@ -149,6 +149,18 @@ public class UserServiceImpl extends ServiceImpl<UserMapper, User>
} }
} }
@Override
public R<String> updateAddress(String token, String address) {
Integer id = Integer.parseInt(getUserId(token));
LambdaUpdateWrapper<User> wrapper = new LambdaUpdateWrapper<>();
wrapper.eq(User::getId, id).set(User::getAddress, address);
if (baseMapper.update(wrapper) == 1){
return R.ok("修改成功");
}else {
return R.fail("修改失败");
}
}
private Boolean checkUser(UserRegisterDTO userRegisterDTO){ private Boolean checkUser(UserRegisterDTO userRegisterDTO){
User user = baseMapper.selectOne(new LambdaQueryWrapper<User>() User user = baseMapper.selectOne(new LambdaQueryWrapper<User>()
.select(User::getUsername) .select(User::getUsername)