|
|
@ -7,22 +7,25 @@
|
|
|
|
## 代码运行
|
|
|
|
## 代码运行
|
|
|
|
该系统为微信小程序模式,以微信为载体实现系统运行,硬件要求为能下载并运行微信app。
|
|
|
|
该系统为微信小程序模式,以微信为载体实现系统运行,硬件要求为能下载并运行微信app。
|
|
|
|
## 使用说明
|
|
|
|
## 使用说明
|
|
|
|
### 登录
|
|
|
|
### 1.登录
|
|
|
|
点击登录按钮进行信息授权进行登录
|
|
|
|
点击登录按钮进行信息授权进行登录
|
|
|
|
***
|
|
|
|
***
|
|
|
|
### 自由点单
|
|
|
|
### 2.自由点单
|
|
|
|
在主页面搜索框中搜索食物名称,可以显示食物信息
|
|
|
|
在主页面搜索框中搜索食物名称,可以显示食物信息
|
|
|
|
***
|
|
|
|
***
|
|
|
|
### 偏好快速选择
|
|
|
|
### 3.偏好快速选择
|
|
|
|
点击主页面的偏好选择按钮进入两个选择页面,在第一页选择食物种类(主食/小吃),在第二页选择口味(香辣/椒麻/香咸/酸甜),页面跳转到确认订单信息
|
|
|
|
点击主页面的偏好选择按钮进入两个选择页面,在第一页选择食物种类(主食/小吃),在第二页选择口味(香辣/椒麻/香咸/酸甜),页面跳转到确认订单信息
|
|
|
|
***
|
|
|
|
***
|
|
|
|
### 转盘随机选择
|
|
|
|
### 4.转盘随机选择
|
|
|
|
点击主页面的随机转盘按钮进入转盘页面,点击开始按钮进行随机选择,选择结束后弹窗提示食物信息
|
|
|
|
点击主页面的随机转盘按钮进入转盘页面,点击开始按钮进行随机选择,选择结束后弹窗提示食物信息
|
|
|
|
***
|
|
|
|
***
|
|
|
|
### 论坛
|
|
|
|
### 5.论坛
|
|
|
|
点击主页面下方的论坛按钮进入论坛,用户可以进行增删查改帖子、点赞评论等操作。
|
|
|
|
点击主页面下方的论坛按钮进入论坛,用户可以进行增删查改帖子、点赞评论等操作
|
|
|
|
***
|
|
|
|
***
|
|
|
|
### 支付
|
|
|
|
### 6.购物车
|
|
|
|
|
|
|
|
点击主页面下方的购物车进入,在购物车内可以对标记的菜品进行增删查改和选中下单支付操作
|
|
|
|
|
|
|
|
***
|
|
|
|
|
|
|
|
### 7.支付
|
|
|
|
通过三种方式确认订单后点击立即支付按钮即可输入支付密码进行支付
|
|
|
|
通过三种方式确认订单后点击立即支付按钮即可输入支付密码进行支付
|
|
|
|
***
|
|
|
|
***
|
|
|
|
# 云开发 quickstart
|
|
|
|
# 云开发 quickstart
|
|
|
@ -32,7 +35,241 @@
|
|
|
|
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
|
|
|
|
- 数据库:一个既可在小程序前端操作,也能在云函数中读写的 JSON 文档型数据库
|
|
|
|
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
|
|
|
|
- 文件存储:在小程序前端直接上传/下载云端文件,在云开发控制台可视化管理
|
|
|
|
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
|
|
|
|
- 云函数:在云端运行的代码,微信私有协议天然鉴权,开发者只需编写业务逻辑代码
|
|
|
|
####为了适应该系统,我们重写了微信小程序的云函数,重写后的云函数有get()和
|
|
|
|
####为了适应该系统,定义全局变量,全局可调用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
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
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)
|