'use strict'; exports.main = async (event, context) => { //event为客户端上传的参数 console.log('event : ', event) const db = uniCloud.database(); let collection = db.collection('mustgo-walking-record'); let res = await collection.add({ start_date: event.startTime, duration: event.duration, // feelings: event.feelings, owner_id: event.userId, distance: event.distance, pace: event.pace, start_point: event.startPoint, end_point: event.endPoint, path_line: event.pathLine }) console.log(res) let sportId = res.id; // userID collection = db.collection('mustgo-user'); res = await collection.where({ _id: event.userId }).get() // console.log(res) let cur = res.data[0]["total_walking_distance"]; cur += event.distance res = await collection.doc(event.userId).update({ total_walking_distance: cur, }) if (res.updated > 0) return { code: 200, message: "保存成功", data: { id: sportId } } //返回数据给客户端 return { code: 500, message: "服务器错误", data: { } } };