Authored by qinchao

新增接口:买家修改收货地址

@@ -119,6 +119,21 @@ public class BuyerOrderController { @@ -119,6 +119,21 @@ public class BuyerOrderController {
119 } 119 }
120 120
121 121
  122 +
  123 + /**
  124 + * 买家修改收货地址
  125 + * @return
  126 + */
  127 + @RequestMapping(params = "method=ufo.buyer.modifyAddress")
  128 + public ApiResponse buyerModifyAddress(@RequestParam(name = "uid") int uid,
  129 + @RequestParam(name = "orderCode") Long orderCode,
  130 + @RequestParam(name = "addressId") String addressId){
  131 + LOG.info("in ufo.order.buyerModifyAddress, req uid {} ,orderCode {} ,addressId ", uid,orderCode,addressId);
  132 + buyerOrderService.buyerModifyAddress(uid,orderCode,addressId);
  133 + return new ApiResponse.ApiResponseBuilder().code(200).message("修改收货地址成功").build();
  134 + }
  135 +
  136 +
122 /** 137 /**
123 * 取消订单 138 * 取消订单
124 */ 139 */
@@ -25,6 +25,14 @@ public interface IBuyerOrderService extends IOrderListService, IOrderDetailServi @@ -25,6 +25,14 @@ public interface IBuyerOrderService extends IOrderListService, IOrderDetailServi
25 */ 25 */
26 void confirm(OrderRequest orderRequest); 26 void confirm(OrderRequest orderRequest);
27 27
  28 +
  29 +
  30 + /**
  31 + * 买家修改收货地址
  32 + * @ addressId 加密过的地址Id
  33 + */
  34 + void buyerModifyAddress(int uid,Long orderCode,String addressIdStr);
  35 +
28 /** 36 /**
29 * 根据uid查询购买的订单数目 37 * 根据uid查询购买的订单数目
30 * @param uid 38 * @param uid
1 package com.yohoufo.order.service.impl; 1 package com.yohoufo.order.service.impl;
2 2
  3 +import com.alibaba.fastjson.JSONObject;
3 import com.yoho.error.ServiceError; 4 import com.yoho.error.ServiceError;
4 import com.yoho.error.exception.ServiceException; 5 import com.yoho.error.exception.ServiceException;
5 import com.yohobuy.ufo.model.order.common.OrderListType; 6 import com.yohobuy.ufo.model.order.common.OrderListType;
@@ -10,17 +11,23 @@ import com.yohobuy.ufo.model.order.resp.OrderCntResp; @@ -10,17 +11,23 @@ import com.yohobuy.ufo.model.order.resp.OrderCntResp;
10 import com.yohobuy.ufo.model.order.resp.OrderListInfo; 11 import com.yohobuy.ufo.model.order.resp.OrderListInfo;
11 import com.yohobuy.ufo.model.order.resp.PageResp; 12 import com.yohobuy.ufo.model.order.resp.PageResp;
12 import com.yohobuy.ufo.model.order.vo.OrderListVo; 13 import com.yohobuy.ufo.model.order.vo.OrderListVo;
  14 +import com.yohoufo.common.exception.UfoServiceException;
  15 +import com.yohoufo.common.utils.AddressUtil;
13 import com.yohoufo.common.utils.DateUtil; 16 import com.yohoufo.common.utils.DateUtil;
14 import com.yohoufo.dal.order.BuyerOrderGoodsMapper; 17 import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
15 import com.yohoufo.dal.order.BuyerOrderMapper; 18 import com.yohoufo.dal.order.BuyerOrderMapper;
  19 +import com.yohoufo.dal.order.BuyerOrderMetaMapper;
16 import com.yohoufo.dal.order.SellerOrderGoodsMapper; 20 import com.yohoufo.dal.order.SellerOrderGoodsMapper;
17 import com.yohoufo.dal.order.model.BuyerOrder; 21 import com.yohoufo.dal.order.model.BuyerOrder;
18 import com.yohoufo.dal.order.model.BuyerOrderGoods; 22 import com.yohoufo.dal.order.model.BuyerOrderGoods;
  23 +import com.yohoufo.dal.order.model.BuyerOrderMeta;
19 import com.yohoufo.dal.order.model.SellerOrderGoods; 24 import com.yohoufo.dal.order.model.SellerOrderGoods;
20 import com.yohoufo.order.common.ActionStatusHold; 25 import com.yohoufo.order.common.ActionStatusHold;
21 import com.yohoufo.order.common.DelStatus; 26 import com.yohoufo.order.common.DelStatus;
  27 +import com.yohoufo.order.constants.MetaKey;
22 import com.yohoufo.order.event.BeforeDepotReceiveEvent; 28 import com.yohoufo.order.event.BeforeDepotReceiveEvent;
23 import com.yohoufo.order.event.BeforeSellerDeliverEvent; 29 import com.yohoufo.order.event.BeforeSellerDeliverEvent;
  30 +import com.yohoufo.order.model.AddressInfo;
24 import com.yohoufo.order.model.request.OrderListRequest; 31 import com.yohoufo.order.model.request.OrderListRequest;
25 import com.yohoufo.order.model.request.OrderRequest; 32 import com.yohoufo.order.model.request.OrderRequest;
26 import com.yohoufo.order.model.response.OrderDetailInfo; 33 import com.yohoufo.order.model.response.OrderDetailInfo;
@@ -31,6 +38,9 @@ import com.yohoufo.order.service.cache.CacheKeyBuilder; @@ -31,6 +38,9 @@ import com.yohoufo.order.service.cache.CacheKeyBuilder;
31 import com.yohoufo.order.service.cache.OrderCacheService; 38 import com.yohoufo.order.service.cache.OrderCacheService;
32 import com.yohoufo.order.service.proxy.InBoxFacade; 39 import com.yohoufo.order.service.proxy.InBoxFacade;
33 import com.yohoufo.order.service.proxy.ProductProxyService; 40 import com.yohoufo.order.service.proxy.ProductProxyService;
  41 +import com.yohoufo.order.service.proxy.UserProxyService;
  42 +import com.yohoufo.order.utils.AddressHelper;
  43 +import org.apache.commons.lang3.StringUtils;
34 import org.slf4j.Logger; 44 import org.slf4j.Logger;
35 import org.slf4j.LoggerFactory; 45 import org.slf4j.LoggerFactory;
36 import org.springframework.beans.factory.annotation.Autowired; 46 import org.springframework.beans.factory.annotation.Autowired;
@@ -76,6 +86,12 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -76,6 +86,12 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
76 @Autowired 86 @Autowired
77 private BuyerOrderCancelService buyerOrderCancelService; 87 private BuyerOrderCancelService buyerOrderCancelService;
78 88
  89 + @Autowired
  90 + private UserProxyService userProxyService;
  91 +
  92 + @Autowired
  93 + private BuyerOrderMetaMapper buyerOrderMetaMapper;
  94 +
79 /** 95 /**
80 * 提交订单 96 * 提交订单
81 * @param orderRequest 97 * @param orderRequest
@@ -107,6 +123,92 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { @@ -107,6 +123,92 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService {
107 } 123 }
108 124
109 125
  126 +
  127 +
  128 + /**
  129 + * 买家修改收货地址:
  130 + * 鉴定中心确定收货之前,都可以修改地址
  131 + * @ addressId 加密过的地址Id
  132 + */
  133 + @Override
  134 + public void buyerModifyAddress(int uid,Long orderCode,String addressIdStr){
  135 + //入参
  136 + if(uid < 0){
  137 + throw new UfoServiceException(400,"参数错误:uid错误");
  138 + }
  139 + if(orderCode==null||orderCode < 0){
  140 + throw new UfoServiceException(400,"参数错误:订单号错误");
  141 + }
  142 + if(StringUtils.isBlank(addressIdStr)){
  143 + throw new UfoServiceException(400,"参数错误:收货地址错误");
  144 + }
  145 +
  146 + // 检查地址是否合法
  147 + int addressId = AddressUtil.getDecryptStr(addressIdStr);
  148 + if (addressId < 0){
  149 + logger.warn("buyerModifyAddress addressId invalidate, uid is {}, order code is {}, addressIdStr is {}", uid,
  150 + orderCode,addressIdStr);
  151 + throw new ServiceException(ServiceError.ORDER_ADDRESSID_INVALIDATE);
  152 + }
  153 +
  154 + //获取地址
  155 + AddressInfo addressInfo = userProxyService.getAddressInfoNotHidden(uid, addressId);
  156 + if(AddressHelper.isNeedUpdate(addressInfo)){
  157 + logger.warn("buyerModifyAddress addressId need update, uid is {}, order code is {}, addressIdStr is {}", uid,
  158 + orderCode,addressIdStr);
  159 + throw new ServiceException(ServiceError.ORDER_ADDRESS_NEED_UPDATE);
  160 + }
  161 +
  162 + AddressInfo hiddenAddress = userProxyService.getHiddenAddressInfo(uid, addressId);
  163 +
  164 + //检查订单
  165 + BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCodeUid(orderCode,uid);
  166 + if(buyerOrder==null){
  167 + logger.warn("buyerModifyAddress check orderCode exist, uid is {}, orderCode is {}",
  168 + uid, orderCode );
  169 + throw new ServiceException(ServiceError.ORDER_NULL);
  170 + }
  171 +
  172 + if(buyerOrder.getStatus()==null){
  173 + logger.warn("buyerModifyAddress check orderCode status is null, uid is {}, orderCode is {} ,status is {}",
  174 + uid, orderCode,buyerOrder.getStatus() );
  175 + throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
  176 + }
  177 +
  178 + //平台确认收货之前,允许修改,否则不允许
  179 + if(buyerOrder.getStatus() >= OrderStatus.PLATFORM_CHECKING.getCode()){
  180 + logger.warn("buyerModifyAddress check orderCode status not invalid, uid is {}, orderCode is {} ,status is {}",
  181 + uid, orderCode,buyerOrder.getStatus() );
  182 + throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE);
  183 + }
  184 +
  185 + //更新收货地址:明文地址
  186 + BuyerOrderMeta meta=new BuyerOrderMeta();
  187 + meta.setUid(uid);
  188 + meta.setOrderCode(orderCode);
  189 + meta.setMetaKey(MetaKey.BUYER_DELIVERY_ADDRESS);
  190 + meta.setMetaValue(JSONObject.toJSONString(addressInfo));
  191 + logger.info("buyerModifyAddress updateDeliveryAddress meta param {} begin ",meta);
  192 + int updateRowNum = buyerOrderMetaMapper.updateMetaValueByUidAndOrderCodeAndMetaKey(meta);
  193 + logger.info("buyerModifyAddress updateDeliveryAddress meta param {} end, updateRowNum {} ",meta,updateRowNum);
  194 +
  195 + // 隐藏地址
  196 + BuyerOrderMeta meta_hiddenAddress=new BuyerOrderMeta();
  197 + meta_hiddenAddress.setUid(uid);
  198 + meta_hiddenAddress.setOrderCode(orderCode);
  199 + meta_hiddenAddress.setMetaKey(MetaKey.BUYER_DELIVERY_HIDDEN_ADDRESS);
  200 + meta_hiddenAddress.setMetaValue(JSONObject.toJSONString(hiddenAddress));
  201 + logger.info("buyerModifyAddress updateDeliveryAddress_hidden meta param {} begin ",meta_hiddenAddress);
  202 + updateRowNum = buyerOrderMetaMapper.updateMetaValueByUidAndOrderCodeAndMetaKey(meta_hiddenAddress);
  203 + logger.info("buyerModifyAddress updateDeliveryAddress_hidden meta param {} end, updateRowNum {} ",meta_hiddenAddress,updateRowNum);
  204 +
  205 + //清地址缓存
  206 + cacheCleaner.delete(Arrays.asList(
  207 + CacheKeyBuilder.orderDetailKey(uid, TabType.BUY.getValue(), orderCode)));
  208 +
  209 + }
  210 +
  211 +
110 /** 212 /**
111 * 取消订单 213 * 取消订单
112 * @param orderRequest 214 * @param orderRequest