...
|
...
|
@@ -26,17 +26,28 @@ function handelResult(result) { |
|
|
}
|
|
|
|
|
|
function getActivityStatus(info = {}, num, now) {
|
|
|
let resData = {
|
|
|
isEnd: true
|
|
|
};
|
|
|
const status = +info.status;
|
|
|
let resStatus = 0;
|
|
|
|
|
|
now = now || (new Date().getTime() / 1000);
|
|
|
|
|
|
if (!info.status || num >= info.limit || now >= info.end_time) {
|
|
|
return resData;
|
|
|
if (!status) {
|
|
|
return resStatus;
|
|
|
}
|
|
|
|
|
|
return {};
|
|
|
if (status === 2) {
|
|
|
resStatus = 4; // 活动已开奖
|
|
|
} else {
|
|
|
resStatus = 2; // 活动已开始
|
|
|
|
|
|
if (now > info.end_time || num >= info.limit) {
|
|
|
resStatus = 3; // 活动已结束
|
|
|
} else if (now < info.start_time) {
|
|
|
resStatus = 1; // 活动未开始
|
|
|
}
|
|
|
}
|
|
|
|
|
|
return resStatus;
|
|
|
}
|
|
|
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
...
|
...
|
@@ -131,7 +142,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
return Promise.resolve(handelResult(resData));
|
|
|
}
|
|
|
|
|
|
return Promise.all([
|
|
|
let query = [
|
|
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
|
|
where id = :actPrizeId limit 1;`, {actPrizeId}, {
|
|
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
...
|
...
|
@@ -139,15 +150,34 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT_CONTENT}
|
|
|
where act_prize_id = :actPrizeId;`, {actPrizeId}, {
|
|
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
|
|
})
|
|
|
]).then(result => {
|
|
|
let [product, content] = result;
|
|
|
}),
|
|
|
this.getUserJoinNum(actPrizeId).then(result => {
|
|
|
return result.data;
|
|
|
})
|
|
|
];
|
|
|
|
|
|
if (extra.uid) {
|
|
|
query.push(mysqlCli.query(`select count(*) as code_num from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
where act_prize_id = :actPrizeId and uid = :uid;`, {
|
|
|
actPrizeId,
|
|
|
uid: extra.uid
|
|
|
}));
|
|
|
}
|
|
|
|
|
|
return Promise.all(query).then(result => {
|
|
|
let [product, content, count] = result;
|
|
|
|
|
|
if (product && product.length) {
|
|
|
resData = product[0];
|
|
|
resData.content = _.sortBy(content || [], o => {
|
|
|
return o.sort;
|
|
|
});
|
|
|
|
|
|
let joinNum = _.get(count, 'join_num', 0);
|
|
|
|
|
|
resData.joinNum = joinNum;
|
|
|
resData.status = getActivityStatus(resData, joinNum);
|
|
|
resData.myCodeNum = _.get(result, '[3][0].code_num', 0);
|
|
|
}
|
|
|
|
|
|
return resData;
|
...
|
...
|
@@ -232,7 +262,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
|
|
|
let status = getActivityStatus(_.get(info, '[0][0]'), _.get(info, '[1].join_num', 0));
|
|
|
|
|
|
if (status.isEnd) {
|
|
|
if (!status || status >= 3) {
|
|
|
return errorData;
|
|
|
}
|
|
|
|
...
|
...
|
|