|
|
/* eslint-disable no-trailing-spaces */
|
|
|
/* eslint-disable max-len */
|
|
|
'use strict';
|
|
|
const model = require('../models/feature');
|
|
|
const _ = require('lodash');
|
|
|
const stringProcess = require('../../../utils/string-process');
|
|
|
const moment = require('moment');
|
|
|
|
|
|
/**
|
|
|
* 限时抢券时间转换
|
|
|
*/
|
|
|
function formatSeckillCouponTime(featureData = {}) {
|
|
|
const {floors = []} = featureData;
|
|
|
|
|
|
const currentTime = new Date().getTime();
|
|
|
const endOfTime = moment().endOf('day').format('x');
|
|
|
|
|
|
for (const floor of floors) {
|
|
|
const {component: componentList = []} = floor;
|
|
|
|
|
|
for (const component of componentList) {
|
|
|
let {seckillCoupon, list = [], type } = component;
|
|
|
|
|
|
if (seckillCoupon === '1' && type === 'tab') {
|
|
|
list = list.sort((t1, t2)=> {
|
|
|
const t1DateTime = new Date(`${t1.year}-${t1.month}-${t1.day} ${t1.hour}:00:00`);
|
|
|
const t2DateTime = new Date(`${t2.year}-${t2.month}-${t2.day} ${t2.hour}:00:00`);
|
|
|
|
|
|
return t1DateTime.getTime() - t2DateTime.getTime();
|
|
|
});
|
|
|
|
|
|
component.list = list.reduce((newList, tabInfo, index, array)=> {
|
|
|
const { hour, year, month, day } = tabInfo;
|
|
|
const nextTab = array[index + 1];
|
|
|
const tabTime = new Date(`${year}-${month}-${day} ${hour}:00:00`).getTime();
|
|
|
const nextTabTime = nextTab ?
|
|
|
new Date(`${nextTab.year}-${nextTab.month}-${nextTab.day} ${nextTab.hour}:00:00`).getTime() :
|
|
|
0;
|
|
|
let statusText = '即将开始';
|
|
|
|
|
|
if (currentTime > tabTime) {
|
|
|
statusText = '立即抢券';
|
|
|
if (currentTime < nextTabTime) {
|
|
|
statusText = '已抢光';
|
|
|
}
|
|
|
}
|
|
|
if (tabTime > +endOfTime) {
|
|
|
statusText = '明日开启';
|
|
|
}
|
|
|
newList.push({...tabInfo, statusText});
|
|
|
return newList;
|
|
|
}, []);
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
exports.index = function(req, res, next) {
|
|
|
let qcdn = _.get(req.app.locals, 'wap.qcloud_cdn');
|
...
|
...
|
@@ -15,6 +67,10 @@ exports.index = function(req, res, next) { |
|
|
return next();
|
|
|
}
|
|
|
|
|
|
formatSeckillCouponTime(result);
|
|
|
|
|
|
console.log('---------result-----', JSON.stringify(result));
|
|
|
|
|
|
let title = stringProcess.paramsFilter(req.query.title) || result.name || '专题活动';
|
|
|
let shareId = _.parseInt(stringProcess.paramsFilter(req.query.share_id));
|
|
|
|
...
|
...
|
|