2020-02-14 23:17:01 +08:00

39 lines
1.1 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// 云函数入口文件
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;
}