use of cn.lili.modules.order.order.entity.dto.PriceDetailDTO in project lilishop by lilishop.
the class FullDiscountExecute method giftOrderHandler.
/**
* 赠品订单处理
*
* @param skuList 赠品列表
* @param originOrder 原始订单
* @param orderTypeEnum 订单类型
*/
private void giftOrderHandler(List<GoodsSku> skuList, Order originOrder, OrderTypeEnum orderTypeEnum) {
// 初始化订单对象/订单日志/自订单
Order order = new Order();
List<OrderItem> orderItems = new ArrayList<>();
List<OrderLog> orderLogs = new ArrayList<>();
// 初始化价格详情
PriceDetailDTO priceDetailDTO = new PriceDetailDTO();
// 复制通用属性
BeanUtil.copyProperties(originOrder, order, "id");
BeanUtil.copyProperties(priceDetailDTO, order, "id");
// 生成订单参数
order.setSn(SnowFlake.createStr("G"));
order.setParentOrderSn(originOrder.getSn());
order.setOrderPromotionType(OrderPromotionTypeEnum.GIFT.name());
order.setOrderStatus(OrderStatusEnum.UNPAID.name());
order.setPayStatus(PayStatusEnum.PAID.name());
order.setOrderType(orderTypeEnum.name());
order.setNeedReceipt(false);
order.setPriceDetailDTO(priceDetailDTO);
order.setClientType(originOrder.getClientType());
// 订单日志
String message = "赠品订单[" + order.getSn() + "]创建";
orderLogs.add(new OrderLog(order.getSn(), originOrder.getMemberId(), UserEnums.MEMBER.name(), originOrder.getMemberName(), message));
// 生成子订单
for (GoodsSku goodsSku : skuList) {
OrderItem orderItem = new OrderItem();
BeanUtil.copyProperties(goodsSku, orderItem, "id");
BeanUtil.copyProperties(priceDetailDTO, orderItem, "id");
orderItem.setAfterSaleStatus(OrderItemAfterSaleStatusEnum.NEW.name());
orderItem.setCommentStatus(CommentStatusEnum.NEW.name());
orderItem.setComplainStatus(OrderComplaintStatusEnum.NEW.name());
orderItem.setNum(1);
orderItem.setOrderSn(order.getSn());
orderItem.setImage(goodsSku.getThumbnail());
orderItem.setGoodsName(goodsSku.getGoodsName());
orderItem.setSkuId(goodsSku.getId());
orderItem.setCategoryId(goodsSku.getCategoryPath().substring(goodsSku.getCategoryPath().lastIndexOf(",") + 1));
orderItem.setGoodsPrice(goodsSku.getPrice());
orderItem.setPriceDetailDTO(priceDetailDTO);
orderItems.add(orderItem);
}
// 保存订单
orderService.save(order);
orderItemService.saveBatch(orderItems);
orderLogService.saveBatch(orderLogs);
// 发送订单已付款消息(PS:不在这里处理逻辑是因为期望加交给消费者统一处理库存等等问题)
OrderMessage orderMessage = new OrderMessage();
orderMessage.setOrderSn(order.getSn());
orderMessage.setPaymentMethod(order.getPaymentMethod());
orderMessage.setNewStatus(OrderStatusEnum.PAID);
String destination = rocketmqCustomProperties.getOrderTopic() + ":" + OrderTagsEnum.STATUS_CHANGE.name();
// 发送订单变更mq消息
rocketMQTemplate.asyncSend(destination, JSONUtil.toJsonStr(orderMessage), RocketmqSendCallbackBuilder.commonCallback());
}
use of cn.lili.modules.order.order.entity.dto.PriceDetailDTO in project lilishop by lilishop.
the class OrderPriceServiceImpl method updateOrderPrice.
/**
* 修改订单价格
* 1.判定订单是否支付
* 2.记录订单原始价格信息
* 3.计算修改的订单金额
* 4.修改订单价格
* 5.保存订单信息
*
* @param orderSn 订单编号
* @param orderPrice 修改订单金额
*/
private Order updateOrderPrice(String orderSn, Double orderPrice) {
Order order = OperationalJudgment.judgment(orderService.getBySn(orderSn));
// 判定是否支付
if (order.getPayStatus().equals(PayStatusEnum.PAID.name())) {
throw new ServiceException(ResultCode.ORDER_UPDATE_PRICE_ERROR);
}
// 获取订单价格信息
PriceDetailDTO orderPriceDetailDTO = order.getPriceDetailDTO();
// 修改订单价格
order.setUpdatePrice(CurrencyUtil.sub(orderPrice, orderPriceDetailDTO.getOriginalPrice()));
// 订单修改金额=使用订单原始金额-修改后金额
orderPriceDetailDTO.setUpdatePrice(CurrencyUtil.sub(orderPrice, orderPriceDetailDTO.getOriginalPrice()));
order.setFlowPrice(orderPriceDetailDTO.getFlowPrice());
// 修改订单
order.setPriceDetailDTO(orderPriceDetailDTO);
orderService.updateById(order);
// 修改子订单
updateOrderItemPrice(order);
return order;
}
use of cn.lili.modules.order.order.entity.dto.PriceDetailDTO in project lilishop by lilishop.
the class CommissionRender method buildCartPrice.
/**
* 购物车佣金计算
*
* @param tradeDTO 购物车展示信息
*/
void buildCartPrice(TradeDTO tradeDTO) {
// 购物车列表
List<CartVO> cartVOS = tradeDTO.getCartList();
// 计算购物车价格
for (CartVO cart : cartVOS) {
// 累加价格
for (CartSkuVO cartSkuVO : cart.getCheckedSkuList()) {
PriceDetailDTO priceDetailDTO = cartSkuVO.getPriceDetailDTO();
// 平台佣金根据分类计算
String categoryId = cartSkuVO.getGoodsSku().getCategoryPath().substring(cartSkuVO.getGoodsSku().getCategoryPath().lastIndexOf(",") + 1);
if (CharSequenceUtil.isNotEmpty(categoryId)) {
Double commissionRate = categoryService.getCategoryById(categoryId).getCommissionRate();
priceDetailDTO.setPlatFormCommissionPoint(commissionRate);
}
// 如果积分订单 积分订单,单独操作订单结算金额和商家结算字段
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.POINTS) && tradeDTO.getSkuList().get(0).getPromotionMap() != null && !tradeDTO.getSkuList().get(0).getPromotionMap().isEmpty()) {
Optional<Map.Entry<String, Object>> pointsPromotions = tradeDTO.getSkuList().get(0).getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.POINTS_GOODS.name())).findFirst();
if (pointsPromotions.isPresent()) {
JSONObject promotionsObj = JSONUtil.parseObj(pointsPromotions.get().getValue());
PointsGoods pointsGoods = JSONUtil.toBean(promotionsObj, PointsGoods.class);
priceDetailDTO.setSettlementPrice(pointsGoods.getSettlementPrice());
}
} else // 如果砍价订单 计算金额,单独操作订单结算金额和商家结算字段
if (tradeDTO.getCartTypeEnum().equals(CartTypeEnum.KANJIA) && tradeDTO.getSkuList().get(0).getPromotionMap() != null && !tradeDTO.getSkuList().get(0).getPromotionMap().isEmpty()) {
Optional<Map.Entry<String, Object>> kanjiaPromotions = tradeDTO.getSkuList().get(0).getPromotionMap().entrySet().stream().filter(i -> i.getKey().contains(PromotionTypeEnum.KANJIA.name())).findFirst();
if (kanjiaPromotions.isPresent()) {
JSONObject promotionsObj = JSONUtil.parseObj(kanjiaPromotions.get().getValue());
KanjiaActivityGoods kanjiaActivityGoods = JSONUtil.toBean(promotionsObj, KanjiaActivityGoods.class);
priceDetailDTO.setSettlementPrice(CurrencyUtil.add(kanjiaActivityGoods.getSettlementPrice(), priceDetailDTO.getBillPrice()));
}
}
}
}
}
use of cn.lili.modules.order.order.entity.dto.PriceDetailDTO in project lilishop by lilishop.
the class OrderPriceServiceImpl method updateOrderItemPrice.
/**
* 修改订单货物金额
* 1.计算订单货物金额在订单金额中的百分比
* 2.订单货物金额=订单修改后金额*订单货物百分比
* 3.订单货物修改价格=订单货物原始价格-订单货物修改后金额
* 4.修改平台佣金
* 5.订单实际金额=修改后订单金额-平台佣金-分销提佣
*
* @param order 订单
*/
private void updateOrderItemPrice(Order order) {
List<OrderItem> orderItems = orderItemService.getByOrderSn(order.getSn());
// 获取总数,入欧最后一个则将其他orderitem的修改金额累加,然后进行扣减
Integer index = orderItems.size();
Double countUpdatePrice = 0D;
for (OrderItem orderItem : orderItems) {
// 获取订单货物价格信息
PriceDetailDTO priceDetailDTO = orderItem.getPriceDetailDTO();
index--;
// 如果是最后一个
if (index == 0) {
// 记录修改金额
priceDetailDTO.setUpdatePrice(CurrencyUtil.sub(order.getUpdatePrice(), countUpdatePrice));
// 修改订单货物金额
orderItem.setFlowPrice(priceDetailDTO.getFlowPrice());
orderItem.setUnitPrice(CurrencyUtil.div(priceDetailDTO.getFlowPrice(), orderItem.getNum()));
orderItem.setPriceDetail(JSONUtil.toJsonStr(priceDetailDTO));
} else {
// SKU占总订单 金额的百分比
Double priceFluctuationRatio = CurrencyUtil.div(priceDetailDTO.getOriginalPrice(), order.getPriceDetailDTO().getOriginalPrice(), 4);
// 记录修改金额
priceDetailDTO.setUpdatePrice(CurrencyUtil.mul(order.getUpdatePrice(), priceFluctuationRatio));
// 修改订单货物金额
orderItem.setFlowPrice(priceDetailDTO.getFlowPrice());
orderItem.setUnitPrice(CurrencyUtil.div(priceDetailDTO.getFlowPrice(), orderItem.getNum()));
orderItem.setPriceDetail(JSONUtil.toJsonStr(priceDetailDTO));
countUpdatePrice = CurrencyUtil.add(countUpdatePrice, priceDetailDTO.getUpdatePrice());
}
}
orderItemService.updateBatchById(orderItems);
}
use of cn.lili.modules.order.order.entity.dto.PriceDetailDTO in project lilishop by lilishop.
the class StoreFlowServiceImpl method payOrder.
/**
* 店铺订单支付流水
* @param orderSn 订单编号
*/
@Override
public void payOrder(String orderSn) {
// 根据订单编号获取子订单列表
List<OrderItem> orderItems = orderItemService.getByOrderSn(orderSn);
// 根据订单编号获取订单数据
Order order = orderService.getBySn(orderSn);
// 获取订单促销类型,如果为促销订单则获取促销商品并获取结算价
String orderPromotionType = order.getOrderPromotionType();
// 循环子订单记录流水
for (OrderItem item : orderItems) {
StoreFlow storeFlow = new StoreFlow();
BeanUtil.copyProperties(item, storeFlow);
// 去掉orderitem的时间。
storeFlow.setCreateTime(null);
// 入账
storeFlow.setId(SnowFlake.getIdStr());
storeFlow.setFlowType(FlowTypeEnum.PAY.name());
storeFlow.setSn(SnowFlake.createStr("SF"));
storeFlow.setOrderSn(item.getOrderSn());
storeFlow.setOrderItemSn(item.getSn());
storeFlow.setStoreId(order.getStoreId());
storeFlow.setStoreName(order.getStoreName());
storeFlow.setMemberId(order.getMemberId());
storeFlow.setMemberName(order.getMemberName());
storeFlow.setGoodsName(item.getGoodsName());
storeFlow.setOrderPromotionType(item.getPromotionType());
// 格式化订单价格详情
PriceDetailDTO priceDetailDTO = JSONUtil.toBean(item.getPriceDetail(), PriceDetailDTO.class);
// 站点优惠券比例=最大比例(100)-店铺承担比例
storeFlow.setSiteCouponPoint(CurrencyUtil.sub(100, priceDetailDTO.getSiteCouponPoint()));
// 平台优惠券 使用金额
storeFlow.setSiteCouponPrice(priceDetailDTO.getSiteCouponPrice());
// 站点优惠券佣金(站点优惠券承担金额=优惠券金额 * (站点承担比例/100))
storeFlow.setSiteCouponCommission(CurrencyUtil.mul(storeFlow.getSiteCouponPrice(), CurrencyUtil.div(storeFlow.getSiteCouponPoint(), 100)));
/**
* @TODO 计算平台佣金
*/
// 店铺流水金额=goodsPrice(商品总金额(商品原价))+ freightPrice(配送费) - discountPrice(优惠金额) - couponPrice(优惠券金额) + updatePrice(订单修改金额)
storeFlow.setFinalPrice(item.getPriceDetailDTO().getFlowPrice());
// 平台收取交易佣金=(flowPrice(流水金额) * platFormCommissionPoint(平台佣金比例))/100
storeFlow.setCommissionPrice(item.getPriceDetailDTO().getPlatFormCommission());
// 单品分销返现支出
storeFlow.setDistributionRebate(item.getPriceDetailDTO().getDistributionCommission());
// 最终结算金额=flowPrice(流水金额) - platFormCommission(平台收取交易佣金) - distributionCommission(单品分销返现支出)
storeFlow.setBillPrice(item.getPriceDetailDTO().getBillPrice());
// 兼容为空,以及普通订单操作
if (CharSequenceUtil.isNotEmpty(orderPromotionType)) {
if (orderPromotionType.equals(OrderPromotionTypeEnum.NORMAL.name())) {
// 普通订单操作
} else // 如果为砍价活动,填写砍价结算价
if (orderPromotionType.equals(OrderPromotionTypeEnum.KANJIA.name())) {
storeFlow.setKanjiaSettlementPrice(item.getPriceDetailDTO().getSettlementPrice());
} else // 如果为砍价活动,填写砍价结算价
if (orderPromotionType.equals(OrderPromotionTypeEnum.POINTS.name())) {
storeFlow.setPointSettlementPrice(item.getPriceDetailDTO().getSettlementPrice());
}
}
// 添加支付方式
storeFlow.setPaymentName(order.getPaymentMethod());
// 添加第三方支付流水号
storeFlow.setTransactionId(order.getReceivableNo());
// 添加付款交易流水
this.save(storeFlow);
}
}
Aggregations