Authored by wujiexiang

优惠券优化 -- 订单详情

package com.yohoufo.dal.promotion.model;
import lombok.ToString;
@ToString
public class UserCoupon {
private Integer id;
... ...
package com.yohoufo.order.model.bo;
import lombok.Builder;
import lombok.Getter;
import lombok.Data;
/**
* Created by jiexiang.wu on 2019/6/10.
* 订单金额明细(用于展示明细),但不包含最终金额(实付金额、最终运费;这两项应该从订单主表获取)
*/
@Builder
@Getter
@Data
public class AmountDetailBo {
/**
... ...
... ... @@ -36,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
/**
* Created by chenchao on 2018/9/20.
... ... @@ -138,14 +139,22 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
throw new ServiceException(ServiceError.ORDER_ORDERS_GOODS_IS_EMPTY);
}
// 收货地址 and 用户信息
AddressInfo userAddress = getHiddenAddressInfo(uid, orderCode, sellerOrderGoods.getId());
//buyer_order_meta 批量查询
List<BuyerOrderMeta> buyerOrderMetas = getBuyerOrderMetas(uid, orderCode, Lists.newArrayList(MetaKey.BUYER_DELIVERY_HIDDEN_ADDRESS, MetaKey.AMOUNT_DETAIL));
Optional<BuyerOrderMeta> buyerDeliveryHiddenAddressMetaOptional = buyerOrderMetas.stream().filter(meta -> StringUtils.equals(MetaKey.BUYER_DELIVERY_HIDDEN_ADDRESS, meta.getMetaKey())).findFirst();
AddressInfo userAddress;
if (buyerDeliveryHiddenAddressMetaOptional.isPresent()) {
userAddress = BuyerOrderMetaMapperSupport.convert(buyerDeliveryHiddenAddressMetaOptional.get(), AddressInfo.class);
} else {
// 收货地址 and 用户信息
userAddress = getHiddenAddressInfo(uid, orderCode, sellerOrderGoods.getId());
}
// 需要查询 时间点 and 物流定位
ExpressInfoDetail lastEID = getExpressInfoDetail(orderStatus, orderCode);
//buyer_order_meta
List<BuyerOrderMeta> buyerOrderMetas = getBuyerOrderMetas(uid, orderCode, Lists.newArrayList(MetaKey.AMOUNT_DETAIL));
BuildNode buildNode = BuildNode.builder()
.tabType(actor)
.buyerOrder(buyerOrder)
... ... @@ -221,11 +230,10 @@ public abstract class AbsOrderDetailService extends AbsOrderViewService implemen
OrderDetailInfo.PriceInfo priceInfo;
//订单金额明细
BuyerOrderMeta amountDetailMeta = buildNode.buyerOrderMetas.stream().filter(meta -> StringUtils.equals(meta.getMetaKey(), MetaKey.AMOUNT_DETAIL))
.findFirst().orElse(null);
Optional<BuyerOrderMeta> buyerAmountDetailMetaOptional = buildNode.buyerOrderMetas.stream().filter(meta -> StringUtils.equals(meta.getMetaKey(), MetaKey.AMOUNT_DETAIL)).findFirst();
if (amountDetailMeta != null) {
AmountDetailBo amountDetailBo = BuyerOrderMetaMapperSupport.convert(amountDetailMeta, AmountDetailBo.class);
if (buyerAmountDetailMetaOptional.isPresent()) {
AmountDetailBo amountDetailBo = BuyerOrderMetaMapperSupport.convert(buyerAmountDetailMetaOptional.get(), AmountDetailBo.class);
//priceInfo
priceInfo = OrderDetailInfo.PriceInfo.builder()
.goodPrice(MathUtils.formatStr(amountDetailBo.getGoodsAmount()))
... ...
... ... @@ -10,7 +10,6 @@ import com.yohobuy.ufo.model.order.constants.ChangePriceStatus;
import com.yohobuy.ufo.model.order.constants.SkupType;
import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
import com.yohoufo.common.alarm.EventBusPublisher;
import com.yohoufo.common.alarm.SmsAlarmEvent;
import com.yohoufo.common.exception.UfoServiceException;
import com.yohoufo.common.utils.AddressUtil;
import com.yohoufo.dal.order.SellerChangePriceRecordMapper;
... ... @@ -26,7 +25,6 @@ import com.yohoufo.order.charge.ChargeService;
import com.yohoufo.order.charge.coupon.CouponService;
import com.yohoufo.order.charge.model.*;
import com.yohoufo.order.constants.ActivityTypeEnum;
import com.yohoufo.order.common.BlackTypeEnum;
import com.yohoufo.order.event.BuyerCancelEvent;
import com.yohoufo.order.event.ErpBuyerOrderEvent;
import com.yohoufo.order.event.NotPaidNoticeEvent;
... ... @@ -367,22 +365,6 @@ public class ShoppingServiceImpl implements IShoppingService {
logger.info("generate new orderCode:{}",orderCode);
//优惠券支付结果
Optional<CouponPayResult> tempPayResult;
//订单金额明细
AmountDetailBo amountDetailBo = AmountDetailBo.builder()
//商品金额
.goodsAmount(chargeResult.getGoodsAmount())
//运费原价
.shippingAmount(chargeResult.getShippingAmount())
//活动金额
.activityCutAmount(chargeResult.getActivityCutResult().getActivityCutAmount())
//活动券减免金额
.couponCutAmount((tempPayResult = chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.ACTIVITY_COUPON.getCode())).isPresent() ? tempPayResult.get().getCouponAmount() : 0.00)
//运费券减免金额
.shippingCouponCutAmount((tempPayResult = chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.SHIPPING_COUPON.getCode())).isPresent() ? tempPayResult.get().getCouponAmount() : 0.00)
.build();
List<CouponPayResult> couponPayResults = chargeResult.getCouponPayResultList().getCouponPayResults();
// 减库存,skup更新成不可售,入库
//BigDecimal shipFee = new BigDecimal(delivery_way_sf_cost);
... ... @@ -410,7 +392,7 @@ public class ShoppingServiceImpl implements IShoppingService {
.activityCutAmount(BigDecimal.valueOf(chargeResult.getActivityCutResult().getActivityCutAmount()))
.build()
)
.amountDetailBo(amountDetailBo)
.amountDetailBo(buildOrderAmountDetailBo(chargeResult))
.build();
BuyerOrderSubmitResult submitResult = ordeCreationService.doSubmitOrder(orderBuilder);
... ... @@ -495,6 +477,30 @@ public class ShoppingServiceImpl implements IShoppingService {
return orderAttributes;
}
/**
* 订单金额明细
* @param chargeResult
* @return
*/
protected AmountDetailBo buildOrderAmountDetailBo(ChargeResult chargeResult) {
//订单金额明细
AmountDetailBo amountDetailBo = new AmountDetailBo();
//商品金额
amountDetailBo.setGoodsAmount(chargeResult.getGoodsAmount());
//运费原价
amountDetailBo.setShippingAmount(chargeResult.getShippingAmount());
//活动金额
amountDetailBo.setActivityCutAmount(chargeResult.getActivityCutResult().getActivityCutAmount());
Optional<CouponPayResult> tempPayResult;
//活动券减免金额
amountDetailBo.setCouponCutAmount((tempPayResult = chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.ACTIVITY_COUPON.getCode())).isPresent() ? tempPayResult.get().getCouponAmount() : 0.00);
//运费券减免金额
amountDetailBo.setShippingCouponCutAmount((tempPayResult = chargeResult.getCouponPayResultList().getCouponPayResultByCouponType(CouponTypeEnum.SHIPPING_COUPON.getCode())).isPresent() ? tempPayResult.get().getCouponAmount() : 0.00);
return amountDetailBo;
}
protected int buildDeliveryWay() {
return OrderConstant.DELIVERY_WAY_SF;
}
... ...
... ... @@ -271,6 +271,8 @@ public class CouponServiceImpl implements ICouponService {
// 获取未使用未过期的优惠券
List<UserCoupon> list = userCouponMapper.selectUsableCouponByUid(uid, DateUtil.getCurrentTimeSecond());
logger.debug("[{}] unused coupons:{}", uid, list);
if (CollectionUtils.isEmpty(list)){
return UserCouponsListBo.builder().build();
}
... ...