Authored by 郝肖肖

'root_id-

... ... @@ -196,6 +196,28 @@ const insertWord = (keyword, mysql) => {
});
}
const getRootKeyword = (ids, mysql) => {
let len = ids.length;
let marks = [];
if (len <= 0) {
return Promise.resolve({});
}
for(let i = 0; i < len; i++) {
marks.push('?');
}
return mysql.query(`SELECT id, keyword FROM seo_keywords_root WHERE id IN (${marks.join(',')}) AND status = 1;`, ids).then(d => {
let ddata = {};
_.each(d, (item) => {
ddata[item.id] = item.keyword;
});
return ddata;
});
}
//redis关键词同步到mysql
r.get('/syncWord', async(ctx) => {
let mysql = new Mysql();
... ... @@ -271,6 +293,7 @@ r.get('/expand', async(ctx) => {
let sortIds = [];
let brandIds = [];
let rootIds = [];
resData.pager = pager(Math.floor((total - 1) / limit) + 1, ctx.query);
... ... @@ -282,13 +305,19 @@ r.get('/expand', async(ctx) => {
if (val.brand_id) {
brandIds.push(`${singleBrandKeyPre}${val.brand_id}`);
}
if (val.root_id) {
rootIds.push(val.root_id);
}
});
brandIds = await mgets(ctx, brandIds);
sortIds = await mgets(ctx, sortIds);
rootIds = await getRootKeyword(rootIds, mysql);
resData.tabs = _.map(d, (elem) => {
return Object.assign({}, elem, {
root: rootIds[elem.root_id],
brand: brandIds[`${singleBrandKeyPre}${elem.brand_id}`],
sort: sortIds[`${singleSortKeyPre}${elem.sort_id}`],
is_push: elem.is_push ? '是' : '否',
... ...