Authored by 邱骏

签到逻辑

... ... @@ -28,12 +28,12 @@ const dailyCheckInController = {
* @returns {Promise.<void>}
*/
async actCreate(req, res) {
console.log(req.body);
const title = req.body.title;
const startTime = req.body.startTime;
const endTime = req.body.endTime;
const normalWheelId = req.body.normalWheelId || '';
let prizeDayArr = req.body.prizeDays ? JSON.parse(req.body.prizeDays) : [];
let prizeDayArr = req.body.prizeDayArr ? JSON.parse(req.body.prizeDayArr) : [];
if (!title || !startTime || !endTime || prizeDayArr.length === 0) {
return res.json({
... ... @@ -61,7 +61,77 @@ const dailyCheckInController = {
} catch (err) {
res.json(err);
}
},
/**
* 获取活动列表获取通过id获取单个活动信息
* @param req
* @param res
* @returns {Promise.<void>}
*/
async actList(req, res) {
try {
let result = await req.ctx(dailyCheckInModel).activityList();
return res.json({
code: 200,
data: result
});
} catch (err) {
return res.json(err);
}
},
/**
* 通过id获取单个活动信息
* @param req
* @param res
* @returns {Promise.<void>}
*/
async actInfo(req, res) {
let actId = req.query.id || 0;
if (!actId) {
return res.json({
code: 400,
message: '缺少参数'
});
}
let result = await req.ctx(dailyCheckInModel).actInfo(actId);
if (result.code !== 201) {
return res.json({
code: 200,
data: result
});
} else {
return res.json(result);
}
},
/**
* 通过id删除一个活动
* @param req
* @param res
* @returns {Promise.<void>}
*/
async actDelete(req, res) {
const id = req.body.id;
try {
const result = await req.ctx(dailyCheckInModel).actDelete(id);
return res.json({
code: 200,
data: result
});
} catch (err) {
return res.json(err);
}
}
};
module.exports = dailyCheckInController;
... ...
... ... @@ -2,8 +2,9 @@
* Created by qiujun on 2019/5/7.
*/
const _ = require('lodash');
const md5 = require('yoho-md5');
const ACTIVITY_TABLE = 'dailysignin:activity'; // 活动表
const aes = require('../../../utils/aes');
const PARENT_TABLE_NAME = 'dailysignin';
const TABLE_NAME = PARENT_TABLE_NAME + ':activity'; // 签到活动表
class ActDailyCheckInModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -14,9 +15,9 @@ class ActDailyCheckInModel extends global.yoho.BaseModel {
// 获取签到活动列表
async activityList() {
let length = await this.client.llenAsync(ACTIVITY_TABLE);
let length = await this.client.llenAsync(TABLE_NAME);
return this.client.lrangeAsync(ACTIVITY_TABLE, 0, length - 1).then(acts => {
return this.client.lrangeAsync(TABLE_NAME, 0, length - 1).then(acts => {
return acts.filter(act => act).map(act => {
return JSON.parse(act);
});
... ... @@ -25,13 +26,46 @@ class ActDailyCheckInModel extends global.yoho.BaseModel {
// 创建签到活动
async createActivity(data) {
let length = await this.client.llenAsync(ACTIVITY_TABLE);
let length = await this.client.llenAsync(TABLE_NAME);
data.id = length + 1;
data.encryptedId = md5(length + 1);
return this.client.rpushAsync(ACTIVITY_TABLE, JSON.stringify(data));
data.encryptedId = aes.encryptUid(length + 1);
return this.client.rpushAsync(TABLE_NAME, JSON.stringify(data));
}
/**
* 获取活动信息
* @param actId
* @returns {Promise.<void>}
*/
async actInfo(actId) {
let idx = parseInt(aes.decryptUid(actId), 10) - 1;
if (idx) {
return this.client.lrangeAsync(TABLE_NAME, idx, idx).then(act => {
return JSON.parse(act[0] || {});
});
} else {
return {
code: 201,
message: '无活动信息'
};
}
}
/**
* 删除活动
* @param id
* @returns {Promise.<*>}
*/
async actDelete(id) {
id = parseInt(aes.decryptUid(id), 10);
return this.client.lsetAsync(TABLE_NAME, id - 1, '');
}
}
... ...
... ... @@ -115,8 +115,13 @@ router.get('/wheelSurf/*', wheelSurf.entry);
// 签到活动管理
router.get('/dailyCheckIn', dailyCheckIn.entry);
router.get('/dailyCheckIn/*', dailyCheckIn.entry);
router.post('/dailyCheckIn/api/create', dailyCheckIn.actCreate);
router.post('/dailyCheckIn/api/create', dailyCheckIn.actCreate); // 创建签到活动
router.get('/dailyCheckIn/api/actList', dailyCheckIn.actList); // 获取活动列表
router.get('/dailyCheckIn/api/actInfo', dailyCheckIn.actInfo); // 获取活动信息
router.post('/dailyCheckIn/api/delete', dailyCheckIn.actDelete);
router.get('/dailyCheckIn/*', dailyCheckIn.entry);
module.exports = router;
... ...
/**
* 签到活动controller
* Created by qiujun on 2019/5/7.
*/
const dailyCheckInModel = require('../models/daily-check-in');
const dailyCheckInController = {
/**
* 普通签到
* @param req
* @param res
* @returns {Promise.<void>}
*/
async checkInNormal(req, res) {
let {actId, uid, sessionKey, appVersion, appSessionType} = req.body;
if (!actId) {
return res.json({
code: 400,
message: '缺少参数'
});
}
if (!parseInt(uid, 10) || !sessionKey || !appVersion || !appSessionType) {
return res.json({
code: 401,
message: '未登录'
});
}
let params = {
actId,
uid: parseInt(uid, 10),
sessionKey,
appVersion,
appSessionType
};
try {
let result = await req.ctx(dailyCheckInModel).checkInNormal(params);
return res.json(result);
} catch (err) {
return res.json(err);
}
},
async checkInCumulative(req, res) {
let {actId, uid, sessionKey, appVersion, appSessionType} = req.body;
if (!actId) {
return res.json({
code: 400,
message: '缺少参数'
});
}
if (!parseInt(uid, 10) || !sessionKey || !appVersion || !appSessionType) {
return res.json({
code: 401,
message: '未登录'
});
}
let params = {
actId,
uid: parseInt(uid, 10),
sessionKey,
appVersion,
appSessionType
};
try {
let result = await req.ctx(dailyCheckInModel).checkInCumulative(params);
return res.json(result);
} catch (err) {
return res.json(err);
}
},
/**
* 获取用户签到累计信息
* @param req
* @param res
* @returns {Promise.<void>}
*/
async getUserCumulativeData(req, res) {
let {actId, uid} = req.query;
if (!actId || !parseInt(uid, 10)) {
return res.json({
code: 400,
message: '缺少参数'
});
}
let params = {
actId,
uid: parseInt(uid, 10)
};
try {
req.ctx(dailyCheckInModel).getUserCumulativeData(params).then(result => {
if (result.code === 200) {
let cumDaysResult = [];
let cumDaysArr = [];
let cumPrizeResult = result.cumPrize;
result.cumDays.map(ret => {
if (ret.createTime) {
cumDaysArr.push(ret.createTime);// 把签到时间拿出来,用于签到日期列表
cumDaysResult.push({ // 每次签到获得的奖品
prizeId: ret.prizeId,
prizeImg: ret.prizeImg,
prizeDesc: ret.prizeDesc,
prizeType: ret.prizeType,
createTime: ret.createTime
});
}
});
return res.json({
code: 200,
actId: actId,
uid: uid,
data: {
signDays: cumDaysArr,
cumDays: cumDaysResult,
cumPrize: cumPrizeResult
}
});
} else {
return res.json(result);
}
});
} catch (err) {
return res.json(err);
}
},
/**
* 保存用户信息
* @param req
* @param res
* @returns {Promise.<void>}
*/
async saveUserInfo(req, res) {
let {uid, actId, phone, nickname} = req.body;
let regExp = /^1[34578]\d{9}$/;
if (!actId || !uid || !phone || phone.toString().length !== 11 || !nickname) {
return res.json({
code: 400,
message: '缺少参数'
});
}
if (!regExp.test(phone)) {
return res.json({
code: 400,
message: '错误的手机号码格式'
});
}
let params = {
actId,
uid,
phone,
nickname
};
try {
let result = await req.ctx(dailyCheckInModel).saveUserInfo(params);
return res.json(result);
} catch (err) {
return res.json(err);
}
},
/**
* 获取用户是否填写过手机号的信息
* @param req
* @param res
* @returns {Promise.<void>}
*/
async getUserInfo(req, res) {
let {uid, actId} = req.query;
if (!actId || !uid) {
return res.json({
code: 400,
message: '缺少参数'
});
}
try {
let result = await req.ctx(dailyCheckInModel).getUserInfo({actId, uid});
return res.json(result);
} catch (err) {
return res.json(err);
}
},
/**
* 获取所有实物中奖人员列表
* @param req
* @param res
* @returns {Promise.<void>}
*/
async getWinnerList(req, res) {
let {actId} = req.query;
if (!actId) {
return res.json({
code: 400,
message: '缺少参数'
});
}
try {
let result = await req.ctx(dailyCheckInModel).getWinnerList({actId: actId});
return res.json({
code: 200,
data: result
});
} catch (err) {
return res.json(err);
}
}
};
module.exports = dailyCheckInController;
... ...
/**
* 签到活动model
* Created by qiujun on 2019/5/7.
*/
const _ = require('lodash');
const aes = require('../../../utils/aes');
const WheelSurfModel = require('./wheel-surf');
const PARENT_TABLE_NAME = 'dailysignin';
const TABLE_NAME = PARENT_TABLE_NAME + ':activity';
class ActDailyCheckIn extends global.yoho.BaseModel {
class DailyCheckInModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.redis = global.yoho.redis;
this.client = this.redis.client;
this.wheelSurfModel = new WheelSurfModel(ctx);
}
/**
* 获取活动信息
* @param actId
* @returns {Promise.<void>}
*/
async getActInfo(actId) {
let idx = 0;
try {
idx = parseInt(aes.decryptUid(actId), 10) - 1;
} catch (err) {
return {
code: 203,
message: '无活动信息'
};
}
if (idx) {
return this.client.lrangeAsync(TABLE_NAME, idx, idx).then(act => {
return JSON.parse(act[0]);
});
} else {
return {
code: 203,
message: '无活动信息'
};
}
}
/**
* 每日签到
* @param data
* @returns {Promise.<void>}
*/
async checkInNormal(data) {
if (data.uid && data.actId) {
let actInfo = await this.getActInfo(data.actId);
if (actInfo.code && actInfo.code === 203) { // 无活动信息,返回
return actInfo;
}
let now = new Date(); // 今天的日期用于判断
if (now.getTime() < parseInt(actInfo.startTime, 10) * 1000) {
return {
code: 203,
message: '活动未开始'
};
}
if (now.getTime() > parseInt(actInfo.endTime, 10) * 1000) {
return {
code: 203,
message: '活动已结束'
};
}
let normalWheelId = actInfo.normalWheelId;
let checkInKey = `${PARENT_TABLE_NAME}:${actInfo.id}:user:${data.uid}:checkin`;
let params = {
act_id: normalWheelId,
uid: data.uid,
sessionKey: data.sessionKey,
appVersion: data.appVersion,
appSessionType: data.appSessionType
};
let getUserCheckInData = await this.client.zrevrangeAsync(checkInKey, 0, 0); // 查询用户最近一次签到信息
let isChecked = false;
if (getUserCheckInData && getUserCheckInData.length > 0) { // 如果有签到信息,判断是否是今日签到的
let checkInData = JSON.parse(getUserCheckInData[0]);
let date = new Date(checkInData.createTime);
if ((new Date(date.toLocaleDateString())).getTime() >= (new Date(now.toLocaleDateString())).getTime()) {
isChecked = true;
}
}
if (!isChecked) { // 没有签到的情况下,签到
return this.wheelSurfModel.goPrize(params).then(prize => {
// console.log(prize);
if (prize.name && prize.type) { // 从大转盘接口返回的奖品信息
let score = (new Date()).getTime();
let checkInData = {
actId: data.actId,
wheelId: normalWheelId,
prizeId: prize.id,
prizeImg: prize.img,
prizeDesc: prize.desc,
prizeType: prize.type,
createTime: score
};
// console.log('checkInData=', checkInData);
return this.client.zaddAsync(checkInKey, score, JSON.stringify(checkInData)).then(() => {
return Object.assign({}, {code: 200}, checkInData);
});
} else {
return {
code: 205,
message: '未中奖',
data: prize
};
}
});
} else {
return {
code: 201,
message: '今天已经签到过咯~'
};
}
}
}
/**
* 对于实物中奖的用户,保存其中奖信息
* @param data
* @returns {Promise.<void>}
*/
async saveUserInfo(data) {
if (data.uid && data.actId) {
let actId;
try {
actId = parseInt(aes.decryptUid(data.actId), 10);
} catch (err) {
return {
code: 203,
message: '无活动信息'
};
}
let userPhoneKey = `${PARENT_TABLE_NAME}:${actId}:user:${data.uid}:info`;
let allPrizeKey = `${PARENT_TABLE_NAME}:${actId}:prizelist`;
let userCumulativeData = await this.getUserCumulativeData({uid: data.uid, actId: data.actId});
if (userCumulativeData.cumPrize.length > 0) {
let userInfo = await this.getUserInfo(data);
if (!userInfo.hasPhoneNum) {
let hasRealPrize = false; // 是否存在实物奖品
let realPrizeArr = []; // 临时存储中到的实物奖品
for (let i = 0; i < userCumulativeData.cumPrize.length; i++) {
let prize = userCumulativeData.cumPrize[i];
if (prize.prizeType === 4) {
hasRealPrize = true;
realPrizeArr.push(prize);
}
}
// console.log('real:', realPrizeArr)
if (hasRealPrize) { // 有实物奖品的情况下
let score = (new Date()).getTime();
let phoneData = {
phone: data.phone.toString(),
nickname: data.nickname,
uid: data.uid
};
return this.client.zaddAsync(userPhoneKey, score, JSON.stringify(phoneData)).then(async() => { // 往用户信息表添加信息
let finalResult = [];
for (let j = 0; j < realPrizeArr.length; j++) {
let prize = realPrizeArr[j];
let prizeData = {
id: parseInt(phoneData.uid, 10).toString(16), // 隐藏一下真实uid
nickname: phoneData.nickname,
daysCount: prize.daysCount,
phone: phoneData.phone.substring(0, 3) + '****' + phoneData.phone.substring(7, 11),
prizeName: prize.prizeDesc.replace('恭喜您获得', '')
};
let result = await this.client.zaddAsync(allPrizeKey, score, JSON.stringify(prizeData)); // 往中奖公布列表添加数据
finalResult.push(result);
}
return {
code: 200,
data: finalResult,
message: '保存成功'
};
});
} else {
return {
code: 204,
message: '无实物奖品中奖信息'
};
}
} else {
return {
code: 203,
message: '您已填写过手机号,请勿重复提交'
};
}
} else {
return {
code: 204,
message: '无中奖信息'
};
}
}
}
/**
* 获取用户是否填写过手机号信息
* @param data
* @returns {Promise.<void>}
*/
async getUserInfo(data) {
if (data.uid && data.actId) {
let actId;
try {
actId = parseInt(aes.decryptUid(data.actId), 10);
} catch (err) {
return {
code: 203,
message: '无活动信息'
};
}
let userPhoneKey = `${PARENT_TABLE_NAME}:${actId}:user:${data.uid}:info`;
let userInfo = await this.client.zrangeAsync(userPhoneKey, 0, 0);
if (userInfo && userInfo.length > 0) {
return {
code: 200,
hasPhoneNum: 1
};
} else {
return {
code: 203,
hasPhoneNum: 0
};
}
}
}
/**
* 获取此次活动所有获得实物奖品的人员列表
* @param data
* @returns {Promise.<void>}
*/
async getWinnerList(data) {
if (data.actId) {
let actId;
try {
actId = parseInt(aes.decryptUid(data.actId), 10);
} catch (err) {
return {
code: 203,
message: '无活动信息'
};
}
let prizeListKey = `${PARENT_TABLE_NAME}:${actId}:prizelist`;
return this.client.zrevrangeAsync(prizeListKey, 0, -1).then(result => {
return result.map(ret => {
return JSON.parse(ret);
});
});
}
}
/**
* 累计签到
* @param data
* @returns {Promise.<void>}
*/
async checkInCumulative(data) {
if (data.uid && data.actId) {
let actInfo = await this.getActInfo(data.actId);
let userCumulativeData = await this.getUserCumulativeData({uid: data.uid, actId: data.actId});
if (actInfo.code && actInfo.code === 203) { // 无活动信息,返回
return actInfo;
}
if (actInfo.prizeDayArr && actInfo.prizeDayArr.length > 0) {
let totalDays = userCumulativeData.cumDays.length; // 累计已签到天数
let prizeKey = `${PARENT_TABLE_NAME}:${actInfo.id}:user:${data.uid}:prize`;
if (totalDays > 0) {
for (let i = 0; i < actInfo.prizeDayArr.length; i++) {
let day = actInfo.prizeDayArr[i]; // 配置的累计天数信息
let daysCount = parseInt(day.count, 10); // 当前循环中累计天数的数量
let wheelId = day.wheelId; // 累计天数信息中配置的大转盘id
let params = {
act_id: wheelId,
uid: data.uid,
sessionKey: data.sessionKey,
appVersion: data.appVersion,
appSessionType: data.appSessionType
};
// console.log('totalDays:', totalDays, '&daysCount:', daysCount, '&day:', day);
// console.log('userCumulativeData:', userCumulativeData.cumPrize);
if (totalDays >= daysCount) { // 比较累计签到的天数是否大于活动设定的累计签到天数
if (userCumulativeData.cumPrize.length > 0) { // 如果获得过签到奖品,则判断是否是已领取过对应的累计奖励
let isGet = false;
for (let j = 0; j < userCumulativeData.cumPrize.length; j++) {
let prizeGet = userCumulativeData.cumPrize[j];
if (parseInt(prizeGet.daysCount, 10) === daysCount) { // 如果获得的累计奖品的天数和当前循环的累计天数相同
isGet = true;
}
}
if (!isGet) {
return this.wheelSurfModel.goPrize(params).then(prize => { // 调用对应的大转盘获取奖品返回
// console.log('prize_' + totalDays + '_' + daysCount, prize);
if (prize.name && prize.type) {
let score = (new Date()).getTime();
let checkInData = {
actId: data.actId,
wheelId: wheelId,
prizeId: prize.id,
prizeImg: prize.img,
prizeDesc: prize.desc,
prizeType: prize.type,
daysCount: daysCount,
createTime: score
};
return this.client.zaddAsync(prizeKey, score, JSON.stringify(checkInData)).then(() => {
return Object.assign({}, {code: 200}, checkInData);
});
}
});
}
} else { // 如果没有获得过累计签到的奖品
return this.wheelSurfModel.goPrize(params).then(prize => { // 调用对应的大转盘获取奖品返回
// console.log('prize:', prize);
if (prize.name && prize.type) {
let score = (new Date()).getTime();
let checkInData = {
actId: data.actId,
wheelId: wheelId,
prizeId: prize.id,
prizeImg: prize.img,
prizeDesc: prize.desc,
prizeType: prize.type,
daysCount: daysCount,
createTime: score
};
return this.client.zaddAsync(prizeKey, score, JSON.stringify(checkInData)).then(() => {
return Object.assign({}, {code: 200}, checkInData);
});
}
});
}
} else {
return {
code: 202,
message: '未满足累计天数要求'
};
}
}
// 循环内全部未返回,则默认返回
return {
code: 202,
message: '未满足累计天数要求'
};
} else { // 累计签到天数为0返回
return {
code: 202,
message: '未满足累计天数要求'
};
}
} else {
return {
code: 201,
message: '无累计抽奖可用'
};
}
}
}
/**
* 获取签到累计天数
* @param data
* @returns {Promise.<{cumDays: *, cumGeted: (*|Array)}>}
*/
async getUserCumulativeData(data) {
if (data.uid && data.actId) {
let actId = 0;
try {
actId = parseInt(aes.decryptUid(data.actId), 10);
} catch (err) {
return {
code: 203,
message: '无活动信息'
};
}
if (actId) {
let checkInKey = `${PARENT_TABLE_NAME}:${actId}:user:${data.uid}:checkin`;
let cumPrizeKey = `${PARENT_TABLE_NAME}:${actId}:user:${data.uid}:prize`;
let cumDays = await this.client.zrangeAsync(checkInKey, 0, -1); // 已签到天数
let cumPrizeGeted = await this.client.zrangeAsync(cumPrizeKey, 0, -1); // 已获得的累计签到奖励
let cumDaysResult = [];
let cumPrizeResult = [];
cumDays.map(day => {
cumDaysResult.push(JSON.parse(day));
});
cumPrizeGeted.map(prize => {
cumPrizeResult.push(JSON.parse(prize));
});
return {
code: 200,
cumDays: cumDaysResult,
cumPrize: cumPrizeResult
};
}
}
}
}
module.exports = ActDailyCheckIn;
module.exports = DailyCheckInModel;
... ...
... ... @@ -186,6 +186,8 @@ class ActWheelSurfModelRedis extends global.yoho.BaseModel {
return conf;
});
let residueCount;
let uid = {
toString: () => {
... ...
... ... @@ -20,6 +20,7 @@ const coupon511 = require('./controllers/coupon511');
const common = require('./controllers/common');
const mutilpartMiddleware = multipart();
const yohoActivitys = require('./controllers/yoho-activitys');
const dailyCheckIn = require('./controllers/daily-check-in');
router.get('/gettoken', qiniu.getToken);
router.get('/share/getSignPackage', wechat.getSignPackage);
... ... @@ -96,4 +97,12 @@ router.get('/activity/yohoActivitys/getArticleList', yohoActivitys.getArticleLis
router.post('/activity/yohoActivitys/addLike', yohoActivitys.addLike);// 给对应文章点赞
// router.get('/activity/yohoActivitys/removeRangeByRand', yohoActivitys.removeRangeByRand); // 删除所有文章
// 签到活动
router.post('/activity/checkIn/checkInNormal', dailyCheckIn.checkInNormal);// 每日签到
router.get('/activity/checkIn/getUserCumulativeData', dailyCheckIn.getUserCumulativeData); // 获取签到信息
router.post('/activity/checkIn/checkInCumulative', dailyCheckIn.checkInCumulative);// 累计签到
router.post('/activity/checkIn/saveUserInfo', dailyCheckIn.saveUserInfo); // 保存用户信息
router.get('/activity/checkIn/getWinnerList', dailyCheckIn.getWinnerList); // 获取实物奖品中奖用户
router.get('/activity/checkIn/getUserInfo', dailyCheckIn.getUserInfo); // 获取用户信息
module.exports = router;
... ...
... ... @@ -20,13 +20,13 @@ module.exports = {
// yohoVerifyUdid: '0f626ede-0e17-460b-a8ea-069ee506e8e9',
domains: {
// api: 'http://api-test3.dev.yohocorp.com/',
// service: 'http://api-test3.dev.yohocorp.com/',
// singleApi: 'http://api-test3.yohops.com:9999/',
api: 'http://api-test3.dev.yohocorp.com/',
service: 'http://api-test3.dev.yohocorp.com/',
singleApi: 'http://api-test3.yohops.com:9999/',
singleApi: 'http://api.yoho.cn/',
api: 'http://api.yoho.cn/',
service: 'http://service.yoho.cn/',
// singleApi: 'http://api.yoho.cn/',
// api: 'http://api.yoho.cn/',
// service: 'http://service.yoho.cn/',
ufo: 'http://2.yohobuy.com',
store: 'http://192.168.102.47:8080/portal-gateway/wechat/',
serviceNotify: 'http://service.yoho.cn/',
... ...
... ... @@ -20,17 +20,17 @@
<Input v-model="normalWheelId" placeholder="平时每日领取对应的大转盘id" style="width: 400px;"></Input>
</FormItem>
<FormItem label="第一次累计天数">
<Input v-model="days1.count" placeholder="第一次累计天数" style="width: 100px;" type="number"></Input>
<Input v-model="days1.count" placeholder="第一次累计天数" style="width: 100px;"></Input>
转盘ID
<Input v-model="days1.wheelId" placeholder="对应的大转盘id" style="width: 200px;"></Input>
</FormItem>
<FormItem label="第二次累计天数">
<Input v-model="days2.count" placeholder="第二次累计天数" style="width: 100px;" type="number"></Input>
<Input v-model="days2.count" placeholder="第二次累计天数" style="width: 100px;"></Input>
转盘ID
<Input v-model="days2.wheelId" placeholder="对应的大转盘id" style="width: 200px;"></Input>
</FormItem>
<FormItem label="第三次累计天数">
<Input v-model="days3.count" placeholder="第二次累计天数" style="width: 100px;" type="number"></Input>
<Input v-model="days3.count" placeholder="第二次累计天数" style="width: 100px;"></Input>
转盘ID
<Input v-model="days3.wheelId" placeholder="对应的大转盘id" style="width: 200px;"></Input>
</FormItem>
... ... @@ -68,6 +68,9 @@
}
};
},
mounted() {
},
methods: {
dateTimeChange(range) {
this.startTime = range[0];
... ... @@ -76,15 +79,16 @@
save() {
let prizeDayArr = [];
if (this.days1.count && this.days1.wheelId) { // 第一次累计
if (parseInt(this.days1.count, 10) && this.days1.wheelId) { // 第一次累计
prizeDayArr.push(this.days1);
if (this.days2.count && this.days2.wheelId) { // 第二次累计
if (this.days2.count <= this.days1.count) {
if (parseInt(this.days2.count, 10) && this.days2.wheelId) { // 第二次累计
if (parseInt(this.days2.count, 10) <= parseInt(this.days1.count, 10)) {
return alert('第二次的天数必须大于第一次的天数');
} else {
prizeDayArr.push(this.days2);
if (this.days3.count && this.days3.wheelId) { // 第三次累计
if (this.days3.count <= this.days2.count) {
if (parseInt(this.days3.count, 10) && this.days3.wheelId) { // 第三次累计
if (parseInt(this.days3.count, 10) <= parseInt(this.days2.count, 10)) {
return alert('第三次的天数必须大于第二次的天数');
} else {
prizeDayArr.push(this.days3);
... ... @@ -94,6 +98,19 @@
}
}
if (!this.title) {
return alert('清填写标题');
}
if (!this.startTime || !this.endTime) {
return alert('请选择开始结束时间');
}
if (!this.normalWheelId) {
return alert('请填写每日领取的大转盘ID');
}
$.ajax({
method: 'post',
url: '/admin/dailyCheckIn/api/create',
... ... @@ -105,10 +122,11 @@
prizeDayArr: JSON.stringify(prizeDayArr)
}
}).then(res => {
console.log(res);
// this.$router.push({name: 'list'});
if (res.code === 200) {
this.$router.push({name: 'list'});
} else {
alert('创建失败');
}
});
},
... ...
... ... @@ -14,60 +14,61 @@
columns1: [
{
title: '活动ID',
key: 'encryptedId'
key: 'encryptedId',
align: 'center'
},
{
title: '活动标题',
key: 'title'
key: 'title',
align: 'center'
},
{
title: '开始时间',
key: 'startTime',
width: 200,
align: 'center',
render: (h, {row}) => {
return h('span', {}, moment(row.startTime * 1000).format('YYYY-MM-DD HH:mm:ss '));
console.log(row);
return h('span', {}, moment(row.startTime * 1000).format('YYYY-MM-DD'));
}
},
{
title: '结束时间',
key: 'endTime',
width: 200,
align: 'center',
render: (h, {row}) => {
return h('span', {}, moment(row.endTime * 1000).format('YYYY-MM-DD HH:mm:ss '));
return h('span', {}, moment(row.endTime * 1000).format('YYYY-MM-DD'));
}
},
{
title: '每日大转盘',
key: 'normalWheelId',
align: 'center'
},
{
title: '累计信息',
key: 'prizeDayArr',
align: 'center',
render: (h, {row}) => {
let elements = [];
for (let i = 0; i < row.prizeDayArr.length; i++) {
let prize = row.prizeDayArr[i];
elements.push(h('span', {style: {display: 'inline-block', borderBottom: '1px solid lightgray'}}, '满' + prize.count + '天: ' + prize.wheelId));
}
return h('div', elements);
}
},
{
title: '操作',
align: 'center',
render: (h, {row}) => {
return h('div', [
h('Button', {
props: {
type: 'primary',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.conf(row.encryptedId);
}
}
}, '配置'),
h('Button', {
props: {
type: 'success',
size: 'small'
},
style: {
marginRight: '5px'
},
on: {
click: () => {
this.prizeSent(row.encryptedId);
}
}
}, '中奖一览'),
h('Button', {
props: {
type: 'error',
size: 'small'
},
... ... @@ -102,7 +103,7 @@
onOk: () => {
$.ajax({
method: 'post',
url: '/admin/wheelSurf/api/delete',
url: '/admin/dailyCheckIn/api/delete',
data: {id}
}).then(() => {
this.list();
... ... @@ -112,7 +113,7 @@
},
list() {
$.ajax({
url: '/admin/wheelSurf/api/list',
url: '/admin/dailyCheckIn/api/actList',
}).then(res => {
this.data = res.data;
});
... ...