|
|
@@ -1,9 +1,11 @@
|
|
|
package cn.hobbystocks.auc.service.impl;
|
|
|
|
|
|
+import cn.hobbystocks.auc.common.exception.ServiceException;
|
|
|
import cn.hobbystocks.auc.common.utils.DateUtils;
|
|
|
import cn.hobbystocks.auc.domain.Auction;
|
|
|
import cn.hobbystocks.auc.domain.Lot;
|
|
|
import cn.hobbystocks.auc.domain.Order;
|
|
|
+import cn.hobbystocks.auc.dto.OrderApiResponse;
|
|
|
import cn.hobbystocks.auc.dto.SkuOrderDTO;
|
|
|
import cn.hobbystocks.auc.forest.OrderApi;
|
|
|
import cn.hobbystocks.auc.mapper.OrderMapper;
|
|
|
@@ -12,18 +14,20 @@ import cn.hobbystocks.auc.service.ILotService;
|
|
|
import cn.hobbystocks.auc.service.IOrderService;
|
|
|
import cn.hobbystocks.auc.vo.OrderVO;
|
|
|
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
|
|
|
-import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.util.Date;
|
|
|
import java.util.List;
|
|
|
+import java.util.Objects;
|
|
|
|
|
|
@Service
|
|
|
-public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements IOrderService {
|
|
|
+public class OrderServiceImpl extends ServiceImpl<OrderMapper, Order> implements IOrderService {
|
|
|
|
|
|
@Autowired
|
|
|
ILotService lotService;
|
|
|
@@ -31,43 +35,36 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements
|
|
|
IAuctionService auctionService;
|
|
|
@Resource
|
|
|
OrderApi orderApi;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ @Value("${hobbystocks.host.orderUrl}")
|
|
|
+ private String orderUrl;
|
|
|
|
|
|
@Override
|
|
|
@Transactional
|
|
|
public OrderVO createSkuOrder(Order order) {
|
|
|
- //查询拍品服务费
|
|
|
Lot lot = lotService.selectLotById(order.getLotId());
|
|
|
Auction auction = auctionService.selectAuctionById(lot.getAuctionId());
|
|
|
BigDecimal serviceTariff = lot.getServiceTariff();
|
|
|
Integer payTimeLimit = lot.getPayTimeLimit();
|
|
|
- if (serviceTariff==null){
|
|
|
- //查询拍卖会服务费
|
|
|
- serviceTariff=auction.getServiceTariff();
|
|
|
+ if (serviceTariff == null) {
|
|
|
+ serviceTariff = auction.getServiceTariff();
|
|
|
+ }
|
|
|
+ if (payTimeLimit == null) {
|
|
|
+ payTimeLimit = auction.getPayTimeLimit();
|
|
|
}
|
|
|
- if (payTimeLimit==null)
|
|
|
- //中拍支付时限(小时)
|
|
|
- payTimeLimit=auction.getPayTimeLimit();
|
|
|
- //计算服务费
|
|
|
- long amount = order.getAmount();
|
|
|
- BigDecimal bigAmount = BigDecimal.valueOf(amount);
|
|
|
- //费率/100*成交价=服务费
|
|
|
- BigDecimal serviceExpense = serviceTariff.divide(BigDecimal.valueOf(100)).multiply(bigAmount);
|
|
|
+ if (Objects.isNull(order.getAmount())) {
|
|
|
+ throw new ServiceException("创建订单失败:成交金额为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ BigDecimal amount = BigDecimal.valueOf(order.getAmount());
|
|
|
+ BigDecimal serviceExpense = serviceTariff.multiply(amount)
|
|
|
+ .divide(BigDecimal.valueOf(100), 0, RoundingMode.HALF_UP);
|
|
|
order.setServiceExpense(serviceExpense);
|
|
|
- //根据支付时限计算订单过期时间,
|
|
|
- Date date = DateUtils.addHours(new Date(), payTimeLimit);
|
|
|
- order.setExpireTime(date);
|
|
|
+ Date expireTime = DateUtils.addHours(new Date(), payTimeLimit);
|
|
|
+ order.setExpireTime(expireTime);
|
|
|
save(order);
|
|
|
|
|
|
- //todo 调用创建订单接口
|
|
|
- SkuOrderDTO skuOrderDTO = new SkuOrderDTO();
|
|
|
- BeanUtils.copyProperties(order,skuOrderDTO);
|
|
|
- skuOrderDTO.setAuctionName(auction.getName());
|
|
|
- skuOrderDTO.setLotName(lot.getName());
|
|
|
- OrderVO orderVO = orderApi.createSkuOrder(skuOrderDTO);
|
|
|
- //todo 记录订单信息
|
|
|
+ OrderApiResponse response = orderApi.createSkuOrder(orderUrl, buildSkuOrderDTO(order, lot, auction));
|
|
|
+ OrderVO orderVO = response.toOrderVO();
|
|
|
order.setOrderId(orderVO.getOrderId());
|
|
|
order.setOrderNo(orderVO.getOrderNo());
|
|
|
order.setStatus(orderVO.getStatus());
|
|
|
@@ -75,6 +72,23 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements
|
|
|
return orderVO;
|
|
|
}
|
|
|
|
|
|
+ SkuOrderDTO buildSkuOrderDTO(Order order, Lot lot, Auction auction) {
|
|
|
+ SkuOrderDTO skuOrderDTO = new SkuOrderDTO();
|
|
|
+ skuOrderDTO.setLotId(order.getLotId());
|
|
|
+ skuOrderDTO.setSpuId(order.getSkuId());
|
|
|
+ skuOrderDTO.setUserId(order.getUserId());
|
|
|
+ skuOrderDTO.setAuctionId(lot.getAuctionId());
|
|
|
+ skuOrderDTO.setAuctionName(auction.getName());
|
|
|
+ skuOrderDTO.setLotName(lot.getName());
|
|
|
+ skuOrderDTO.setLotImage(lot.getImgs());
|
|
|
+ skuOrderDTO.setMerchantId(Objects.isNull(order.getMerchantId()) ? lot.getMerchantId() : order.getMerchantId());
|
|
|
+ skuOrderDTO.setPaymentAmount(order.getAmount());
|
|
|
+ skuOrderDTO.setServiceExpense(order.getServiceExpense().longValue());
|
|
|
+ skuOrderDTO.setTotalAmount(BigDecimal.valueOf(order.getAmount()).add(order.getServiceExpense()).longValue());
|
|
|
+ skuOrderDTO.setExpireTime(order.getExpireTime());
|
|
|
+ return skuOrderDTO;
|
|
|
+ }
|
|
|
+
|
|
|
@Override
|
|
|
public int modifyOrder(Order order) {
|
|
|
return getBaseMapper().updateOrderStatus(order);
|
|
|
@@ -82,8 +96,6 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper,Order> implements
|
|
|
|
|
|
@Override
|
|
|
public List<Order> getOrderListByUserAndAuction(Long auctionId, Integer userId) {
|
|
|
- return getBaseMapper().selectOrderByAuctionId(auctionId,userId);
|
|
|
+ return getBaseMapper().selectOrderByAuctionId(auctionId, userId);
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|