Authored by yyq

fix batchSend

... ... @@ -771,47 +771,41 @@ class AdminModel extends global.yoho.BaseModel {
* @returns {*}
*/
async sendWechatMessage(id, channel = 0) {
let info = await Promise.all([
mysqlCli.query(`select name from ${TABLE_ACT_PRIZE_PRODUCT}
where id = :id limit 1`, {id}),
mysqlCli.query(`select uid from ${TABLE_ACT_PRIZE_PRODUCT_USER}
mysqlCli.query(`select distinct uid from ${TABLE_ACT_PRIZE_PRODUCT_USER}
where act_prize_id = :id`, {id})
]);
let productInfo = _.get(info, '[0][0]');
let userList = [];
const miniAppType = ((+channel) === 1 ? 63 : 0);
const baseUrl = miniAppType ? 'pages/zeroSell/detail' : 'page/subPackage/pages/zeroSell/detail';
_.forEach(_.get(info, '[1]', []), value => {
userList.push(value.uid);
});
userList = _.compact(_.uniq(userList));
let msgApi = [];
let msgData = {
method: 'wechat.message.send',
sendScene: 'MINI_WINNING_NOTICE',
// miniAppType: ((+channel) === 1 ? 63 : 29),
miniAppType,
miniAppType: ((+channel) === 1 ? 63 : 29),
params: JSON.stringify({
activityTitle: productInfo.name,
activityTime: moment().format('YYYY-MM-DD HH:mm') + ':00',
pageUrl: `${baseUrl}?actPrizeId=${id}`
// pageUrl: 'pages/zeroSell/detail?actPrizeId=' + id
pageUrl: 'pages/zeroSell/detail?actPrizeId=' + id
})
};
_.forEach(_.chunk(userList, NOTICE_BATCH_SEND_USER_NUM), value => {
value = _.compact(value);
if (value && value.length) {
msgApi.push(this.get({data: Object.assign({uidList: value}, msgData)}).then(result => {
msgApi.push(() => {
return this.get({data: Object.assign({uidList: value}, msgData)}).then(result => {
logger.info(`zerobuy_winning_notice send ${result.code === 200 ? 'success' : 'fail'} uids: ${value.join(',')}`);
}));
});
});
}
});
... ... @@ -832,7 +826,7 @@ class AdminModel extends global.yoho.BaseModel {
this.batchSend(_.drop(apis, NOTICE_BATCH_SEND_API_NUM));
}, NOTICE_BATCH_SEND_INTERVAL);
return Promise.all(_.take(apis, NOTICE_BATCH_SEND_API_NUM));
return Promise.all(_.take(apis, NOTICE_BATCH_SEND_API_NUM).map(rp => rp()));
}
}
... ...