Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

修复、优化、添加 #939

Merged
merged 14 commits into from
Nov 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 90 additions & 7 deletions dataModels/ColumnPostModel.js
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,26 @@ schema.statics.getCategoriesOrder = async (categoriesId) => {
return order;
};

/*
* 生成在各主分类和辅分类交叉页面数据的排序
* @param {[String]} categoriesId 主分类数组
* @param {[String]} categoriesId 辅分类数组
* */
schema.statics.getColumnPostOrder = async (mainIds, minorIds) => {
const SettingModel = mongoose.model('settings');
const cIds = ['default', ...mainIds];
const mcIds = ['default', 'other', ...minorIds];
const order = {};
for (const cid of cIds) {
for (const mcid of mcIds) {
order[`cid_${cid}_${mcid}`] = await SettingModel.operateSystemID(
'columnPostOrders',
1,
);
}
}
return order;
};
/*
* 拓展专栏首页专栏引用文章
* @params {string} columnId 专栏 ID
Expand Down Expand Up @@ -629,12 +649,15 @@ schema.statics.addColumnPosts = async (
for (const pid of postsId) {
let columnPost = await ColumnPostModel.findOne({ columnId, pid });
//获取著分类排序
const order = await ColumnPostModel.getCategoriesOrder(categoriesId);
// const order = await ColumnPostModel.getCategoriesOrder(categoriesId);
if (columnPost) {
await columnPost.updateOne({
cid: categoriesId_,
mcid: minorCategoriesId_,
order,
order: await ColumnPostModel.getColumnPostOrder(
categoriesId,
minorCategoriesId,
),
});
continue;
}
Expand All @@ -647,7 +670,10 @@ schema.statics.addColumnPosts = async (
_id: await SettingModel.operateSystemID('columnPosts', 1),
tid: '',
top: post.toc,
order,
order: await ColumnPostModel.getColumnPostOrder(
categoriesId,
minorCategoriesId,
),
tUid: thread.uid,
pid,
type: thread.oc === pid ? 'thread' : 'post',
Expand Down Expand Up @@ -777,12 +803,15 @@ schema.statics.createColumnPost = async function (article, selectCategory) {
}
//如果article存在sid,通过sid查找专栏
const column = await ColumnModel.findOnly({ _id: sid });
const order = await ColumnPostModel.getCategoriesOrder(
selectCategory.selectedMainCategoriesId,
);
// const order = await ColumnPostModel.getCategoriesOrder(
// selectCategory.selectedMainCategoriesId,
// );
const columnPost = ColumnPostModel({
_id: await SettingModel.operateSystemID('columnPosts', 1),
order,
order: await ColumnPostModel.getColumnPostOrder(
selectCategory.selectedMainCategoriesId,
selectCategory.selectedMinorCategoriesId,
),
columnId: sid,
from: article.uid === column.uid ? 'own' : 'reprint',
top: toc,
Expand Down Expand Up @@ -830,4 +859,58 @@ schema.methods.extendColumnPost = async function () {
return ColumnModel.findOne({ _id: columnId });
};

/*
* 检查专栏文章列表中的order字段排序是否正确
* */
schema.statics.checkColumnPostOrder = async function (columnId, cid, mcid) {
const ColumnPostModel = mongoose.model('columnPosts');
const ColumnPostCategoryModel = mongoose.model('columnPostCategories');
const SettingModel = mongoose.model('settings');
let keyName = '';
const match = {
columnId,
};
if (cid) {
const childCategoryId = await ColumnPostCategoryModel.getChildCategoryId(
cid,
);
childCategoryId.push(cid);
match.cid = { $in: childCategoryId };
if (mcid) {
keyName = `cid_${cid}_${mcid}`;
} else {
keyName = `cid_${cid}_default`;
}
} else {
if (mcid) {
keyName = `cid_default_${mcid}`;
} else {
keyName = `cid_default_default`;
}
}
if (mcid) {
match.mcid = mcid === 'other' ? [] : mcid;
}
match[`order.${keyName}`] = {
$exists: false,
};
const sort = {};
sort[`order.${keyName}`] = -1;
const columnPosts = await ColumnPostModel.find(match).sort(sort).lean();
for (const columnPost of columnPosts) {
const obj = {};
obj[`order.${keyName}`] = await SettingModel.operateSystemID(
'columnPostDownOrders',
-1,
);
await ColumnPostModel.updateOne(
{
_id: columnPost._id,
},
{
$set: obj,
},
);
}
};
module.exports = mongoose.model('columnPosts', schema);
4 changes: 2 additions & 2 deletions languages/zh_cn/messageTypes.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,8 @@
"shopBuyerApplyRefund": "【交易系统】买家申请退款",
"shopBuyerRefundChange": "【交易系统】订单退款状态更新",
"shopSellerRefundChange": "【交易系统】订单退款状态更新",
"warningPost": "管理员提醒-文章",
"warningThread": "管理员提醒-回复",
"warningPost": "管理员提醒-回复",
"warningThread": "管理员提醒-文章",
"newReview": "【审核系统】内容待审核",
"passReview": "【审核系统】内容通过审核",
"fundApplicant": "【基金系统】申请状态更新",
Expand Down
3 changes: 2 additions & 1 deletion pages/columns/settings/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,8 @@ var app = new Vue({
nkcAPI("/m/" + this.column._id + "/post", "POST", {
type: type,
postsId: id,
categoryId: app.category._id==="all"? "": app.category._id
categoryId: app.category._id==="all"? "": app.category._id,
minorCategoriesId: app.minorCategory._id==="all"? "": app.minorCategory._id
})
.then(function(data) {
if(data.columnTopped) app.column.topped = data.columnTopped;
Expand Down
2 changes: 1 addition & 1 deletion pages/interface_thread_userpatch.pug
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
-var uid = user.uid
.ThreadBox.m-b-1(style='overflow: hidden;')
.ThreadBox.m-b-1.box-shadow(style='overflow: hidden;')
.UserProfileSection1
.media
a(href=tools.getUrl('userAvatar', user.avatar, 'lg') target="_blank").media-left
Expand Down
Loading
Loading