Authored by chenchao

use optimize coupon

... ... @@ -338,7 +338,8 @@ public class ChargeService {
List<String> couponCodes = chargeParam.getCouponCodes();
switch (chargeParam.getChargeStage()) {
case PAYMENT: {
case PAYMENT:
case COMPUTE:{
if (CollectionUtils.isEmpty(couponCodes)) {
//场景:砍价活动不需要推荐
return;
... ... @@ -352,7 +353,6 @@ public class ChargeService {
case SELECT_COUPON:
calculateSelectCoupons(chargeContext);
break;
case COMPUTE:
case SUBMIT: {
if (CollectionUtils.isEmpty(couponCodes)) {
return;
... ...
... ... @@ -112,7 +112,7 @@ public class ShoppingController {
ShoppingRequest req = ShoppingRequest.builder().uid(uid)
.skup(skup)
.couponCodes(activityTypeEnum.isCouponFlag() ? CouponCodeUtils.asList(couponCode) : null)
.couponCodes(activityTypeEnum.isCouponFlag() ? CouponCodeUtils.asListDefaultUseAutoRecommended(couponCode) : null)
.addressId(addressId)
.userActivityId(userActivityId).activityType(activityTypeEnum)
.appVersion(appVersion)
... ...
... ... @@ -170,7 +170,7 @@ public class ShoppingServiceImpl implements IShoppingService {
response.setDamagesDesc(shoppingSupport.getDamagesDesc(compensate, skupType));
//推荐券(可用券个数)
response.setRecommendedCouponInfo(shoppingSupport.getRecommendedCouponInfo(chargeResult));
response.setRecommendedCouponInfo(couponSupport.getRecommendedCouponInfo(chargeResult));
//活动信息
response.setActivityInfo(shoppingSupport.getActivityInfo(chargeResult));
... ... @@ -397,7 +397,6 @@ public class ShoppingServiceImpl implements IShoppingService {
response.setCouponInfo(couponSupport.getCouponInfo(chargeResult));
response.setPromotionFormulaList(shoppingSupport.getPromotionFormula(chargeResult));
response.setAmount(MathUtils.formatStr(chargeResult.getFinalAmount()));
return response;
}
... ...
... ... @@ -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();
}
}
}
... ...
... ... @@ -236,39 +236,7 @@ public class ShoppingSupport {
return ActivityInfo.builder().userActivityId(activityCutResult.getUserActivityId()).activityType(activityCutResult.getActivityType()).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();
}
}
public DepositResp getDepositResp(SkupType skupType){
DepositResp depositResp = null;
... ...
... ... @@ -19,6 +19,14 @@ public class CouponCodeUtils {
return Lists.newArrayList(couponCode.split(CouponConstants.COUPON_CODE_SPLIT_TOKEN));
}
public static List<String> asListDefaultUseAutoRecommended(String couponCode) {
if (StringUtils.isEmpty(couponCode)) {
return CouponConstants.AUTO_RECOMMENDED_COUPON_CODES;
}
return Lists.newArrayList(couponCode.split(CouponConstants.COUPON_CODE_SPLIT_TOKEN));
}
public static String asString(List<String> list) {
return StringUtils.join(list, CouponConstants.COUPON_CODE_SPLIT_TOKEN);
}
... ...