|
|
package com.yohoufo.order.model;
|
|
|
|
|
|
import com.yohobuy.ufo.model.order.common.OrderAttributes;
|
|
|
import com.yohobuy.ufo.model.order.constants.BusinessClientEnum;
|
|
|
import com.yohobuy.ufo.model.order.constants.OrderConstant;
|
|
|
import com.yohobuy.ufo.model.order.constants.SkupType;
|
|
|
import com.yohobuy.ufo.model.order.vo.AddressInfo;
|
|
|
import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
|
|
|
import com.yohoufo.dal.order.model.SellerOrderGoods;
|
|
|
import com.yohoufo.order.charge.ChargeContext;
|
|
|
import com.yohoufo.order.charge.model.ChargeGoods;
|
|
|
import com.yohoufo.order.charge.model.ChargeResult;
|
|
|
import com.yohoufo.order.charge.model.SingleFeeDetail;
|
|
|
import com.yohoufo.order.model.bo.ActivityBo;
|
|
|
import com.yohoufo.order.model.bo.AmountDetailBo;
|
|
|
import com.yohoufo.order.model.bo.CouponBo;
|
|
|
import com.yohoufo.order.model.bo.CouponBoList;
|
|
|
import com.yohoufo.order.model.dto.OrderBuilder;
|
|
|
import com.yohoufo.order.service.impl.ShoppingServiceImpl;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.commons.lang3.tuple.Pair;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.Objects;
|
|
|
import java.util.function.Function;
|
|
|
import java.util.stream.Collectors;
|
|
|
|
|
|
public class OrderBuilderFactory {
|
|
|
|
|
|
public OrderBuilder create(int uid, long orderCode, String channelNo, String clientType,
|
|
|
Pair<AddressInfo, AddressInfo> userAddressPair,
|
|
|
ShoppingServiceImpl.GoodsPrepareData goodsPrepareData,
|
|
|
Function<SkupType, Integer> deliveryWayFunc,
|
|
|
SellerOrderGoods psog,
|
|
|
ChargeContext chargeContext,
|
|
|
String businessClient) {
|
|
|
//算费结果
|
|
|
ChargeResult chargeResult = chargeContext.getChargeResult();
|
|
|
ChargeGoods chargeGoods = chargeContext.getChargeGoods();
|
|
|
SkupType skupType = chargeGoods.getSkupType();
|
|
|
Integer businessClientCode = null;
|
|
|
if (StringUtils.isNotBlank(businessClient)){
|
|
|
if(OrderConstant.BusinessClient.TAOBAO_FLEAMARKET.equalsIgnoreCase(businessClient)) {
|
|
|
businessClientCode = BusinessClientEnum.TAOBAO_FLEAMARKET_CLIENT.getCode();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return OrderBuilder.builder()
|
|
|
.uid(uid)
|
|
|
.skup(psog.getId())
|
|
|
.depositCode(goodsPrepareData.getDepositCode())
|
|
|
.orderCode(orderCode)
|
|
|
.productId(psog.getProductId())
|
|
|
.paymentType(OrderConstant.PAYMENT_ONLINE)
|
|
|
.deliverWay(deliveryWayFunc.apply(skupType))
|
|
|
.channelNo(channelNo)
|
|
|
.amount(BigDecimal.valueOf(chargeResult.getFinalAmount()))
|
|
|
.shipFee(BigDecimal.valueOf(chargeResult.getFinalShippingAmount()))
|
|
|
.couponBoList(buildOrderCouponBoList(chargeResult))
|
|
|
.hiddenAddressInfo(userAddressPair.getRight())
|
|
|
.addressInfo(userAddressPair.getLeft())
|
|
|
.clientType(clientType)
|
|
|
.attributes(buildOrderAttribute(psog, chargeGoods.isDepositRequirement()).getCode())
|
|
|
.originalAttributes(psog.getAttributes())
|
|
|
.sellerOrderGoods(psog)
|
|
|
.activityBo(buildOrderActivityBo(chargeResult))
|
|
|
.amountDetailBo(buildOrderAmountDetailBo(chargeResult))
|
|
|
.tariffFee(chargeResult.getTariffFee())
|
|
|
.depositFee(buildDepositFee(chargeGoods))
|
|
|
.promotionCutAmount(chargeResult.getPromotionCutAmount())
|
|
|
.useableFullPromotionList(chargeGoods.getUseableFullPromotionList())
|
|
|
.businessClient(businessClientCode)
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取订单attribute属性
|
|
|
*
|
|
|
* @return
|
|
|
*/
|
|
|
protected OrderAttributes buildOrderAttribute(SellerOrderGoods skup, boolean isDepositRequirement) {
|
|
|
if (isDepositRequirement) {
|
|
|
return OrderAttributes.DEPOSITE;
|
|
|
}
|
|
|
OrderAttributes orderAttributes = OrderAttributes.getOrderAttributes(skup.getAttributes());
|
|
|
return orderAttributes;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 活动优惠
|
|
|
*
|
|
|
* @param chargeResult
|
|
|
* @return
|
|
|
*/
|
|
|
protected ActivityBo buildOrderActivityBo(ChargeResult chargeResult) {
|
|
|
return ActivityBo.builder().activityType(chargeResult.getActivityCutResult().getActivityType())
|
|
|
.userActivityId(chargeResult.getActivityCutResult().getUserActivityId())
|
|
|
//以计算结果为准
|
|
|
.activityCutAmount(BigDecimal.valueOf(chargeResult.getActivityCutResult().getActivityCutAmount()))
|
|
|
.build();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 优惠券支付结果
|
|
|
*
|
|
|
* @param chargeResult
|
|
|
* @return
|
|
|
*/
|
|
|
protected CouponBoList buildOrderCouponBoList(ChargeResult chargeResult) {
|
|
|
return CouponBoList.builder().couponBos(chargeResult.getCouponPayResultList().getCouponPayResults().stream()
|
|
|
.map(couponPayResult -> CouponBo.builder()
|
|
|
.couponCode(couponPayResult.getCouponCode())
|
|
|
.couponType(couponPayResult.getCouponType())
|
|
|
.couponAmount(BigDecimal.valueOf(couponPayResult.getCouponAmount()))
|
|
|
.build()
|
|
|
)
|
|
|
.collect(Collectors.toList())
|
|
|
).build();
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 订单金额明细
|
|
|
* @param chargeResult
|
|
|
* @return
|
|
|
*/
|
|
|
protected AmountDetailBo buildOrderAmountDetailBo(ChargeResult chargeResult) {
|
|
|
//订单金额明细
|
|
|
final AmountDetailBo amountDetailBo = new AmountDetailBo();
|
|
|
//商品金额
|
|
|
amountDetailBo.setGoodsAmount(chargeResult.getGoodsAmount());
|
|
|
//运费原价
|
|
|
amountDetailBo.setShippingAmount(chargeResult.getShippingAmount());
|
|
|
//活动金额
|
|
|
amountDetailBo.setActivityCutAmount(chargeResult.getActivityCutResult().getActivityCutAmount());
|
|
|
|
|
|
//税费
|
|
|
SingleFeeDetail tariffFee;
|
|
|
if (Objects.nonNull(tariffFee = chargeResult.getTariffFee())) {
|
|
|
amountDetailBo.setTariffRate(tariffFee.getRate());
|
|
|
amountDetailBo.setTariffAmount(tariffFee.getAmount());
|
|
|
amountDetailBo.setTariffCutAmount(tariffFee.getCutAmount());
|
|
|
}
|
|
|
SingleFeeDetail shipFeeDetail;
|
|
|
if (Objects.nonNull(shipFeeDetail = chargeResult.getShipFeeDetail())){
|
|
|
amountDetailBo.setShippingActivityCutAmount(shipFeeDetail.getCutAmount());
|
|
|
}
|
|
|
|
|
|
SingleFeeDetail depositFee;
|
|
|
if (Objects.nonNull(depositFee=chargeResult.getDepositFee())){
|
|
|
amountDetailBo.setDepositAmount(depositFee.getAmount());
|
|
|
}
|
|
|
|
|
|
SingleFeeDetail quickDeliveFee = chargeResult.getQuickDeliverServiceFee();
|
|
|
if (Objects.nonNull(quickDeliveFee)){
|
|
|
amountDetailBo.setQuickDeliveServiceAmount(quickDeliveFee.getAmount());
|
|
|
}
|
|
|
//活动券减免金额
|
|
|
chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.ACTIVITY_COUPON.getCode()).
|
|
|
ifPresent(tempPayResult -> amountDetailBo.setCouponCutAmount(tempPayResult.getCouponAmount()));
|
|
|
|
|
|
//运费券减免金额
|
|
|
chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.SHIPPING_COUPON.getCode()).
|
|
|
ifPresent(tempPayResult -> amountDetailBo.setShippingCouponCutAmount(tempPayResult.getCouponAmount()));
|
|
|
|
|
|
amountDetailBo.setPromotionCutAmount(chargeResult.getPromotionCutAmount());
|
|
|
return amountDetailBo;
|
|
|
}
|
|
|
|
|
|
private SingleFeeDetail buildDepositFee(ChargeGoods chargeGoods){
|
|
|
BigDecimal qdsf = chargeGoods.getQuickDeliverServiceFee();
|
|
|
BigDecimal smf = chargeGoods.getStorageManagementFee();
|
|
|
double amount = 0D;
|
|
|
if (Objects.nonNull(qdsf)){
|
|
|
amount = qdsf.doubleValue();
|
|
|
}
|
|
|
if (Objects.nonNull(smf)){
|
|
|
amount = smf.doubleValue();
|
|
|
}
|
|
|
SingleFeeDetail sfd = SingleFeeDetail.builder().amount(amount).build();
|
|
|
return sfd;
|
|
|
}
|
|
|
|
|
|
} |
...
|
...
|
|