Files
t/uniCloud-alipay/cloudfunctions/article_info/index.obj.js
T
2025-06-13 20:46:10 +08:00

135 lines
2.6 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
const db = uniCloud.database();
const _ = db.command;
const jqb_db = uniCloud.databaseForJQL();
module.exports = {
_before: function() { // 通用预处理器
},
async getDetail(query) {
console.log(query)
const res = await db.collection("uni-cms-articles").doc(query.id).get();
return res;
},
async isSelectVote(query) {
try {
let {
user_id,
vote_id
} = query;
const res = await db.collection("cms-vote")
.where({
user_id: user_id,
vote_id: vote_id
})
.count();
let isSelectVote = false;
console.log(res.total)
if (res.total > 0) {
isSelectVote = true;
} else {
isSelectVote = false;
}
return {
code: 200,
isSelectVote: isSelectVote
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
},
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 get() {
const res = await db.collection(dbCollectionName).doc("67ba7308bf7490a7f48d3ba3").field(
"_id,is_admin,user_id,category_id,title,content,excerpt,article_status,is_sticky,is_essence,comment_status,thumbnail,publish_date"
).get();
console.log(res);
return res;
},
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
}
}
}
}