...
|
...
|
@@ -2,7 +2,9 @@ package com.yohoufo.order.service.impl; |
|
|
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.common.TabType;
|
|
|
import com.yohobuy.ufo.model.order.resp.PageResp;
|
|
|
import com.yohobuy.ufo.model.order.vo.OrderListVo;
|
|
|
import com.yohoufo.common.utils.DateUtil;
|
|
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.BuyerOrderMapper;
|
...
|
...
|
@@ -21,6 +23,9 @@ import com.yohoufo.order.model.request.OrderRequest; |
|
|
import com.yohoufo.order.model.response.OrderDetailInfo;
|
|
|
import com.yohoufo.order.model.response.OrderSummaryResp;
|
|
|
import com.yohoufo.order.service.IBuyerOrderService;
|
|
|
import com.yohoufo.order.service.cache.CacheCleaner;
|
|
|
import com.yohoufo.order.service.cache.CacheKeyBuilder;
|
|
|
import com.yohoufo.order.service.cache.OrderCacheService;
|
|
|
import com.yohoufo.order.service.proxy.InBoxFacade;
|
|
|
import com.yohoufo.order.service.proxy.ProductProxyService;
|
|
|
import com.yohoufo.order.utils.SmsHelper;
|
...
|
...
|
@@ -29,6 +34,7 @@ import org.slf4j.LoggerFactory; |
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.util.Arrays;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
@Service
|
...
|
...
|
@@ -64,6 +70,12 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
@Autowired
|
|
|
private SellerAddressService sellerAddressService;
|
|
|
|
|
|
@Autowired
|
|
|
private OrderCacheService orderCacheService;
|
|
|
|
|
|
@Autowired
|
|
|
private CacheCleaner cacheCleaner;
|
|
|
|
|
|
/**
|
|
|
* 提交订单
|
|
|
* @param orderRequest
|
...
|
...
|
@@ -72,12 +84,15 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
OrderStatus expectStatus = OrderStatus.WAITING_RECEIVE;
|
|
|
// 参数检查 ![待收货] 不合法
|
|
|
DataNode node = checkStatusAndRequest(orderRequest, expectStatus);
|
|
|
int uid;
|
|
|
long orderCode;
|
|
|
// TODO 更新状态为已收货、SKUP的状态应该还是已出售
|
|
|
if (1 == buyerOrderMapper.updateStatusByOrderCode(orderRequest.getOrderCode(), orderRequest.getUid(),
|
|
|
if (1 == buyerOrderMapper.updateStatusByOrderCode(orderCode=orderRequest.getOrderCode(), uid=orderRequest.getUid(),
|
|
|
expectStatus.getCode(),
|
|
|
OrderStatus.DONE.getCode(),
|
|
|
DateUtil.getCurrentTimeSecond())) {
|
|
|
// TODO 分账操作
|
|
|
|
|
|
cacheCleaner.cleanDetail(uid, orderCode);
|
|
|
} else {
|
|
|
throw new ServiceException(ServiceError.ORDER_STATUS_INVALIDATE); // 更新失败,可能是因为订单状态已经被并发修改
|
|
|
}
|
...
|
...
|
@@ -112,15 +127,16 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
|
|
|
// 更新订单状态
|
|
|
final OrderStatus orderStatus = targetStatus;
|
|
|
|
|
|
final long orderCode;
|
|
|
final int buyerUid;
|
|
|
BuyerOrder tbo = new BuyerOrder();
|
|
|
tbo.setStatus(orderStatus.getCode());
|
|
|
tbo.setUid(orderRequest.getUid());
|
|
|
tbo.setOrderCode(orderRequest.getOrderCode());
|
|
|
tbo.setUid(buyerUid = orderRequest.getUid());
|
|
|
tbo.setOrderCode(orderCode = orderRequest.getOrderCode());
|
|
|
tbo.setUpdateTime(DateUtil.getCurrentTimeSecond());
|
|
|
buyerOrderMapper.updateByOrderCode(tbo);
|
|
|
// 更新skup的状态[出售中] 卖家订单为[可售]
|
|
|
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(), orderRequest.getOrderCode());
|
|
|
BuyerOrderGoods bog = buyerOrderGoodsMapper.selectByOrderCode(orderRequest.getUid(), orderCode);
|
|
|
int skup = bog.getSkup();
|
|
|
SellerOrderGoods psog= sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
Integer skupStatus = psog.getStatus();
|
...
|
...
|
@@ -130,13 +146,22 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
tsog.setStatus(SkupStatus.CAN_SELL.getCode());
|
|
|
sellerOrderGoodsMapper.updateByPrimaryKeySelective(tsog);
|
|
|
|
|
|
|
|
|
|
|
|
// 恢复product skup的库存
|
|
|
boolean isReturnSuccess = productProxyService.returnStorage(skup);
|
|
|
//
|
|
|
int sellerUid = dataNode.buyerOrderInDB.getSellerUid();
|
|
|
AddressInfo addressInfo = sellerAddressService.getAddressInfo(sellerUid, skup);
|
|
|
inBoxFacade.noticSellerWhenBuyerCancel(sellerUid, psog.getProductName(), SmsHelper.getPhones(addressInfo));
|
|
|
inBoxFacade.buyerCancelOrder(orderRequest.getUid(), orderRequest.getOrderCode());
|
|
|
inBoxFacade.buyerCancelOrder(orderRequest.getUid(), orderCode);
|
|
|
|
|
|
//
|
|
|
cacheCleaner.delete(Arrays.asList(CacheKeyBuilder.orderListKey(sellerUid, TabType.SELL.getValue()),
|
|
|
CacheKeyBuilder.orderListKey(buyerUid, TabType.BUY.getValue()),
|
|
|
CacheKeyBuilder.orderDetailKey(sellerUid, orderCode),
|
|
|
CacheKeyBuilder.orderDetailKey(buyerUid, orderCode)));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -181,12 +206,44 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
|
|
|
@Override
|
|
|
public OrderDetailInfo getOrderDetail(OrderRequest orderRequest) {
|
|
|
return buyerOrderDetailService.getOrderDetail(orderRequest);
|
|
|
int uid;
|
|
|
long orderCode;
|
|
|
OrderDetailInfo orderDetailInfo = orderCacheService.getOrderDetailInfo(uid = orderRequest.getUid(), orderCode=orderRequest.getOrderCode());
|
|
|
if(Objects.nonNull(orderDetailInfo)){
|
|
|
return orderDetailInfo;
|
|
|
}
|
|
|
orderDetailInfo = buyerOrderDetailService.getOrderDetail(orderRequest);
|
|
|
|
|
|
if(Objects.nonNull(orderDetailInfo)){
|
|
|
orderCacheService.cacheOrderDetailInfo(uid, orderCode, orderDetailInfo);
|
|
|
}
|
|
|
return orderDetailInfo;
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
public PageResp getOrderList(OrderListRequest request) {
|
|
|
return buyerOrderListService.getOrderList(request);
|
|
|
|
|
|
OrderListVo orderListVo = orderCacheService.getOrderListInfos(request);
|
|
|
PageResp.PageRespBuilder respBuilder;
|
|
|
if (Objects.nonNull(orderListVo)){
|
|
|
respBuilder = PageResp.builder()
|
|
|
.page(request.getPage())
|
|
|
.pageSize(orderListVo.getPageSize())
|
|
|
.total(orderListVo.getTotal())
|
|
|
.pagetotal(orderListVo.getPagetotal());;
|
|
|
return respBuilder.data(orderListVo.getOrderList()).build();
|
|
|
}
|
|
|
PageResp orderListInfoRsp = buyerOrderListService.getOrderList(request);
|
|
|
|
|
|
if (orderListInfoRsp != null){
|
|
|
orderListVo = OrderListVo.builder().page(orderListInfoRsp.getPage())
|
|
|
.pageSize(orderListInfoRsp.getPageSize())
|
|
|
.orderList(orderListInfoRsp.getData())
|
|
|
.total(orderListInfoRsp.getTotal())
|
|
|
.pagetotal(orderListInfoRsp.getPagetotal()).build();
|
|
|
orderCacheService.cacheOrderList(request, orderListVo);
|
|
|
}
|
|
|
return orderListInfoRsp;
|
|
|
}
|
|
|
|
|
|
|
...
|
...
|
@@ -196,7 +253,14 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
* @return
|
|
|
*/
|
|
|
public OrderSummaryResp selectOrderNumByUid(int uid) {
|
|
|
Integer num = buyerOrderMapper.selectOrderNumByUid(uid);
|
|
|
Integer num =orderCacheService.getOrderSummary(uid, TabType.BUY);
|
|
|
if (num == null){
|
|
|
num = buyerOrderMapper.selectOrderNumByUid(uid);
|
|
|
}
|
|
|
if (num != null){
|
|
|
orderCacheService.cacheOrderSummary(uid, TabType.BUY, num);
|
|
|
}
|
|
|
|
|
|
return null == num ? new OrderSummaryResp("buy", 0) : new OrderSummaryResp("buy", num);
|
|
|
}
|
|
|
|
...
|
...
|
@@ -220,7 +284,11 @@ public class BuyerOrderServiceImpl implements IBuyerOrderService { |
|
|
BuyerOrder target = new BuyerOrder();
|
|
|
target.setId(buyerOrder.getId());
|
|
|
target.setBuyerOrderStatus(DelStatus.IS_DEL.getCode());
|
|
|
return buyerOrderMapper.updateByPrimaryKeySelective(target) == 1;
|
|
|
boolean result = buyerOrderMapper.updateByPrimaryKeySelective(target) == 1;
|
|
|
if(result){
|
|
|
cacheCleaner.cleanList(uid, TabType.BUY.getValue());
|
|
|
}
|
|
|
return result;
|
|
|
}else{
|
|
|
logger.warn("buyer delete fail, order status {}", status);
|
|
|
}
|
...
|
...
|
|