Showing
1 changed file
with
29 additions
and
0 deletions
@@ -196,6 +196,28 @@ const insertWord = (keyword, mysql) => { | @@ -196,6 +196,28 @@ const insertWord = (keyword, mysql) => { | ||
196 | }); | 196 | }); |
197 | } | 197 | } |
198 | 198 | ||
199 | +const getRootKeyword = (ids, mysql) => { | ||
200 | + let len = ids.length; | ||
201 | + let marks = []; | ||
202 | + | ||
203 | + if (len <= 0) { | ||
204 | + return Promise.resolve({}); | ||
205 | + } | ||
206 | + | ||
207 | + for(let i = 0; i < len; i++) { | ||
208 | + marks.push('?'); | ||
209 | + } | ||
210 | + return mysql.query(`SELECT id, keyword FROM seo_keywords_root WHERE id IN (${marks.join(',')}) AND status = 1;`, ids).then(d => { | ||
211 | + let ddata = {}; | ||
212 | + | ||
213 | + _.each(d, (item) => { | ||
214 | + ddata[item.id] = item.keyword; | ||
215 | + }); | ||
216 | + | ||
217 | + return ddata; | ||
218 | + }); | ||
219 | +} | ||
220 | + | ||
199 | //redis关键词同步到mysql | 221 | //redis关键词同步到mysql |
200 | r.get('/syncWord', async(ctx) => { | 222 | r.get('/syncWord', async(ctx) => { |
201 | let mysql = new Mysql(); | 223 | let mysql = new Mysql(); |
@@ -271,6 +293,7 @@ r.get('/expand', async(ctx) => { | @@ -271,6 +293,7 @@ r.get('/expand', async(ctx) => { | ||
271 | 293 | ||
272 | let sortIds = []; | 294 | let sortIds = []; |
273 | let brandIds = []; | 295 | let brandIds = []; |
296 | + let rootIds = []; | ||
274 | 297 | ||
275 | resData.pager = pager(Math.floor((total - 1) / limit) + 1, ctx.query); | 298 | resData.pager = pager(Math.floor((total - 1) / limit) + 1, ctx.query); |
276 | 299 | ||
@@ -282,13 +305,19 @@ r.get('/expand', async(ctx) => { | @@ -282,13 +305,19 @@ r.get('/expand', async(ctx) => { | ||
282 | if (val.brand_id) { | 305 | if (val.brand_id) { |
283 | brandIds.push(`${singleBrandKeyPre}${val.brand_id}`); | 306 | brandIds.push(`${singleBrandKeyPre}${val.brand_id}`); |
284 | } | 307 | } |
308 | + | ||
309 | + if (val.root_id) { | ||
310 | + rootIds.push(val.root_id); | ||
311 | + } | ||
285 | }); | 312 | }); |
286 | 313 | ||
287 | brandIds = await mgets(ctx, brandIds); | 314 | brandIds = await mgets(ctx, brandIds); |
288 | sortIds = await mgets(ctx, sortIds); | 315 | sortIds = await mgets(ctx, sortIds); |
316 | + rootIds = await getRootKeyword(rootIds, mysql); | ||
289 | 317 | ||
290 | resData.tabs = _.map(d, (elem) => { | 318 | resData.tabs = _.map(d, (elem) => { |
291 | return Object.assign({}, elem, { | 319 | return Object.assign({}, elem, { |
320 | + root: rootIds[elem.root_id], | ||
292 | brand: brandIds[`${singleBrandKeyPre}${elem.brand_id}`], | 321 | brand: brandIds[`${singleBrandKeyPre}${elem.brand_id}`], |
293 | sort: sortIds[`${singleSortKeyPre}${elem.sort_id}`], | 322 | sort: sortIds[`${singleSortKeyPre}${elem.sort_id}`], |
294 | is_push: elem.is_push ? '是' : '否', | 323 | is_push: elem.is_push ? '是' : '否', |
-
Please register or login to post a comment