...
|
...
|
@@ -3,23 +3,19 @@ package com.yohoufo.order.service.deposit; |
|
|
import com.google.common.collect.Lists;
|
|
|
import com.yoho.error.ServiceError;
|
|
|
import com.yoho.error.exception.ServiceException;
|
|
|
import com.yohobuy.ufo.model.order.bo.DepositDetailBo;
|
|
|
import com.yohobuy.ufo.model.order.bo.GoodsInfo;
|
|
|
import com.yohobuy.ufo.model.order.common.OrderCodeType;
|
|
|
import com.yohobuy.ufo.model.order.constants.DepositEventTypeEnum;
|
|
|
import com.yohobuy.ufo.model.order.constants.OrderConstant;
|
|
|
import com.yohobuy.ufo.model.order.constants.StorageDepositStatusEnum;
|
|
|
import com.yohobuy.ufo.model.order.req.DepositOrderComputeReq;
|
|
|
import com.yohobuy.ufo.model.order.resp.DepositOrderComputeResp;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
|
|
import com.yohoufo.common.exception.UfoServiceException;
|
|
|
import com.yohoufo.common.utils.StringUtil;
|
|
|
import com.yohoufo.dal.order.BuyerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.DepositOrderMapper;
|
|
|
import com.yohoufo.dal.order.SellerOrderGoodsMapper;
|
|
|
import com.yohoufo.dal.order.StorageDepositMapper;
|
|
|
import com.yohoufo.dal.order.model.BuyerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.DepositOrder;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.dal.order.model.StorageDeposit;
|
|
|
import com.yohoufo.dal.order.*;
|
|
|
import com.yohoufo.dal.order.model.*;
|
|
|
import com.yohoufo.order.convert.GoodsInfoConvertor;
|
|
|
import com.yohoufo.order.model.response.OrderSubmitResponse;
|
|
|
import com.yohoufo.order.service.DepositService;
|
...
|
...
|
@@ -33,6 +29,7 @@ import org.springframework.stereotype.Service; |
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.List;
|
|
|
import java.util.Objects;
|
|
|
|
|
|
/**
|
|
|
* Created by li.ma on 2019/7/9.
|
...
|
...
|
@@ -51,7 +48,7 @@ public class DepositOrderService { |
|
|
private SellerOrderGoodsMapper sellerOrderGoodsMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private BuyerOrderGoodsMapper buyerOrderGoodsMapper;
|
|
|
private BuyerOrderMapper buyerOrderMapper;
|
|
|
|
|
|
@Autowired
|
|
|
private IBuyerOrderMetaService buyerOrderMetaService;
|
...
|
...
|
@@ -68,42 +65,42 @@ public class DepositOrderService { |
|
|
* @return
|
|
|
*/
|
|
|
public DepositOrderComputeResp computePublishPrd(DepositOrderComputeReq req) {
|
|
|
StorageDeposit storageDeposit = checkStorageDeposit(req); // 不存在的时候有异常
|
|
|
StorageDeposit storageDeposit = checkStorageDeposit(req,
|
|
|
Lists.newArrayList(StorageDepositStatusEnum.HAS_IN.getCode())); // 不存在的时候有异常
|
|
|
|
|
|
int depositRemainDay = depositService.getRemainDay(req.getUid(), req.getDepositCode()); // 还可存放多久 单位天
|
|
|
|
|
|
Integer skup = storageDeposit.getSkup();
|
|
|
Long orderCode = storageDeposit.getOrderCode();
|
|
|
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
GoodsInfo goodsInfo = null;
|
|
|
if (null != sellerOrderGoods) {
|
|
|
goodsInfo = GoodsInfoConvertor.SellerOrderGoods2GoodsInfo(sellerOrderGoods);
|
|
|
}
|
|
|
List<BuyerOrderGoods> buyerOrderGoodses = buyerOrderGoodsMapper.selectBySkups(Lists.newArrayList(skup));
|
|
|
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode);
|
|
|
if (CollectionUtils.isNotEmpty(buyerOrderGoodses)) {
|
|
|
priceInfo.setGoodPrice(buyerOrderGoodses.get(0).getGoodsAmount());
|
|
|
}
|
|
|
GoodsInfo goodsInfo = getGoodsInfo(skup); // 查询购买商品的详细信息
|
|
|
|
|
|
|
|
|
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, req.getAddress_id()); // 获取各种费用
|
|
|
|
|
|
AddressInfo addressInfo = buyerOrderMetaService.getAddressInfo(req.getUid(), orderCode);
|
|
|
setBuyerPrice(orderCode, priceInfo); // 设置入手价
|
|
|
|
|
|
AddressInfo addressInfo = buyerOrderMetaService.getHiddenAddressInfo(req.getUid(), orderCode);
|
|
|
|
|
|
return DepositOrderComputeResp.builder().depositRemainDay(getReplacedContent(DepositOrderComputeResp.DEPOSITREMAINDAY_TIP, depositRemainDay))
|
|
|
.userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).build();
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public OrderSubmitResponse publishDepositOrder(DepositOrderComputeReq req) {
|
|
|
Integer uid = req.getUid();
|
|
|
if (uid == null || uid <= 0){
|
|
|
throw new ServiceException(ServiceError.ORDER_REQUEST_PARM_IS_EMPTY);
|
|
|
}
|
|
|
checkStorageDeposit(req);
|
|
|
StorageDeposit storageDeposit = checkStorageDeposit(req,
|
|
|
Lists.newArrayList(StorageDepositStatusEnum.HAS_IN.getCode())); //查看在库状态的库存
|
|
|
|
|
|
long orderCode = orderCodeGenerator.generate(OrderCodeType.STORAGE_MANAGEMENT);
|
|
|
|
|
|
int now = (int) (System.currentTimeMillis()/1000);
|
|
|
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode);
|
|
|
DepositOrderComputeResp.PriceInfo priceInfo = getFeeInfo(orderCode, req.getAddress_id());
|
|
|
|
|
|
DepositOrder depositOrder = DepositOrder.builder().uid(uid).amount(priceInfo.getAmount())
|
|
|
.contractFee(priceInfo.getContractFee())
|
...
|
...
|
@@ -111,6 +108,9 @@ public class DepositOrderService { |
|
|
.createTime(now).depositCode(req.getDepositCode())
|
|
|
.eventType(DepositEventTypeEnum.DEPOSIT_RECALL_FEE.getCode()).orderCode(orderCode).payment(0).status(0).updateTime(now).build();
|
|
|
|
|
|
// TODO 创建召回地址
|
|
|
storageDeposit.getOrderCode();
|
|
|
|
|
|
LOG.info("enter publishDepositOrder begin save depositOrder {} ",depositOrder);
|
|
|
int num = depositOrderMapper.insert(depositOrder); // 生成订单数据,insert db
|
|
|
LOG.info("enter publishDepositOrder end save depositOrder {} ,num {}",depositOrder, num);
|
...
|
...
|
@@ -118,18 +118,83 @@ public class DepositOrderService { |
|
|
return OrderSubmitResponse.builder().orderCode(orderCode).paymentStatus(OrderConstant.N_STR).build();
|
|
|
}
|
|
|
|
|
|
private StorageDeposit checkStorageDeposit(DepositOrderComputeReq req) {
|
|
|
StorageDeposit storageDeposit = storageDepositMapper.selectByDepositCode(req.getUid(), req.getDepositCode());
|
|
|
if (null == storageDeposit || null == storageDeposit.getSkup() || null == storageDeposit.getOrderCode()) {
|
|
|
LOG.warn("storageDepositMapper.selectByDepositCode not exist, req is {}", req);
|
|
|
throw new UfoServiceException(400, "在库状态的库存不存在");
|
|
|
|
|
|
|
|
|
public void updateByOrderCode(DepositOrder order) {
|
|
|
depositOrderMapper.updatePayment(order);
|
|
|
}
|
|
|
|
|
|
public DepositOrder selectByOrderCodeUid(long orderCode, int uid) {
|
|
|
return depositOrderMapper.selectByOrderCode(orderCode);
|
|
|
}
|
|
|
|
|
|
public int updateStatusByOrderCode(DepositOrder order) {
|
|
|
return depositOrderMapper.updateStatusByOrderCode(order);
|
|
|
}
|
|
|
|
|
|
public DepositOrder selectByOrderCode(Long orderCode) {
|
|
|
return depositOrderMapper.selectByOrderCode(orderCode);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询召回订单详情
|
|
|
* @param req
|
|
|
* @return
|
|
|
*/
|
|
|
public DepositOrderComputeResp depositOrderInfo(DepositOrderComputeReq req) {
|
|
|
StorageDeposit storageDeposit = checkStorageDeposit(req,
|
|
|
Lists.newArrayList(StorageDepositStatusEnum.WAITING_QUERY.getCode(), StorageDepositStatusEnum.WAITING_OUT.getCode())); // 不存在的时候有异常
|
|
|
|
|
|
DepositDetailBo depositDetailBo = depositService.convert(storageDeposit);
|
|
|
|
|
|
AddressInfo addressInfo = buyerOrderMetaService.getHiddenAddressInfo(req.getUid(), storageDeposit.getOrderCode());
|
|
|
|
|
|
GoodsInfo goodsInfo = getGoodsInfo(storageDeposit.getSkup()); // 查询购买商品的详细信息
|
|
|
|
|
|
DepositOrderComputeResp.PriceInfo priceInfo = getOrderFeeInfo(req.getDepositCode()); // 获取各种费用
|
|
|
|
|
|
setBuyerPrice(storageDeposit.getOrderCode(), priceInfo); // 设置入手价
|
|
|
|
|
|
return DepositOrderComputeResp.builder().userAddress(addressInfo).priceInfo(priceInfo).goodsInfo(goodsInfo).depositDetailBo(depositDetailBo).build();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 查询召回订单的各种详情
|
|
|
* @param depositCode
|
|
|
* @return
|
|
|
*/
|
|
|
private DepositOrderComputeResp.PriceInfo getOrderFeeInfo(String depositCode) {
|
|
|
DepositOrderComputeResp.PriceInfo priceInfo = DepositOrderComputeResp.PriceInfo.builder().build();
|
|
|
|
|
|
DepositOrder depositOrder = depositOrderMapper.selectByDepositCode(depositCode, DepositEventTypeEnum.DEPOSIT_RECALL_FEE.getCode()); // 自动到期之后寄回的,没有订单
|
|
|
if (Objects.isNull(depositOrder)) {
|
|
|
return DepositOrderComputeResp.PriceInfo.builder().build();
|
|
|
}
|
|
|
|
|
|
return storageDeposit;
|
|
|
return DepositOrderComputeResp.PriceInfo.builder().amount(depositOrder.getAmount())
|
|
|
.contractFee(depositOrder.getContractFee())
|
|
|
.shipFee(depositOrder.getShipFee()).build();
|
|
|
}
|
|
|
|
|
|
|
|
|
private void setBuyerPrice(Long orderCode, DepositOrderComputeResp.PriceInfo priceInfo) {
|
|
|
BuyerOrder buyerOrder = buyerOrderMapper.selectByOrderCode(orderCode);
|
|
|
if (!Objects.isNull(buyerOrder)) {
|
|
|
priceInfo.setGoodPrice(buyerOrder.getAmount());
|
|
|
}
|
|
|
}
|
|
|
|
|
|
private GoodsInfo getGoodsInfo(Integer skup) {
|
|
|
SellerOrderGoods sellerOrderGoods = sellerOrderGoodsMapper.selectByPrimaryKey(skup);
|
|
|
GoodsInfo goodsInfo = null;
|
|
|
if (null != sellerOrderGoods) {
|
|
|
goodsInfo = GoodsInfoConvertor.SellerOrderGoods2GoodsInfo(sellerOrderGoods);
|
|
|
}
|
|
|
return goodsInfo;
|
|
|
}
|
|
|
|
|
|
// 查询召回所需要的费用
|
|
|
private DepositOrderComputeResp.PriceInfo getFeeInfo(Long orderCode) {
|
|
|
private DepositOrderComputeResp.PriceInfo getFeeInfo(Long orderCode, String addressId) {
|
|
|
BigDecimal contractFee = new BigDecimal(15); // 违约金
|
|
|
BigDecimal shipFee = new BigDecimal(15); // 运费
|
|
|
BigDecimal amount = contractFee.add(shipFee);
|
...
|
...
|
@@ -141,19 +206,13 @@ public class DepositOrderService { |
|
|
return StringUtil.getReplacedContent(content, params);
|
|
|
}
|
|
|
|
|
|
public void updateByOrderCode(DepositOrder order) {
|
|
|
depositOrderMapper.updatePayment(order);
|
|
|
}
|
|
|
|
|
|
public DepositOrder selectByOrderCodeUid(long orderCode, int uid) {
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
public int updateStatusByOrderCode(DepositOrder order) {
|
|
|
return depositOrderMapper.updateStatusByOrderCode(order);
|
|
|
}
|
|
|
private StorageDeposit checkStorageDeposit(DepositOrderComputeReq req, List<Integer> statusList) {
|
|
|
StorageDeposit storageDeposit = storageDepositMapper.selectByDepositCode(req.getUid(), req.getDepositCode(), statusList);
|
|
|
if (null == storageDeposit || null == storageDeposit.getSkup() || null == storageDeposit.getOrderCode()) {
|
|
|
LOG.warn("storageDepositMapper.selectByDepositCode not exist, req is {}", req);
|
|
|
throw new UfoServiceException(400, "在库状态的库存不存在");
|
|
|
}
|
|
|
|
|
|
public DepositOrder selectByOrderCode(Long orderCode) {
|
|
|
return depositOrderMapper.selectByOrderCode(orderCode);
|
|
|
return storageDeposit;
|
|
|
}
|
|
|
} |
...
|
...
|
|