Authored by 邱骏

签到

/**
* 签到活动controller
* Created by qiujun on 2019/5/7.
*/
const moment = require('moment');
const dailyCheckInModel = require('../models/daily-check-in');
const dailyCheckInController = {
entry(req, res) {
if (req.xhr) {
return res.json({
code: 404,
message: 'invalid url'
});
}
res.render('activity/daily-check-in', {
bodyClass: 'nav-md',
module: 'admin',
page: 'daily-check-in'
});
},
/**
* 创建活动
* @param req
* @param res
* @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) : [];
if (!title || !startTime || !endTime || prizeDayArr.length === 0) {
return res.json({
code: 400,
message: '缺少参数'
});
}
const params = {
title,
startTime,
endTime,
normalWheelId,
prizeDayArr
};
try {
const result = await req.ctx(dailyCheckInModel).createActivity(params);
return res.json({
code: 200,
data: result
});
} catch (err) {
res.json(err);
}
}
};
module.exports = dailyCheckInController;
... ...
/**
* Created by qiujun on 2019/5/7.
*/
const _ = require('lodash');
const md5 = require('yoho-md5');
const ACTIVITY_TABLE = 'dailysignin:activity'; // 活动表
class ActDailyCheckInModel extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.redis = global.yoho.redis;
this.client = this.redis.client;
}
// 获取签到活动列表
async activityList() {
let length = await this.client.llenAsync(ACTIVITY_TABLE);
return this.client.lrangeAsync(ACTIVITY_TABLE, 0, length - 1).then(acts => {
return acts.filter(act => act).map(act => {
return JSON.parse(act);
});
});
}
// 创建签到活动
async createActivity(data) {
let length = await this.client.llenAsync(ACTIVITY_TABLE);
data.id = length + 1;
data.encryptedId = md5(length + 1);
return this.client.rpushAsync(ACTIVITY_TABLE, JSON.stringify(data));
}
}
module.exports = ActDailyCheckInModel;
... ...
... ... @@ -12,6 +12,7 @@ const coupon = require('./controllers/coupon');
const multipart = require('connect-multiparty');
const guochao = require('./controllers/guochao');
const wheelSurf = require('./controllers/wheel-surf');
const dailyCheckIn = require('./controllers/daily-check-in');
const mutilpartMiddleware = multipart();
// 管理员[page]
... ... @@ -112,5 +113,10 @@ router.get('/wheelSurf/api/prize/exportRecords', wheelSurf.exportRecords);
router.get('/wheelSurf/*', wheelSurf.entry);
// 签到活动管理
router.get('/dailyCheckIn', dailyCheckIn.entry);
router.get('/dailyCheckIn/*', dailyCheckIn.entry);
router.post('/dailyCheckIn/api/create', dailyCheckIn.actCreate);
module.exports = router;
... ...
<!-- page content -->
<div class="vue-app-container">
<App></App>
</div>
<!-- /page content -->
... ...
/**
* Created by qiujun on 2019/5/7.
*/
... ...
/**
* Created by qiujun on 2019/5/7.
*/
class ActDailyCheckIn extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
}
module.exports = ActDailyCheckIn;
... ...
... ... @@ -40,7 +40,7 @@ module.exports = {
corsAllowOrigin: [
'http://localhost:8081',
'http://localhost:8888',
'http://localhost:8080',
'http://localhost:8080',
'http://localhost:1234',
'http://localhost:63342',
'http://huodong.yoho.cn',
... ...
... ... @@ -54,6 +54,8 @@
<li><a href="/admin/activity/upload_excel">上传Y100excel</a></li>
<li><a href="/admin/activity/zerobuy">0元购</a></li>
<li><a href="/admin/wheelSurf">大转盘</a></li>
<li><a href="/admin/dailyCheckIn">累计签到活动</a></li>
<li><a href="/admin/dailyCheckInCreate" style="display: none">签到活动创建</a></li>
</ul>
</li>
<li><a><i class="fa fa-users"></i> 用户管理 <span class="fa fa-chevron-down"></span></a>
... ...
import Vue from 'vue';
import VueRouter from 'vue-router';
import iView from 'iview';
import App from 'vue@/App.vue';
import {list, create} from 'vue@/daily-check-in';
import 'admin/daily-check-in.page.css';
import 'iview/dist/styles/iview.css';
Vue.use(VueRouter);
Vue.use(iView);
const router = new VueRouter({
routes: [
{path: '/admin/dailyCheckIn', name: 'list', component: list},
{path: '/admin/dailyCheckIn/create', name: 'create', component: create}
],
mode: 'history'
});
new Vue({
el: '.vue-app-container',
components: {
App
},
router
});
... ...
<template>
<div>
<div class="row">
<div class="col-md-12 col-sm-12 col-xs-12">
<div class="x_panel">
<div class="x_title">
<h2>签到活动创建</h2>
<div class="clearfix"></div>
</div>
<div class="x_content">
<Form>
<FormItem label="活动名称">
<Input v-model="title" placeholder="活动名称" style="width: 400px"></Input>
</FormItem>
<FormItem label="活动时间">
<DatePicker type="daterange" placeholder="开始时间-结束时间"
style="width: 400px" @on-change="dateTimeChange"></DatePicker>
</FormItem>
<FormItem label="每日领取大转盘ID">
<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>
转盘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>
转盘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>
转盘ID
<Input v-model="days3.wheelId" placeholder="对应的大转盘id" style="width: 200px;"></Input>
</FormItem>
<FormItem>
<Button type="primary" @click="save">保存</Button>
<Button style="margin-left: 8px" @click="cancel">取消</Button>
</FormItem>
</Form>
</div>
</div>
</div>
</div>
</div>
</template>
<script>
import moment from 'moment';
export default {
data() {
return {
title: '',
startTime: '',
endTime: '',
normalWheelId: '',
days1: {
count: 0,
wheelId: ''
},
days2: {
count: 0,
wheelId: ''
},
days3: {
count: 0,
wheelId: ''
}
};
},
methods: {
dateTimeChange(range) {
this.startTime = range[0];
this.endTime = range[1];
},
save() {
let prizeDayArr = [];
if (this.days1.count && this.days1.wheelId) { // 第一次累计
prizeDayArr.push(this.days1);
if (this.days2.count && this.days2.wheelId) { // 第二次累计
if (this.days2.count <= this.days1.count) {
return alert('第二次的天数必须大于第一次的天数');
} else {
prizeDayArr.push(this.days2);
if (this.days3.count && this.days3.wheelId) { // 第三次累计
if (this.days3.count <= this.days2.count) {
return alert('第三次的天数必须大于第二次的天数');
} else {
prizeDayArr.push(this.days3);
}
}
}
}
}
$.ajax({
method: 'post',
url: '/admin/dailyCheckIn/api/create',
data: {
title: this.title,
startTime: moment(this.startTime).format('X'),
endTime: moment(this.endTime).format('X'),
normalWheelId: this.normalWheelId,
prizeDayArr: JSON.stringify(prizeDayArr)
}
}).then(res => {
console.log(res);
// this.$router.push({name: 'list'});
});
},
cancel() {
this.$router.push({name: 'list'});
}
},
components: {
}
};
</script>
<style>
</style>
... ...
import list from './list';
import create from './create';
export {
list,
create
};
... ...
<template>
<div class="list">
<Button type="primary" class="create-btn" @click="toCreate">创建新活动</Button>
<div class="activity-list">
<Table :columns="columns1" :data="data"></Table>
</div>
</div>
</template>
<script>
import moment from 'moment';
module.exports = {
data() {
return {
columns1: [
{
title: '活动ID',
key: 'encryptedId'
},
{
title: '活动标题',
key: 'title'
},
{
title: '开始时间',
key: 'startTime',
render: (h, {row}) => {
return h('span', {}, moment(row.startTime * 1000).format('YYYY-MM-DD HH:mm:ss '));
}
},
{
title: '结束时间',
key: 'endTime',
render: (h, {row}) => {
return h('span', {}, moment(row.endTime * 1000).format('YYYY-MM-DD HH:mm:ss '));
}
},
{
title: '操作',
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'
},
on: {
click: () => {
this.delete(row.encryptedId);
}
}
}, '删除')
]);
}
}
],
data: []
};
},
methods: {
toCreate() {
this.$router.push({name: 'create'});
},
conf(actId) {
this.$router.push({name: 'conf', query: {actId}});
},
prizeSent(actId) {
this.$router.push({name: 'prizeSent', query: {actId}});
},
delete(id) {
this.$Modal.confirm({
title: '删除',
content: '删除后不可恢复,确认删除?',
cancelText: '取消',
onOk: () => {
$.ajax({
method: 'post',
url: '/admin/wheelSurf/api/delete',
data: {id}
}).then(() => {
this.list();
});
}
});
},
list() {
$.ajax({
url: '/admin/wheelSurf/api/list',
}).then(res => {
this.data = res.data;
});
}
},
created() {
this.list();
}
};
</script>
<style lang="scss">
.activity-list {
width: 100%;
}
.create-btn {
margin-bottom: 10px;
}
</style>
... ...