Authored by 匡佳华

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

... ... @@ -18,13 +18,16 @@ import com.yohobuy.ufo.model.promotion.constant.PromotionStatusEnum;
import com.yohobuy.ufo.model.promotion.constant.PromotionTypeEnum;
import com.yohobuy.ufo.model.promotion.request.PromotionActivityReq;
import com.yohobuy.ufo.model.promotion.response.promotionActivity.*;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.CollectionUtils;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
/**
... ... @@ -127,11 +130,12 @@ public class PromotionServiceImpl implements IPromotionService {
activityRsp.setJoinLimitTimes(activity.getJoinLimitTimes());
activityRsp.setProductLimitType(activity.getProductLimitType());
activityRsp.setStatus(activity.getStatus());
if(activity.getProductLimitType().split(",").length == 9){//是否选择全部商品类型
if(activity.getProductLimitType().split(",").length == 10){//是否选择全部商品类型
activityRsp.setIsProductTypeAll(1);
}else {
activityRsp.setIsProductTypeAll(0);
}
activityRsp.setBusinessClient(activity.getBusinessClient());
//2、获取活动取促销满减金额/折扣配置
List<PromotionTypeCondition> amountConditions = typeConditionMapper.selectByPromotionId(id);
... ... @@ -193,8 +197,11 @@ public class PromotionServiceImpl implements IPromotionService {
log.info("updateStatusById with id:{},status:{},user:{}",id,status,operator.getUserId());
if(status == 1) {
PromotionActivity activity = activityMapper.selectByPrimaryKey(id);//获取当前活动的开始结束时间
PromotionActivity activityCheck = activityMapper.selectActivityWithinTime(activity.getStartTime(), activity.getEndTime(), id);
if (activityCheck != null) {
if(StringUtils.isEmpty(activity.getBusinessClient())){
log.warn("updateStatusById fail: activity not set businessClient. id is {}, status is {}", id, status);
return new ApiResponse.ApiResponseBuilder().code(201).message("该活动未设置购买渠道,请先设置购买渠道!").build();
}
if (isExistRunningActivity(id, activity.getStartTime(), activity.getEndTime(), activity.getBusinessClient())) {
log.warn("updateStatusById fail: exist same promotionType activity. id is {}, status is {}", id, status);
return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build();
}
... ... @@ -221,6 +228,7 @@ public class PromotionServiceImpl implements IPromotionService {
activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(),DateUtil.DATE_TIME_FORMAT));
activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT));
activity.setStatus(req.getInitStatus());
activity.setBusinessClient(req.getBusinessClient());
activityMapper.insert(activity);
return activity.getId();
}
... ... @@ -239,6 +247,7 @@ public class PromotionServiceImpl implements IPromotionService {
activity.setProductLimitType(req.getProductTypeLimitList());
activity.setStartTime(DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT));
activity.setEndTime(DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT));
activity.setBusinessClient(req.getBusinessClient());
activityMapper.updateByPrimaryKey(activity);
}
... ... @@ -273,7 +282,7 @@ public class PromotionServiceImpl implements IPromotionService {
typeConditionMapper.insertBatch(typeConditions);
}
//保存营销活动校验
//保存营销活动校验
private ApiResponse checkParams(PromotionActivityReq req){
Integer startTime = DateUtil.getTimeSecondsFromStr(req.getStartTimeStr(), DateUtil.DATE_TIME_FORMAT);
Integer endTime = DateUtil.getTimeSecondsFromStr(req.getEndTimeStr(), DateUtil.DATE_TIME_FORMAT);
... ... @@ -282,7 +291,7 @@ public class PromotionServiceImpl implements IPromotionService {
return new ApiResponse.ApiResponseBuilder().code(201).message("结束时间必须大于开始时间").build();
}
if(req.getInitStatus().equals(PromotionStatusEnum.OPEN.getCode())
&&(activityMapper.selectActivityWithinTime(startTime, endTime, req.getId()) != null)){
&&(isExistRunningActivity(req.getId(), startTime, endTime, req.getBusinessClient()))){
log.warn("checkParams fail: exist same promotionType activity. req is {}", req);
return new ApiResponse.ApiResponseBuilder().code(201).message("该时段已经存在相同类型的活动,请修改活动时间").build();
}
... ... @@ -305,6 +314,25 @@ public class PromotionServiceImpl implements IPromotionService {
return new ApiResponse.ApiResponseBuilder().code(200).message("校验成功").build();
}
//开启活动时,校验:同一时间,相同渠道的,只能有一个促销活动
private boolean isExistRunningActivity(Integer activityId, Integer startTime, Integer endTime, String businessClient){
//(1) 查询该时间段内是否有其他活动正在生效中
List<PromotionActivity> activityList = activityMapper.selectActivityWithinTime(startTime, endTime, activityId);
if(CollectionUtils.isEmpty(activityList)){
return false;
}
//(2) 校验该时间段生效活动的购买渠道是否和当前开启活动的购买渠道重复
String[] businessClientNew = businessClient.split(",");
for(PromotionActivity activity: activityList){
if(StringUtils.isEmpty(activity.getBusinessClient())) continue;
List<String> businessClientExist = Arrays.asList(activity.getBusinessClient().split(","));
for(String newClient: businessClientNew){
if(businessClientExist.contains(newClient)) return true;
}
}
return false;
}
private String getActivityStatusStr(PromotionActivity activity){
if(PromotionStatusEnum.CLOSE.getCode().equals(activity.getStatus())){
return "已关闭";
... ...
... ... @@ -21,5 +21,8 @@ public interface PromotionActivityMapper {
List<PromotionActivity> selectListByPage(@Param("record") PromotionActivityReq record, @Param("currentTime") Integer currentTime);
PromotionActivity selectActivityWithinTime(@Param("startTime") Integer startTime, @Param("endTime") Integer endTime, @Param("activityId") Integer activityId);
List<PromotionActivity> selectActivityWithinTime(@Param("startTime") Integer startTime, @Param("endTime") Integer endTime, @Param("activityId") Integer activityId);
}
\ No newline at end of file
... ...
... ... @@ -26,6 +26,8 @@ public class PromotionActivity {
private Integer updateTime;
private String businessClient;
public Integer getId() {
return id;
}
... ... @@ -121,4 +123,12 @@ public class PromotionActivity {
public void setUpdateTime(Integer updateTime) {
this.updateTime = updateTime;
}
public String getBusinessClient() {
return businessClient;
}
public void setBusinessClient(String businessClient) {
this.businessClient = businessClient;
}
}
\ No newline at end of file
... ...
... ... @@ -14,6 +14,8 @@
<result column="join_limit_times" property="joinLimitTimes" 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>
<sql id="Base_Column_List" >
id, activity_name, start_time, end_time, promotion_type, product_scope_type,
... ... @@ -22,7 +24,7 @@
</sql>
<select id="selectActivityWithinTime" resultMap="BaseResultMap">
select id from promotion_activity
select id, business_client from promotion_activity
where <![CDATA[ end_time > #{startTime, jdbcType=INTEGER} ]]>
and <![CDATA[ start_time < #{endTime, jdbcType=INTEGER} ]]>
and id != #{activityId, jdbcType=INTEGER}
... ... @@ -30,7 +32,7 @@
</select>
<select id="selectByPrimaryKey" resultMap="BaseResultMap" parameterType="java.lang.Integer" >
select
id, activity_name, label, start_time, end_time, promotion_type, product_limit_type, join_limit_type, join_limit_times, status
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 id = #{id,jdbcType=INTEGER}
</select>
... ... @@ -42,14 +44,13 @@
insert into promotion_activity ( activity_name, label, start_time,
end_time, promotion_type,
product_limit_type, join_limit_type, join_limit_times,
status, create_time,
update_time
status, create_time, update_time, business_client
)
values (#{activityName,jdbcType=VARCHAR},#{label,jdbcType=VARCHAR}, #{startTime,jdbcType=INTEGER},
#{endTime,jdbcType=INTEGER}, #{promotionType,jdbcType=TINYINT},
#{productLimitType,jdbcType=VARCHAR}, #{joinLimitType,jdbcType=TINYINT}, #{joinLimitTimes,jdbcType=INTEGER},
#{status,jdbcType=TINYINT}, #{createTime,jdbcType=INTEGER},
#{updateTime,jdbcType=INTEGER}
#{updateTime,jdbcType=INTEGER}, #{businessClient,jdbcType=VARCHAR}
)
</insert>
<update id="updateByPrimaryKeySelective" parameterType="com.yoho.ufo.dal.model.PromotionActivity" >
... ... @@ -75,7 +76,8 @@
join_limit_type = #{joinLimitType,jdbcType=TINYINT},
join_limit_times = #{joinLimitTimes,jdbcType=INTEGER},
status = #{status,jdbcType=TINYINT},
update_time = #{updateTime,jdbcType=INTEGER}
update_time = #{updateTime,jdbcType=INTEGER},
business_client = #{businessClient, jdbcType=VARCHAR}
where id = #{id,jdbcType=INTEGER}
</update>
... ...
... ... @@ -91,11 +91,20 @@
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span><label>购买渠道:</label></td>
<td colspan="3">
<input type="checkbox" name="businessClient" id="businessClientUFO" value="ufo">UFO
<input type="checkbox" name="businessClient" id="businessClientH5" value="h5/xianyu" >闲鱼
</td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span><label>活动是否开启:</label></td>
<td colspan="3">
<input class="easyui-combobox" id="initStatus" name="initStatus" data-options="required:true" style="width: 200px;"/>
</td>
</tr>
</table>
</div>
</form>
... ... @@ -301,7 +310,7 @@
}, 100);
}
//设定商品适用类型
//设定订单适用类型
if(loadData.isProductTypeAll == 1){
$("#promotionEditDiv").find("input:checkbox[name='isAll']").prop("checked", true);
$("#promotionEditDiv").find("input:checkbox[name='productLimitChose']").prop("checked", true);
... ... @@ -314,6 +323,17 @@
}
}
//设置渠道适用类型
var businessClient = loadData.businessClient;
var clientArray = businessClient.split(",");
for(var i = 0; i < clientArray.length; i++){
if(clientArray[i] == "ufo"){
$("#promotionEditForm #businessClientUFO").prop("checked", true);
}else if(clientArray[i] == "h5/xianyu"){
$("#promotionEditForm #businessClientH5").prop("checked", true);
}
}
})
}
... ...
... ... @@ -339,7 +339,21 @@
}
}*/
//组装可用商品类型
//组装购买渠道
var businessClient = "";
var businessClientCheck = $("#promotionEditDiv").find("input:checked[name='businessClient']");
if(businessClientCheck != null){
$(businessClientCheck).each(function (index, item) {
businessClient = businessClient + $(item).val() + ",";
});
}
if(businessClient == ""){
$.messager.alert("提示","请选择购买渠道!", "error");
return false;
}
//组装可用订单类型
var productLimitType = "";
if($("#promotionEditForm #isAll").prop('checked') == true){
var values = $("#promotionEditDiv").find("input:checkbox[name='productLimitChose']");
... ... @@ -356,7 +370,7 @@
}
}
if(productLimitType == ""){
$.messager.alert("提示", "请选择可用商品类型!", "error");
$.messager.alert("提示", "请选择可用订单类型!", "error");
return false;
}
param.id = id;
... ...