...
|
...
|
@@ -126,6 +126,44 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
*/
|
|
|
@Override
|
|
|
public void buyerModifyAddress(int uid, long orderCode,AddressInfo changedAddress){
|
|
|
//参数检查和状态检查
|
|
|
paramAndStatusCheck_BuyerModifyAddress(uid,orderCode,changedAddress);
|
|
|
|
|
|
AddressInfo dbAddressInfo = buyerOrderMetaService.getAddressInfo(uid,orderCode);
|
|
|
if(dbAddressInfo==null){
|
|
|
logger.warn("dbAddressInfo is null ,uid {} ,orderCode {}",uid,orderCode);
|
|
|
throw new UfoServiceException(400,"找不到地址信息");
|
|
|
}
|
|
|
|
|
|
AddressInfo dbAddressInfo_hidden = buyerOrderMetaService.getHiddenAddressInfo(uid,orderCode);
|
|
|
if(dbAddressInfo_hidden==null){
|
|
|
logger.warn("dbAddressInfo_hidden is null ,uid {} ,orderCode {}",uid,orderCode);
|
|
|
throw new UfoServiceException(400,"找不到地址信息");
|
|
|
}
|
|
|
|
|
|
boolean changed = convertAddressInfoFrontRequest(uid,orderCode,dbAddressInfo,dbAddressInfo_hidden,changedAddress);
|
|
|
|
|
|
//至少有一个要更新,否则直接返回
|
|
|
if(!changed){
|
|
|
logger.warn("buyerModifyAddress no change address return now!");
|
|
|
//throw new UfoServiceException(400,"地址信息无变化");
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
//更新收货地址:明文地址 . 隐藏地址
|
|
|
JSONObject jo_address = (JSONObject)JSON.toJSON(dbAddressInfo);
|
|
|
jo_address.remove("uid");
|
|
|
String jo_address_string=jo_address.toJSONString();
|
|
|
BuyerOrderMetaUpdateReq updateInfo = new BuyerOrderMetaUpdateReq();
|
|
|
updateInfo.setUid(uid);
|
|
|
updateInfo.setOrderCode(orderCode);
|
|
|
updateInfo.setAddress(jo_address_string);
|
|
|
logger.info("buyerModifyAddress begin update address , uid is {}, orderCode is {},update address info {}",
|
|
|
uid, orderCode ,jo_address_string);
|
|
|
buyerOrderMetaService.updateDeliveryAddress(updateInfo);
|
|
|
}
|
|
|
|
|
|
private void paramAndStatusCheck_BuyerModifyAddress(int uid, long orderCode,AddressInfo changedAddress){
|
|
|
//入参
|
|
|
if(uid <= 0){
|
|
|
throw new UfoServiceException(400,"参数错误:uid错误");
|
...
|
...
|
@@ -142,18 +180,33 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
throw new UfoServiceException(400,"地址信息填写错误");
|
|
|
}
|
|
|
|
|
|
AddressInfo dbAddressInfo = buyerOrderMetaService.getAddressInfo(uid,orderCode);
|
|
|
if(dbAddressInfo==null){
|
|
|
logger.warn("dbAddressInfo is null ,uid {} ,orderCode {}",uid,orderCode);
|
|
|
throw new UfoServiceException(400,"找不到地址信息");
|
|
|
//检查订单
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode,uid);
|
|
|
if(buyerOrder==null){
|
|
|
logger.warn("buyerModifyAddress check orderCode exist, uid is {}, orderCode is {}",
|
|
|
uid, orderCode );
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
AddressInfo dbAddressInfo_hidden = buyerOrderMetaService.getHiddenAddressInfo(uid,orderCode);
|
|
|
if(dbAddressInfo_hidden==null){
|
|
|
logger.warn("dbAddressInfo_hidden is null ,uid {} ,orderCode {}",uid,orderCode);
|
|
|
throw new UfoServiceException(400,"找不到地址信息");
|
|
|
if(buyerOrder.getStatus()==null){
|
|
|
logger.warn("buyerModifyAddress check orderCode status is null, uid is {}, orderCode is {} ,status is {}",
|
|
|
uid, orderCode,buyerOrder.getStatus() );
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
|
|
|
}
|
|
|
|
|
|
//买家已付款,卖家已发货,只有这两种状态的情况下,才允许改地址
|
|
|
boolean allowChange = ActionStatusHold.buyerCanModifyAddress(buyerOrder.getStatus());
|
|
|
if(!allowChange){
|
|
|
logger.warn("buyerModifyAddress check orderCode status not invalid, uid is {}, orderCode is {} ,status is {}",
|
|
|
uid, orderCode,buyerOrder.getStatus() );
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 把变的信息项更新
|
|
|
*/
|
|
|
private boolean convertAddressInfoFrontRequest(int uid, long orderCode,AddressInfo dbAddressInfo,AddressInfo dbAddressInfo_hidden,AddressInfo changedAddress){
|
|
|
//详细地址没有变化
|
|
|
if(StringUtils.equals(dbAddressInfo_hidden.getAddress(),changedAddress.getAddress())){
|
|
|
changedAddress.setAddress(dbAddressInfo.getAddress());
|
...
|
...
|
@@ -182,87 +235,39 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
}
|
|
|
}
|
|
|
|
|
|
boolean changed = convertAddressInfoFrontRequest(dbAddressInfo,changedAddress);
|
|
|
|
|
|
//至少有一个要更新,否则直接返回
|
|
|
if(!changed){
|
|
|
logger.warn("buyerModifyAddress no change address return now!");
|
|
|
//throw new UfoServiceException(400,"地址信息无变化");
|
|
|
return ;
|
|
|
}
|
|
|
|
|
|
//检查订单
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode,uid);
|
|
|
if(buyerOrder==null){
|
|
|
logger.warn("buyerModifyAddress check orderCode exist, uid is {}, orderCode is {}",
|
|
|
uid, orderCode );
|
|
|
throw new ServiceException(ServiceError.ORDER_NULL);
|
|
|
}
|
|
|
|
|
|
if(buyerOrder.getStatus()==null){
|
|
|
logger.warn("buyerModifyAddress check orderCode status is null, uid is {}, orderCode is {} ,status is {}",
|
|
|
uid, orderCode,buyerOrder.getStatus() );
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
|
|
|
}
|
|
|
|
|
|
//买家已付款,卖家已发货,只有这两种状态的情况下,才允许改地址
|
|
|
boolean allowChange = ActionStatusHold.buyerCanModifyAddress(buyerOrder.getStatus());
|
|
|
if(!allowChange){
|
|
|
logger.warn("buyerModifyAddress check orderCode status not invalid, uid is {}, orderCode is {} ,status is {}",
|
|
|
uid, orderCode,buyerOrder.getStatus() );
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
|
|
|
}
|
|
|
|
|
|
//更新收货地址:明文地址 . 隐藏地址
|
|
|
JSONObject jo_address = (JSONObject)JSON.toJSON(dbAddressInfo);
|
|
|
jo_address.remove("uid");
|
|
|
String jo_address_string=jo_address.toJSONString();
|
|
|
BuyerOrderMetaUpdateReq updateInfo = new BuyerOrderMetaUpdateReq();
|
|
|
updateInfo.setUid(uid);
|
|
|
updateInfo.setOrderCode(orderCode);
|
|
|
updateInfo.setAddress(jo_address_string);
|
|
|
logger.info("buyerModifyAddress begin update address , uid is {}, orderCode is {},update address info {}",
|
|
|
uid, orderCode ,jo_address_string);
|
|
|
buyerOrderMetaService.updateDeliveryAddress(updateInfo);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 把变的信息项更新
|
|
|
*/
|
|
|
private boolean convertAddressInfoFrontRequest(AddressInfo dbAddressInfo,AddressInfo req){
|
|
|
boolean changed =false;
|
|
|
if(!StringUtils.equals(req.getConsignee(),dbAddressInfo.getConsignee())){
|
|
|
if(!StringUtils.equals(changedAddress.getConsignee(),dbAddressInfo.getConsignee())){
|
|
|
changed = true;
|
|
|
dbAddressInfo.setConsignee(req.getConsignee());
|
|
|
dbAddressInfo.setConsignee(changedAddress.getConsignee());
|
|
|
}
|
|
|
if(!StringUtils.equals(req.getAddress(),dbAddressInfo.getAddress())){
|
|
|
if(!StringUtils.equals(changedAddress.getAddress(),dbAddressInfo.getAddress())){
|
|
|
changed = true;
|
|
|
dbAddressInfo.setAddress(req.getAddress());
|
|
|
dbAddressInfo.setAddress(changedAddress.getAddress());
|
|
|
}
|
|
|
if(!StringUtils.equals(req.getAreaCode(),dbAddressInfo.getAreaCode())){
|
|
|
if(!StringUtils.equals(changedAddress.getAreaCode(),dbAddressInfo.getAreaCode())){
|
|
|
changed = true;
|
|
|
dbAddressInfo.setAreaCode(req.getAreaCode());
|
|
|
dbAddressInfo.setAreaCode(changedAddress.getAreaCode());
|
|
|
}
|
|
|
if(!StringUtils.equals(req.getArea(),dbAddressInfo.getArea())){
|
|
|
if(!StringUtils.equals(changedAddress.getArea(),dbAddressInfo.getArea())){
|
|
|
changed = true;
|
|
|
dbAddressInfo.setArea(req.getArea());
|
|
|
dbAddressInfo.setArea(changedAddress.getArea());
|
|
|
}
|
|
|
if(!StringUtils.equals(req.getMobile(),dbAddressInfo.getMobile())){
|
|
|
if(!StringUtils.equals(changedAddress.getMobile(),dbAddressInfo.getMobile())){
|
|
|
changed = true;
|
|
|
dbAddressInfo.setMobile(req.getMobile());
|
|
|
dbAddressInfo.setMobile(changedAddress.getMobile());
|
|
|
}
|
|
|
|
|
|
//address_id 比较特殊,地址id根本不存在,所以如果前台不传,则把原来的置0
|
|
|
if(req.getAddress_id()!=null&&req.getAddress_id()>0){
|
|
|
if(changedAddress.getAddress_id()!=null&&changedAddress.getAddress_id()>0){
|
|
|
//changed = true; //此项目不作为信息更改判断根据
|
|
|
dbAddressInfo.setAddress_id(req.getAddress_id());
|
|
|
dbAddressInfo.setAddress_id(changedAddress.getAddress_id());
|
|
|
}else{
|
|
|
dbAddressInfo.setAddress_id(0);
|
|
|
}
|
|
|
|
|
|
if(StringUtils.isNotBlank(req.getIsUpdate())){
|
|
|
if(StringUtils.isNotBlank(changedAddress.getIsUpdate())){
|
|
|
//changed = true; //此项目不作为信息更改判断根据
|
|
|
dbAddressInfo.setIsUpdate(req.getIsUpdate());
|
|
|
dbAddressInfo.setIsUpdate(changedAddress.getIsUpdate());
|
|
|
}
|
|
|
return changed;
|
|
|
}
|
...
|
...
|
|