39 lines
1.1 KiB
JavaScript
39 lines
1.1 KiB
JavaScript
// 云函数入口文件
|
||
const cloud = require('wx-server-sdk')
|
||
|
||
cloud.init()
|
||
const db = cloud.database()
|
||
const _ = db.command
|
||
const wxContext = cloud.getWXContext()
|
||
|
||
var commonUpload = async (data) => {
|
||
let rightAnswer = []
|
||
await db.collection('sD_common').doc('XKg1i1sqTi00tq1N').get().then(res => {
|
||
rightAnswer = res.data.rightAnswer //这玩意的返回值莫名其妙会套上一层right,,但是不影响使用
|
||
})
|
||
//event.data是对象!妈的坑人!
|
||
for (let i in data) {
|
||
i = parseInt(i)
|
||
if (data[i] === rightAnswer[i]) {
|
||
let object = {}
|
||
object[i + 1] = _.inc(1)//不能直接传进去,在外边构造然后传进去
|
||
db.collection('sD_common').doc('XKjJSXkPDdDCJ8rz').update({
|
||
data: object
|
||
}).catch(err => {
|
||
return err;
|
||
})
|
||
}
|
||
}
|
||
db.collection('sD_common').doc('XKjJSXkPDdDCJ8rz').update({
|
||
data: {
|
||
total: _.inc(1)
|
||
}
|
||
}).catch(err => {
|
||
return err;
|
||
})
|
||
}
|
||
// 云函数入口函数
|
||
exports.main = async (event, context) => {
|
||
let common = await commonUpload(event.data);
|
||
return common;
|
||
} |