...
|
...
|
@@ -6,6 +6,7 @@ |
|
|
const _ = require('lodash');
|
|
|
const moment = require('moment');
|
|
|
const mysqlCli = global.yoho.utils.mysqlCli;
|
|
|
const logger = global.yoho.logger;
|
|
|
const MemoryCache = require('../../../utils/memory-cache');
|
|
|
|
|
|
const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product';
|
...
|
...
|
@@ -68,6 +69,14 @@ function getActivityStatus(info = {}, num, now) { |
|
|
return resStatus;
|
|
|
}
|
|
|
|
|
|
function replaceHttp(url) {
|
|
|
if (url && url.indexOf('http:') > -1) {
|
|
|
url = url.replace(/http:/ig, 'https:');
|
|
|
}
|
|
|
|
|
|
return url;
|
|
|
}
|
|
|
|
|
|
function handelActivityList(list, nums) {
|
|
|
let now = new Date().getTime() / 1000;
|
|
|
|
...
|
...
|
@@ -75,6 +84,7 @@ function handelActivityList(list, nums) { |
|
|
nums = _.concat([], nums);
|
|
|
|
|
|
_.forEach(list, (value, index) => {
|
|
|
value.cover_img = replaceHttp(value.cover_img);
|
|
|
value.price = '¥' + (value.price || 0).toFixed(2);
|
|
|
value.status = getActivityStatus(value, nums[index], now);
|
|
|
});
|
...
|
...
|
@@ -82,6 +92,33 @@ function handelActivityList(list, nums) { |
|
|
return list;
|
|
|
}
|
|
|
|
|
|
// 抽奖码创建统计,并生成日志
|
|
|
const prizeCodeCreateCount = {
|
|
|
succedTime: 0,
|
|
|
failedTime: 0,
|
|
|
logTime: 0,
|
|
|
success() {
|
|
|
this.succedTime++;
|
|
|
this.log();
|
|
|
},
|
|
|
fail() {
|
|
|
this.failedTime++;
|
|
|
this.log();
|
|
|
},
|
|
|
log() {
|
|
|
let now = new Date().getTime() / 1000;
|
|
|
|
|
|
if (now - this.logTime < 60 * 10) {
|
|
|
return;
|
|
|
}
|
|
|
|
|
|
this.logTime = now;
|
|
|
|
|
|
// 记录抽奖码创建成功失败次数
|
|
|
logger.info(`prize_code_create succed: ${this.succedTime}; failed: ${this.failedTime}`);
|
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
...
|
...
|
@@ -100,11 +137,27 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
page = parseInt(page, 10) || 1;
|
|
|
|
|
|
let limit = `${(page - 1) * PAGE_SIZE},${PAGE_SIZE}`;
|
|
|
let where = ['act_id = :actId'];
|
|
|
|
|
|
let now = new Date().getTime() / 1000;
|
|
|
|
|
|
switch (+extra.type) {
|
|
|
case 1:
|
|
|
where.push('status > 0 and start_time > :now');
|
|
|
break;
|
|
|
case 2:
|
|
|
where.push('status > 0');
|
|
|
where.push('(status > 1 or end_time < :now or is_full > 0)');
|
|
|
break;
|
|
|
default:
|
|
|
where.push('status = 1 and start_time <= :now and end_time >= :now and is_full = 0');
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return mysqlCli.query(`select * from ${TABLE_ACT_PRIZE_PRODUCT}
|
|
|
where act_id = :actId and status > 0
|
|
|
order by sort desc limit ${limit}`, {
|
|
|
actId
|
|
|
where ${where.join(' and ')} order by sort desc limit ${limit}`, {
|
|
|
actId,
|
|
|
now
|
|
|
}, {
|
|
|
cache: PRODUCT_CACHE_TIMES
|
|
|
}).then(result => {
|
...
|
...
|
@@ -216,11 +269,16 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
if (product && product.length) {
|
|
|
resData = product[0] || {};
|
|
|
resData.content = _.sortBy(content || [], o => {
|
|
|
if (+o.floor_type === 2) {
|
|
|
o.content = replaceHttp(o.content);
|
|
|
}
|
|
|
|
|
|
return o.sort;
|
|
|
});
|
|
|
|
|
|
let joinNum = _.get(count, 'join_num', 0);
|
|
|
|
|
|
resData.cover_img = replaceHttp(resData.cover_img);
|
|
|
resData.price = '¥' + resData.price.toFixed(2);
|
|
|
resData.joinNum = joinNum;
|
|
|
resData.status = getActivityStatus(resData, joinNum);
|
...
|
...
|
@@ -364,11 +422,15 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
|
|
|
if (info && info.length) {
|
|
|
if (isRetry) {
|
|
|
prizeCodeCreateCount.fail(); // 记录生成抽奖码失败
|
|
|
|
|
|
return '';
|
|
|
} else {
|
|
|
return this.createPrizeCode(length, true);
|
|
|
}
|
|
|
} else {
|
|
|
prizeCodeCreateCount.success(); // 记录生成抽奖码成功
|
|
|
|
|
|
return prizeCode;
|
|
|
}
|
|
|
}
|
...
|
...
|
@@ -485,16 +547,32 @@ module.exports = class extends global.yoho.BaseModel { |
|
|
* @returns {*}
|
|
|
*/
|
|
|
sendWechatMessage(uid, actPrizeId, extra = {}) {
|
|
|
let info = {};
|
|
|
let baseUri = 'page/subPackage/pages/zeroSell/detail';
|
|
|
|
|
|
switch (+extra.miniAppType) {
|
|
|
case 29:
|
|
|
info.miniAppType = extra.miniAppType;
|
|
|
baseUri = 'pages/zeroSell/detail';
|
|
|
break;
|
|
|
default:
|
|
|
break;
|
|
|
}
|
|
|
|
|
|
return this.get({
|
|
|
data: {
|
|
|
data: Object.assign({
|
|
|
method: 'wechat.message.send',
|
|
|
sendScene: 'MINI_ACTIVITY_JOIN',
|
|
|
params: JSON.stringify({
|
|
|
activityTitle: extra.actName,
|
|
|
activityTime: `${timeFormat(extra.actStartTime)} - ${timeFormat(extra.actEndTime)}`,
|
|
|
pageUrl: '/page/subPackage/pages/zeroSell/detail?actPrizeId=' + actPrizeId
|
|
|
pageUrl: `${baseUri}?actPrizeId=${actPrizeId}`
|
|
|
}),
|
|
|
uidList: [uid]
|
|
|
}, info)
|
|
|
}).then(result => {
|
|
|
if (result.code !== 200) {
|
|
|
logger.info(`zerobuy_join_notice send fail uid: ${uid}`);
|
|
|
}
|
|
|
});
|
|
|
}
|
...
|
...
|
|