Authored by tanling

优惠券|促销 增加渠道

... ... @@ -29,4 +29,6 @@ public class Activity {
private Integer updateTime;
private String businessClient;
}
... ...
... ... @@ -43,6 +43,16 @@ public class Coupon {
private String skupAllowType;
private String businessClient;
public String getBusinessClient() {
return businessClient;
}
public void setBusinessClient(String businessClient) {
this.businessClient = businessClient;
}
public String getSkupAllowType() {
return skupAllowType;
}
... ...
... ... @@ -14,10 +14,11 @@
<result column="status" property="status" jdbcType="INTEGER"/>
<result column="create_time" property="createTime" jdbcType="INTEGER"/>
<result column="update_time" property="updateTime" jdbcType="INTEGER"/>
<result column="business_client" property="businessClient" jdbcType="VARCHAR"/>
</resultMap>
<select id="selectRunningActivity" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status
select id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status,business_client
from promotion_activity
where status = 1
and #{currentTime, jdbcType=INTEGER} between start_time and end_time
... ...
... ... @@ -22,11 +22,12 @@
<result column="remark" jdbcType="VARCHAR" property="remark" />
<result column="skup_forbid_type" jdbcType="VARCHAR" property="skupForbidType" />
<result column="skup_allow_type" jdbcType="VARCHAR" property="skupAllowType" />
<result column="business_client" jdbcType="VARCHAR" property="businessClient" />
</resultMap>
<sql id="Base_Column_List">
id, coupon_token, coupon_name, coupon_amount, coupon_type, coupon_num, use_num, send_num,
use_limit_type, use_limit_value, product_limit_type, product_limit_value, start_time,
end_time, status, create_time, pid, remark,skup_forbid_type,skup_allow_type
end_time, status, create_time, pid, remark,skup_forbid_type,skup_allow_type,business_client
</sql>
<select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
select
... ...
... ... @@ -115,6 +115,7 @@ public class ChargeContextFactory {
.promotionSelected(promotionSelected)
.activityCouponsSelected(activityCouponsSelected)
.recommendedPromotion(recommendedPromotion)
.businessClient(request.getBusinessClient())
.build();
ChargeGoods chargeGoods = ChargeGoods.builder()
.goodsPrice(skupInfo.getGoodsPrice())
... ...
... ... @@ -5,6 +5,7 @@ import com.yoho.error.ServiceError;
import com.yoho.error.exception.ServiceException;
import com.yohobuy.ufo.model.promotion.UserCouponsBo;
import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
import com.yohoufo.common.utils.StringUtil;
import com.yohoufo.order.charge.ChargeContext;
import com.yohoufo.order.charge.CouponRuleMatcher;
import com.yohoufo.order.charge.model.ChargeParam;
... ... @@ -12,10 +13,12 @@ import com.yohoufo.order.charge.model.CouponMatchResult;
import com.yohoufo.order.service.proxy.CouponProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
... ... @@ -104,6 +107,13 @@ public class CouponService {
toMatchUserCouponBos = toMatchUserCouponBos.stream().filter(userCouponsBo -> userCouponsBo.getCouponType() != CouponTypeEnum.SHIPPING_COUPON.getCode()).collect(Collectors.toList());
}
// 渠道匹配
toMatchUserCouponBos = toMatchUserCouponBos.stream()
.filter(userCouponsBo -> StringUtils.isBlank(userCouponsBo.getBusinessClient())
|| (StringUtils.isBlank(chargeContext.getChargeParam().getBusinessClient()) &&
Arrays.asList(userCouponsBo.getBusinessClient().split(",")).contains(chargeContext.getChargeParam().getBusinessClient())))
.collect(Collectors.toList());
//规则匹配
List<CouponMatchResult> matchResults = couponRuleMatcher.match(toMatchUserCouponBos, chargeContext);
... ...
... ... @@ -64,4 +64,9 @@ public class ChargeParam {
private AmountCutPolicy shipFeeCutPolicy;
/**
* business_client: 'h5/xianyu',
*/
private String businessClient;
}
... ...
... ... @@ -18,6 +18,7 @@ import com.yohoufo.order.service.proxy.PromotionProxyService;
import com.yohoufo.order.utils.LoggerUtils;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.MapUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.commons.lang3.tuple.Pair;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -98,7 +99,7 @@ public class PromotionService {
uid, skup, salePrice, promotionId);
//fetch promotions
Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap
= buildPromotion2CalculatorMap(uid, skup);
= buildPromotion2CalculatorMap(uid, skup, context.getChargeParam().getBusinessClient());
if (MapUtils.isEmpty(promotion2CalculatorMap)){
logger.warn("caculatePromotions.calculateByPromotionId promotion2CalculatorMap empty, uid {} skup {} salePrice {} ",
... ... @@ -191,7 +192,7 @@ public class PromotionService {
//fetch promotions
Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap
= buildPromotion2CalculatorMap(uid, skup);
= buildPromotion2CalculatorMap(uid, skup, context.getChargeParam().getBusinessClient());
if (MapUtils.isEmpty(promotion2CalculatorMap)){
logger.warn("caculatePromotions.findAllMatched promotion2CalculatorList empty, uid {} skup {} salePrice {} ",
... ... @@ -251,13 +252,14 @@ public class PromotionService {
ChargeGoods chargeGoods = context.getChargeGoods();
int skup = chargeGoods.getSkup();
BigDecimal salePrice = chargeGoods.getGoodsPrice();
String businessClient = context.getChargeParam().getBusinessClient();
logger.info("caculatePromotions.recommendedPromotion uid {} skup {} salePrice {}", uid, skup, salePrice);
logger.info("caculatePromotions.recommendedPromotion uid {} skup {} salePrice {}, businessClient {}", uid, skup, salePrice, businessClient);
ChargeResult chargeResult = context.getChargeResult();
//fetch promotions
Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap
= buildPromotion2CalculatorMap(uid, skup);
= buildPromotion2CalculatorMap(uid, skup, context.getChargeParam().getBusinessClient());
if (MapUtils.isEmpty(promotion2CalculatorMap)){
logger.warn("caculatePromotions.recommendedPromotion promotion2CalculatorList empty, uid {} skup {} salePrice {} ",
... ... @@ -465,7 +467,8 @@ public class PromotionService {
}
private Map<Integer, Pair<PromotionActivityRspBo,PromotionCalculator>> buildPromotion2CalculatorMap(int uid,
int skup){
int skup,
String businessClient){
List<PromotionActivityRspBo> promotionBoList = promotionProxyService.findUseablePromotions(uid, skup);
if (CollectionUtils.isEmpty(promotionBoList)){
... ... @@ -473,6 +476,14 @@ public class PromotionService {
uid, skup, promotionBoList);
return null;
}
// 渠道过滤
promotionBoList = promotionBoList.stream().filter(
promotion ->
StringUtils.isBlank(promotion.getBusinessClient())
|| (StringUtils.isNotBlank(businessClient) && Arrays.asList(promotion.getBusinessClient().split(",")).contains(businessClient))).collect(Collectors.toList());
Predicate<PromotionActivityRspBo> predicate = resp->Objects.nonNull(resp.getPromotionTypeEnum());
Function<PromotionActivityRspBo,Pair<PromotionActivityRspBo,PromotionCalculator>> ppFunction =
(resp)-> Pair.of(resp, promotionCalculatorProvider.findByPromotionType(resp.getPromotionTypeEnum()));
... ...
... ... @@ -41,7 +41,8 @@ public class ShoppingController {
@RequestParam(name="depositRequirement", required = false, defaultValue = OrderConstant.N_STR)String depositRequirement,
//接口版本,控制不同的动作
@RequestParam(name = "api_version", required = false, defaultValue = "0") int apiVersion,
@RequestParam(value = "app_version", required = false)String appVersion){
@RequestParam(value = "app_version", required = false)String appVersion,
@RequestParam(value = "business_client", required = false) String businessClient){
//活动类型
ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(activityType);
... ... @@ -54,6 +55,7 @@ public class ShoppingController {
.apiVersion(apiVersion)
.appVersion(appVersion)
.addressId(addressId)
.businessClient(businessClient)
.build();
logger.info("in ufo.order.payment, req {}", req);
PaymentResponse paymentResponse = buyerOrderService.payment(req);
... ... @@ -72,7 +74,8 @@ public class ShoppingController {
@RequestParam(name = "skup") int skup,
@RequestParam(name = "addressId", required = false) String addressId,
@RequestParam(name = "coupon_code",required = false) String couponCode,
@RequestParam(name="depositRequirement", required = false, defaultValue = OrderConstant.N_STR)String depositRequirement) {
@RequestParam(name="depositRequirement", required = false, defaultValue = OrderConstant.N_STR)String depositRequirement,
@RequestParam(value = "business_client", required = false) String businessClient) {
//活动类型
ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(0);
... ... @@ -82,6 +85,7 @@ public class ShoppingController {
.userActivityId(0).activityType(activityTypeEnum)
.depositRequirement(depositRequirement)
.addressId(addressId)
.businessClient(businessClient)
.build();
logger.info("in ufo.order.selectCoupon, req {}", req);
ShoppingCouponListResp resp = buyerOrderService.selectCoupon(req);
... ... @@ -104,7 +108,8 @@ public class ShoppingController {
@RequestParam(name="promotionId", required = false)Integer promotionId,
//接口版本,控制不同的动作
@RequestParam(name = "api_version", required = false, defaultValue = "0") int apiVersion,
@RequestParam(value = "app_version", required = false)String appVersion) {
@RequestParam(value = "app_version", required = false)String appVersion,
@RequestParam(value = "business_client", required = false) String businessClient) {
//活动类型
ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(activityType);
... ... @@ -118,6 +123,7 @@ public class ShoppingController {
.depositRequirement(depositRequirement)
.apiVersion(apiVersion)
.promotionId(promotionId)
.businessClient(businessClient)
.build();
logger.info("in ufo.order.compute, req {}", req);
ComputeResponse resp = buyerOrderService.compute(req);
... ... @@ -176,7 +182,8 @@ public class ShoppingController {
public ApiResponse autoRecommendedCoupon(@RequestParam(name = "uid") int uid,
@RequestParam(name = "skup") int skup,
@RequestParam(name = "addressId") String addressId,
@RequestParam(name="depositRequirement", defaultValue = OrderConstant.N_STR)String depositRequirement) {
@RequestParam(name="depositRequirement", defaultValue = OrderConstant.N_STR)String depositRequirement,
@RequestParam(value = "business_client", required = false) String businessClient) {
//活动类型
ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.COMMON;
ShoppingRequest req = ShoppingRequest.builder()
... ...
... ... @@ -69,6 +69,8 @@ public class CouponConvert {
couponBo.setProductIdExclude(productIds);
}
couponBo.setBusinessClient(coupon.getBusinessClient());
return couponBo;
}
... ...
... ... @@ -99,6 +99,7 @@ public class ActivityServiceImpl implements IActivityService {
rspBo.setEndTime(activity.getEndTime());
rspBo.setPromotionType(activity.getPromotionType());
rspBo.setLabel(activity.getLabel());
rspBo.setBusinessClient(activity.getBusinessClient());
List<Integer> productLimitTypeList = new ArrayList<>();
for(String productLimitType : activity.getProductLimitType().split(",")){
productLimitTypeList.add(Integer.valueOf(productLimitType));
... ...