|
|
@ -1,12 +1,279 @@
|
|
|
|
# 云开发 quickstart
|
|
|
|
# **节时不节食软件系统**
|
|
|
|
|
|
|
|
## 软件定位
|
|
|
|
|
|
|
|
在当前严峻的疫情影响下,校内食堂是大学生用餐的唯一选择。由于学生用餐时间集中,食堂人流量大,菜品准备时间长以及学生的“选择困难症”等问题使得用餐效率较低。“菜品选择”这一概念提出,在用户点外卖时首先通过“菜品选择”这一途径,替有选择困难的用户做出决定,减少一些不必要的时间。对于年轻的一代的生活节奏和思想观念,“菜品选择”这一软件系统能解决他们不少选择上的难题。
|
|
|
|
|
|
|
|
在这个选择多样化的时代,大学生常常面临着“今天吃什么?”的困扰。校内五花八门的餐饮给我们提供了数不清的选项:价格、味道、菜式等等,大学生面对众多选择时会觉得异常困难、难以做出满意的选择。或者大学生在工作学业繁忙之时,需要软件来帮其做出快速选择。有些人心中有许多心仪的选项,于是不断纠结,左右为难摇摆不定;有些人没有特别想吃的菜品,或者吃腻了想换个口味,总想挑到最合适的选项,最后什么也没买。这直接导致了他们决策时间过长,不仅饥肠辘辘,而且心烦意乱,影响生活和情绪。因此,需要寻找一种有效方法来减少大学生的决策时间,帮助他们筛选信息做出选择。
|
|
|
|
|
|
|
|
## 软件功能
|
|
|
|
|
|
|
|
该系统主要实现登录、自由点单、偏好快速选择、转盘随机选择、论坛购物车和支付七大主要功能,其中通过登录功能实现新用户的注册和老用户的登录;通过论坛功能让用户进行发表帖子、评论讨论等操作;通过自由点单、偏好快速选择和转盘随机选择来确定订单,通过购物车来存储标记的食物信息并跳转支付功能;通过支付功能实现支付和订单信息的回传
|
|
|
|
|
|
|
|
## 代码运行
|
|
|
|
|
|
|
|
该系统为微信小程序模式,以微信为载体实现系统运行,硬件要求为能下载并运行微信app。
|
|
|
|
|
|
|
|
## 使用说明
|
|
|
|
|
|
|
|
### 1.登录
|
|
|
|
|
|
|
|
点击登录按钮进行信息授权进行登录
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
### 2.自由点单
|
|
|
|
|
|
|
|
在主页面搜索框中搜索食物名称,可以显示食物信息
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
### 3.偏好快速选择
|
|
|
|
|
|
|
|
点击主页面的偏好选择按钮进入两个选择页面,在第一页选择食物种类(主食/小吃),在第二页选择口味(香辣/椒麻/香咸/酸甜),页面跳转到确认订单信息
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
### 4.转盘随机选择
|
|
|
|
|
|
|
|
点击主页面的随机转盘按钮进入转盘页面,点击开始按钮进行随机选择,选择结束后弹窗提示食物信息
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
### 5.论坛
|
|
|
|
|
|
|
|
点击主页面下方的论坛按钮进入论坛,用户可以进行增删查改帖子、点赞评论等操作
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
### 6.购物车
|
|
|
|
|
|
|
|
点击主页面下方的购物车进入,在购物车内可以对标记的菜品进行增删查改和选中下单支付操作
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
### 7.支付
|
|
|
|
|
|
|
|
通过三种方式确认订单后点击立即支付按钮即可输入支付密码进行支付
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
##代码目录结构
|
|
|
|
|
|
|
|
![代码目录]("C:\Users\嘉鸿宝贝\Desktop\图片1.png")
|
|
|
|
|
|
|
|
## 云开发 quickstart
|
|
|
|
|
|
|
|
|
|
|
|
这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:
|
|
|
|
这是云开发的快速启动指引,其中演示了如何上手使用云开发的三大基础能力:
|
|
|
|
|
|
|
|
|
|
|
|
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
|
|
|
|
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
|
|
|
|
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
|
|
|
|
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
|
|
|
|
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
|
|
|
|
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
|
|
|
|
|
|
|
|
####为了适应该系统,定义全局变量,全局可调用openid,我们重写了微信小程序的云函数,重写后的云函数代码如下
|
|
|
|
|
|
|
|
##### 1.get
|
|
|
|
|
|
|
|
``` JavaScript
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"permissions": {
|
|
|
|
|
|
|
|
"openapi": [
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"permissions": {
|
|
|
|
|
|
|
|
"openapi": [
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"name": "get",
|
|
|
|
|
|
|
|
"version": "1.0.0",
|
|
|
|
|
|
|
|
"description": "",
|
|
|
|
|
|
|
|
"main": "index.js",
|
|
|
|
|
|
|
|
"scripts": {
|
|
|
|
|
|
|
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"author": "",
|
|
|
|
|
|
|
|
"license": "ISC",
|
|
|
|
|
|
|
|
"dependencies": {
|
|
|
|
|
|
|
|
"wx-server-sdk": "~2.6.3"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
##### 2.quickstartFunctions
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```JavaScript
|
|
|
|
|
|
|
|
const cloud = require('wx-server-sdk');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cloud.init({
|
|
|
|
|
|
|
|
env: cloud.DYNAMIC_CURRENT_ENV
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const db = cloud.database();
|
|
|
|
|
|
|
|
// 创建集合云函数入口函数
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 创建集合
|
|
|
|
|
|
|
|
await db.createCollection('sales');
|
|
|
|
|
|
|
|
await db.collection('sales').add({
|
|
|
|
|
|
|
|
// data 字段表示需新增的 JSON 数据
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
region: '华东',
|
|
|
|
|
|
|
|
city: '上海',
|
|
|
|
|
|
|
|
sales: 11
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await db.collection('sales').add({
|
|
|
|
|
|
|
|
// data 字段表示需新增的 JSON 数据
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
region: '华东',
|
|
|
|
|
|
|
|
city: '南京',
|
|
|
|
|
|
|
|
sales: 11
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await db.collection('sales').add({
|
|
|
|
|
|
|
|
// data 字段表示需新增的 JSON 数据
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
region: '华南',
|
|
|
|
|
|
|
|
city: '广州',
|
|
|
|
|
|
|
|
sales: 22
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
await db.collection('sales').add({
|
|
|
|
|
|
|
|
// data 字段表示需新增的 JSON 数据
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
region: '华南',
|
|
|
|
|
|
|
|
city: '深圳',
|
|
|
|
|
|
|
|
sales: 22
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: true
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
// 这里catch到的是该collection已经存在,从业务逻辑上来说是运行成功的,所以catch返回success给前端,避免工具在前端抛出异常
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: true,
|
|
|
|
|
|
|
|
data: 'create collection success'
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cloud = require('wx-server-sdk');
|
|
|
|
|
|
|
|
cloud.init({
|
|
|
|
|
|
|
|
env: cloud.DYNAMIC_CURRENT_ENV
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// 获取小程序二维码云函数入口函数
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
|
|
|
|
// 获取小程序二维码的buffer
|
|
|
|
|
|
|
|
const resp = await cloud.openapi.wxacode.get({
|
|
|
|
|
|
|
|
path: 'pages/index/index'
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const { buffer } = resp;
|
|
|
|
|
|
|
|
// 将图片上传云存储空间
|
|
|
|
|
|
|
|
const upload = await cloud.uploadFile({
|
|
|
|
|
|
|
|
cloudPath: 'code.png',
|
|
|
|
|
|
|
|
fileContent: buffer
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
return upload.fileID;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cloud = require('wx-server-sdk');
|
|
|
|
|
|
|
|
cloud.init({
|
|
|
|
|
|
|
|
env: "cloud1-8g5wmepxce8a3b8a"
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
// 获取openId云函数入口函数
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
|
|
|
|
// 获取基础信息
|
|
|
|
|
|
|
|
const wxContext = cloud.getWXContext();
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
openid: wxContext.OPENID,
|
|
|
|
|
|
|
|
appid: wxContext.APPID,
|
|
|
|
|
|
|
|
unionid: wxContext.UNIONID,
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cloud = require('wx-server-sdk');
|
|
|
|
|
|
|
|
cloud.init({
|
|
|
|
|
|
|
|
env: cloud.DYNAMIC_CURRENT_ENV
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const db = cloud.database();
|
|
|
|
|
|
|
|
// 查询数据库集合云函数入口函数
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
|
|
|
|
// 返回数据库查询结果
|
|
|
|
|
|
|
|
return await db.collection('sales').get();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cloud = require('wx-server-sdk');
|
|
|
|
|
|
|
|
cloud.init({
|
|
|
|
|
|
|
|
env: cloud.DYNAMIC_CURRENT_ENV
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const db = cloud.database();
|
|
|
|
|
|
|
|
const $ = db.command.aggregate;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 聚合记录云函数入口函数
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
|
|
|
|
// 返回数据库聚合结果
|
|
|
|
|
|
|
|
return db.collection('sales').aggregate()
|
|
|
|
|
|
|
|
.group({
|
|
|
|
|
|
|
|
_id: '$region',
|
|
|
|
|
|
|
|
sum: $.sum('$sales')
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.end();
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cloud = require('wx-server-sdk');
|
|
|
|
|
|
|
|
cloud.init({
|
|
|
|
|
|
|
|
env: cloud.DYNAMIC_CURRENT_ENV
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
const db = cloud.database();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 修改数据库信息云函数入口函数
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
// 遍历修改数据库信息
|
|
|
|
|
|
|
|
for (let i = 0; i < event.data.length; i++) {
|
|
|
|
|
|
|
|
await db.collection('sales').where({
|
|
|
|
|
|
|
|
_id: event.data[i]._id
|
|
|
|
|
|
|
|
})
|
|
|
|
|
|
|
|
.update({
|
|
|
|
|
|
|
|
data: {
|
|
|
|
|
|
|
|
sales: event.data[i].sales
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: true,
|
|
|
|
|
|
|
|
data: event.data
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
|
|
return {
|
|
|
|
|
|
|
|
success: false,
|
|
|
|
|
|
|
|
errMsg: e
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"permissions": {
|
|
|
|
|
|
|
|
"openapi": [
|
|
|
|
|
|
|
|
"wxacode.get"
|
|
|
|
|
|
|
|
]
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const getOpenId = require('./getOpenId/index');
|
|
|
|
|
|
|
|
const getMiniProgramCode = require('./getMiniProgramCode/index');
|
|
|
|
|
|
|
|
const createCollection = require('./createCollection/index');
|
|
|
|
|
|
|
|
const selectRecord = require('./selectRecord/index');
|
|
|
|
|
|
|
|
const updateRecord = require('./updateRecord/index');
|
|
|
|
|
|
|
|
const sumRecord = require('./sumRecord/index');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 云函数入口函数
|
|
|
|
|
|
|
|
exports.main = async (event, context) => {
|
|
|
|
|
|
|
|
switch (event.type) {
|
|
|
|
|
|
|
|
case 'getOpenId':
|
|
|
|
|
|
|
|
return await getOpenId.main(event, context);
|
|
|
|
|
|
|
|
case 'getMiniProgramCode':
|
|
|
|
|
|
|
|
return await getMiniProgramCode.main(event, context);
|
|
|
|
|
|
|
|
case 'createCollection':
|
|
|
|
|
|
|
|
return await createCollection.main(event, context);
|
|
|
|
|
|
|
|
case 'selectRecord':
|
|
|
|
|
|
|
|
return await selectRecord.main(event, context);
|
|
|
|
|
|
|
|
case 'updateRecord':
|
|
|
|
|
|
|
|
return await updateRecord.main(event, context);
|
|
|
|
|
|
|
|
case 'sumRecord':
|
|
|
|
|
|
|
|
return await sumRecord.main(event, context);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
"name": "quickstartFunctions",
|
|
|
|
|
|
|
|
"version": "1.0.0",
|
|
|
|
|
|
|
|
"description": "",
|
|
|
|
|
|
|
|
"main": "index.js",
|
|
|
|
|
|
|
|
"scripts": {
|
|
|
|
|
|
|
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
"author": "",
|
|
|
|
|
|
|
|
"license": "ISC",
|
|
|
|
|
|
|
|
"dependencies": {
|
|
|
|
|
|
|
|
"wx-server-sdk": "~2.4.0"
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
```
|
|
|
|
## 参考文档
|
|
|
|
## 参考文档
|
|
|
|
|
|
|
|
|
|
|
|
- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)
|
|
|
|
- [云开发文档](https://developers.weixin.qq.com/miniprogram/dev/wxcloud/basis/getting-started.html)
|
|
|
|
|
|
|
|
##结论
|
|
|
|
|
|
|
|
本系统能够基本实现一个外卖点餐系统的全部功能,同时能为用户提供两种高效的选择方式,希望能真正帮助大家解决选择困扰,实现节约时间的目的。
|