Authored by 周少峰

Merge branch 'feature/randomKeywords'

... ... @@ -372,13 +372,25 @@ r.post('/expand/del', async(ctx) => {
* @return {[type]} [description]
*/
r.post('/expand/randWords', async(ctx) => {
let expandModel = new ExpandModel(ctx);
let key = `golobal:yoho:seo:keywords:isRun`;
return expandModel.getRanData().then(d => {
return ctx.body = {
code: 200,
message: 'success'
};
return ctx.redis.getAsync(key).then((d) => {
if (d) {
return ctx.body = {
code: 201,
message: '正在执行中...'
};
}
let expandModel = new ExpandModel(ctx);
return expandModel.getRanData().then(d => {
return ctx.body = {
code: 200,
message: 'success'
};
});
});
});
... ...
... ... @@ -9,6 +9,7 @@ const keywordsRedis = {
'keywordsAllIds': `golobal:yoho:seo:keywords:allIds`,// 关键词表符合条件所有id
'keywordsSortId': `golobal:yoho:seo:keywords:sortId`,// 分类下的所有关键词
'keywordsId': `golobal:yoho:seo:keywords:id`,// 每条关键词关联其它12条关键词
'keywordsIsRun': `golobal:yoho:seo:keywords:isRun`,// 判断是否正在执行中
};
class expandModel extends model {
... ... @@ -22,12 +23,18 @@ class expandModel extends model {
getRanData() {
this.dataIds = [];
return this.mysql.query(`SELECT sort_id FROM seo_keywords WHERE status = 1 GROUP BY sort_id;`).then(rdata => {
return this.redis.setAsync(`${keywordsRedis.keywordsIsRun}`, 1).then(() => {// 设置正在运行的key
return this.redis.expireAsync(`${keywordsRedis.keywordsIsRun}`, 5 * 60);// 设置正在运行的key有效期
}).then(() => {
return this.mysql.query(`SELECT sort_id FROM seo_keywords WHERE status = 1 GROUP BY sort_id;`);
}).then(rdata => {
return Promise.each(rdata, (item) => this._setSortToRedis(item.sort_id));
}).then(d => {
return this.redis.setAsync(`${keywordsRedis.keywordsAllIds}`, JSON.stringify(this.dataIds));
}).then(d => {
this.redis.delAsync(`${keywordsRedis.keywordsIsRun}`);
this.dataIds = [];
return d;
});
... ...
... ... @@ -183,7 +183,6 @@
.panel-body .rand-words.is-run {
background: #f5f5f5 url(/images/loaders/loader1.gif) no-repeat center;
border: 1px solid #ddd;
color: #aca899;
cursor: no-drop;
}
... ... @@ -244,7 +243,7 @@
$.ajax({
  url: '/keywords/expand/randWords',
  timeout: 1000,
  timeout: 1000 * 60 * 5,// 数据量大
  type: 'post',
  data: {},
  dataType: 'json',
... ... @@ -252,6 +251,10 @@
if (data.code === 200) {
layer.msg('关键词关联成功');
that.removeClass('is-run');
} else {
setTimeout(function() {
that.removeClass('is-run');
}, 1000 * 60 * 3);
}
  }
});
... ...