From 13825a23c74bf8c5a6c5b278fb4cac4805382993 Mon Sep 17 00:00:00 2001 From: MicroMilo Date: Thu, 25 May 2023 20:02:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BA=91=E5=AF=B9=E8=B1=A1=E9=87=8D=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../fe-sport-feelings.param.json | 7 - .../cloudfunctions/fe-sport-feelings/index.js | 36 ---- .../fe-sport-feelings/package.json | 7 - .../cloudfunctions/fe-sport-index/index.js | 38 ---- .../fe-sport-index/package.json | 7 - .../fe-sport-object/fe-sport-object.param.js | 11 ++ .../fe-sport-object/index.obj.js | 186 ++++++++++++++++++ .../package.json | 2 +- .../cloudfunctions/fe-sport-run-rank/index.js | 31 --- .../cloudfunctions/fe-sport-run-save/index.js | 64 ------ .../fe-sport-run-save/package.json | 7 - .../fe-sport-walk-rank/index.js | 31 --- .../fe-sport-walk-rank/package.json | 7 - .../fe-sport-walk-save/index.js | 64 ------ .../fe-sport-walk-save/package.json | 7 - 15 files changed, 198 insertions(+), 307 deletions(-) delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/fe-sport-feelings.param.json delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/index.js delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/package.json delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/index.js delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/package.json create mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/fe-sport-object.param.js create mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/index.obj.js rename alpha/admin/uniCloud-aliyun/cloudfunctions/{fe-sport-run-rank => fe-sport-object}/package.json (68%) delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-rank/index.js delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/index.js delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/package.json delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/index.js delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/package.json delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/index.js delete mode 100644 alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/package.json diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/fe-sport-feelings.param.json b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/fe-sport-feelings.param.json deleted file mode 100644 index f038991..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/fe-sport-feelings.param.json +++ /dev/null @@ -1,7 +0,0 @@ -// 本文件中的json内容将在云函数【运行】时作为参数传给云函数。 -// 配置教程参考:https://uniapp.dcloud.net.cn/uniCloud/rundebug.html#runparam -{ - "type": "跑步", - "id": "645b8a67e1a35c371b015038", - "feeling": "good" -} \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/index.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/index.js deleted file mode 100644 index d1868aa..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/index.js +++ /dev/null @@ -1,36 +0,0 @@ -'use strict'; -exports.main = async (event, context) => { - //event为客户端上传的参数 - console.log('event : ', event) - - const db = uniCloud.database(); - - let table; - if (event.type == '跑步') - table = 'mustgo-running-record'; - else - table = 'mustgo-walking-record'; - - const collection = db.collection(table); - let res = await collection.doc(event.id).update({ - feelings: event.feeling - }) - - if (res.updated > 0) { - return { - code: 200, - message: "保存成功", - data: { - - } - } - } - - //返回数据给客户端 - return { - code: 500, - message: "服务器错误", - data: { - } - } -}; diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/package.json b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/package.json deleted file mode 100644 index f5f9539..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-feelings/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "fe-sport-feelings", - "dependencies": {}, - "extensions": { - "uni-cloud-jql": {} - } -} \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/index.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/index.js deleted file mode 100644 index 4ee1f08..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/index.js +++ /dev/null @@ -1,38 +0,0 @@ -'use strict'; -exports.main = async (event, context) => { - //event为客户端上传的参数 - console.log('event : ', event) - - const db = uniCloud.database(); - let fieldName; - if (event.type == "跑步") { - fieldName = "total_running_distance"; - } else { - fieldName = "total_walking_distance"; - } - const collection = db.collection('mustgo-user'); - - let res = await collection.orderBy(fieldName, "desc").get() - console.log(res) - - for (let i = 0; i < res.data.length; i ++) { - if (res.data[i]["_id"] == event.userId) { - return { - code: 200, - message: "查询成功", - data :{ - totalRunningDistance: res.data[i][fieldName], - totalRunningRank: i + 1 - } - } - } - } - - //返回数据给客户端 - return { - code: 500, - message: "服务器错误", - data: { - } - } -}; diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/package.json b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/package.json deleted file mode 100644 index 33cb80e..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-index/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "fe-sport-run-index", - "dependencies": {}, - "extensions": { - "uni-cloud-jql": {} - } -} \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/fe-sport-object.param.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/fe-sport-object.param.js new file mode 100644 index 0000000..10ab720 --- /dev/null +++ b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/fe-sport-object.param.js @@ -0,0 +1,11 @@ +feelings({ + type: "跑步", + id: "645cddc5f5cf3a2df4bdb9a3", + feeling: "normal" +}) + +index({ + type: "跑步", + userId: "645c972809e298919852519f" +}); + diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/index.obj.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/index.obj.js new file mode 100644 index 0000000..d591335 --- /dev/null +++ b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/index.obj.js @@ -0,0 +1,186 @@ +// 云对象教程: https://uniapp.dcloud.net.cn/uniCloud/cloud-obj +// jsdoc语法提示教程:https://ask.dcloud.net.cn/docs/#//ask.dcloud.net.cn/article/129 +module.exports = { + _before: function() { // 通用预处理器 + + }, + async index(event) { + // 参数校验,如无参数则不需要 + if (!event.type) { + return { + code: 400, + message: "客户端错误", + data: {} + } + } + // 业务逻辑 + + const db = uniCloud.database(); + let fieldName; + if (event.type == "跑步") { + fieldName = "total_running_distance"; + } else { + fieldName = "total_walking_distance"; + } + const collection = db.collection('mustgo-user'); + + let res = await collection.orderBy(fieldName, "desc").get() + + for (let i = 0; i < res.data.length; i++) { + if (res.data[i]["_id"] == event.userId) { + return { + code: 200, + message: "查询成功", + data: { + totalRunningDistance: res.data[i][fieldName], + totalRunningRank: i + 1 + } + } + } + } + + // 返回结果 + return { + code: 500, + message: "服务器错误", + data: {} + } + }, + async rank(event) { + const db = uniCloud.database(); + const collection = db.collection('mustgo-user'); + + let fieldName; + if (event.type == "跑步") { + fieldName = "total_running_distance"; + } else { + fieldName = "total_walking_distance"; + } + let res = await collection.orderBy(fieldName, "desc").get() + console.log(res) + + let userlist = new Array; + for (let i = 0; i < res.data.length; i++) { + let user = { + "rank": i + 1, + "icon": res.data[i]["icon"], + "username": res.data[i]["name"], + "distance":res.data[i][fieldName] + } + userlist.push(user) + } + + //返回数据给客户端 + return { + "code": 200, + "message": "成功返回累计排名", + "data": { + "userList": userlist + } + } + }, + async save(event) { + //event为客户端上传的参数 + console.log('event : ', event) + + const db = uniCloud.database(); + + let table, fieldName; + if (event.type == "跑步") { + table = "mustgo-running-record"; + fieldName = "total_running_distance"; + } else { + table = "mustgo-walking-record"; + fieldName = "total_walking_distance"; + } + let collection = db.collection(table); + + 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][fieldName]; + 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: { + } + } + }, + async feelings(event) { + const db = uniCloud.database(); + + let table; + if (event.type == '跑步') + table = 'mustgo-running-record'; + else + table = 'mustgo-walking-record'; + + const collection = db.collection(table); + let res = await collection.doc(event.id).update({ + feelings: event.feeling + }) + + if (res.updated > 0) { + return { + code: 200, + message: "保存成功", + data: { + + } + } + } + + //返回数据给客户端 + return { + code: 500, + message: "服务器错误", + data: { + } + } + } +} \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-rank/package.json b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/package.json similarity index 68% rename from alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-rank/package.json rename to alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/package.json index 4733a9f..6862c5a 100644 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-rank/package.json +++ b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-object/package.json @@ -1,5 +1,5 @@ { - "name": "fe-sport-run-rank", + "name": "fe-sport-object", "dependencies": {}, "extensions": { "uni-cloud-jql": {} diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-rank/index.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-rank/index.js deleted file mode 100644 index 4d6fee9..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-rank/index.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; -exports.main = async (event, context) => { - //event为客户端上传的参数 - console.log('event : ', event) - - const db = uniCloud.database(); - const collection = db.collection('mustgo-user'); - - let res = await collection.orderBy("total_running_distance", "desc").get() - console.log(res) - - let userlist = new Array; - for (let i = 0; i < res.data.length; i++) { - let user = { - "rank": i + 1, - "icon": res.data[i]["icon"], - "username": res.data[i]["name"], - "distance":res.data[i]["total_running_distance"] - } - userlist.push(user) - } - - //返回数据给客户端 - return { - "code": 200, - "message": "成功返回跑步累计排名", - "data": { - "userList": userlist - } - } -}; \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/index.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/index.js deleted file mode 100644 index 9cbfbaf..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/index.js +++ /dev/null @@ -1,64 +0,0 @@ -'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: { - } - } -}; diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/package.json b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/package.json deleted file mode 100644 index bffbe64..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-run-save/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "fe-sport-run-save", - "dependencies": {}, - "extensions": { - "uni-cloud-jql": {} - } -} \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/index.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/index.js deleted file mode 100644 index 801c951..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/index.js +++ /dev/null @@ -1,31 +0,0 @@ -'use strict'; -exports.main = async (event, context) => { - //event为客户端上传的参数 - console.log('event : ', event) - - const db = uniCloud.database(); - const collection = db.collection('mustgo-user'); - - let res = await collection.orderBy("total_walking_distance", "desc").get() - console.log(res) - - let userlist = new Array; - for (let i = 0; i < res.data.length; i++) { - let user = { - "rank": i + 1, - "icon": res.data[i]["icon"], - "username": res.data[i]["name"], - "distance":res.data[i]["total_walking_distance"] - } - userlist.push(user) - } - - //返回数据给客户端 - return { - "code": 200, - "message": "成功返回健走累计排名", - "data": { - "userList": userlist - } - } -}; \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/package.json b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/package.json deleted file mode 100644 index de322fd..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-rank/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "fe-sport-walk-rank", - "dependencies": {}, - "extensions": { - "uni-cloud-jql": {} - } -} \ No newline at end of file diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/index.js b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/index.js deleted file mode 100644 index 52ad85c..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/index.js +++ /dev/null @@ -1,64 +0,0 @@ -'use strict'; -exports.main = async (event, context) => { - //event为客户端上传的参数 - console.log('event : ', event) - - const db = uniCloud.database(); - let collection = db.collection('mustgo-walking-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_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: { - } - } -}; diff --git a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/package.json b/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/package.json deleted file mode 100644 index 34b3127..0000000 --- a/alpha/admin/uniCloud-aliyun/cloudfunctions/fe-sport-walk-save/package.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "name": "fe-sport-walk-save", - "dependencies": {}, - "extensions": { - "uni-cloud-jql": {} - } -} \ No newline at end of file -- GitLab