console.log(ID) await db.collection('usersdatas').doc(q).update({ data: { groupmembersid: _.addToSet(ID), } }); await db.collection('usersdatas').doc(m).update({ data: { threepartysid: _.addToSet(ID), } }); if(q === m){ await db.collection('usersinternet').doc(ID).set({ data: { //qrcodesid: q, isThreeParty: true, threepartyid: q, isGroupMember:'', isNoGroupMember: true, threepartycreators: this.data.qrcodes.threepartycreators, threepartymobile: this.data.qrcodes.threepartymobile, threepartypartName: this.data.qrcodes.threepartypartName, productvolume: this.data.qrcodes.productvolume, groupmemberid: m , groupmembercreators: this.data.groupmembercreators, groupmembermobile: this.data.groupmembermobile, isGroupRegister: true , isEnable: true , createdatatime: Date.now(), startdate: this.data.realToday, closedate:'', } }); }else{ await db.collection('usersinternet').doc(ID).set({ data: { //qrcodesid: q, threepartyid: q, isGroupMember:'', isNoGroupMember: true, threepartycreators: this.data.qrcodes.threepartycreators, threepartymobile: this.data.qrcodes.threepartymobile, threepartypartName: this.data.qrcodes.threepartypartName, productvolume: this.data.qrcodes.productvolume, groupmemberid: m , groupmembercreators: this.data.groupmembercreators, groupmembermobile: this.data.groupmembermobile, isGroupRegister: true , isEnable: true , createdatatime: Date.now(), startdate: this.data.realToday, closedate:'', } }); };。把这个功能改成在云函数中运行,请你修改代码 ,把改好的云函数代码和小程序端代码发给我
时间: 2024-02-06 14:08:45 浏览: 145
好的,以下是云函数的代码:
```js
// 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
env: cloud.DYNAMIC_CURRENT_ENV
})
const db = cloud.database()
const _ = db.command
// 云函数入口函数
exports.main = async (event, context) => {
const { ID, q, m, data } = event
try {
await db.collection('usersdatas').doc(q).update({
data: {
groupmembersid: _.addToSet(ID)
}
})
await db.collection('usersdatas').doc(m).update({
data: {
threepartysid: _.addToSet(ID)
}
})
if (q === m) {
await db.collection('usersinternet').doc(ID).set({
data: {
threepartyid: q,
isGroupMember: '',
isNoGroupMember: true,
threepartycreators: data.qrcodes.threepartycreators,
threepartymobile: data.qrcodes.threepartymobile,
threepartypartName: data.qrcodes.threepartypartName,
productvolume: data.qrcodes.productvolume,
groupmemberid: m,
groupmembercreators: data.groupmembercreators,
groupmembermobile: data.groupmembermobile,
isGroupRegister: true,
isEnable: true,
createdatatime: Date.now(),
startdate: data.realToday,
closedate: ''
}
})
} else {
await db.collection('usersinternet').doc(ID).set({
data: {
threepartyid: q,
isGroupMember: '',
isNoGroupMember: true,
threepartycreators: data.qrcodes.threepartycreators,
threepartymobile: data.qrcodes.threepartymobile,
threepartypartName: data.qrcodes.threepartypartName,
productvolume: data.qrcodes.productvolume,
groupmemberid: m,
groupmembercreators: data.groupmembercreators,
groupmembermobile: data.groupmembermobile,
isGroupRegister: true,
isEnable: true,
createdatatime: Date.now(),
startdate: data.realToday,
closedate: ''
}
})
}
return { success: true }
} catch (err) {
console.log(err)
return { success: false }
}
}
```
小程序端代码为:
```js
wx.cloud.callFunction({
name: 'updateData',
data: {
ID: ID,
q: q,
m: m,
data: this.data
},
success: res => {
console.log('更新成功', res)
},
fail: err => {
console.error('更新失败', err)
}
})
```
阅读全文