...
|
...
|
@@ -51,8 +51,15 @@ function getActivityStatus(info = {}, num, now) { |
|
|
} else {
|
|
|
resStatus = 2; // 活动已开始
|
|
|
|
|
|
if (now > info.end_time || num >= info.limit) {
|
|
|
// 当传入参与人数时以参与人数为准
|
|
|
if (num >= info.limit) { // 参与人数达到活动限制人数
|
|
|
resStatus = 3; // 活动已结束
|
|
|
} else if (now > info.end_time) {
|
|
|
if (info.is_full > 0) {
|
|
|
resStatus = 3; // 活动已结束
|
|
|
} else {
|
|
|
resStatus = 5; // 人数未达到,活动失败
|
|
|
}
|
|
|
} else if (now < info.start_time) {
|
|
|
resStatus = 1; // 活动未开始
|
|
|
}
|
...
|
...
|
@@ -116,16 +123,27 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
const page = parseInt(extra.page, 10) || 1;
|
|
|
|
|
|
let limit = `${(page - 1) * PAGE_SIZE},${PAGE_SIZE}`;
|
|
|
let now = new Date().getTime() / 1000;
|
|
|
|
|
|
uid = parseInt(uid, 10) || 0;
|
|
|
|
|
|
return mysqlCli.query(`select u.*, p.name, p.price, p.status, p.cover_img, p.start_time, p.end_time from
|
|
|
let where = '';
|
|
|
|
|
|
if (extra.type) {
|
|
|
where = '(p.status = 2 or (p.is_full = 0 and p.end_time <= :now))';
|
|
|
} else {
|
|
|
where = '(p.status < 2 != (p.is_full = 0 and p.end_time <= :now))';
|
|
|
}
|
|
|
|
|
|
return mysqlCli.query(`select u.*, p.name, p.price, p.status, p.cover_img,
|
|
|
p.start_time, p.end_time, p.is_full from
|
|
|
${TABLE_ACT_PRIZE_PRODUCT_USER} u left join
|
|
|
${TABLE_ACT_PRIZE_PRODUCT} p on u.act_prize_id = p.id
|
|
|
where u.act_id = :actId and u.uid = :uid and p.status ${+extra.type ? '=' : '<'} 2
|
|
|
where u.act_id = :actId and u.uid = :uid and ${where}
|
|
|
order by u.create_time desc limit ${limit}`, {
|
|
|
uid,
|
|
|
actId
|
|
|
actId,
|
|
|
now
|
|
|
}).then(result => {
|
|
|
return handelResult(handelActivityList(result));
|
|
|
});
|
...
|
...
|
@@ -297,8 +315,15 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
};
|
|
|
|
|
|
let productInfo = _.get(info, '[0][0]');
|
|
|
let joinNum = _.get(info, '[1].join_num', 0);
|
|
|
|
|
|
// 参与人数满时更新活动状态
|
|
|
if (+info.is_full === 0 && joinNum >= info.limit) {
|
|
|
mysqlCli.update(`update ${TABLE_ACT_PRIZE_PRODUCT} set is_full = 1
|
|
|
where id = :actPrizeId and is_full = 0 limit 1`, {actPrizeId});
|
|
|
}
|
|
|
|
|
|
let status = getActivityStatus(productInfo, _.get(info, '[1].join_num', 0));
|
|
|
let status = getActivityStatus(productInfo, joinNum);
|
|
|
|
|
|
if (!status || status >= 3) {
|
|
|
return errorData;
|
...
|
...
|
|