Authored by yyq

export

... ... @@ -315,7 +315,7 @@ module.exports = class extends global.yoho.BaseModel {
if (info && info.length && !isRetry) {
return this.createPrizeCode(length, true);
} else {
return prizeCode;
return '';
}
}
... ...
... ... @@ -31,9 +31,31 @@ const zeroBuy = {
}));
}).catch(next);
},
zeroBuyStatusEdit(req, res, next) {
req.ctx(ActivityModel).editZerobuyStatus(req.body.id, req.body.status)
zeroBuySwitch(req, res, next) {
console.log(req.body.on ? 1 : 0);
req.ctx(ActivityModel).editZerobuyStatus(req.body.id, req.body.on ? 1 : 0)
.then(res.json).catch(next);
},
zeroBuyPublish(req, res, next) {
req.ctx(ActivityModel).editZerobuyStatus(req.body.id, 2)
.then(res.json).catch(next);
},
zeroBuyExport(req, res, next) {
let id = req.query.id;
if (!id) {
return res.json({
code: 400,
message: INVALID_PARAMS
});
}
req.ctx(ActivityModel).getZerobuyExportList(req.query.id)
.then(result => {
res.setHeader('Content-Type', 'application/vnd.openxmlformats');
res.setHeader('Content-Disposition', `attachment; filename=zerobuy_${id}_${new Date().getTime()}.xlsx`);
res.end(excelExport.execute(result), 'binary');
}).catch(next);
}
};
... ...
... ... @@ -6,6 +6,8 @@
const mysqlCli = global.yoho.utils.mysqlCli;
const _ = require('lodash');
const moment = require('moment');
const pager = require('../../../utils/pager');
const TB_USER = 'user';
... ... @@ -18,7 +20,15 @@ const TB_ACT_ARTICLE_Y100 = 'act_article_y100';
const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product';
// const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content';
// const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user';
const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user';
const timeFormat = (time) => {
if (_.isNumber(time)) {
time = moment.unix(time);
}
return moment(time).format('YYYY-MM-DD HH:mm:ss');
};
class AdminModel extends global.yoho.BaseModel {
constructor(ctx) {
... ... @@ -458,11 +468,11 @@ class AdminModel extends global.yoho.BaseModel {
* @returns {*}
*/
editZerobuyStatus(id, status) {
if (!id || !status) {
return {
if (!id || !_.inRange(status, 0, 3)) {
return Promise.resolve({
code: 400,
message: '缺少参数'
};
});
}
return mysqlCli.update(`update ${TABLE_ACT_PRIZE_PRODUCT} set status = :status where id = :id`, {
... ... @@ -475,6 +485,86 @@ class AdminModel extends global.yoho.BaseModel {
};
});
}
getZerobuyExportList(id) {
return Promise.all([
mysqlCli.query(`select uid, user_name, prize_code, is_share_take, share_uid, create_time
from ${TABLE_ACT_PRIZE_PRODUCT_USER} where act_prize_id = :id
order by create_time asc`, {id}),
mysqlCli.query(`select 'limit' from ${TABLE_ACT_PRIZE_PRODUCT}
where id = :id limit 1`, {id})
]).then(result => {
let [codes, product] = result;
const limit = _.get(product, '[0].limit', 0);
let users = {};
let userNum = 0;
let rows = [];
let index = 0;
_.forEach(codes, value => {
if (userNum >= limit) {
return;
}
if (!users[value.uid]) {
userNum++;
users[value.uid] = 1;
}
if (userNum >= limit && !users[value.uid]) {
return;
}
rows.push([
++index,
value.uid,
value.user_name,
value.prize_code,
value.is_share_take ? '是' : '',
value.share_uid ? value.share_uid : '',
timeFormat(value.create_time)
]);
});
return {
name: 'sheet',
cols: [
{
caption: '编号',
type: 'number'
},
{
caption: 'uid',
type: 'number'
},
{
caption: '昵称',
type: 'string'
},
{
caption: '邀请码',
type: 'string'
},
{
caption: '是否分享获得',
type: 'string'
},
{
caption: '邀请者',
type: 'string'
},
{
caption: '获得时间',
type: 'string'
}
],
rows
};
});
}
}
module.exports = AdminModel;
... ...
... ... @@ -21,7 +21,9 @@ router.get('/activity/createY100Article', activity.createY100ArticlePage);
router.get('/activity/y100Article', activity.actY100ArticleListPage);
router.get('/activity/upload_excel', activity.uploadExcelPage);
router.get('/activity/zerobuy', activity.zeroBuyList);
router.post('/activity/zerobuy/editStatus', activity.zeroBuyStatusEdit);
router.post('/activity/zerobuy/switch', activity.zeroBuySwitch);
router.post('/activity/zerobuy/publish', activity.zeroBuyPublish);
router.get('/activity/zerobuy/export', activity.zeroBuyExport);
// 用户管理[page]
router.get('/user/list', user.userListPage);
... ...
... ... @@ -3,30 +3,23 @@ require('admin/activity.page.css');
const $alert = $('#alert-modal');
const $confirm = $('#confirm-modal');
// $('#alert-modal').modal('show')
function bindEvent() {
const editStatusFn = function(id, status) {
return $.ajax({
method: 'post',
url: '/admin/activity/zerobuy/editStatus',
data: {
id,
status
}
});
};
const editFn = function() {
window.open('/admin/activity/zerobuy/edit?id=' +
$(this).parent().data('id'), '_blank');
$(this).data('id'), '_blank');
};
const switchFn = function() {
let $this = $(this);
let status = $this.hasClass('btn-switch-open') ? 1 : 0;
editStatusFn($this.data('id'), status).then(res => {
$.ajax({
method: 'post',
url: '/admin/activity/zerobuy/switch',
data: {
id: $this.data('id'),
on: $this.hasClass('btn-switch-open') ? 1 : ''
}
}).then(res => {
if (res.code === 200) {
location.reload();
} else {
... ... @@ -37,12 +30,17 @@ function bindEvent() {
};
const exportFn = function() {
window.open(`/admin/activity/zerobuy/export?id=${$(this).data('id')}`, '_blank');
};
let publishId;
const publishFn = function() {
editStatusFn(publishId, 2).then(res => {
$.ajax({
method: 'post',
url: '/admin/activity/zerobuy/publish',
data: {
id: $confirm.data('id')
}
}).then(res => {
if (res.code === 200) {
location.reload();
} else {
... ... @@ -52,13 +50,12 @@ function bindEvent() {
});
};
$('.btn-edit').on('click', editFn);
$('.btn-switch-open').on('click', switchFn);
$('.btn-switch-close').on('click', switchFn);
$('.btn-export').on('click', exportFn);
$('.btn-publish').on('click', function() {
publishId = $(this).data('id');
$confirm.data('id', $(this).data('id'));
$confirm.modal('show');
});
$('.sure-publish-btn').on('click', publishFn);
... ...