feat: 完成分龄页开发

This commit is contained in:
R524809
2026-05-06 17:28:51 +08:00
parent 50394154f7
commit 9bdf850f20
54 changed files with 3499 additions and 1021 deletions
@@ -0,0 +1,37 @@
const cloud = require('wx-server-sdk');
cloud.init({ env: cloud.DYNAMIC_CURRENT_ENV });
const VALID_FIELDS = new Set(['likes', 'downloads']);
exports.main = async (event) => {
try {
const db = cloud.database();
const command = db.command;
const collection = db.collection('worksheets');
const id = String(event.id || '').trim();
const field = String(event.field || '').trim();
if (!id) throw new Error('worksheet id 不能为空');
if (!VALID_FIELDS.has(field)) throw new Error('统计字段不合法');
await collection.doc(id).update({
data: {
[field]: command.inc(1),
updatedAt: db.serverDate(),
},
});
return {
success: true,
data: { _id: id, field },
};
} catch (error) {
return {
success: false,
message:
error instanceof Error ? error.message : '更新统计失败',
};
}
};