...
|
...
|
@@ -509,6 +509,57 @@ class ArticleModel extends global.yoho.BaseModel { |
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取Y100列表-随机
|
|
|
* @returns {*}
|
|
|
*/
|
|
|
async articleY100RandomList({actId, num}) {
|
|
|
const params = {
|
|
|
actId,
|
|
|
};
|
|
|
let maxSql = `
|
|
|
SELECT
|
|
|
max(\`index\`) as maxIndex
|
|
|
FROM ${TABLE_ACT_ARTICLE_Y100} AAY
|
|
|
WHERE AAy.act_id = :actId`;
|
|
|
|
|
|
const maxResult = await mysqlCli.query(maxSql, params);
|
|
|
let maxIndex = maxResult[0].maxIndex;
|
|
|
|
|
|
if (num > maxIndex) {
|
|
|
throw '随机数量超过数据库大小';
|
|
|
}
|
|
|
const ids = [],
|
|
|
selectIds = [];
|
|
|
|
|
|
for (let i = 0; i <= maxIndex; i++) {
|
|
|
ids.push(i);
|
|
|
}
|
|
|
|
|
|
for (let i = 0; i < num; i++) {
|
|
|
const index = parseInt(Math.random() * ids.length, 10);
|
|
|
|
|
|
selectIds.push(ids[index]);
|
|
|
ids.splice(index, 1);
|
|
|
}
|
|
|
|
|
|
let sql = `
|
|
|
SELECT
|
|
|
AA.id,
|
|
|
AA.good_count,
|
|
|
AA.create_time,
|
|
|
AAY.name,
|
|
|
AAY.img_url
|
|
|
FROM ${TABLE_ACT_ARTICLE} AA
|
|
|
INNER JOIN ${TABLE_ACT_ARTICLE_Y100} AAY ON AA.id = AAY.article_id
|
|
|
WHERE AA.act_id = :actId`;
|
|
|
|
|
|
sql += ` and AAY.index in (${selectIds.join(',')})`;
|
|
|
sql += ` order by field(AAY.index,${selectIds.join(',')});`;
|
|
|
|
|
|
return mysqlCli.query(sql, params);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取Y100详情
|
|
|
* @returns {*}
|
|
|
*/
|
...
|
...
|
@@ -525,8 +576,10 @@ class ArticleModel extends global.yoho.BaseModel { |
|
|
AAY.style,
|
|
|
AAY.interest,
|
|
|
AAY.skns,
|
|
|
AAY.create_time
|
|
|
AAY.create_time,
|
|
|
AA.good_count
|
|
|
FROM ${TABLE_ACT_ARTICLE_Y100} AAY
|
|
|
INNER JOIN ${TABLE_ACT_ARTICLE} AA ON AAY.article_id = AA.id
|
|
|
where AAY.id = :id`;
|
|
|
|
|
|
const query = await mysqlCli.query(sql, {
|
...
|
...
|
|