Authored by 邱骏

update

... ... @@ -4,6 +4,7 @@
* @date: 19/07/2018
*/
const zerobuyModel = require('../models/zero-buy');
const logger = global.yoho.logger;
module.exports = {
list(req, res, next) {
... ... @@ -43,7 +44,11 @@ module.exports = {
codeGain(req, res, next) {
let params = req.body;
if (!params.uid || !params.actPrizeId || !params.userName || !params.userThumb) {
params.userName = params.userName || '_';
params.userThumb = params.userThumb || 'https://img10.static.yhbimg.com/headimg/2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
if (!params.uid || !params.actPrizeId) {
logger.error(`用户参数错误:${JSON.stringify(params)}`);
return res.json({
code: 400,
message: '参数非法'
... ...
... ... @@ -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}`);
}
});
}
... ...
... ... @@ -5,6 +5,7 @@
*/
const mysqlCli = global.yoho.utils.mysqlCli;
const logger = global.yoho.logger;
const _ = require('lodash');
const moment = require('moment');
... ... @@ -21,6 +22,10 @@ const TABLE_ACT_PRIZE_PRODUCT = 'act_prize_product';
const TABLE_ACT_PRIZE_PRODUCT_CONTENT = 'act_prize_product_content';
const TABLE_ACT_PRIZE_PRODUCT_USER = 'act_prize_product_user';
const NOTICE_BATCH_SEND_USER_NUM = 400; // 批量发送模板消息每个请求uid数量
const NOTICE_BATCH_SEND_API_NUM = 10; // 批量发送模板消息每个批次请求数量
const NOTICE_BATCH_SEND_INTERVAL = 5000; // 批量发送模板消息批次间隔时间(ms)
const timeFormat = (time) => {
if (_.isNumber(time)) {
time = moment.unix(time);
... ... @@ -761,13 +766,15 @@ class AdminModel extends global.yoho.BaseModel {
params: JSON.stringify({
activityTitle: productInfo.name,
activityTime: moment().format('YYYY-MM-DD HH:mm') + ':00',
pageUrl: '/page/subPackage/pages/zeroSell/detail?actPrizeId=' + id
pageUrl: 'page/subPackage/pages/zeroSell/detail?actPrizeId=' + id
})
};
_.forEach(_.chunk(userList, 400), value => {
_.forEach(_.chunk(userList, NOTICE_BATCH_SEND_USER_NUM), value => {
if (value && value.length) {
msgApi.push(this.get({data: Object.assign({uidList: value}, msgData)}));
msgApi.push(this.get({data: Object.assign({uidList: value}, msgData)}).then(result => {
logger.info(`zerobuy_winning_notice send ${result.code === 200 ? 'success' : 'fail'} uids: ${value.join(',')}`);
}));
}
});
... ... @@ -785,10 +792,10 @@ class AdminModel extends global.yoho.BaseModel {
}
setTimeout(() => {
this.batchSend(_.drop(apis, 20));
}, 1000);
this.batchSend(_.drop(apis, NOTICE_BATCH_SEND_API_NUM));
}, NOTICE_BATCH_SEND_INTERVAL);
return Promise.all(_.take(apis, 20));
return Promise.all(_.take(apis, NOTICE_BATCH_SEND_API_NUM));
}
}
... ...
... ... @@ -5,11 +5,18 @@
*/
const qiniu = require('qiniu');
const qiniuConfig = global.yoho.config.qiniu;
const qiniuYohoCdnConfig = global.yoho.config.qiniuYohoCdn;
function getToken(req, res) {
let mac = new qiniu.auth.digest.Mac(qiniuConfig.ACCESS_KEY, qiniuConfig.SECRET_KEY);
let conf = qiniuConfig;
if (req.query.type === 'yohoCdn') {
conf = qiniuYohoCdnConfig;
}
let mac = new qiniu.auth.digest.Mac(conf.ACCESS_KEY, conf.SECRET_KEY);
let options = {
scope: qiniuConfig.BUCKET_NAME,
scope: conf.BUCKET_NAME
};
let putPolicy = new qiniu.rs.PutPolicy(options);
let uploadToken = putPolicy.uploadToken(mac);
... ...
... ... @@ -108,6 +108,12 @@ module.exports = {
SECRET_KEY: '_x2VtO7fEmylgjojmLi7qwTBtRm30S8BrO0FxOPK',
BUCKET_NAME: 'cmsimg01'
},
qiniuYohoCdn: {
ACCESS_KEY: 'BwWhoJN536BnV3CzlE20AjNKC9O2bP0l5tFpKsDU',
SECRET_KEY: '_x2VtO7fEmylgjojmLi7qwTBtRm30S8BrO0FxOPK',
ORIGIN: 'https://cdn.yoho.cn',
BUCKET_NAME: 'yohocdn'
},
yohoSecret: '3bd815162342d9733f06ab6811082c64',
wechat: {
appID: 'wx1fe49f08f41b6c26', // jsapi 用
... ...
e0e69bae4039883aecb1ac961021a274
\ No newline at end of file
... ...
... ... @@ -116,7 +116,7 @@ function initUpload() {
Qiniu.uploader({ // eslint-disable-line
runtimes: 'html5,flash,html4',
browse_button: 'upload-btn',
uptoken_url: '/api/getToken',
uptoken_url: '/api/getToken?type=yohoCdn',
unique_names: true,
multi_selection: false,
filters: {
... ... @@ -125,7 +125,7 @@ function initUpload() {
}]
},
dragdrop: false,
domain: 'http://img01.yohoboys.com/',
domain: 'https://cdn.yoho.cn/',
max_file_size: '10mb',
max_retries: 3,
chunk_size: '10mb',
... ...
... ... @@ -59,7 +59,6 @@ class SqlHelper {
});
}
async execute(sql, params, options = {}) {
// console.log(sql);
let cacheTime = parseInt(options.cache, 10) || 0;
let cacheKey;
... ...