info
This commit is contained in:
@@ -0,0 +1,87 @@
|
||||
const db = uniCloud.database();
|
||||
const _ = db.command;
|
||||
const jqb_db = uniCloud.databaseForJQL();
|
||||
module.exports = {
|
||||
_before: function () { // 通用预处理器
|
||||
|
||||
},
|
||||
async getInfo(query) {
|
||||
try {
|
||||
|
||||
let user_id = query.user_id;
|
||||
let article_id = query.article_id;
|
||||
|
||||
let isLike = false;
|
||||
let isCollect = false;
|
||||
|
||||
const likeRes = await db.collection("cms-articles-like").where({
|
||||
user_id: user_id,
|
||||
article_id: article_id
|
||||
})
|
||||
.count();
|
||||
|
||||
if (likeRes.total > 0) {
|
||||
isLike = true;
|
||||
}
|
||||
|
||||
const collectRes = await db.collection("cms-articles-collect").where({
|
||||
user_id: user_id,
|
||||
article_id: article_id
|
||||
})
|
||||
.count();
|
||||
|
||||
|
||||
if (collectRes.total > 0) {
|
||||
isCollect = true;
|
||||
}
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
isLike: isLike,
|
||||
isCollect: isCollect
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
return {
|
||||
code: 500,
|
||||
msg: e.message
|
||||
}
|
||||
}
|
||||
},
|
||||
async getCmsArticleLog(query) {
|
||||
try {
|
||||
|
||||
let article_id = query.article_id;
|
||||
// cms-articles-log
|
||||
|
||||
// 生成文章日志临时表(过滤 article_id)
|
||||
const logTemp = jqb_db.collection("cms-articles-log")
|
||||
.where({ article_id: article_id })
|
||||
.field('article_id, user_id, first_view_time')
|
||||
.getTemp();
|
||||
|
||||
// 生成用户信息临时表(仅返回必要字段)
|
||||
const userTemp = jqb_db.collection("uni-id-users")
|
||||
.field('_id,avatar_file')
|
||||
.getTemp();
|
||||
|
||||
// 联表查询并分页
|
||||
const collectRes = await jqb_db.collection(logTemp, userTemp)
|
||||
.orderBy('logTemp.first_view_time asc') // 按时间倒序
|
||||
.skip(0)
|
||||
.limit(21)
|
||||
.get();
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
cmsArticleLog: collectRes.data
|
||||
}
|
||||
} catch(e) {
|
||||
console.log(e.message);
|
||||
return {
|
||||
code: 500,
|
||||
msg: e.message
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user