...
|
...
|
@@ -13,6 +13,9 @@ const Mysql = require('../../../lib/mysql-promise'); |
|
|
const Promise = require('bluebird');
|
|
|
const r = new Router();
|
|
|
const rp = require('request-promise');
|
|
|
const config = require('../../../config/config');
|
|
|
const singleBrandKeyPre = config.singleBrandKeyPre;
|
|
|
const singleSortKeyPre = config.singleSortKeyPre;
|
|
|
|
|
|
const multiAsync=(multi)=>{
|
|
|
return multi.execAsync().then(function(res) {
|
...
|
...
|
@@ -73,6 +76,26 @@ const searchDataValues = async(ctx, value)=>{ |
|
|
return multiAsync(multi);
|
|
|
}
|
|
|
|
|
|
const mgets = async(ctx, item) => {
|
|
|
let redis = ctx.redis;
|
|
|
let operation = [];
|
|
|
item = _.uniq(item);
|
|
|
|
|
|
if (item.length <= 0) {
|
|
|
return Promise.resolve({});
|
|
|
}
|
|
|
|
|
|
return redis.mgetAsync(item).then(d => {
|
|
|
let ddata = {};
|
|
|
|
|
|
_.each(item, (el, index) => {
|
|
|
ddata[el] = d[index];
|
|
|
});
|
|
|
|
|
|
return ddata;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
r.get('/', async(ctx) => {
|
|
|
let resData = {};
|
|
|
let q = ctx.request.query,
|
...
|
...
|
@@ -180,16 +203,16 @@ r.get('/syncWord', async(ctx) => { |
|
|
}).then(ddata => {
|
|
|
return Promise.map(ddata, (word) => insertWord(word, mysql), {concurrency: 15});
|
|
|
}).then(d => {
|
|
|
return mysql.close(d);
|
|
|
}).then(d => {
|
|
|
return ctx.body = {
|
|
|
code: 200,
|
|
|
message: 'success',
|
|
|
data: d
|
|
|
};
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
r.get('/expand', async(ctx) => {
|
|
|
let resData = {};
|
|
|
let q = ctx.request.query;
|
...
|
...
|
@@ -239,28 +262,48 @@ r.get('/expand', async(ctx) => { |
|
|
break;
|
|
|
}
|
|
|
|
|
|
return mysql.query(`SELECT COUNT(*) as total FROM seo_keywords WHERE 1 = 1 ${wheres}`, conditions).then(d => {
|
|
|
total = d[0] && d[0].total || 0;
|
|
|
conditions.push((page - 1) * limit, limit);
|
|
|
return mysql.query(`SELECT * FROM seo_keywords WHERE 1 = 1 ${wheres} limit ?, ?`, conditions);
|
|
|
}).then(d => {
|
|
|
|
|
|
resData.pager = pager(Math.floor((total - 1) / limit) + 1, ctx.query);
|
|
|
|
|
|
resData.tabs = _.map(d, (elem) => {
|
|
|
return Object.assign({}, elem, {
|
|
|
is_push: elem.is_push ? '是' : '否',
|
|
|
add_time: elem.add_time && moment(elem.add_time * 1000).format('YYYY-MM-DD HH:mm'),
|
|
|
});
|
|
|
});
|
|
|
let d = await mysql.query(`SELECT COUNT(*) as total FROM seo_keywords WHERE 1 = 1 ${wheres}`, conditions);
|
|
|
|
|
|
total = d[0] && d[0].total || 0;
|
|
|
conditions.push((page - 1) * limit, limit);
|
|
|
|
|
|
resData.typeList = typeList;
|
|
|
resData.typeName = typeName;
|
|
|
resData.type = type;
|
|
|
resData.query = query;
|
|
|
d = await mysql.query(`SELECT * FROM seo_keywords WHERE 1 = 1 ${wheres} limit ?, ?`, conditions);
|
|
|
|
|
|
return ctx.render('action/keywords/expand', resData);
|
|
|
d = await mysql.close(d);
|
|
|
|
|
|
let sortIds = [];
|
|
|
let brandIds = [];
|
|
|
|
|
|
resData.pager = pager(Math.floor((total - 1) / limit) + 1, ctx.query);
|
|
|
|
|
|
_.each(d, (val) => {
|
|
|
if (val.sort_id) {
|
|
|
sortIds.push(`${singleSortKeyPre}${val.sort_id}`);
|
|
|
}
|
|
|
|
|
|
if (val.brand_id) {
|
|
|
brandIds.push(`${singleBrandKeyPre}${val.brand_id}`);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
brandIds = await mgets(ctx, brandIds);
|
|
|
sortIds = await mgets(ctx, sortIds);
|
|
|
|
|
|
resData.tabs = _.map(d, (elem) => {
|
|
|
return Object.assign({}, elem, {
|
|
|
brand: brandIds[`${singleBrandKeyPre}${elem.brand_id}`],
|
|
|
sort: sortIds[`${singleSortKeyPre}${elem.sort_id}`],
|
|
|
is_push: elem.is_push ? '是' : '否',
|
|
|
add_time: elem.add_time && moment(elem.add_time * 1000).format('YYYY-MM-DD HH:mm'),
|
|
|
});
|
|
|
});
|
|
|
|
|
|
resData.typeList = typeList;
|
|
|
resData.typeName = typeName;
|
|
|
resData.type = type;
|
|
|
resData.query = query;
|
|
|
|
|
|
return ctx.render('action/keywords/expand', resData);
|
|
|
});
|
|
|
|
|
|
r.post('/expand/del', async(ctx) => {
|
...
|
...
|
@@ -284,6 +327,8 @@ r.post('/expand/del', async(ctx) => { |
|
|
}
|
|
|
|
|
|
return mysql.query(`DELETE FROM seo_keywords WHERE id IN (${marks.join(',')})`, ids).then(d => {
|
|
|
return mysql.close(d);
|
|
|
}).then(d => {
|
|
|
return ctx.body = {
|
|
|
code: 200,
|
|
|
message: 'success',
|
...
|
...
|
|