修改地址逻辑
This commit is contained in:
parent
753903b388
commit
126b8bff39
|
@ -65,4 +65,10 @@ public class UserController {
|
|||
public R<String> addAddress(@RequestHeader String token, @RequestBody AddressDTO 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,6 +44,11 @@ public class User implements Serializable {
|
|||
*/
|
||||
private Integer status;
|
||||
|
||||
/**
|
||||
* 用户地址
|
||||
*/
|
||||
private String address;
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
@Override
|
||||
|
|
|
@ -64,4 +64,12 @@ public interface UserService extends IService<User> {
|
|||
* @return 添加信息
|
||||
*/
|
||||
R<String> addAddress(String token, AddressDTO addressDTO);
|
||||
|
||||
/**
|
||||
* 修改用户地址
|
||||
* @param token 用户token
|
||||
* @param address 地址
|
||||
* @return 更新信息
|
||||
*/
|
||||
R<String> updateAddress(String token, String address);
|
||||
}
|
||||
|
|
|
@ -56,12 +56,10 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderList>
|
|||
if (shoppingCarts == null || shoppingCarts.isEmpty()){
|
||||
return R.fail(CommonStatusConstant.SHOPPINGCART_ERROR);
|
||||
}
|
||||
System.out.println(order);
|
||||
|
||||
User user = userService.getById(id);
|
||||
Integer addressId = order.getAddressId();
|
||||
Address address = addressService.getById(addressId);
|
||||
System.out.println(address);
|
||||
String address = user.getAddress();
|
||||
if (address == null){
|
||||
return R.fail(CommonStatusConstant.ADDRESS_ERROR);
|
||||
}
|
||||
|
@ -81,21 +79,15 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderList>
|
|||
|
||||
order.setId(orderId);
|
||||
order.setUserId(id);
|
||||
order.setAddress((address.getProvince() == null ? "" : address.getProvince())
|
||||
+ (address.getCity() == null ? "" : address.getCity())
|
||||
+ (address.getDistrict() == null ? "" : address.getDistrict())
|
||||
+ (address.getDetail() == null ? "" : address.getDetail()));
|
||||
System.out.println(order);
|
||||
order.setAddress(address);
|
||||
boolean save = this.save(order);
|
||||
if (!save){
|
||||
return R.fail(CommonStatusConstant.INSERT_ERROR);
|
||||
}
|
||||
|
||||
boolean b = orderItemService.saveBatch(orderItems);
|
||||
if (!b){
|
||||
return R.fail(CommonStatusConstant.INSERT_ERROR);
|
||||
}
|
||||
|
||||
shoppingCartService.remove(wrapper);
|
||||
|
||||
return R.ok("添加成功");
|
||||
|
|
|
@ -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){
|
||||
User user = baseMapper.selectOne(new LambdaQueryWrapper<User>()
|
||||
.select(User::getUsername)
|
||||
|
|
Loading…
Reference in New Issue