Authored by 匡佳华

促销活动:添加购买渠道配置

@@ -18,13 +18,16 @@ import com.yohobuy.ufo.model.promotion.constant.PromotionStatusEnum; @@ -18,13 +18,16 @@ import com.yohobuy.ufo.model.promotion.constant.PromotionStatusEnum;
18 import com.yohobuy.ufo.model.promotion.constant.PromotionTypeEnum; 18 import com.yohobuy.ufo.model.promotion.constant.PromotionTypeEnum;
19 import com.yohobuy.ufo.model.promotion.request.PromotionActivityReq; 19 import com.yohobuy.ufo.model.promotion.request.PromotionActivityReq;
20 import com.yohobuy.ufo.model.promotion.response.promotionActivity.*; 20 import com.yohobuy.ufo.model.promotion.response.promotionActivity.*;
  21 +import org.apache.commons.lang.StringUtils;
21 import org.slf4j.Logger; 22 import org.slf4j.Logger;
22 import org.slf4j.LoggerFactory; 23 import org.slf4j.LoggerFactory;
23 import org.springframework.beans.factory.annotation.Autowired; 24 import org.springframework.beans.factory.annotation.Autowired;
24 import org.springframework.stereotype.Service; 25 import org.springframework.stereotype.Service;
  26 +import org.springframework.util.CollectionUtils;
25 27
26 28
27 import java.util.ArrayList; 29 import java.util.ArrayList;
  30 +import java.util.Arrays;
28 import java.util.List; 31 import java.util.List;
29 32
30 /** 33 /**
@@ -127,11 +130,12 @@ public class PromotionServiceImpl implements IPromotionService { @@ -127,11 +130,12 @@ public class PromotionServiceImpl implements IPromotionService {
127 activityRsp.setJoinLimitTimes(activity.getJoinLimitTimes()); 130 activityRsp.setJoinLimitTimes(activity.getJoinLimitTimes());
128 activityRsp.setProductLimitType(activity.getProductLimitType()); 131 activityRsp.setProductLimitType(activity.getProductLimitType());
129 activityRsp.setStatus(activity.getStatus()); 132 activityRsp.setStatus(activity.getStatus());
130 - if(activity.getProductLimitType().split(",").length == 9){//是否选择全部商品类型 133 + if(activity.getProductLimitType().split(",").length == 10){//是否选择全部商品类型
131 activityRsp.setIsProductTypeAll(1); 134 activityRsp.setIsProductTypeAll(1);
132 }else { 135 }else {
133 activityRsp.setIsProductTypeAll(0); 136 activityRsp.setIsProductTypeAll(0);
134 } 137 }
  138 + activityRsp.setBusinessClient(activity.getBusinessClient());
135 139
136 //2、获取活动取促销满减金额/折扣配置 140 //2、获取活动取促销满减金额/折扣配置
137 List<PromotionTypeCondition> amountConditions = typeConditionMapper.selectByPromotionId(id); 141 List<PromotionTypeCondition> amountConditions = typeConditionMapper.selectByPromotionId(id);
@@ -193,8 +197,11 @@ public class PromotionServiceImpl implements IPromotionService { @@ -193,8 +197,11 @@ public class PromotionServiceImpl implements IPromotionService {
193 log.info("updateStatusById with id:{},status:{},user:{}",id,status,operator.getUserId()); 197 log.info("updateStatusById with id:{},status:{},user:{}",id,status,operator.getUserId());
194 if(status == 1) { 198 if(status == 1) {
195 PromotionActivity activity = activityMapper.selectByPrimaryKey(id);//获取当前活动的开始结束时间 199 PromotionActivity activity = activityMapper.selectByPrimaryKey(id);//获取当前活动的开始结束时间
196 - PromotionActivity activityCheck = activityMapper.selectActivityWithinTime(activity.getStartTime(), activity.getEndTime(), id);  
197 - if (activityCheck != null) { 200 + if(StringUtils.isEmpty(activity.getBusinessClient())){
  201 + log.warn("updateStatusById fail: activity not set businessClient. id is {}, status is {}", id, status);
  202 + return new ApiResponse.ApiResponseBuilder().code(201).message("该活动未设置购买渠道,请先设置购买渠道!").build();
  203 + }
  204 + if (isExistRunningActivity(id, activity.getStartTime(), activity.getEndTime(), activity.getBusinessClient())) {
198 log.warn("updateStatusById fail: exist same promotionType activity. id is {}, status is {}", id, status); 205 log.warn("updateStatusById fail: exist same promotionType activity. id is {}, status is {}", id, status);
199 return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build(); 206 return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build();
200 } 207 }
@@ -221,6 +228,7 @@ public class PromotionServiceImpl implements IPromotionService { @@ -221,6 +228,7 @@ public class PromotionServiceImpl implements IPromotionService {
221 activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(),DateUtil.DATE_TIME_FORMAT)); 228 activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(),DateUtil.DATE_TIME_FORMAT));
222 activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT)); 229 activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT));
223 activity.setStatus(req.getInitStatus()); 230 activity.setStatus(req.getInitStatus());
  231 + activity.setBusinessClient(req.getBusinessClient());
224 activityMapper.insert(activity); 232 activityMapper.insert(activity);
225 return activity.getId(); 233 return activity.getId();
226 } 234 }
@@ -239,6 +247,7 @@ public class PromotionServiceImpl implements IPromotionService { @@ -239,6 +247,7 @@ public class PromotionServiceImpl implements IPromotionService {
239 activity.setProductLimitType(req.getProductTypeLimitList()); 247 activity.setProductLimitType(req.getProductTypeLimitList());
240 activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT)); 248 activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT));
241 activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT)); 249 activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT));
  250 + activity.setBusinessClient(req.getBusinessClient());
242 activityMapper.updateByPrimaryKey(activity); 251 activityMapper.updateByPrimaryKey(activity);
243 } 252 }
244 253
@@ -273,7 +282,7 @@ public class PromotionServiceImpl implements IPromotionService { @@ -273,7 +282,7 @@ public class PromotionServiceImpl implements IPromotionService {
273 typeConditionMapper.insertBatch(typeConditions); 282 typeConditionMapper.insertBatch(typeConditions);
274 } 283 }
275 284
276 - //保存营销活动校验 285 + //保存营销活动校验
277 private ApiResponse checkParams(PromotionActivityReq req){ 286 private ApiResponse checkParams(PromotionActivityReq req){
278 Integer startTime = DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT); 287 Integer startTime = DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT);
279 Integer endTime = DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT); 288 Integer endTime = DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT);
@@ -282,7 +291,7 @@ public class PromotionServiceImpl implements IPromotionService { @@ -282,7 +291,7 @@ public class PromotionServiceImpl implements IPromotionService {
282 return new ApiResponse.ApiResponseBuilder().code(201).message("结束时间必须大于开始时间").build(); 291 return new ApiResponse.ApiResponseBuilder().code(201).message("结束时间必须大于开始时间").build();
283 } 292 }
284 if(req.getInitStatus().equals(PromotionStatusEnum.OPEN.getCode()) 293 if(req.getInitStatus().equals(PromotionStatusEnum.OPEN.getCode())
285 - &&(activityMapper.selectActivityWithinTime(startTime, endTime, req.getId()) != null)){ 294 + &&(isExistRunningActivity(req.getId(), startTime, endTime, req.getBusinessClient()))){
286 log.warn("checkParams fail: exist same promotionType activity. req is {}", req); 295 log.warn("checkParams fail: exist same promotionType activity. req is {}", req);
287 return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build(); 296 return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build();
288 } 297 }
@@ -305,6 +314,25 @@ public class PromotionServiceImpl implements IPromotionService { @@ -305,6 +314,25 @@ public class PromotionServiceImpl implements IPromotionService {
305 return new ApiResponse.ApiResponseBuilder().code(200).message("校验成功").build(); 314 return new ApiResponse.ApiResponseBuilder().code(200).message("校验成功").build();
306 } 315 }
307 316
  317 + //开启活动时,校验:同一时间,相同渠道的,只能有一个促销活动
  318 + private boolean isExistRunningActivity(Integer activityId, Integer startTime, Integer endTime, String businessClient){
  319 + //(1) 查询该时间段内是否有其他活动正在生效中
  320 + List<PromotionActivity> activityList = activityMapper.selectActivityWithinTime(startTime, endTime, activityId);
  321 + if(CollectionUtils.isEmpty(activityList)){
  322 + return false;
  323 + }
  324 + //(2) 校验该时间段生效活动的购买渠道是否和当前开启活动的购买渠道重复
  325 + String[] businessClientNew = businessClient.split(",");
  326 + for(PromotionActivity activity: activityList){
  327 + if(StringUtils.isEmpty(activity.getBusinessClient())) continue;
  328 + List<String> businessClientExist = Arrays.asList(activity.getBusinessClient().split(","));
  329 + for(String newClient: businessClientNew){
  330 + if(businessClientExist.contains(newClient)) return true;
  331 + }
  332 + }
  333 + return false;
  334 + }
  335 +
308 private String getActivityStatusStr(PromotionActivity activity){ 336 private String getActivityStatusStr(PromotionActivity activity){
309 if(PromotionStatusEnum.CLOSE.getCode().equals(activity.getStatus())){ 337 if(PromotionStatusEnum.CLOSE.getCode().equals(activity.getStatus())){
310 return "已关闭"; 338 return "已关闭";
@@ -21,5 +21,8 @@ public interface PromotionActivityMapper { @@ -21,5 +21,8 @@ public interface PromotionActivityMapper {
21 21
22 List<PromotionActivity> selectListByPage(@Param("record") PromotionActivityReq record, @Param("currentTime") Integer currentTime); 22 List<PromotionActivity> selectListByPage(@Param("record") PromotionActivityReq record, @Param("currentTime") Integer currentTime);
23 23
24 - PromotionActivity selectActivityWithinTime(@Param("startTime") Integer startTime, @Param("endTime") Integer endTime, @Param("activityId") Integer activityId); 24 + List<PromotionActivity> selectActivityWithinTime(@Param("startTime") Integer startTime, @Param("endTime") Integer endTime, @Param("activityId") Integer activityId);
  25 +
  26 +
  27 +
25 } 28 }
@@ -26,6 +26,8 @@ public class PromotionActivity { @@ -26,6 +26,8 @@ public class PromotionActivity {
26 26
27 private Integer updateTime; 27 private Integer updateTime;
28 28
  29 + private String businessClient;
  30 +
29 public Integer getId() { 31 public Integer getId() {
30 return id; 32 return id;
31 } 33 }
@@ -121,4 +123,12 @@ public class PromotionActivity { @@ -121,4 +123,12 @@ public class PromotionActivity {
121 public void setUpdateTime(Integer updateTime) { 123 public void setUpdateTime(Integer updateTime) {
122 this.updateTime = updateTime; 124 this.updateTime = updateTime;
123 } 125 }
  126 +
  127 + public String getBusinessClient() {
  128 + return businessClient;
  129 + }
  130 +
  131 + public void setBusinessClient(String businessClient) {
  132 + this.businessClient = businessClient;
  133 + }
124 } 134 }
@@ -14,6 +14,8 @@ @@ -14,6 +14,8 @@
14 <result column="join_limit_times" property="joinLimitTimes" jdbcType="INTEGER" /> 14 <result column="join_limit_times" property="joinLimitTimes" 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" />
  18 +
17 </resultMap> 19 </resultMap>
18 <sql id="Base_Column_List" > 20 <sql id="Base_Column_List" >
19 id, activity_name, start_time, end_time, promotion_type, product_scope_type, 21 id, activity_name, start_time, end_time, promotion_type, product_scope_type,
@@ -22,7 +24,7 @@ @@ -22,7 +24,7 @@
22 </sql> 24 </sql>
23 25
24 <select id="selectActivityWithinTime" resultMap="BaseResultMap"> 26 <select id="selectActivityWithinTime" resultMap="BaseResultMap">
25 - select id from promotion_activity 27 + select id, business_client from promotion_activity
26 where <![CDATA[ end_time > #{startTime, jdbcType=INTEGER} ]]> 28 where <![CDATA[ end_time > #{startTime, jdbcType=INTEGER} ]]>
27 and <![CDATA[ start_time < #{endTime, jdbcType=INTEGER} ]]> 29 and <![CDATA[ start_time < #{endTime, jdbcType=INTEGER} ]]>
28 and id != #{activityId, jdbcType=INTEGER} 30 and id != #{activityId, jdbcType=INTEGER}
@@ -30,7 +32,7 @@ @@ -30,7 +32,7 @@
30 </select> 32 </select>
31 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" > 33 <select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
32 select 34 select
33 - id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status 35 + id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status, business_client
34 from promotion_activity 36 from promotion_activity
35 where id = #{id,jdbcType=INTEGER} 37 where id = #{id,jdbcType=INTEGER}
36 </select> 38 </select>
@@ -42,14 +44,13 @@ @@ -42,14 +44,13 @@
42 insert into promotion_activity ( activity_name, label, start_time, 44 insert into promotion_activity ( activity_name, label, start_time,
43 end_time, promotion_type, 45 end_time, promotion_type,
44 product_limit_type, join_limit_type, join_limit_times, 46 product_limit_type, join_limit_type, join_limit_times,
45 - status, create_time,  
46 - update_time 47 + status, create_time, update_time, business_client
47 ) 48 )
48 values (#{activityName,jdbcType=VARCHAR},#{label,jdbcType=VARCHAR}, #{startTime,jdbcType=INTEGER}, 49 values (#{activityName,jdbcType=VARCHAR},#{label,jdbcType=VARCHAR}, #{startTime,jdbcType=INTEGER},
49 #{endTime,jdbcType=INTEGER}, #{promotionType,jdbcType=TINYINT}, 50 #{endTime,jdbcType=INTEGER}, #{promotionType,jdbcType=TINYINT},
50 #{productLimitType,jdbcType=VARCHAR}, #{joinLimitType,jdbcType=TINYINT}, #{joinLimitTimes,jdbcType=INTEGER}, 51 #{productLimitType,jdbcType=VARCHAR}, #{joinLimitType,jdbcType=TINYINT}, #{joinLimitTimes,jdbcType=INTEGER},
51 #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER}, 52 #{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER},
52 - #{updateTime,jdbcType=INTEGER} 53 + #{updateTime,jdbcType=INTEGER}, #{businessClient,jdbcType=VARCHAR}
53 ) 54 )
54 </insert> 55 </insert>
55 <update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.PromotionActivity" > 56 <update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.PromotionActivity" >
@@ -75,7 +76,8 @@ @@ -75,7 +76,8 @@
75 join_limit_type = #{joinLimitType,jdbcType=TINYINT}, 76 join_limit_type = #{joinLimitType,jdbcType=TINYINT},
76 join_limit_times = #{joinLimitTimes,jdbcType=INTEGER}, 77 join_limit_times = #{joinLimitTimes,jdbcType=INTEGER},
77 status = #{status,jdbcType=TINYINT}, 78 status = #{status,jdbcType=TINYINT},
78 - update_time = #{updateTime,jdbcType=INTEGER} 79 + update_time = #{updateTime,jdbcType=INTEGER},
  80 + business_client = #{businessClient, jdbcType=VARCHAR}
79 where id = #{id,jdbcType=INTEGER} 81 where id = #{id,jdbcType=INTEGER}
80 </update> 82 </update>
81 83
@@ -91,11 +91,20 @@ @@ -91,11 +91,20 @@
91 </tr> 91 </tr>
92 92
93 <tr style="height: 60px"> 93 <tr style="height: 60px">
  94 + <td width="10%"><span style="color:red">*</span><label>购买渠道:</label></td>
  95 + <td colspan="3">
  96 + <input type="checkbox" name="businessClient" id="businessClientUFO" value="ufo">UFO
  97 + <input type="checkbox" name="businessClient" id="businessClientH5" value="h5/xianyu" >闲鱼
  98 + </td>
  99 + </tr>
  100 +
  101 + <tr style="height: 60px">
94 <td width="10%"><span style="color:red">*</span><label>活动是否开启:</label></td> 102 <td width="10%"><span style="color:red">*</span><label>活动是否开启:</label></td>
95 <td colspan="3"> 103 <td colspan="3">
96 <input class="easyui-combobox" id="initStatus" name="initStatus" data-options="required:true" style="width: 200px;"/> 104 <input class="easyui-combobox" id="initStatus" name="initStatus" data-options="required:true" style="width: 200px;"/>
97 </td> 105 </td>
98 </tr> 106 </tr>
  107 +
99 </table> 108 </table>
100 </div> 109 </div>
101 </form> 110 </form>
@@ -301,7 +310,7 @@ @@ -301,7 +310,7 @@
301 }, 100); 310 }, 100);
302 } 311 }
303 312
304 - //设定商品适用类型 313 + //设定订单适用类型
305 if(loadData.isProductTypeAll == 1){ 314 if(loadData.isProductTypeAll == 1){
306 $("#promotionEditDiv").find("input:checkbox[name='isAll']").prop("checked", true); 315 $("#promotionEditDiv").find("input:checkbox[name='isAll']").prop("checked", true);
307 $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']").prop("checked", true); 316 $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']").prop("checked", true);
@@ -314,6 +323,17 @@ @@ -314,6 +323,17 @@
314 } 323 }
315 } 324 }
316 325
  326 + //设置渠道适用类型
  327 + var businessClient = loadData.businessClient;
  328 + var clientArray = businessClient.split(",");
  329 + for(var i = 0; i < clientArray.length; i++){
  330 + if(clientArray[i] == "ufo"){
  331 + $("#promotionEditForm #businessClientUFO").prop("checked", true);
  332 + }else if(clientArray[i] == "h5/xianyu"){
  333 + $("#promotionEditForm #businessClientH5").prop("checked", true);
  334 + }
  335 + }
  336 +
317 337
318 }) 338 })
319 } 339 }
@@ -339,7 +339,21 @@ @@ -339,7 +339,21 @@
339 } 339 }
340 }*/ 340 }*/
341 341
342 - //组装可用商品类型 342 + //组装购买渠道
  343 + var businessClient = "";
  344 + var businessClientCheck = $("#promotionEditDiv").find("input:checked[name='businessClient']");
  345 + if(businessClientCheck != null){
  346 + $(businessClientCheck).each(function (index, item) {
  347 + businessClient = businessClient + $(item).val() + ",";
  348 + });
  349 + }
  350 + if(businessClient == ""){
  351 + $.messager.alert("提示","请选择购买渠道!", "error");
  352 + return false;
  353 + }
  354 +
  355 +
  356 + //组装可用订单类型
343 var productLimitType = ""; 357 var productLimitType = "";
344 if($("#promotionEditForm #isAll").prop('checked') == true){ 358 if($("#promotionEditForm #isAll").prop('checked') == true){
345 var values = $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']"); 359 var values = $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']");
@@ -356,7 +370,7 @@ @@ -356,7 +370,7 @@
356 } 370 }
357 } 371 }
358 if(productLimitType == ""){ 372 if(productLimitType == ""){
359 - $.messager.alert("提示", "请选择可用商品类型!", "error"); 373 + $.messager.alert("提示", "请选择可用订单类型!", "error");
360 return false; 374 return false;
361 } 375 }
362 param.id = id; 376 param.id = id;