送货地址bug修复
This commit is contained in:
parent
01af3bc673
commit
978a4beb24
@ -10,6 +10,8 @@ import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|||||||
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
|
||||||
import com.suisung.mall.common.api.CommonResult;
|
import com.suisung.mall.common.api.CommonResult;
|
||||||
import com.suisung.mall.common.api.ResultCode;
|
import com.suisung.mall.common.api.ResultCode;
|
||||||
|
import com.suisung.mall.common.constant.CommonConstant;
|
||||||
|
import com.suisung.mall.common.constant.ConstantError;
|
||||||
import com.suisung.mall.common.domain.UserDto;
|
import com.suisung.mall.common.domain.UserDto;
|
||||||
import com.suisung.mall.common.exception.ApiException;
|
import com.suisung.mall.common.exception.ApiException;
|
||||||
import com.suisung.mall.common.exception.ApiUserException;
|
import com.suisung.mall.common.exception.ApiUserException;
|
||||||
@ -170,7 +172,7 @@ public class ShopUserDeliveryAddressServiceImpl extends BaseServiceImpl<ShopUser
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ud_id > 0) {
|
if (ud_id!=null && ud_id > 0) {
|
||||||
ShopUserDeliveryAddress address = get(ud_id);
|
ShopUserDeliveryAddress address = get(ud_id);
|
||||||
Integer _user_id = address.getUser_id();
|
Integer _user_id = address.getUser_id();
|
||||||
if (!ObjectUtil.equal(_user_id, user_id)) {
|
if (!ObjectUtil.equal(_user_id, user_id)) {
|
||||||
@ -180,22 +182,23 @@ public class ShopUserDeliveryAddressServiceImpl extends BaseServiceImpl<ShopUser
|
|||||||
deliveryAddress.setUd_id(null);
|
deliveryAddress.setUd_id(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(deliveryAddress.getUd_label()==null || deliveryAddress.getUd_label()<=0) {
|
||||||
|
deliveryAddress.setUd_label(1000);
|
||||||
|
}
|
||||||
|
|
||||||
deliveryAddress.setUser_id(user_id);
|
deliveryAddress.setUser_id(user_id);
|
||||||
|
if (!saveOrUpdate(deliveryAddress)) {// 保存或更改
|
||||||
if (ud_is_default != null && ud_is_default != 0) {
|
|
||||||
// 默认地址只能一个,其他都设置非默认
|
|
||||||
updateDefaultAddress(ud_id, user_id);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (deliveryAddress.getUd_label() != null && !deliveryAddress.getUd_label().equals(0)) {
|
|
||||||
// 标签对用户来说是唯一的,设置了某个标签,其他之前的地址标签要置空
|
|
||||||
updateAddressLabel(ud_id, user_id, deliveryAddress.getUd_label());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!saveOrUpdate(deliveryAddress)) {
|
|
||||||
throw new ApiException(ResultCode.FAILED);
|
throw new ApiException(ResultCode.FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 默认地址只能一个,其他都设置非默认
|
||||||
|
if(deliveryAddress.getUd_is_default()!=null && deliveryAddress.getUd_is_default().equals(CommonConstant.Enable)) {
|
||||||
|
updateDefaultAddress(deliveryAddress.getUd_id(), user_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 标签对用户来说是唯一的,设置了某个标签,其他之前的地址标签要置空
|
||||||
|
updateAddressLabel(deliveryAddress.getUd_id(), user_id, deliveryAddress.getUd_label());
|
||||||
|
|
||||||
return CommonResult.success(deliveryAddress.getUd_id(), I18nUtil._("操作成功"));
|
return CommonResult.success(deliveryAddress.getUd_id(), I18nUtil._("操作成功"));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -252,9 +255,12 @@ public class ShopUserDeliveryAddressServiceImpl extends BaseServiceImpl<ShopUser
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateDefaultAddress(Integer ud_id, Integer user_id) {
|
public Boolean updateDefaultAddress(Integer ud_id, Integer user_id) {
|
||||||
|
if (ud_id == null || ud_id <= 0 || user_id == null || user_id <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QueryWrapper<ShopUserDeliveryAddress> addressQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopUserDeliveryAddress> addressQueryWrapper = new QueryWrapper<>();
|
||||||
addressQueryWrapper.eq("user_id", user_id).ne("ud_id", ud_id);
|
addressQueryWrapper.eq("user_id", user_id).eq("ud_is_default",1).ne("ud_id", ud_id);
|
||||||
|
|
||||||
ShopUserDeliveryAddress deliveryAddress = new ShopUserDeliveryAddress();
|
ShopUserDeliveryAddress deliveryAddress = new ShopUserDeliveryAddress();
|
||||||
deliveryAddress.setUd_is_default(0);
|
deliveryAddress.setUd_is_default(0);
|
||||||
@ -271,12 +277,37 @@ public class ShopUserDeliveryAddressServiceImpl extends BaseServiceImpl<ShopUser
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public Boolean updateAddressLabel(Integer udId, Integer userId, Integer updLabel) {
|
public Boolean updateAddressLabel(Integer udId, Integer userId, Integer updLabel) {
|
||||||
|
if (udId == null || udId <= 0 || userId == null || userId <= 0 || updLabel == null || updLabel <= 0) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QueryWrapper<ShopUserDeliveryAddress> addressQueryWrapper = new QueryWrapper<>();
|
QueryWrapper<ShopUserDeliveryAddress> addressQueryWrapper = new QueryWrapper<>();
|
||||||
addressQueryWrapper.eq("user_id", userId).eq("label", updLabel).ne("ud_id", udId);
|
addressQueryWrapper.eq("user_id", userId).eq("ud_label", updLabel).ne("ud_id", udId);
|
||||||
|
|
||||||
ShopUserDeliveryAddress updDeliveryAddress = new ShopUserDeliveryAddress();
|
ShopUserDeliveryAddress updDeliveryAddress = new ShopUserDeliveryAddress();
|
||||||
updDeliveryAddress.setUd_label(0);
|
updDeliveryAddress.setUd_label(1000); // 没有标签的意义
|
||||||
return edit(updDeliveryAddress, addressQueryWrapper);
|
return edit(updDeliveryAddress, addressQueryWrapper);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取用户的最后一个地址的自增ID
|
||||||
|
* @param userId
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Integer getLastId(Integer userId) {
|
||||||
|
if (userId == null || userId <= 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
QueryWrapper<ShopUserDeliveryAddress> addressQueryWrapper = new QueryWrapper<>();
|
||||||
|
addressQueryWrapper.eq("user_id", userId).orderByDesc("ud_id").last("limit 1").select("ud_id");
|
||||||
|
|
||||||
|
ShopUserDeliveryAddress record = getOne(addressQueryWrapper);
|
||||||
|
if (record == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
return record.getUd_id();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user