Authored by tanling

优惠券|促销 增加渠道

@@ -29,4 +29,6 @@ public class Activity { @@ -29,4 +29,6 @@ public class Activity {
29 29
30 private Integer updateTime; 30 private Integer updateTime;
31 31
  32 + private String businessClient;
  33 +
32 } 34 }
@@ -43,6 +43,16 @@ public class Coupon { @@ -43,6 +43,16 @@ public class Coupon {
43 43
44 private String skupAllowType; 44 private String skupAllowType;
45 45
  46 + private String businessClient;
  47 +
  48 + public String getBusinessClient() {
  49 + return businessClient;
  50 + }
  51 +
  52 + public void setBusinessClient(String businessClient) {
  53 + this.businessClient = businessClient;
  54 + }
  55 +
46 public String getSkupAllowType() { 56 public String getSkupAllowType() {
47 return skupAllowType; 57 return skupAllowType;
48 } 58 }
@@ -14,10 +14,11 @@ @@ -14,10 +14,11 @@
14 <result column="status" property="status" jdbcType="INTEGER"/> 14 <result column="status" property="status" jdbcType="INTEGER"/>
15 <result column="create_time" property="createTime" jdbcType="INTEGER"/> 15 <result column="create_time" property="createTime" jdbcType="INTEGER"/>
16 <result column="update_time" property="updateTime" jdbcType="INTEGER"/> 16 <result column="update_time" property="updateTime" jdbcType="INTEGER"/>
  17 + <result column="business_client" property="businessClient" jdbcType="VARCHAR"/>
17 </resultMap> 18 </resultMap>
18 19
19 <select id="selectRunningActivity" parameterType="java.lang.Integer" resultMap="BaseResultMap"> 20 <select id="selectRunningActivity" parameterType="java.lang.Integer" resultMap="BaseResultMap">
20 - select id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status 21 + select id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status,business_client
21 from promotion_activity 22 from promotion_activity
22 where status = 1 23 where status = 1
23 and #{currentTime, jdbcType=INTEGER} between start_time and end_time 24 and #{currentTime, jdbcType=INTEGER} between start_time and end_time
@@ -22,11 +22,12 @@ @@ -22,11 +22,12 @@
22 <result column="remark" jdbcType="VARCHAR" property="remark" /> 22 <result column="remark" jdbcType="VARCHAR" property="remark" />
23 <result column="skup_forbid_type" jdbcType="VARCHAR" property="skupForbidType" /> 23 <result column="skup_forbid_type" jdbcType="VARCHAR" property="skupForbidType" />
24 <result column="skup_allow_type" jdbcType="VARCHAR" property="skupAllowType" /> 24 <result column="skup_allow_type" jdbcType="VARCHAR" property="skupAllowType" />
  25 + <result column="business_client" jdbcType="VARCHAR" property="businessClient" />
25 </resultMap> 26 </resultMap>
26 <sql id="Base_Column_List"> 27 <sql id="Base_Column_List">
27 id, coupon_token, coupon_name, coupon_amount, coupon_type, coupon_num, use_num, send_num, 28 id, coupon_token, coupon_name, coupon_amount, coupon_type, coupon_num, use_num, send_num,
28 use_limit_type, use_limit_value, product_limit_type, product_limit_value, start_time, 29 use_limit_type, use_limit_value, product_limit_type, product_limit_value, start_time,
29 - end_time, status, create_time, pid, remark,skup_forbid_type,skup_allow_type 30 + end_time, status, create_time, pid, remark,skup_forbid_type,skup_allow_type,business_client
30 </sql> 31 </sql>
31 <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap"> 32 <select id="selectByPrimaryKey" parameterType="java.lang.Integer" resultMap="BaseResultMap">
32 select 33 select
@@ -115,6 +115,7 @@ public class ChargeContextFactory { @@ -115,6 +115,7 @@ public class ChargeContextFactory {
115 .promotionSelected(promotionSelected) 115 .promotionSelected(promotionSelected)
116 .activityCouponsSelected(activityCouponsSelected) 116 .activityCouponsSelected(activityCouponsSelected)
117 .recommendedPromotion(recommendedPromotion) 117 .recommendedPromotion(recommendedPromotion)
  118 + .businessClient(request.getBusinessClient())
118 .build(); 119 .build();
119 ChargeGoods chargeGoods = ChargeGoods.builder() 120 ChargeGoods chargeGoods = ChargeGoods.builder()
120 .goodsPrice(skupInfo.getGoodsPrice()) 121 .goodsPrice(skupInfo.getGoodsPrice())
@@ -5,6 +5,7 @@ import com.yoho.error.ServiceError; @@ -5,6 +5,7 @@ import com.yoho.error.ServiceError;
5 import com.yoho.error.exception.ServiceException; 5 import com.yoho.error.exception.ServiceException;
6 import com.yohobuy.ufo.model.promotion.UserCouponsBo; 6 import com.yohobuy.ufo.model.promotion.UserCouponsBo;
7 import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum; 7 import com.yohobuy.ufo.model.promotion.constant.CouponTypeEnum;
  8 +import com.yohoufo.common.utils.StringUtil;
8 import com.yohoufo.order.charge.ChargeContext; 9 import com.yohoufo.order.charge.ChargeContext;
9 import com.yohoufo.order.charge.CouponRuleMatcher; 10 import com.yohoufo.order.charge.CouponRuleMatcher;
10 import com.yohoufo.order.charge.model.ChargeParam; 11 import com.yohoufo.order.charge.model.ChargeParam;
@@ -12,10 +13,12 @@ import com.yohoufo.order.charge.model.CouponMatchResult; @@ -12,10 +13,12 @@ import com.yohoufo.order.charge.model.CouponMatchResult;
12 import com.yohoufo.order.service.proxy.CouponProxyService; 13 import com.yohoufo.order.service.proxy.CouponProxyService;
13 import com.yohoufo.order.utils.LoggerUtils; 14 import com.yohoufo.order.utils.LoggerUtils;
14 import org.apache.commons.collections.CollectionUtils; 15 import org.apache.commons.collections.CollectionUtils;
  16 +import org.apache.commons.lang3.StringUtils;
15 import org.slf4j.Logger; 17 import org.slf4j.Logger;
16 import org.springframework.beans.factory.annotation.Autowired; 18 import org.springframework.beans.factory.annotation.Autowired;
17 import org.springframework.stereotype.Component; 19 import org.springframework.stereotype.Component;
18 20
  21 +import java.util.Arrays;
19 import java.util.Comparator; 22 import java.util.Comparator;
20 import java.util.List; 23 import java.util.List;
21 import java.util.Optional; 24 import java.util.Optional;
@@ -104,6 +107,13 @@ public class CouponService { @@ -104,6 +107,13 @@ public class CouponService {
104 toMatchUserCouponBos = toMatchUserCouponBos.stream().filter(userCouponsBo -> userCouponsBo.getCouponType() != CouponTypeEnum.SHIPPING_COUPON.getCode()).collect(Collectors.toList()); 107 toMatchUserCouponBos = toMatchUserCouponBos.stream().filter(userCouponsBo -> userCouponsBo.getCouponType() != CouponTypeEnum.SHIPPING_COUPON.getCode()).collect(Collectors.toList());
105 } 108 }
106 109
  110 + // 渠道匹配
  111 + toMatchUserCouponBos = toMatchUserCouponBos.stream()
  112 + .filter(userCouponsBo -> StringUtils.isBlank(userCouponsBo.getBusinessClient())
  113 + || (StringUtils.isBlank(chargeContext.getChargeParam().getBusinessClient()) &&
  114 + Arrays.asList(userCouponsBo.getBusinessClient().split(",")).contains(chargeContext.getChargeParam().getBusinessClient())))
  115 + .collect(Collectors.toList());
  116 +
107 //规则匹配 117 //规则匹配
108 List<CouponMatchResult> matchResults = couponRuleMatcher.match(toMatchUserCouponBos, chargeContext); 118 List<CouponMatchResult> matchResults = couponRuleMatcher.match(toMatchUserCouponBos, chargeContext);
109 119
@@ -64,4 +64,9 @@ public class ChargeParam { @@ -64,4 +64,9 @@ public class ChargeParam {
64 64
65 private AmountCutPolicy shipFeeCutPolicy; 65 private AmountCutPolicy shipFeeCutPolicy;
66 66
  67 + /**
  68 + * business_client: 'h5/xianyu',
  69 + */
  70 + private String businessClient;
  71 +
67 } 72 }
@@ -18,6 +18,7 @@ import com.yohoufo.order.service.proxy.PromotionProxyService; @@ -18,6 +18,7 @@ import com.yohoufo.order.service.proxy.PromotionProxyService;
18 import com.yohoufo.order.utils.LoggerUtils; 18 import com.yohoufo.order.utils.LoggerUtils;
19 import org.apache.commons.collections.CollectionUtils; 19 import org.apache.commons.collections.CollectionUtils;
20 import org.apache.commons.collections.MapUtils; 20 import org.apache.commons.collections.MapUtils;
  21 +import org.apache.commons.lang3.StringUtils;
21 import org.apache.commons.lang3.tuple.Pair; 22 import org.apache.commons.lang3.tuple.Pair;
22 import org.slf4j.Logger; 23 import org.slf4j.Logger;
23 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
@@ -98,7 +99,7 @@ public class PromotionService { @@ -98,7 +99,7 @@ public class PromotionService {
98 uid, skup, salePrice, promotionId); 99 uid, skup, salePrice, promotionId);
99 //fetch promotions 100 //fetch promotions
100 Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap 101 Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap
101 - = buildPromotion2CalculatorMap(uid, skup); 102 + = buildPromotion2CalculatorMap(uid, skup, context.getChargeParam().getBusinessClient());
102 103
103 if (MapUtils.isEmpty(promotion2CalculatorMap)){ 104 if (MapUtils.isEmpty(promotion2CalculatorMap)){
104 logger.warn("caculatePromotions.calculateByPromotionId promotion2CalculatorMap empty, uid {} skup {} salePrice {} ", 105 logger.warn("caculatePromotions.calculateByPromotionId promotion2CalculatorMap empty, uid {} skup {} salePrice {} ",
@@ -191,7 +192,7 @@ public class PromotionService { @@ -191,7 +192,7 @@ public class PromotionService {
191 192
192 //fetch promotions 193 //fetch promotions
193 Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap 194 Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap
194 - = buildPromotion2CalculatorMap(uid, skup); 195 + = buildPromotion2CalculatorMap(uid, skup, context.getChargeParam().getBusinessClient());
195 196
196 if (MapUtils.isEmpty(promotion2CalculatorMap)){ 197 if (MapUtils.isEmpty(promotion2CalculatorMap)){
197 logger.warn("caculatePromotions.findAllMatched promotion2CalculatorList empty, uid {} skup {} salePrice {} ", 198 logger.warn("caculatePromotions.findAllMatched promotion2CalculatorList empty, uid {} skup {} salePrice {} ",
@@ -251,13 +252,14 @@ public class PromotionService { @@ -251,13 +252,14 @@ public class PromotionService {
251 ChargeGoods chargeGoods = context.getChargeGoods(); 252 ChargeGoods chargeGoods = context.getChargeGoods();
252 int skup = chargeGoods.getSkup(); 253 int skup = chargeGoods.getSkup();
253 BigDecimal salePrice = chargeGoods.getGoodsPrice(); 254 BigDecimal salePrice = chargeGoods.getGoodsPrice();
  255 + String businessClient = context.getChargeParam().getBusinessClient();
254 256
255 - logger.info("caculatePromotions.recommendedPromotion uid {} skup {} salePrice {}", uid, skup, salePrice); 257 + logger.info("caculatePromotions.recommendedPromotion uid {} skup {} salePrice {}, businessClient {}", uid, skup, salePrice, businessClient);
256 ChargeResult chargeResult = context.getChargeResult(); 258 ChargeResult chargeResult = context.getChargeResult();
257 259
258 //fetch promotions 260 //fetch promotions
259 Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap 261 Map<Integer,Pair<PromotionActivityRspBo,PromotionCalculator>> promotion2CalculatorMap
260 - = buildPromotion2CalculatorMap(uid, skup); 262 + = buildPromotion2CalculatorMap(uid, skup, context.getChargeParam().getBusinessClient());
261 263
262 if (MapUtils.isEmpty(promotion2CalculatorMap)){ 264 if (MapUtils.isEmpty(promotion2CalculatorMap)){
263 logger.warn("caculatePromotions.recommendedPromotion promotion2CalculatorList empty, uid {} skup {} salePrice {} ", 265 logger.warn("caculatePromotions.recommendedPromotion promotion2CalculatorList empty, uid {} skup {} salePrice {} ",
@@ -465,7 +467,8 @@ public class PromotionService { @@ -465,7 +467,8 @@ public class PromotionService {
465 } 467 }
466 468
467 private Map<Integer, Pair<PromotionActivityRspBo,PromotionCalculator>> buildPromotion2CalculatorMap(int uid, 469 private Map<Integer, Pair<PromotionActivityRspBo,PromotionCalculator>> buildPromotion2CalculatorMap(int uid,
468 - int skup){ 470 + int skup,
  471 + String businessClient){
469 472
470 List<PromotionActivityRspBo> promotionBoList = promotionProxyService.findUseablePromotions(uid, skup); 473 List<PromotionActivityRspBo> promotionBoList = promotionProxyService.findUseablePromotions(uid, skup);
471 if (CollectionUtils.isEmpty(promotionBoList)){ 474 if (CollectionUtils.isEmpty(promotionBoList)){
@@ -473,6 +476,14 @@ public class PromotionService { @@ -473,6 +476,14 @@ public class PromotionService {
473 uid, skup, promotionBoList); 476 uid, skup, promotionBoList);
474 return null; 477 return null;
475 } 478 }
  479 +
  480 + // 渠道过滤
  481 + promotionBoList = promotionBoList.stream().filter(
  482 + promotion ->
  483 + StringUtils.isBlank(promotion.getBusinessClient())
  484 + || (StringUtils.isNotBlank(businessClient) && Arrays.asList(promotion.getBusinessClient().split(",")).contains(businessClient))).collect(Collectors.toList());
  485 +
  486 +
476 Predicate<PromotionActivityRspBo> predicate = resp->Objects.nonNull(resp.getPromotionTypeEnum()); 487 Predicate<PromotionActivityRspBo> predicate = resp->Objects.nonNull(resp.getPromotionTypeEnum());
477 Function<PromotionActivityRspBo,Pair<PromotionActivityRspBo,PromotionCalculator>> ppFunction = 488 Function<PromotionActivityRspBo,Pair<PromotionActivityRspBo,PromotionCalculator>> ppFunction =
478 (resp)-> Pair.of(resp, promotionCalculatorProvider.findByPromotionType(resp.getPromotionTypeEnum())); 489 (resp)-> Pair.of(resp, promotionCalculatorProvider.findByPromotionType(resp.getPromotionTypeEnum()));
@@ -41,7 +41,8 @@ public class ShoppingController { @@ -41,7 +41,8 @@ public class ShoppingController {
41 @RequestParam(name="depositRequirement", required = false, defaultValue = OrderConstant.N_STR)String depositRequirement, 41 @RequestParam(name="depositRequirement", required = false, defaultValue = OrderConstant.N_STR)String depositRequirement,
42 //接口版本,控制不同的动作 42 //接口版本,控制不同的动作
43 @RequestParam(name = "api_version", required = false, defaultValue = "0") int apiVersion, 43 @RequestParam(name = "api_version", required = false, defaultValue = "0") int apiVersion,
44 - @RequestParam(value = "app_version", required = false)String appVersion){ 44 + @RequestParam(value = "app_version", required = false)String appVersion,
  45 + @RequestParam(value = "business_client", required = false) String businessClient){
45 46
46 //活动类型 47 //活动类型
47 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(activityType); 48 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(activityType);
@@ -54,6 +55,7 @@ public class ShoppingController { @@ -54,6 +55,7 @@ public class ShoppingController {
54 .apiVersion(apiVersion) 55 .apiVersion(apiVersion)
55 .appVersion(appVersion) 56 .appVersion(appVersion)
56 .addressId(addressId) 57 .addressId(addressId)
  58 + .businessClient(businessClient)
57 .build(); 59 .build();
58 logger.info("in ufo.order.payment, req {}", req); 60 logger.info("in ufo.order.payment, req {}", req);
59 PaymentResponse paymentResponse = buyerOrderService.payment(req); 61 PaymentResponse paymentResponse = buyerOrderService.payment(req);
@@ -72,7 +74,8 @@ public class ShoppingController { @@ -72,7 +74,8 @@ public class ShoppingController {
72 @RequestParam(name = "skup") int skup, 74 @RequestParam(name = "skup") int skup,
73 @RequestParam(name = "addressId", required = false) String addressId, 75 @RequestParam(name = "addressId", required = false) String addressId,
74 @RequestParam(name = "coupon_code",required = false) String couponCode, 76 @RequestParam(name = "coupon_code",required = false) String couponCode,
75 - @RequestParam(name="depositRequirement", required = false, defaultValue = OrderConstant.N_STR)String depositRequirement) { 77 + @RequestParam(name="depositRequirement", required = false, defaultValue = OrderConstant.N_STR)String depositRequirement,
  78 + @RequestParam(value = "business_client", required = false) String businessClient) {
76 //活动类型 79 //活动类型
77 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(0); 80 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(0);
78 81
@@ -82,6 +85,7 @@ public class ShoppingController { @@ -82,6 +85,7 @@ public class ShoppingController {
82 .userActivityId(0).activityType(activityTypeEnum) 85 .userActivityId(0).activityType(activityTypeEnum)
83 .depositRequirement(depositRequirement) 86 .depositRequirement(depositRequirement)
84 .addressId(addressId) 87 .addressId(addressId)
  88 + .businessClient(businessClient)
85 .build(); 89 .build();
86 logger.info("in ufo.order.selectCoupon, req {}", req); 90 logger.info("in ufo.order.selectCoupon, req {}", req);
87 ShoppingCouponListResp resp = buyerOrderService.selectCoupon(req); 91 ShoppingCouponListResp resp = buyerOrderService.selectCoupon(req);
@@ -104,7 +108,8 @@ public class ShoppingController { @@ -104,7 +108,8 @@ public class ShoppingController {
104 @RequestParam(name="promotionId", required = false)Integer promotionId, 108 @RequestParam(name="promotionId", required = false)Integer promotionId,
105 //接口版本,控制不同的动作 109 //接口版本,控制不同的动作
106 @RequestParam(name = "api_version", required = false, defaultValue = "0") int apiVersion, 110 @RequestParam(name = "api_version", required = false, defaultValue = "0") int apiVersion,
107 - @RequestParam(value = "app_version", required = false)String appVersion) { 111 + @RequestParam(value = "app_version", required = false)String appVersion,
  112 + @RequestParam(value = "business_client", required = false) String businessClient) {
108 113
109 //活动类型 114 //活动类型
110 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(activityType); 115 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.find(activityType);
@@ -118,6 +123,7 @@ public class ShoppingController { @@ -118,6 +123,7 @@ public class ShoppingController {
118 .depositRequirement(depositRequirement) 123 .depositRequirement(depositRequirement)
119 .apiVersion(apiVersion) 124 .apiVersion(apiVersion)
120 .promotionId(promotionId) 125 .promotionId(promotionId)
  126 + .businessClient(businessClient)
121 .build(); 127 .build();
122 logger.info("in ufo.order.compute, req {}", req); 128 logger.info("in ufo.order.compute, req {}", req);
123 ComputeResponse resp = buyerOrderService.compute(req); 129 ComputeResponse resp = buyerOrderService.compute(req);
@@ -176,7 +182,8 @@ public class ShoppingController { @@ -176,7 +182,8 @@ public class ShoppingController {
176 public ApiResponse autoRecommendedCoupon(@RequestParam(name = "uid") int uid, 182 public ApiResponse autoRecommendedCoupon(@RequestParam(name = "uid") int uid,
177 @RequestParam(name = "skup") int skup, 183 @RequestParam(name = "skup") int skup,
178 @RequestParam(name = "addressId") String addressId, 184 @RequestParam(name = "addressId") String addressId,
179 - @RequestParam(name="depositRequirement", defaultValue = OrderConstant.N_STR)String depositRequirement) { 185 + @RequestParam(name="depositRequirement", defaultValue = OrderConstant.N_STR)String depositRequirement,
  186 + @RequestParam(value = "business_client", required = false) String businessClient) {
180 //活动类型 187 //活动类型
181 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.COMMON; 188 ActivityTypeEnum activityTypeEnum = ActivityTypeEnum.COMMON;
182 ShoppingRequest req = ShoppingRequest.builder() 189 ShoppingRequest req = ShoppingRequest.builder()
@@ -69,6 +69,8 @@ public class CouponConvert { @@ -69,6 +69,8 @@ public class CouponConvert {
69 couponBo.setProductIdExclude(productIds); 69 couponBo.setProductIdExclude(productIds);
70 } 70 }
71 71
  72 + couponBo.setBusinessClient(coupon.getBusinessClient());
  73 +
72 return couponBo; 74 return couponBo;
73 } 75 }
74 76
@@ -99,6 +99,7 @@ public class ActivityServiceImpl implements IActivityService { @@ -99,6 +99,7 @@ public class ActivityServiceImpl implements IActivityService {
99 rspBo.setEndTime(activity.getEndTime()); 99 rspBo.setEndTime(activity.getEndTime());
100 rspBo.setPromotionType(activity.getPromotionType()); 100 rspBo.setPromotionType(activity.getPromotionType());
101 rspBo.setLabel(activity.getLabel()); 101 rspBo.setLabel(activity.getLabel());
  102 + rspBo.setBusinessClient(activity.getBusinessClient());
102 List<Integer> productLimitTypeList = new ArrayList<>(); 103 List<Integer> productLimitTypeList = new ArrayList<>();
103 for(String productLimitType : activity.getProductLimitType().split(",")){ 104 for(String productLimitType : activity.getProductLimitType().split(",")){
104 productLimitTypeList.add(Integer.valueOf(productLimitType)); 105 productLimitTypeList.add(Integer.valueOf(productLimitType));