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

31 lines
832 B
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()
// 云函数入口函数
exports.main = async (event, context) => {
var allData = '',state = -1 //有个人记录就是1无就是0 下面执行出错就是-1
await db.collection('sD_personal').where({
_openid: wxContext.OPENID
}).get().then(async res => {
//where查询如果为空返回[]
if (res.data.length){
allData = res.data[0].allData;
state = 1;
} else {
//如果不存在则调取默认模板
await db.collection('sD_common').doc('XKg1i1sqTi00tq1N').get().then(res1 => {
allData = res1.data.allData;
state = 0;
})
}
})
return {
allData: allData,
state:state
}
}