This commit is contained in:
2025-06-13 20:48:15 +08:00
parent 898b816655
commit a41fbbd663
42 changed files with 7189 additions and 0 deletions
@@ -0,0 +1,168 @@
const { count } = require("console");
const db = uniCloud.database();
const _ =db.command;
module.exports = {
_before: function () { // 通用预处理器
},
async getVoteInfo(query) {
try {
let {
vote_id,
user_id
} = query;
// 用户选择
const user_res = await db.collection("cms-vote")
.where({
user_id: user_id,
vote_id: vote_id
})
.get();
// 获得总选择
const all_res = await db.collection("cms-vote-info")
.where({
vote_id: vote_id
})
.get();
return {
code: 200,
user_data: user_res.data[0],
all_data: all_res.data[0]
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
},
async add_vote(query) {
try {
let {
vote_id,
selectValue,
user_id,
type
} = query;
let t = await db.collection("cms-vote")
.where({
user_id: user_id,
vote_id: vote_id
})
.count();
if (t.total > 0) {
return {
code: 500,
msg: "已投票!"
}
} else {
await db.collection("cms-vote").add({
vote_id: vote_id,
selectValue: selectValue,
user_id: user_id,
type: type
});
const res = await db.collection("cms-vote-info")
.where({
vote_id: vote_id
})
.count();
if (res.total > 0) {
if (type === "单选(默认)") {
const voteInfo = await db.collection("cms-vote-info")
.where({
vote_id: vote_id
})
.get();
console.log(voteInfo)
let values = voteInfo.data[0].selectValue;
values[selectValue] = (values[selectValue] || 0) + 1;
await db.collection("cms-vote-info")
.where({
vote_id: vote_id
})
.update({
selectValue: values,
count: voteInfo.data[0].count + 1
});
} else {
const voteInfo = await db.collection("cms-vote-info")
.where({
vote_id: vote_id
})
.get();
console.log(voteInfo)
let values = voteInfo.data[0].selectValue;
for (let i = 0; i < selectValue.length ; i ++ ) {
values[selectValue[i]] = (values[selectValue[i]] || 0) + 1;
console.log((values[selectValue] || 0) + 1, values);
}
console.log(values);
await db.collection("cms-vote-info")
.where({
vote_id: vote_id
})
.update({
selectValue: values,
count: voteInfo.data[0].count + 1
});
}
} else {
if (type === "单选(默认)") {
await db.collection("cms-vote-info")
.add({
vote_id: vote_id,
selectValue: {
[selectValue]: 1
},
type: type,
count: 1
});
} else {
let values = {};
for (let i = 0 ; i < selectValue.length; i ++ ) {
values[selectValue[i]] = 1;
}
console.log(values);
await db.collection("cms-vote-info")
.add({
vote_id: vote_id,
selectValue: values,
type: type,
count: 1
});
}
}
return {
code: 200
}
}
} catch(e) {
return {
code: 500,
msg: e.message
}
}
}
}
@@ -0,0 +1,7 @@
{
"name": "cms-vote",
"dependencies": {},
"extensions": {
"uni-cloud-jql": {}
}
}
@@ -0,0 +1,2 @@
// 本文件中的内容将在云对象【运行】时解析为运行参数
// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/rundebug.html#run-obj-param
@@ -0,0 +1,70 @@
{
"bsonType": "object",
"required": [
"temptele_name",
"select_src",
"font_color",
"temptele_src",
"backgrond_color",
"select_icon_color",
"icon_color",
"user_name_color",
"btn_color"
],
"permission": {
"read": true,
"create": "'admin' in auth.role", // 登录用户可创建
"update": "'admin' in auth.role", // 仅作者可修改
"delete": "'admin' in auth.role" // 作者或管理员可删除
},
"properties": {
"_id": {
"description": "ID,系统自动生成",
"bsonType": "objectId"
},
"font_color": {
"bsonType": "string",
"description": "文字颜色代码",
"pattern": "^#[0-9a-fA-F]{3,6}$"
},
"backgrond_color": {
"bsonType": "string",
"description": "背景颜色代码",
"pattern": "^#[0-9a-fA-F]{3,6}$"
},
"select_src": {
"bsonType": "string",
"description": "素材选择(选择模板的样例图)地址"
},
"temptele_src": {
"bsonType": "string",
"description": "模板图片(实际使用)地址"
},
"temptele_name": {
"bsonType": "string",
"description": "模板名称",
"minLength": 2,
"maxLength": 50
},
"select_icon_color": {
"bsonType": "string",
"description": "图标选中颜色的代码",
"pattern": "^#[0-9a-fA-F]{3,6}$"
},
"icon_color": {
"bsonType": "string",
"description": "图标未选中颜色的代码",
"pattern": "^#[0-9a-fA-F]{3,6}$"
},
"user_name_color": {
"bsonType": "string",
"description": "默认用户名字颜色的代码",
"pattern": "^#[0-9a-fA-F]{3,6}$"
},
"btn_color": {
"bsonType": "string",
"description": "按钮(回复和删除评论)默认颜色的代码",
"pattern": "^#[0-9a-fA-F]{3,6}$"
}
}
}
@@ -0,0 +1,27 @@
{
"bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"vote_id": {
"bsonType": "string"
},
"selectValue": {
"bsonType": "object"
},
"type": {
"bsonType": "string"
},
"count": {
"bsonType": "int"
}
}
}
@@ -0,0 +1,27 @@
{
"bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id": {
"bsonType": "string"
},
"vote_id": {
"bsonType": "string"
},
"selectValue": {
"bsonType": "array"
},
"type": {
"bsonType": "string"
}
}
}
+23
View File
@@ -0,0 +1,23 @@
{
"uni-cms-unlock-record": {
"data": [],
"index": [
{
"IndexName": "unique_article_trans_",
"MgoKeySchema": {
"MgoIndexKeys": [{
"Name": "unique_id",
"Direction": "1"
},{
"Name": "article_id",
"Direction": "1"
},{
"Name": "trans_id",
"Direction": "1"
}],
"MgoIsUnique": false
}
}
]
}
}
+1
View File
@@ -0,0 +1 @@
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}}
@@ -0,0 +1 @@
{"bsonType":"object","required":[],"permission":{"read":false,"create":false,"update":false,"delete":false},"properties":{"_id":{"description":"ID,系统自动生成"}}}
@@ -0,0 +1,25 @@
// 文档教程: https://uniapp.dcloud.net.cn/uniCloud/schema
{
"bsonType": "object",
"required": [],
"permission": {
"read": true,
"create": true,
"update": true,
"delete": true
},
"properties": {
"_id": {
"description": "ID,系统自动生成"
},
"user_id": {
"bsonType": "string",
"foreignKey": "uni-id-users._id",
"pattern": "^[0-9a-f]{24}$"
},
"vote_id": {
"bsonType": "string",
"foreignKey": "cms_vote.vote_id"
}
}
}