test
This commit is contained in:
@@ -2,55 +2,83 @@ const db = uniCloud.database();
|
||||
const _ = db.command;
|
||||
const jqb_db = uniCloud.databaseForJQL();
|
||||
module.exports = {
|
||||
_before: function () { // 通用预处理器
|
||||
_before: function() { // 通用预处理器
|
||||
|
||||
},
|
||||
async getDetail(query) {
|
||||
console.log(query)
|
||||
const res = await db.collection("uni-cms-articles").doc(query.id).get();
|
||||
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 {
|
||||
|
||||
// const tt = await db.collection("uni-cms-articles").doc("67ba7308bf7490a7f48d3ba3").get();
|
||||
// console.log(tt);
|
||||
|
||||
|
||||
|
||||
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();
|
||||
|
||||
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();
|
||||
|
||||
|
||||
user_id: user_id,
|
||||
article_id: article_id
|
||||
})
|
||||
.count();
|
||||
|
||||
|
||||
if (collectRes.total > 0) {
|
||||
isCollect = true;
|
||||
}
|
||||
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
isLike: isLike,
|
||||
isCollect: isCollect
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
return {
|
||||
code: 500,
|
||||
@@ -59,40 +87,44 @@ module.exports = {
|
||||
}
|
||||
},
|
||||
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();
|
||||
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();
|
||||
.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();
|
||||
.field('_id,avatar_file')
|
||||
.getTemp();
|
||||
|
||||
// 联表查询并分页
|
||||
const collectRes = await jqb_db.collection(logTemp, userTemp)
|
||||
.orderBy('logTemp.first_view_time asc') // 按时间倒序
|
||||
.skip(0)
|
||||
.limit(21)
|
||||
.get();
|
||||
|
||||
.orderBy('logTemp.first_view_time asc') // 按时间倒序
|
||||
.skip(0)
|
||||
.limit(21)
|
||||
.get();
|
||||
|
||||
return {
|
||||
code: 200,
|
||||
cmsArticleLog: collectRes.data
|
||||
}
|
||||
} catch(e) {
|
||||
} catch (e) {
|
||||
console.log(e.message);
|
||||
return {
|
||||
code: 500,
|
||||
@@ -100,4 +132,4 @@ module.exports = {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user