'use strict'; exports.main = async (event, context) => { //event为客户端上传的参数 console.log('event : ', event) const db = uniCloud.database(); let collection = db.collection('mustgo-running-record'); if (event.distance < 0.01) { return { code: 400, message: "距离过短,不予保存", data: { } } } let res = await collection.add({ start_date: event.startTime, duration: event.duration, 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_running_distance"]; cur += event.distance res = await collection.doc(event.userId).update({ total_running_distance: cur, }) if (res.updated > 0) return { code: 200, message: "保存成功", data: { id: sportId } } //返回数据给客户端 return { code: 500, message: "服务器错误", data: { } } };