Authored by yyq

add status

... ... @@ -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;
... ...
... ... @@ -732,12 +732,9 @@ class AdminModel extends global.yoho.BaseModel {
});
}
/**
* 向参加活动用户发送开奖消息
* @param uid
* @param actPrizeId
* @param extra
* @param id
* @returns {*}
*/
async sendWechatMessage(id) {
... ... @@ -774,11 +771,24 @@ class AdminModel extends global.yoho.BaseModel {
}
});
if (!msgApi.length) {
return Promise.resolve();
return this.batchSend(msgApi);
}
/**
* 分批发送模板消息
* @param apis
* @returns {*}
*/
batchSend(apis) {
if (_.isEmpty(apis)) {
return;
}
return Promise.all(msgApi);
setTimeout(() => {
this.batchSend(_.drop(apis, 20));
}, 1000);
return Promise.all(_.take(apis, 20));
}
}
... ...
/*
true
@author: yyq <kingcoon@163.com>
@date: 2018-08-10 10:43:55
*/
#注意:GO;分割执行块
ALTER TABLE act_prize_product ADD `is_full` TINYINT DEFAULT 0 comment '是否参与活动人数已满';
GO;
... ...
module.exports = ['_migration', '20170913102356', '20170927092926', '20171025145423', '20171102104558', '20171115144710', '20180131104311', '20180402134610', '20180413105509', '20180719134813'];
module.exports = ['_migration', '20170913102356', '20170927092926', '20171025145423', '20171102104558', '20171115144710', '20180131104311', '20180402134610', '20180413105509', '20180719134813', '20180810104355'];
... ...