Authored by 张帅

种草社区奖励活动

package com.yohobuy.platform.grass.restapi;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.grass.service.IGrassRewardsService;
import com.yohobuy.platform.model.common.ApiResponse;
import com.yohobuy.platform.model.grass.request.GrassRewardReq;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
@RequestMapping("/grassRewards")
public class GrassRewardsController {
private static final Logger logger = LoggerFactory.getLogger(GrassRewardsController.class);
@Autowired
private IGrassRewardsService grassRewardsService;
@RequestMapping("/getGrassRewardsList")
public ApiResponse getGrassRewardsList( @RequestBody GrassRewardReq req){
logger.info("grassRewards getRewardsList begin, req is {}", req);
return new ApiResponse.ApiResponseBuilder().data(grassRewardsService.getRewardsList(req)).build();
}
@RequestMapping("/addGrassReward")
public ApiResponse addGrassReward(@RequestBody GrassRewardReq req){
logger.info("grassRewards addReward begin, req is {}", req);
try {
grassRewardsService.addReward(req);
} catch (PlatformException e) {
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
}
return new ApiResponse.ApiResponseBuilder().build();
}
@RequestMapping("/updateGrassReward")
public ApiResponse updateGrassReward(@RequestBody GrassRewardReq req){
logger.info("grassRewards updateReward begin, req is {}", req);
try {
grassRewardsService.updateReward(req);
} catch (PlatformException e) {
return new ApiResponse.ApiResponseBuilder().code(e.getCode()).message(e.getMessage()).build();
}
return new ApiResponse.ApiResponseBuilder().build();
}
}
... ...
package com.yohobuy.platform.grass.service;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassRewardReq;
import com.yohobuy.platform.model.grass.response.ArticleDetailRspBo;
import com.yohobuy.platform.model.grass.response.GrassRewardRsp;
import java.util.List;
/**
* Created on 2019/8/6.
*/
public interface IGrassRewardsService {
void addReward(GrassRewardReq req) throws PlatformException;
void updateReward(GrassRewardReq req) throws PlatformException;
PageResponseVO<GrassRewardRsp> getRewardsList(GrassRewardReq req);
}
... ...
... ... @@ -1815,30 +1815,45 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
private boolean sendTopicReward(Integer articleId,Integer uid,int publishTime){
boolean hasSend = false;
try {
//未关联话题,不发话题奖励
GrassArticleTopic grassArticleTopic = grassArticleTopicDao.selectByArticleId(articleId);
if(grassArticleTopic == null || grassArticleTopic.getTopicId() == null){
return false;
}
Integer topicId = grassArticleTopic.getTopicId();
TopicRewardsRelate topicRewardsRelate = topicRewardsRelateDAO.selectByTopicId(topicId);
if(topicRewardsRelate == null){
return false;
}
GrassRewardsConfig rewardsConfig = grassRewardsConfigDAO.selectByPrimaryKey(topicRewardsRelate.getRewardId());
// int now = DateUtil.getCurrentTimeSeconds();
if(rewardsConfig.getStartTime()!= 0 && publishTime < rewardsConfig.getStartTime()){
logger.info("sendTopicReward rewardsConfig not start, rewardId is {}, startTime is {}",rewardsConfig.getId(), rewardsConfig.getStartTime());
return false;
List<TopicRewardsRelate> list = topicRewardsRelateDAO.selectByTopicId(topicId);
GrassRewardsConfig rewardsConfig = null;
//1、先取单独配置的话题活动奖励,按照优先级,去正处于有效状态的奖励活动
if(CollectionUtils.isNotEmpty(list)){
List<Integer> rewardIds = list.stream().map(TopicRewardsRelate::getRewardId).collect(Collectors.toList());
List<GrassRewardsConfig> rewardsConfigList = grassRewardsConfigDAO.selectByIds(rewardIds);
rewardsConfigList = rewardsConfigList.stream().sorted((o1, o2) -> {if(o1.getPriority() <= o2.getPriority()) return 1; else return -1;}).collect(Collectors.toList());
for (GrassRewardsConfig grassRewardsConfig : rewardsConfigList) {
if(checkRewardValid(grassRewardsConfig,publishTime)){
rewardsConfig = grassRewardsConfig;
}
}
}
if(rewardsConfig.getEndTime()!= 0 && publishTime > rewardsConfig.getEndTime()){
logger.info("sendTopicReward rewardsConfig already end, rewardId is {}, endTime is {}",rewardsConfig.getId(), rewardsConfig.getEndTime());
return false;
// 2、1取不到时, 取活动配置表里话题的奖励活动,是否存在正处于有效状态的对所有话题有效的奖励活动
if(rewardsConfig == null){
List<GrassRewardsConfig> topicRewards = grassRewardsConfigDAO.selectByType(2);
//生效中的,对所有话题有效的奖励活动
//奖励活动取优先级最高的
topicRewards = topicRewards.stream().sorted((o1, o2) -> {if(o1.getPriority() <= o2.getPriority()) return 1; else return -1;}).collect(Collectors.toList());
for (GrassRewardsConfig topicReward : topicRewards) {
if(checkRewardValid(topicReward, publishTime) && topicReward.getAllTopic() == 1){
rewardsConfig = topicReward;
}
}
}
if(rewardsConfig.getStatus()!= 1 ){
logger.info("sendTopicReward rewardsConfig status error, rewardId is {}, status is {}",rewardsConfig.getId(), rewardsConfig.getStatus());
//3、 1.2两步都取不到,则代表该话题没有奖励
if(rewardsConfig == null){
return false;
}
//一个奖励周期, 单位 天 未配置 则 奖励周期为活动的开始结束时间
Integer rewardInterval = rewardsConfig.getRewardInterval();
Integer startTime = rewardsConfig.getStartTime();
... ... @@ -1907,7 +1922,9 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
}
private GrassRewardsConfig getValidRewardConfig(List<GrassRewardsConfig> rewardsConfigList, int publishTime){
//按优先级取
GrassRewardsConfig grassRewardsConfig =null;
rewardsConfigList = rewardsConfigList.stream().sorted((o1, o2) -> {if(o1.getPriority() <= o2.getPriority()) return 1; else return -1;}).collect(Collectors.toList());
for (GrassRewardsConfig rewardsConfig : rewardsConfigList) {
if(rewardsConfig.getStartTime()!= 0 && publishTime < rewardsConfig.getStartTime()){
logger.info("sendPublishReward rewardsConfig not start, rewardId is {}, startTime is {}",rewardsConfig.getId(), rewardsConfig.getStartTime());
... ... @@ -1923,6 +1940,23 @@ public class GrassArticleServiceImpl implements IGrassArticleService {
return grassRewardsConfig;
}
private boolean checkRewardValid(GrassRewardsConfig rewardsConfig, int publishTime){
if(rewardsConfig.getStartTime()!= 0 && publishTime < rewardsConfig.getStartTime()){
logger.info("sendTopicReward rewardsConfig not start, rewardId is {}, startTime is {}",rewardsConfig.getId(), rewardsConfig.getStartTime());
return false;
}
if(rewardsConfig.getEndTime()!= 0 && publishTime > rewardsConfig.getEndTime()){
logger.info("sendTopicReward rewardsConfig already end, rewardId is {}, endTime is {}",rewardsConfig.getId(), rewardsConfig.getEndTime());
return false;
}
if(rewardsConfig.getStatus()!= 1 ){
logger.info("sendTopicReward rewardsConfig status error, rewardId is {}, status is {}",rewardsConfig.getId(), rewardsConfig.getStatus());
return false;
}
return true;
}
private void callSnsSendReward(Integer articleId, Integer rewardId, Integer type,Integer uid){
try {
Map<String, Object> reqMap = Maps.newHashMap();
... ...
package com.yohobuy.platform.grass.service.impl;
import com.google.common.collect.Lists;
import com.yohobuy.platform.common.exception.PlatformException;
import com.yohobuy.platform.common.util.DateUtil;
import com.yohobuy.platform.common.util.YHBeanUtils;
import com.yohobuy.platform.dal.grass.IGrassRewardsConfigDAO;
import com.yohobuy.platform.dal.grass.ITopicRewardsRelateDAO;
import com.yohobuy.platform.dal.grass.model.GrassRewardsConfig;
import com.yohobuy.platform.dal.grass.model.TopicRewardsRelate;
import com.yohobuy.platform.grass.service.IGrassRefreshCacheService;
import com.yohobuy.platform.grass.service.IGrassRewardsService;
import com.yohobuy.platform.model.common.PageResponseVO;
import com.yohobuy.platform.model.grass.request.GrassCacheReq;
import com.yohobuy.platform.model.grass.request.GrassRewardReq;
import com.yohobuy.platform.model.grass.response.GrassRewardRsp;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import static java.util.Arrays.asList;
/**
* Created on 2019/8/6.
*/
@Service
public class GrassRewardsServiceImpl implements IGrassRewardsService {
private static final Logger logger = LoggerFactory.getLogger(GrassRewardsServiceImpl.class);
@Resource
private IGrassRewardsConfigDAO grassRewardsConfigDAO;
@Resource
private ITopicRewardsRelateDAO topicRewardsRelateDAO;
@Autowired
private IGrassRefreshCacheService grassRefreshCacheService;
@Override
public void addReward(GrassRewardReq req) throws PlatformException {
checkParams(req);
GrassRewardsConfig rewardsConfig = YHBeanUtils.copyBeans(GrassRewardsConfig.class, req);
grassRewardsConfigDAO.insertRewardSeletive(rewardsConfig);
String includTopics = req.getIncludeTopics();
if(StringUtils.isNotEmpty(includTopics) && req.getType()==2 && null==req.getAllTopic()){
addTopicRelates(includTopics, rewardsConfig.getId());
}
//处理前台缓存
clearRewardCache(rewardsConfig.getId(), req.getIncludeTopics());
}
@Override
public void updateReward(GrassRewardReq req) throws PlatformException {
if(req.getOperateType() == 2){
checkParams(req);
}
if(req.getRewardId() == null){
throw new PlatformException("reward is null ", 405);
}
GrassRewardsConfig rewardsConfig = YHBeanUtils.copyBeans(GrassRewardsConfig.class, req);
rewardsConfig.setId(req.getRewardId());
Boolean notAllTopic = StringUtils.isNotEmpty(req.getIncludeTopics()) && req.getType()==2 && null==req.getAllTopic();
if(notAllTopic){
rewardsConfig.setAllTopic(0);
}
grassRewardsConfigDAO.updateByPrimaryKeySelective(rewardsConfig);
//编辑和删除的时候需要操作,启停用不处理
if(req.getOperateType() != 1){
topicRewardsRelateDAO.deleteByRewardId(req.getRewardId());
String includeTopics = req.getIncludeTopics();
if(notAllTopic){
addTopicRelates(includeTopics, req.getRewardId());
}
}
//处理前台缓存
clearRewardCache(rewardsConfig.getId(), req.getIncludeTopics());
}
private void clearRewardCache(Integer rewardId, String topicIds) {
logger.info("clearRewardCache, type=1001");
GrassCacheReq cacheReq = new GrassCacheReq();
cacheReq.setClearCode(2001);
cacheReq.setElementId(String.valueOf(rewardId));
if(StringUtils.isNotEmpty(topicIds)){
List<String> list = Arrays.stream(topicIds.split(",")).collect(Collectors.toList());
cacheReq.setTopicIdList(list);
}
grassRefreshCacheService.refreshGrassCache(cacheReq);
}
@Override
public PageResponseVO<GrassRewardRsp> getRewardsList(GrassRewardReq req) {
Integer type = req.getType();
Integer startTime = req.getStartTime();
Integer endTime = req.getEndTime();
Integer status = req.getStatus();
Integer valid = req.getValid();
String rewardName = StringUtils.isEmpty(req.getRewardName())? null : req.getRewardName();
Integer priorityOrder = req.getPriorityOrder();
int total = grassRewardsConfigDAO.selectTotalByCondition(type, startTime, endTime,
status, priorityOrder, rewardName,valid,DateUtil.getCurrentTimeSeconds());
if(total == 0){
PageResponseVO<GrassRewardRsp> response = new PageResponseVO<>();
response.setPage(req.getPage());
response.setSize(req.getSize());
response.setTotal(0);
response.setList(Lists.newArrayList());
return response;
}
int limit = (req.getPage()-1) * req.getSize();
List<GrassRewardsConfig> rewardsConfigList = grassRewardsConfigDAO.selectListByCondition(type, startTime, endTime,
status, priorityOrder, rewardName,valid,DateUtil.getCurrentTimeSeconds(),limit, req.getSize());
List<Integer> rewardIds = rewardsConfigList.stream().map(GrassRewardsConfig::getId).collect(Collectors.toList());
List<TopicRewardsRelate> rewardsRelateList = topicRewardsRelateDAO.selectByRewardIds(rewardIds);
//把topicId 根据 rewardId 分组
Map<Integer, List<Integer>> map = rewardsRelateList.stream().collect(Collectors.groupingBy(TopicRewardsRelate::getRewardId,Collectors.mapping(TopicRewardsRelate::getTopicId, Collectors.toList())));
List<GrassRewardRsp> rewardRspList = Lists.newArrayList();
for (GrassRewardsConfig rewardsConfig : rewardsConfigList) {
GrassRewardRsp rspBo = YHBeanUtils.copyBeans(GrassRewardRsp.class, rewardsConfig);
rspBo.setRewardId(rewardsConfig.getId());
if(rspBo.getType() ==2){
List<Integer> topicIds = map.get(rspBo.getRewardId());
if(topicIds !=null){
rspBo.setIncludeTopics(StringUtils.join(topicIds, ","));
}
}
rspBo.setStartTimeStr(DateUtil.int2DateStr(rspBo.getStartTime(),DateUtil.DATE_TIME_FORMAT));
rspBo.setEndTimeStr(DateUtil.int2DateStr(rspBo.getEndTime(),DateUtil.DATE_TIME_FORMAT));
int currentTime = DateUtil.getCurrentTimeSeconds();
if(rewardsConfig.getStartTime() <= currentTime && (rewardsConfig.getEndTime() >= currentTime || rewardsConfig.getEndTime() == 0) ){
rspBo.setValid(1);
}else {
rspBo.setValid(2);
}
rewardRspList.add(rspBo);
}
PageResponseVO<GrassRewardRsp> response = new PageResponseVO<>();
response.setPage(req.getPage());
response.setSize(req.getSize());
response.setTotal(total);
response.setList(rewardRspList);
return response;
}
private void addTopicRelates(String includTopics ,Integer rewardId){
String[] topicIds = includTopics.split(",");
List<TopicRewardsRelate> list = Lists.newArrayList();
int now = DateUtil.getCurrentTimeSeconds();
for (String topicId : topicIds) {
TopicRewardsRelate rewardsRelate = new TopicRewardsRelate();
rewardsRelate.setTopicId(Integer.valueOf(topicId));
rewardsRelate.setRewardId(rewardId);
rewardsRelate.setStatus(1);
rewardsRelate.setCreateTime(now);
list.add(rewardsRelate);
}
if(CollectionUtils.isNotEmpty(list)){
topicRewardsRelateDAO.insertBatch(list);
}
}
private void checkParams(GrassRewardReq req) throws PlatformException {
if(req.getType() == null){
throw new PlatformException("reward type is null ", 405);
}
if(req.getStartTime() == null){
throw new PlatformException("reward startTime is null ", 405);
}
if(req.getMaxTime() == null){
throw new PlatformException("reward maxtime is null ", 405);
}
if(req.getNum() == null){
throw new PlatformException("reward num is null ", 405);
}
}
}
... ...
... ... @@ -24,7 +24,7 @@
<dependency>
<groupId>com.yoho.service.platform.model</groupId>
<artifactId>platform-service-model</artifactId>
<version>1.2.3-6.9.9-SNAPSHOT</version>
<version>1.2.3-6.9.10-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.yoho.dsf.yhplatform</groupId>
... ... @@ -59,7 +59,7 @@
<dependency>
<groupId>com.yohobuy.platform</groupId>
<artifactId>platform-common</artifactId>
<version>1.0.3-6.9.9-SNAPSHOT</version>
<version>1.0.3-6.9.10-SNAPSHOT</version>
</dependency>
... ...
<!DOCTYPE html>
<div id="tt" class="easyui-layout" fit="true" style="overflow-y: scroll">
<form name="activityAddForm" id="activityAddForm" method="post" enctype="multipart/form-data">
<div style="margin-top: 20px;margin-left: 30px">
<table border="0" style="width:95%;margin-top:5px;line-height:30px;" id="tab">
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span><label>活动类型</label></td>
<td>
<input class="easyui-combobox" id="rewardType" name="type" style="width: 380px;">
</input>
</td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>活动名称</td>
<td width="50%">
<input id="rewardNameN" name="rewardName" class="easyui-textbox" style="width: 380px;"/></td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>活动描述</td>
<td width="50%">
<input id="descriptionN" name="description" class="easyui-textbox" style="width: 380px;"/></td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>开始结束时间</td>
<td width="40%">
<input id="startTimeStr" name="startTimeStr" class="easyui-datetimebox" data-options="prompt:'开始时间'"/>~
<input id="endTimeStr" name="endTimeStr" class="easyui-datetimebox" data-options="prompt:'结束时间'"/>
</td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>优先级</td>
<td width="50%">
<input id="priorityN" name="priority" class="easyui-textbox" style="width: 380px;"/></td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>奖励类型</td>
<td width="50%">
<input id="coin" name="rewardType" class="easyui-combobox" style="width: 380px;"/></td>
</tr>
<tr style="height: 60px">
<td width="10%"><span style="color:red">*</span>单次奖励数量</td>
<td width="50%">
<input id="numN" name="num" type="number" class="easyui-textbox" style="width: 380px;"/></td>
</tr>
<tr class="interval" style="height: 60px">
<td width="10%"><span style="color:red">*</span>奖励次数/周期</td>
<td width="50%">
<input id="maxTimeN" name="maxTime" type="number" class="easyui-textbox" style="width: 160px;"/>次/
<input id="rewardIntervalN" name="rewardInterval" type="number" class="easyui-textbox" style="width: 160px;"/>
</td>
</tr>
<tr class="topic" style="height: 60px">
<td width="10%"><span style="color:red">*</span>关联话题</td>
<td width="30%">
<input type="radio" id="allRadio" name="type" value="1" checked>全部话题&nbsp;&nbsp;
<input type="radio" id="normalRadio" name="type" value="2">部分话题&nbsp;&nbsp;
<br>
<textarea id="includeTopicsN" name="includeTopics" style="width: 380px;"/>
<input id="allTopic" name="allTopic" type="hidden" />
</td>
</tr>
<tr class="config" style="height: 60px">
<td width="10%"><span style="color:red">*</span>活动短语</td>
<td width="50%">
<input id="context" name="context" class="easyui-textbox" style="width: 380px;"/></td>
</tr>
<tr class="config" style="height: 60px">
<td width="20%"><span style="color:red">*</span>活动图片</td>
<td>
<div id="imageUpload">
</div>
<span style=" margin-left: 10px; color: red"> 图片宽高(186x170)</span>
</td>
</tr>
</table>
</div>
</form>
</div>
<script>
function getStrLength(str) {
var cArr = str.match(/[^\x00-\xff]/ig);
return str.length + (cArr == null ? 0 : cArr.length);
}
$(function () {
$("#imageUpload").imageUpload({
width: 171,
height: 120,
realInputName: "imageUrl",
url: serverContextPath + '/fileupload/upload',
queryParams: {
bucket: "grassImg"
},
onBeforeSubmit: function () {
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后...",
interval: 500,
text: ""
});
},
filterFileName: function (data) {
debugger;
if (!data || data.code != 200) {
$.messager.progress("close");
$.messager.alert("错误",data.message);
return "";
}
return data.data;
},
onLoadSuccess: function (data) {
$.messager.progress("close");
return false;
}
});
// 名称不能为空
$("#rewardNameN").textbox({
required: true,
missingMessage: "活动名称不能为空",
prompt: "请输入活动名称(不能超过30个字)",
onChange: function(data){
if (data!="" && getStrLength(data) > 30) {
$.messager.alert("提示", "活动名称长度不能超过30个字", "info");
$("#rewardNameN").focus();
$("#rewardNameN").textbox("setValue","");
}
}
});
// 优先级
$("#priorityN").textbox({
required: true,
missingMessage: "优先级不能为空",
prompt: "正整数",
onChange: function(data){
if(data != "" && Number(data) < 0 ){
$.messager.alert("提示", "优先级必须为正整数!", "info");
$("#priorityN").textbox("setValue","");
}
}
});
$("#numN").textbox({
required: true,
prompt: "有货币数量",
onChange: function(data){
debugger
if(data != "" && Number(data) < 0){
$.messager.alert("提示", "有货币数量必须大于0!", "info");
$("#numN").textbox("setValue","");
}
}
});
$("#maxTimeN").textbox({
required: true,
prompt: "最大次数",
onChange: function(data){
debugger
if(data != "" && Number(data) < 0){
$.messager.alert("提示", "最大次数必须大于0!", "info");
$("#maxTimeN").textbox("setValue","");
}
}
});
$("#rewardIntervalN").textbox({
required: true,
prompt: "奖励周期",
onChange: function(data){
debugger
if(data != "" && Number(data) < 0){
$.messager.alert("提示", "奖励周期必须大于0!", "info");
$("#rewardIntervalN").textbox("setValue","");
}
}
});
$("#coin").combobox({
valueField : "value",
textField : "text",
required:true,
prompt: "请选择奖品类型",
disabled:true,
data:[{text:"有货币奖励",value:"1"}]
});
$("#coin").combobox('setValue',1);
$("#includeTopicsN").hide();
$("#allRadio").click(function(){
$("#includeTopicsN").hide();
});
$("#normalRadio").click(function(){
$("#includeTopicsN").show();
});
debugger
var data = paramObject.mkData;
$("#rewardType").combobox({
valueField : "value",
textField : "text",
required:true,
prompt: "请选择奖品类型",
data:[{text:"首发奖励",value:"3"},{text:"发布奖励",value:"1"},{text:"话题奖励",value:"2"}],
onChange: function(){
var type =$("#rewardType").combobox("getValue");
debugger
if(type == 1){
$(".interval").attr("style","display:");
$(".topic").attr("style","display:none");
$(".config").attr("style","display:");
$("#maxTimeN").textbox({disabled:false});
$("#rewardIntervalN").textbox({disabled:false});
}
if(type ==2){
$(".interval").attr("style","display:");
$(".topic").attr("style","display:");
$(".config").attr("style","display:");
$("#maxTimeN").textbox({disabled:false});
$("#rewardIntervalN").textbox({disabled:false});
}
if(type ==3){
$(".interval").attr("style","display:");
$(".topic").attr("style","display:none");
$(".config").attr("style","display:none");
$("#maxTimeN").textbox("setValue","1");
$("#rewardIntervalN").textbox("setValue","0");
$("#maxTimeN").textbox({disabled:true});
$("#rewardIntervalN").textbox({disabled:true});
}
}
});
$("#rewardType").combobox('setValue',1);
if (data){
if(data.allTopic==1){
$("#allRadio").prop("checked",true);
$("#normalRadio").prop("checked",false);
}else {
$("#allRadio").prop("checked",false);
$("#normalRadio").prop("checked",true);
$("#includeTopicsN").show();
}
$("#startTimeStr").datetimebox('setValue',data.startTimeStr);
$("#endTimeStr").datetimebox('setValue',data.endTimeStr);
$("#maxTimeN").textbox("setValue", data.maxTime);
$("#numN").textbox("setValue", data.num);
$("#priorityN").textbox("setValue", data.priority);
$("#rewardIntervalN").textbox("setValue", data.rewardInterval);
$("#includeTopicsN").val( data.includeTopics);
$("#descriptionN").textbox("setValue", data.description);
$("#rewardNameN").textbox("setValue", data.rewardName);
$("#rewardType").combobox('setValue',data.type);
$("#rewardType").combobox('readonly',true);
$("#imageUpload").imageUpload('setValue',data.imageUrl);
}
});
</script>
\ No newline at end of file
... ...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title>Yoho!Buy运营平台</title>
<script src="/pfcms/js/include.js"></script>
<script src="/pfcms/js/ajaxfileupload.js"></script>
<script src="/pfcms/js/jquery.imageUpload.js"></script>
<script charset="utf-8" src="/pfcms/ueditor/ueditor.config.js"></script>
<script charset="utf-8" src="/pfcms/ueditor/ueditor.all.min.js"></script>
<link rel="stylesheet" href="/pfcms/css/swiper.min.css">
<script src="/pfcms/js/utils/swiper.min.js"></script>
<!--建议手动加在语言,避免在ie下有时因为加载语言失败导致编辑器加载失败-->
<!--这里加载的语言文件会覆盖你在配置项目里添加的语言类型,比如你在配置项目里配置的是英文,这里加载的中文,那最后就是中文-->
<script type="text/javascript" charset="utf-8" src="/pfcms/ueditor/lang/zh-cn/zh-cn.js"></script>
<script charset="utf-8" src="/pfcms/ueditor/ueditor.yoho.js"></script>
<style>
/* 可以设置样式,也可以不设置*/
.swiper-container {
width: 700px;
height: 400px;
}
.btn-long {
width: 120px;
height: 37px;
line-height: 37px;
font-size: 15px;
color: white;
border-radius: 5px;
display: inline-block;
cursor: pointer;
text-align: center;
}
.btn-long:hover {
opacity: 0.9;
}
</style>
</head>
<!--<body class="easyui-layout" fit="true" style="overflow-y: scroll" >-->
<body class="easyui-layout" >
<div region="north" style="height: 200px;">
<!--<div region="north" style="height: 30%;">-->
<script>
document.write(addHead('种草社区管理', '种草奖励活动管理'));
</script>
<div style="margin-left: 20px;margin-top: 10px">
<a id="addBtn" class="btn-long" style="background-color: #5CB85C;">新增奖品+</a>
</div>
<div style="margin-left: 20px;margin-top: 10px">
<input class="easyui-combobox" id="type">
</input>
<input class="easyui-combobox" id="valid">
</input>
<input class="easyui-combobox" id="status">
</input>
<input class="easyui-textbox" id="rewardName">
</input>
<input class="easyui-combobox" id="priorityOrder">
</input>
<!--<input id="startTimeStr" name="startTimeStr" class="easyui-datetimebox" data-options="prompt:'发布时间(开始)'"/>-->
<!--<input id="endTimeStr" name="endTimeStr" class="easyui-datetimebox" data-options="prompt:'发布时间(结束)'"/>-->
<!--</input>-->
<a id="searchBtn" class="btn-info">查询</a>
<!--<a id="addActivityBtn" class="btn-success">新增</a>-->
<a id="allBtn" class="btn-info">全部 </a>
</div></div>
<div region="center" id="activityList" style="margin-left: 20px" >
<table id="activityListTable" ></table>
</div>
</body>
<script>
$(function() {
//用于页面刷新后的数据行定位
var index ="";
$("#addBtn").click(function () {
getEditDialog(null);
});
$("#allBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
//清空筛选数据
$("#rewardName").textbox("setValue","");
$("#type").combobox("setValue","");
$("#valid").combobox("setValue","");
$("#status").combobox("setValue","");
$("#priorityOrder").combobox("setValue","");
$("#activityListTable").datagrid("load", {
});
}
});
$("#rewardName").textbox({
required:false,
prompt: "活动名称"
});
$("#type").combobox({
valueField : "value",
textField : "text",
required:false,
prompt: "活动类型",
data:[{text:"全部",value:"8"},{text:"首发奖励",value:"3"},{text:"发布奖励",value:"1"},{text:"话题奖励",value:"2"}]
});
$("#valid").combobox({
valueField : "value",
textField : "text",
required:false,
prompt: "生效状态",
data:[{text:"全部",value:"8"},{text:"生效",value:"1"},{text:"失效",value:"2"}]
});
$("#status").combobox({
valueField : "value",
textField : "text",
required:false,
prompt: "启用状态",
data:[{text:"全部",value:"0"},{text:"启用",value:"1"},{text:"停用",value:"2"}]
});
$("#priorityOrder").combobox({
valueField : "value",
textField : "text",
required:false,
editable:false,
prompt: "优先级顺序",
data:[{text:"全部",value:"8"},{text:"降序",value:"1"},{text:"升序",value:"2"}]
});
// 检索按钮
$("#searchBtn").linkbutton({
iconCls : "icon-search",
onClick : function() {
// var startTime="";
// var endTime="";
// if ($("#startTimeStr").datetimebox('getValue')!='') {
// startTime = parseInt(new Date($("#startTimeStr").datetimebox('getValue')).getTime() );
// }
// if ($("#endTimeStr").datetimebox('getValue')!='') {
// endTime = parseInt(new Date($("#endTimeStr").datetimebox('getValue')).getTime() );
// }
$("#activityListTable").datagrid("load", {
type: $("#type").combobox("getValue"),
valid: $("#valid").combobox("getValue"),
status: $("#status").combobox("getValue"),
priorityOrder: $("#priorityOrder").combobox("getValue"),
rewardName: $("#rewardName").textbox("getValue")
// startTimeStr:startTime,
// endTimeStr:endTime,
});
}
});
$("#activityListTable").myDatagrid({
fit: true,
fitColumns: true,
striped: true,
queryParams: {
},
url: serverContextPath + "/grassRewards/getRewardsList",
method: 'POST',
loadFilter: function (data) {
var tmp = defaultLoadFilter(data);
tmp.rows = tmp.list;
return tmp;
},
columns: [[
{
title: "活动id",
field: "rewardId",
width: 25,
align: "center"
},
{
title: "活动名称",
field: "rewardName",
width: 25,
align: "left"
},
{
title: "活动描述",
field: "description",
width: 60,
align: "left"
},{
title: "类型",
field: "type",
width: 20,
align: "left",
formatter: function (value, rowData, rowIndex) {
var str = '';
if(rowData.type == '1'){
str = "发布奖励";
}
if(rowData.type == '2'){
str = "话题奖励";
}
if(rowData.type == '3'){
str = "首发奖励";
}
return str;
}
},{
title: "优先级",
field: "priority",
width: 30,
align: "left"
},{
title: "开始时间",
field: "startTimeStr",
width: 30,
align: "left"
},{
title: "结束时间",
field: "endTimeStr",
width: 20,
align: "left"
},{
title: "当前状态",
field: "valid",
width: 20,
align: "left",
formatter: function (value, rowData, rowIndex) {
var str = '';
if(rowData.valid == '1'){
str = "生效中";
}
if(rowData.valid == '2'){
str = "失效";
}
return str;
}
},{
title: "是否启用",
field: "status",
width: 20,
align: "left",
formatter: function (value, rowData, rowIndex) {
var str = '';
if(rowData.status == '1'){
str = "启用";
}
if(rowData.status == '2'){
str = "停用";
}
return str;
}
},
{
title: "操作",
field: "ddg",
width: 50,
align: "center",
formatter: function (value, rowData, rowIndex) {
var str='';
str += "<a role='edit'";
var classStr = "class='btn-success'";
str += classStr +" dataId='" + rowData.articleId +"' sort='"+ rowData.sort + "' index='"+ rowIndex + "' style='margin-left:10px'>";
var optStr = "编辑</a>" ;
str += optStr;
if(rowData.status == 1){
str += "<a role='switchR' class='btn-success' dataId='"+rowData.rewardId+ "' status='2' index='"+ rowIndex + "' style='margin-left:10px'>停用</a>";
}else{
str += "<a role='switchR' class='btn-success' dataId='"+rowData.rewardId+ "' status='1' index='"+ rowIndex + "' style='margin-left:10px'>启用</a>";
}
str += "<a role='deleteR' class='btn-success' dataId='"+rowData.rewardId+ "' index='"+ rowIndex + "' style='margin-left:10px'>删除</a>";
return str;
}
}
]],
cache: false,
pagination: true,
pageSize: 10,
pageList: [10],
idField: "id",
singleSelect: true,
onLoadSuccess: function (data) {
if(index != ""){
$(this).datagrid("scrollTo",index);
index = "";
}else{
$(this).datagrid("scrollTo",0);
}
$(this).datagrid("getPanel").find("a[role='edit']").linkbutton({
iconCls : "icon-edit",
onClick: function () {
var dataId = $(this).attr("dataId");
index = $(this).attr("index");
getEditDialog(data.rows[index]);
}
});
$(this).datagrid("getPanel").find("a[role='switchR']").linkbutton({
iconCls : "icon-edit",
onClick: function () {
var status = $(this).attr("status");
var dataId = $(this).attr("dataId");
index = $(this).attr("index");
var message = "";
if(status == 1){
message = "启用";
}
if(status == 2){
message = "停用";
}
$.messager.confirm("确认", "确认"+message+"吗?", function (flag) {
if(flag){
switchRecommend(dataId, status);
}
});
}
});
// 编辑
$(this).datagrid("getPanel").find("a[role='showDetail']").linkbutton({
iconCls : "icon-edit",
onClick : function() {
index = $(this).attr("index");
var articleId = $(this).attr("dataId");
var row = $("#activityListTable").datagrid('getData').rows[index];
getDetailDialog(row);
}
});
$(this).datagrid("getPanel").find("a[role='deleteR']").linkbutton({
iconCls : "icon-edit",
onClick: function () {
var dataId = $(this).attr("dataId");
$.messager.confirm("确认", "确认删除吗?", function (flag) {
if(flag){
$.post(serverContextPath + "/grassRewards/updateReward?operateType=3&rewardId=" + dataId + "&status=3" , function (data){
if(data.code != 200){
alert(data.message);
}else{
$("#activityListTable").datagrid("reload");
}
}, "json");
}
});
}
});
}
});
function switchRecommend(id, status) {
$.post(serverContextPath + "/grassRewards/updateReward?operateType=1&rewardId=" + id + "&status=" + status, function (data) {
if(data.code != 200){
alert(data.message);
}else{
$("#activityListTable").datagrid("reload");
}
}, "json");
}
// 编辑活动
function getEditDialog(data){
debugger
var activityList = $("<div id='activityList'>").appendTo($(document.body));
var title = data == null ? "新增活动":"编辑活动";
var textVar = data == null ? "保存":"保存";
var msgVar = data == null ? "确认新增活动吗?":"确认保存活动吗?";
var url = data == null ? serverContextPath + "/grassRewards/addReward" : serverContextPath + "/grassRewards/updateReward?operateType=2&";
window.self.paramObject.mkData = data;
$(activityList).myDialog({
title: title,
width: "70%",
height: "80%",
resizable:false,
buttons:[{
id : "saveBtn",
text:textVar,
iconCls : "icon-save",
handler:function(){
debugger;
$("#activityAddForm").form("submit", {
url: url,
onSubmit: function (param) {
if(data != null){
param.rewardId = data.rewardId;
}
var allRadio =$("#allRadio").prop("checked");
if(allRadio){
$("#allTopic").val("1");
}
if ($("#startTimeStr").datetimebox('getValue')!='') {
param.startTime = parseInt(new Date($("#startTimeStr").datetimebox('getValue')).getTime()/1000 );
}
if ($("#endTimeStr").datetimebox('getValue')!='') {
param.endTime = parseInt(new Date($("#endTimeStr").datetimebox('getValue')).getTime()/1000 );
}
if (!$("#activityAddForm").form("validate")) {
return false;
}
$.messager.progress({
title: "正在执行",
msg: "正在执行,请稍后..."
});
return true;
},
success: function (data) {
debugger;
$.messager.progress("close");
data = JSON.parse(data);
if (data.code == 200) {
$(activityList).dialog("close");
$("#activityListTable").datagrid("reload");
$.messager.show({
title: "提示",
msg: title + "成功!",
height: 120
});
} else {
$.messager.alert("失败", data.message, "error");
}
}
});
}
}, {
text: "关闭",
iconCls: "icon-cancel",
handler: function () {
$.messager.confirm("确认", "确认关闭吗?", function (flag) {
if(flag){
$(activityList).dialog("close");
}
});
}
}],
modal: true,
href: contextPath + "/html/grass/rewards/rewardsEdit.html"
});
}
});
</script>
</html>
\ No newline at end of file
... ...