...
|
...
|
@@ -7,8 +7,10 @@ import com.yohoufo.common.utils.DateUtil; |
|
|
import com.yohoufo.order.charge.model.ChargeResult;
|
|
|
import com.yohoufo.order.charge.model.CouponMatchResult;
|
|
|
import com.yohoufo.order.charge.model.CouponPayResult;
|
|
|
import com.yohoufo.order.charge.model.CouponPayResultList;
|
|
|
import com.yohoufo.order.constants.CouponConstants;
|
|
|
import com.yohoufo.order.model.response.CouponInfo;
|
|
|
import com.yohoufo.order.model.response.RecommendedCouponInfo;
|
|
|
import com.yohoufo.order.model.response.ShoppingCoupon;
|
|
|
import com.yohoufo.order.utils.CouponCodeUtils;
|
|
|
import com.yohoufo.order.utils.MathUtils;
|
...
|
...
|
@@ -85,4 +87,38 @@ public class CouponSupport { |
|
|
.build();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 券自动推荐结果
|
|
|
* @param chargeResult
|
|
|
* @return
|
|
|
*/
|
|
|
public RecommendedCouponInfo getRecommendedCouponInfo(ChargeResult chargeResult) {
|
|
|
CouponPayResultList couponPayResultList = chargeResult.getCouponPayResultList();
|
|
|
|
|
|
/**
|
|
|
* usableCouponCount 有可用张数,couponPayResults 实际使用的券
|
|
|
* 特殊场景
|
|
|
* usableCouponCount > 0 ,但couponPayResults为空
|
|
|
*/
|
|
|
int usableCouponCount = couponPayResultList.getUsableCouponCount();
|
|
|
List<CouponPayResult> couponPayResults = couponPayResultList.getCouponPayResults();
|
|
|
if (CollectionUtils.isNotEmpty(couponPayResults)) {
|
|
|
int usedCouponCount = couponPayResults.size();
|
|
|
String couponPayAmountStr = MathUtils.formatCurrencyStr(couponPayResults.stream().mapToDouble(coupon -> coupon.getCouponAmount()).sum());
|
|
|
String couponCodes = CouponCodeUtils.asString(couponPayResults.stream().map(coupon -> coupon.getCouponCode()).collect(Collectors.toList()));
|
|
|
return RecommendedCouponInfo.builder()
|
|
|
.usableCouponCount(usableCouponCount)
|
|
|
.usedCouponCount(usedCouponCount)
|
|
|
.couponAmountStr(couponPayAmountStr)
|
|
|
.couponCode(couponCodes)
|
|
|
.desc(MessageFormat.format(CouponConstants.COUPON_AUTO_RECOMMENDED_DESC_FORMAT, usableCouponCount, usedCouponCount)).build();
|
|
|
} else {
|
|
|
return RecommendedCouponInfo.builder()
|
|
|
.usableCouponCount(usableCouponCount)
|
|
|
.usedCouponCount(0)
|
|
|
.desc(MessageFormat.format(CouponConstants.USABLE_COUPON_DESC_FORMAT, usableCouponCount))
|
|
|
.build();
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|