Showing
5 changed files
with
140 additions
and
29 deletions
@@ -315,7 +315,7 @@ module.exports = class extends global.yoho.BaseModel { | @@ -315,7 +315,7 @@ module.exports = class extends global.yoho.BaseModel { | ||
315 | if (info && info.length && !isRetry) { | 315 | if (info && info.length && !isRetry) { |
316 | return this.createPrizeCode(length, true); | 316 | return this.createPrizeCode(length, true); |
317 | } else { | 317 | } else { |
318 | - return prizeCode; | 318 | + return ''; |
319 | } | 319 | } |
320 | } | 320 | } |
321 | 321 |
@@ -31,9 +31,31 @@ const zeroBuy = { | @@ -31,9 +31,31 @@ const zeroBuy = { | ||
31 | })); | 31 | })); |
32 | }).catch(next); | 32 | }).catch(next); |
33 | }, | 33 | }, |
34 | - zeroBuyStatusEdit(req, res, next) { | ||
35 | - req.ctx(ActivityModel).editZerobuyStatus(req.body.id, req.body.status) | 34 | + zeroBuySwitch(req, res, next) { |
35 | + console.log(req.body.on ? 1 : 0); | ||
36 | + req.ctx(ActivityModel).editZerobuyStatus(req.body.id, req.body.on ? 1 : 0) | ||
36 | .then(res.json).catch(next); | 37 | .then(res.json).catch(next); |
38 | + }, | ||
39 | + zeroBuyPublish(req, res, next) { | ||
40 | + req.ctx(ActivityModel).editZerobuyStatus(req.body.id, 2) | ||
41 | + .then(res.json).catch(next); | ||
42 | + }, | ||
43 | + zeroBuyExport(req, res, next) { | ||
44 | + let id = req.query.id; | ||
45 | + | ||
46 | + if (!id) { | ||
47 | + return res.json({ | ||
48 | + code: 400, | ||
49 | + message: INVALID_PARAMS | ||
50 | + }); | ||
51 | + } | ||
52 | + | ||
53 | + req.ctx(ActivityModel).getZerobuyExportList(req.query.id) | ||
54 | + .then(result => { | ||
55 | + res.setHeader('Content-Type', 'application/vnd.openxmlformats'); | ||
56 | + res.setHeader('Content-Disposition', `attachment; filename=zerobuy_${id}_${new Date().getTime()}.xlsx`); | ||
57 | + res.end(excelExport.execute(result), 'binary'); | ||
58 | + }).catch(next); | ||
37 | } | 59 | } |
38 | }; | 60 | }; |
39 | 61 |
@@ -6,6 +6,8 @@ | @@ -6,6 +6,8 @@ | ||
6 | 6 | ||
7 | const mysqlCli = global.yoho.utils.mysqlCli; | 7 | const mysqlCli = global.yoho.utils.mysqlCli; |
8 | const _ = require('lodash'); | 8 | const _ = require('lodash'); |
9 | +const moment = require('moment'); | ||
10 | + | ||
9 | const pager = require('../../../utils/pager'); | 11 | const pager = require('../../../utils/pager'); |
10 | 12 | ||
11 | const TB_USER = 'user'; | 13 | const TB_USER = 'user'; |
@@ -18,7 +20,15 @@ const TB_ACT_ARTICLE_Y100 = 'act_article_y100'; | @@ -18,7 +20,15 @@ const TB_ACT_ARTICLE_Y100 = 'act_article_y100'; | ||
18 | const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product'; | 20 | const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product'; |
19 | 21 | ||
20 | // const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content'; | 22 | // const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content'; |
21 | -// const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user'; | 23 | +const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user'; |
24 | + | ||
25 | +const timeFormat = (time) => { | ||
26 | + if (_.isNumber(time)) { | ||
27 | + time = moment.unix(time); | ||
28 | + } | ||
29 | + | ||
30 | + return moment(time).format('YYYY-MM-DD HH:mm:ss'); | ||
31 | +}; | ||
22 | 32 | ||
23 | class AdminModel extends global.yoho.BaseModel { | 33 | class AdminModel extends global.yoho.BaseModel { |
24 | constructor(ctx) { | 34 | constructor(ctx) { |
@@ -458,11 +468,11 @@ class AdminModel extends global.yoho.BaseModel { | @@ -458,11 +468,11 @@ class AdminModel extends global.yoho.BaseModel { | ||
458 | * @returns {*} | 468 | * @returns {*} |
459 | */ | 469 | */ |
460 | editZerobuyStatus(id, status) { | 470 | editZerobuyStatus(id, status) { |
461 | - if (!id || !status) { | ||
462 | - return { | 471 | + if (!id || !_.inRange(status, 0, 3)) { |
472 | + return Promise.resolve({ | ||
463 | code: 400, | 473 | code: 400, |
464 | message: '缺少参数' | 474 | message: '缺少参数' |
465 | - }; | 475 | + }); |
466 | } | 476 | } |
467 | 477 | ||
468 | return mysqlCli.update(`update ${TABLE_ACT_PRIZE_PRODUCT} set status = :status where id = :id`, { | 478 | return mysqlCli.update(`update ${TABLE_ACT_PRIZE_PRODUCT} set status = :status where id = :id`, { |
@@ -475,6 +485,86 @@ class AdminModel extends global.yoho.BaseModel { | @@ -475,6 +485,86 @@ class AdminModel extends global.yoho.BaseModel { | ||
475 | }; | 485 | }; |
476 | }); | 486 | }); |
477 | } | 487 | } |
488 | + | ||
489 | + getZerobuyExportList(id) { | ||
490 | + return Promise.all([ | ||
491 | + mysqlCli.query(`select uid, user_name, prize_code, is_share_take, share_uid, create_time | ||
492 | + from ${TABLE_ACT_PRIZE_PRODUCT_USER} where act_prize_id = :id | ||
493 | + order by create_time asc`, {id}), | ||
494 | + mysqlCli.query(`select 'limit' from ${TABLE_ACT_PRIZE_PRODUCT} | ||
495 | + where id = :id limit 1`, {id}) | ||
496 | + ]).then(result => { | ||
497 | + let [codes, product] = result; | ||
498 | + | ||
499 | + const limit = _.get(product, '[0].limit', 0); | ||
500 | + | ||
501 | + let users = {}; | ||
502 | + let userNum = 0; | ||
503 | + | ||
504 | + let rows = []; | ||
505 | + let index = 0; | ||
506 | + | ||
507 | + _.forEach(codes, value => { | ||
508 | + if (userNum >= limit) { | ||
509 | + return; | ||
510 | + } | ||
511 | + | ||
512 | + if (!users[value.uid]) { | ||
513 | + userNum++; | ||
514 | + users[value.uid] = 1; | ||
515 | + } | ||
516 | + | ||
517 | + if (userNum >= limit && !users[value.uid]) { | ||
518 | + return; | ||
519 | + } | ||
520 | + | ||
521 | + rows.push([ | ||
522 | + ++index, | ||
523 | + value.uid, | ||
524 | + value.user_name, | ||
525 | + value.prize_code, | ||
526 | + value.is_share_take ? '是' : '', | ||
527 | + value.share_uid ? value.share_uid : '', | ||
528 | + timeFormat(value.create_time) | ||
529 | + ]); | ||
530 | + }); | ||
531 | + | ||
532 | + return { | ||
533 | + name: 'sheet', | ||
534 | + cols: [ | ||
535 | + { | ||
536 | + caption: '编号', | ||
537 | + type: 'number' | ||
538 | + }, | ||
539 | + { | ||
540 | + caption: 'uid', | ||
541 | + type: 'number' | ||
542 | + }, | ||
543 | + { | ||
544 | + caption: '昵称', | ||
545 | + type: 'string' | ||
546 | + }, | ||
547 | + { | ||
548 | + caption: '邀请码', | ||
549 | + type: 'string' | ||
550 | + }, | ||
551 | + { | ||
552 | + caption: '是否分享获得', | ||
553 | + type: 'string' | ||
554 | + }, | ||
555 | + { | ||
556 | + caption: '邀请者', | ||
557 | + type: 'string' | ||
558 | + }, | ||
559 | + { | ||
560 | + caption: '获得时间', | ||
561 | + type: 'string' | ||
562 | + } | ||
563 | + ], | ||
564 | + rows | ||
565 | + }; | ||
566 | + }); | ||
567 | + } | ||
478 | } | 568 | } |
479 | 569 | ||
480 | module.exports = AdminModel; | 570 | module.exports = AdminModel; |
@@ -21,7 +21,9 @@ router.get('/activity/createY100Article', activity.createY100ArticlePage); | @@ -21,7 +21,9 @@ router.get('/activity/createY100Article', activity.createY100ArticlePage); | ||
21 | router.get('/activity/y100Article', activity.actY100ArticleListPage); | 21 | router.get('/activity/y100Article', activity.actY100ArticleListPage); |
22 | router.get('/activity/upload_excel', activity.uploadExcelPage); | 22 | router.get('/activity/upload_excel', activity.uploadExcelPage); |
23 | router.get('/activity/zerobuy', activity.zeroBuyList); | 23 | router.get('/activity/zerobuy', activity.zeroBuyList); |
24 | -router.post('/activity/zerobuy/editStatus', activity.zeroBuyStatusEdit); | 24 | +router.post('/activity/zerobuy/switch', activity.zeroBuySwitch); |
25 | +router.post('/activity/zerobuy/publish', activity.zeroBuyPublish); | ||
26 | +router.get('/activity/zerobuy/export', activity.zeroBuyExport); | ||
25 | 27 | ||
26 | // 用户管理[page] | 28 | // 用户管理[page] |
27 | router.get('/user/list', user.userListPage); | 29 | router.get('/user/list', user.userListPage); |
@@ -3,30 +3,23 @@ require('admin/activity.page.css'); | @@ -3,30 +3,23 @@ require('admin/activity.page.css'); | ||
3 | const $alert = $('#alert-modal'); | 3 | const $alert = $('#alert-modal'); |
4 | const $confirm = $('#confirm-modal'); | 4 | const $confirm = $('#confirm-modal'); |
5 | 5 | ||
6 | -// $('#alert-modal').modal('show') | ||
7 | - | ||
8 | function bindEvent() { | 6 | function bindEvent() { |
9 | - const editStatusFn = function(id, status) { | ||
10 | - return $.ajax({ | ||
11 | - method: 'post', | ||
12 | - url: '/admin/activity/zerobuy/editStatus', | ||
13 | - data: { | ||
14 | - id, | ||
15 | - status | ||
16 | - } | ||
17 | - }); | ||
18 | - }; | ||
19 | - | ||
20 | const editFn = function() { | 7 | const editFn = function() { |
21 | window.open('/admin/activity/zerobuy/edit?id=' + | 8 | window.open('/admin/activity/zerobuy/edit?id=' + |
22 | - $(this).parent().data('id'), '_blank'); | 9 | + $(this).data('id'), '_blank'); |
23 | }; | 10 | }; |
24 | 11 | ||
25 | const switchFn = function() { | 12 | const switchFn = function() { |
26 | let $this = $(this); | 13 | let $this = $(this); |
27 | - let status = $this.hasClass('btn-switch-open') ? 1 : 0; | ||
28 | 14 | ||
29 | - editStatusFn($this.data('id'), status).then(res => { | 15 | + $.ajax({ |
16 | + method: 'post', | ||
17 | + url: '/admin/activity/zerobuy/switch', | ||
18 | + data: { | ||
19 | + id: $this.data('id'), | ||
20 | + on: $this.hasClass('btn-switch-open') ? 1 : '' | ||
21 | + } | ||
22 | + }).then(res => { | ||
30 | if (res.code === 200) { | 23 | if (res.code === 200) { |
31 | location.reload(); | 24 | location.reload(); |
32 | } else { | 25 | } else { |
@@ -37,12 +30,17 @@ function bindEvent() { | @@ -37,12 +30,17 @@ function bindEvent() { | ||
37 | }; | 30 | }; |
38 | 31 | ||
39 | const exportFn = function() { | 32 | const exportFn = function() { |
40 | - | 33 | + window.open(`/admin/activity/zerobuy/export?id=${$(this).data('id')}`, '_blank'); |
41 | }; | 34 | }; |
42 | 35 | ||
43 | - let publishId; | ||
44 | const publishFn = function() { | 36 | const publishFn = function() { |
45 | - editStatusFn(publishId, 2).then(res => { | 37 | + $.ajax({ |
38 | + method: 'post', | ||
39 | + url: '/admin/activity/zerobuy/publish', | ||
40 | + data: { | ||
41 | + id: $confirm.data('id') | ||
42 | + } | ||
43 | + }).then(res => { | ||
46 | if (res.code === 200) { | 44 | if (res.code === 200) { |
47 | location.reload(); | 45 | location.reload(); |
48 | } else { | 46 | } else { |
@@ -52,13 +50,12 @@ function bindEvent() { | @@ -52,13 +50,12 @@ function bindEvent() { | ||
52 | }); | 50 | }); |
53 | }; | 51 | }; |
54 | 52 | ||
55 | - | ||
56 | $('.btn-edit').on('click', editFn); | 53 | $('.btn-edit').on('click', editFn); |
57 | $('.btn-switch-open').on('click', switchFn); | 54 | $('.btn-switch-open').on('click', switchFn); |
58 | $('.btn-switch-close').on('click', switchFn); | 55 | $('.btn-switch-close').on('click', switchFn); |
59 | $('.btn-export').on('click', exportFn); | 56 | $('.btn-export').on('click', exportFn); |
60 | $('.btn-publish').on('click', function() { | 57 | $('.btn-publish').on('click', function() { |
61 | - publishId = $(this).data('id'); | 58 | + $confirm.data('id', $(this).data('id')); |
62 | $confirm.modal('show'); | 59 | $confirm.modal('show'); |
63 | }); | 60 | }); |
64 | $('.sure-publish-btn').on('click', publishFn); | 61 | $('.sure-publish-btn').on('click', publishFn); |
-
Please register or login to post a comment