...
|
...
|
@@ -139,7 +139,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
let limit = `${(page - 1) * PAGE_SIZE},${PAGE_SIZE}`;
|
|
|
let where = ['act_id = :actId'];
|
|
|
|
|
|
let now = new Date().getTime() / 1000;
|
|
|
let now = moment().startOf('minute').unix();
|
|
|
|
|
|
switch (+extra.type) {
|
|
|
case 1:
|
...
|
...
|
@@ -163,7 +163,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
now,
|
|
|
channel: extra.channel
|
|
|
}, {
|
|
|
cache: PRODUCT_CACHE_TIMES
|
|
|
cache: 60
|
|
|
}).then(result => {
|
|
|
return handelResult(handelActivityList(result));
|
|
|
});
|
...
|
...
|
@@ -197,7 +197,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
}
|
|
|
|
|
|
return mysqlCli.query(`select u.*, p.name, p.price, p.status, p.cover_img,
|
|
|
p.start_time, p.end_time, p.is_full from
|
|
|
p.start_time, p.end_time, p.is_full, p.lottery_info 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 ${where}
|
...
|
...
|
@@ -218,7 +218,9 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
*/
|
|
|
getListRecommend(actPrizeId, extra = {}) {
|
|
|
const actId = parseInt(extra.actId, 10) || 0;
|
|
|
const time = new Date().getTime() / 1000;
|
|
|
const now = moment();
|
|
|
const minute = parseInt(now.minute() / 5, 10) * 5;
|
|
|
const time = now.startOf('hour').unix() + minute * 60;
|
|
|
|
|
|
let where = 'act_id = :actId and status = 1 and start_time < :time and end_time > :time';
|
|
|
|
...
|
...
|
@@ -232,7 +234,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
actId,
|
|
|
actPrizeId
|
|
|
}, {
|
|
|
cache: PRODUCT_CACHE_TIMES
|
|
|
cache: 5 * 60
|
|
|
}).then(result => {
|
|
|
_.remove(result, n => {
|
|
|
return +n.id === +actPrizeId;
|
...
|
...
|
@@ -257,11 +259,11 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
let query = [
|
|
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
|
|
where id = :actPrizeId limit 1;`, {actPrizeId}, {
|
|
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
|
|
cache: extra.noCache ? 0 : 60
|
|
|
}),
|
|
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT_CONTENT}
|
|
|
where act_prize_id = :actPrizeId;`, {actPrizeId}, {
|
|
|
cache: extra.noCache ? 0 : PRODUCT_CACHE_TIMES
|
|
|
cache: extra.noCache ? 0 : 5 * 60
|
|
|
}),
|
|
|
this.getUserJoinNum(actPrizeId).then(result => {
|
|
|
return result.data;
|
...
|
...
|
@@ -322,7 +324,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
actPrizeId,
|
|
|
actId
|
|
|
}, {
|
|
|
cache: RECENT_CODE_CACHE_TIME
|
|
|
cache: 2 * 60
|
|
|
}).then(result => {
|
|
|
return handelResult(_.uniqBy(result, 'uid'));
|
|
|
});
|
...
|
...
|
@@ -352,14 +354,17 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
* @returns {*}
|
|
|
*/
|
|
|
getUserJoinNum(actPrizeId, noCache) {
|
|
|
return mysqlCli.query(`select count(distinct uid) as join_num from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
where act_prize_id = :actPrizeId;`, {
|
|
|
actPrizeId
|
|
|
}, {
|
|
|
cache: noCache ? 0 : MINUTE_TIMES / 6
|
|
|
}).then(result => {
|
|
|
return handelResult({join_num: _.get(result, '[0].join_num')});
|
|
|
});
|
|
|
// 前台不需要显示参与人数,且sql影响性能,故直接返回1
|
|
|
return Promise.resolve(handelResult({join_num: 1}));
|
|
|
|
|
|
// return mysqlCli.query(`select count(distinct uid) as join_num from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
// where act_prize_id = :actPrizeId;`, {
|
|
|
// actPrizeId
|
|
|
// }, {
|
|
|
// cache: noCache ? 0 : MINUTE_TIMES / 6
|
|
|
// }).then(result => {
|
|
|
// return handelResult({join_num: _.get(result, '[0].join_num')});
|
|
|
// });
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -374,7 +379,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
|
|
|
let info = await Promise.all([
|
|
|
mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
|
|
where id = :actPrizeId limit 1;`, {actPrizeId}, {cache: PRODUCT_CACHE_TIMES}),
|
|
|
where id = :actPrizeId limit 1;`, {actPrizeId}, {cache: 60}),
|
|
|
this.getUserJoinNum(actPrizeId, true).then(result => {
|
|
|
return result.data;
|
|
|
})
|
...
|
...
|
@@ -388,8 +393,6 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
let productInfo = _.get(info, '[0][0]');
|
|
|
let joinNum = _.get(info, '[1].join_num', 0);
|
|
|
|
|
|
|
|
|
|
|
|
let status = getActivityStatus(productInfo, joinNum);
|
|
|
|
|
|
if (!status || status >= 3) {
|
...
|
...
|
@@ -400,9 +403,7 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
delete extra.shareUid;
|
|
|
}
|
|
|
|
|
|
if (extra.shareUid) {
|
|
|
this.sendPrizeCode(extra.shareUid, actPrizeId, {isShareTake: true});
|
|
|
}
|
|
|
let shareUid = extra.shareUid;
|
|
|
|
|
|
return new Promise((resolve, reject) => {
|
|
|
this.sendPrizeCode(uid, actPrizeId, Object.assign(extra, {
|
...
|
...
|
@@ -411,10 +412,16 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
actStartTime: productInfo.start_time,
|
|
|
actEndTime: productInfo.end_time
|
|
|
})).then(response => {
|
|
|
// 参与人数满时更新活动状态
|
|
|
if (+response.code === 200 && (+productInfo.is_full === 0) && (joinNum + 1) >= productInfo.limit) {
|
|
|
mysqlCli.update(`update ${TABLE_ACT_PRIZE_PRODUCT} set is_full = 1
|
|
|
where id = :actPrizeId and is_full = 0 limit 1`, {actPrizeId});
|
|
|
if (+response.code === 200) {
|
|
|
if (shareUid) {
|
|
|
this.sendPrizeCode(shareUid, actPrizeId, {isShareTake: true});
|
|
|
}
|
|
|
|
|
|
// 参与人数满时更新活动状态
|
|
|
if ((+productInfo.is_full === 0) && (joinNum + 1) >= productInfo.limit) {
|
|
|
mysqlCli.update(`update ${TABLE_ACT_PRIZE_PRODUCT} set is_full = 1
|
|
|
where id = :actPrizeId and is_full = 0 limit 1`, {actPrizeId});
|
|
|
}
|
|
|
}
|
|
|
resolve(response);
|
|
|
})
|
...
|
...
|
@@ -435,24 +442,27 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
const mapStr = 'QQWERTYUIOPASDFGHJKLZXCVBNM12345678900';
|
|
|
let prizeCode = '';
|
|
|
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
prizeCode += mapStr[parseInt(Math.random() * mapStr.length, 10)];
|
|
|
}
|
|
|
const info = await mysqlCli.query(`select id from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
where act_prize_id = :actPrizeId and prize_code = :prizeCode limit 1`, {actPrizeId, prizeCode});
|
|
|
|
|
|
if (info && info.length) {
|
|
|
if (isRetry) {
|
|
|
prizeCodeCreateCount.fail(); // 记录生成抽奖码失败
|
|
|
return '';
|
|
|
} else {
|
|
|
return this.createPrizeCode(actPrizeId, length, true);
|
|
|
}
|
|
|
} else {
|
|
|
prizeCodeCreateCount.success(); // 记录生成抽奖码成功
|
|
|
|
|
|
return prizeCode;
|
|
|
}
|
|
|
for (let i = 0; i < length; i++) {
|
|
|
prizeCode += mapStr[parseInt(Math.random() * mapStr.length, 10)];
|
|
|
}
|
|
|
|
|
|
return prizeCode; // 不校验重复,直接返回抽奖嘛,如需校验请删除该行使用下面代码
|
|
|
|
|
|
// const info = await mysqlCli.query(`select id from ${TABLE_ACT_PRIZE_PRODUCT_USER}
|
|
|
// where act_prize_id = :actPrizeId and prize_code = :prizeCode limit 1`, {actPrizeId, prizeCode});
|
|
|
|
|
|
// if (info && info.length) {
|
|
|
// if (isRetry) {
|
|
|
// prizeCodeCreateCount.fail(); // 记录生成抽奖码失败
|
|
|
// return '';
|
|
|
// } else {
|
|
|
// return this.createPrizeCode(actPrizeId, length, true);
|
|
|
// }
|
|
|
// } else {
|
|
|
// prizeCodeCreateCount.success(); // 记录生成抽奖码成功
|
|
|
|
|
|
// return prizeCode;
|
|
|
// }
|
|
|
}
|
|
|
|
|
|
/**
|
...
|
...
|
@@ -568,32 +578,20 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
*/
|
|
|
sendWechatMessage(uid, actPrizeId, extra = {}) {
|
|
|
let info = {};
|
|
|
let baseUri = 'page/subPackage/pages/zeroSell/detail';
|
|
|
|
|
|
switch (+extra.miniAppType) {
|
|
|
case 63:
|
|
|
// case 29:
|
|
|
info.miniAppType = extra.miniAppType;
|
|
|
baseUri = 'pages/zeroSell/detail';
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
let baseUri = 'pages/zeroSell/detail';
|
|
|
|
|
|
return this.get({
|
|
|
data: Object.assign({
|
|
|
data: {
|
|
|
method: 'wechat.message.send',
|
|
|
sendScene: 'MINI_ACTIVITY_JOIN',
|
|
|
|
|
|
// miniAppType: extra.miniAppType ? +extra.miniAppType : 29,
|
|
|
miniAppType: info.miniAppType || 0,
|
|
|
miniAppType: +extra.miniAppType === 63 ? extra.miniAppType : 29,
|
|
|
params: JSON.stringify({
|
|
|
activityTitle: extra.actName,
|
|
|
activityTime: `${timeFormat(extra.actStartTime)} - ${timeFormat(extra.actEndTime)}`,
|
|
|
pageUrl: `${baseUri}?actPrizeId=${actPrizeId}`
|
|
|
}),
|
|
|
uidList: [uid]
|
|
|
}, info)
|
|
|
}
|
|
|
}).then(result => {
|
|
|
if (result.code !== 200) {
|
|
|
logger.info(`zerobuy_join_notice send fail uid: ${uid}`);
|
...
|
...
|
|