Merge branch 'develop' of https://bdgit.educoder.net/pgpoiyf9w/clothesProject into guoxuanyu_branch
# Conflicts: # app.js # app.json # pages/navigation/index/add/add.js # pages/navigation/index/add/add.wxml # pages/navigation/index/add/camera/camera.js # pages/navigation/index/add/camera/camera.json # pages/navigation/index/add/camera/camera.wxml # pages/navigation/index/delete/delete.js # pages/navigation/index/delete/delete.wxml # pages/navigation/index/index.js # pages/navigation/index/index.wxml # pages/navigation/index/recommand/recommand.wxml # project.config.jsonguoxuanyu_branch
@ -0,0 +1,6 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,32 @@
|
|||||||
|
// 云函数入口文件
|
||||||
|
const cloud = require('wx-server-sdk')
|
||||||
|
|
||||||
|
cloud.init() // 使用当前云环境
|
||||||
|
const db=cloud.database()
|
||||||
|
const MAX_LIMIT=100
|
||||||
|
// 云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
const wxContext = cloud.getWXContext()
|
||||||
|
//先取出集合记录总数
|
||||||
|
const countResult=await db.collection('cloth').count()
|
||||||
|
const total=countResult.total
|
||||||
|
//计算分几次取
|
||||||
|
const batchTimes = Math.ceil(total / 100)
|
||||||
|
// 承载所有读操作的 promise 的数组
|
||||||
|
const tasks = []
|
||||||
|
for (let i = 0; i < batchTimes; i++) {
|
||||||
|
const promise = db.collection('cloth').skip(i * MAX_LIMIT).limit(MAX_LIMIT).get()
|
||||||
|
tasks.push(promise)
|
||||||
|
}
|
||||||
|
// 等待所有
|
||||||
|
return (await Promise.all(tasks)).reduce((acc, cur) => {
|
||||||
|
return {
|
||||||
|
event,
|
||||||
|
openid: wxContext.OPENID,
|
||||||
|
appid: wxContext.APPID,
|
||||||
|
unionid: wxContext.UNIONID,
|
||||||
|
data: acc.data.concat(cur.data),
|
||||||
|
errMsg: acc.errMsg,
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"permissions": {
|
||||||
|
"openapi": [
|
||||||
|
"wxacode.get"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,20 @@
|
|||||||
|
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;
|
||||||
|
};
|
@ -0,0 +1,17 @@
|
|||||||
|
const cloud = require('wx-server-sdk');
|
||||||
|
|
||||||
|
cloud.init({
|
||||||
|
env: cloud.DYNAMIC_CURRENT_ENV
|
||||||
|
});
|
||||||
|
|
||||||
|
// 获取openId云函数入口函数
|
||||||
|
exports.main = async (event, context) => {
|
||||||
|
// 获取基础信息
|
||||||
|
const wxContext = cloud.getWXContext();
|
||||||
|
|
||||||
|
return {
|
||||||
|
openid: wxContext.OPENID,
|
||||||
|
appid: wxContext.APPID,
|
||||||
|
unionid: wxContext.UNIONID,
|
||||||
|
};
|
||||||
|
};
|
@ -0,0 +1,25 @@
|
|||||||
|
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);
|
||||||
|
}
|
||||||
|
};
|
@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"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"
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,12 @@
|
|||||||
|
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();
|
||||||
|
};
|
@ -0,0 +1,18 @@
|
|||||||
|
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();
|
||||||
|
};
|
@ -0,0 +1,32 @@
|
|||||||
|
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
|
||||||
|
};
|
||||||
|
}
|
||||||
|
};
|
After Width: | Height: | Size: 75 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 172 KiB |
After Width: | Height: | Size: 110 KiB |
After Width: | Height: | Size: 252 KiB |
After Width: | Height: | Size: 140 KiB |
After Width: | Height: | Size: 119 KiB |
After Width: | Height: | Size: 132 KiB |
After Width: | Height: | Size: 170 KiB |
After Width: | Height: | Size: 66 KiB |
After Width: | Height: | Size: 158 KiB |
After Width: | Height: | Size: 171 KiB |
After Width: | Height: | Size: 150 KiB |
After Width: | Height: | Size: 193 KiB |
After Width: | Height: | Size: 116 KiB |
After Width: | Height: | Size: 104 KiB |
After Width: | Height: | Size: 116 KiB |
After Width: | Height: | Size: 116 KiB |
After Width: | Height: | Size: 180 KiB |
After Width: | Height: | Size: 125 KiB |
After Width: | Height: | Size: 38 KiB |
After Width: | Height: | Size: 53 KiB |
After Width: | Height: | Size: 26 KiB |
After Width: | Height: | Size: 25 KiB |
After Width: | Height: | Size: 112 KiB |
After Width: | Height: | Size: 28 KiB |
After Width: | Height: | Size: 86 KiB |
After Width: | Height: | Size: 33 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 60 KiB |
After Width: | Height: | Size: 115 KiB |
After Width: | Height: | Size: 103 KiB |
After Width: | Height: | Size: 45 KiB |
After Width: | Height: | Size: 42 KiB |
After Width: | Height: | Size: 35 KiB |
After Width: | Height: | Size: 21 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 40 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 76 KiB |
After Width: | Height: | Size: 22 KiB |
After Width: | Height: | Size: 1.2 MiB |
After Width: | Height: | Size: 67 KiB |
After Width: | Height: | Size: 36 KiB |
After Width: | Height: | Size: 48 KiB |
After Width: | Height: | Size: 29 KiB |
After Width: | Height: | Size: 834 KiB |
After Width: | Height: | Size: 940 KiB |
After Width: | Height: | Size: 2.4 MiB |
After Width: | Height: | Size: 693 KiB |
After Width: | Height: | Size: 389 KiB |
After Width: | Height: | Size: 67 KiB |
After Width: | Height: | Size: 357 KiB |
After Width: | Height: | Size: 382 KiB |
After Width: | Height: | Size: 118 KiB |
After Width: | Height: | Size: 596 KiB |
After Width: | Height: | Size: 273 KiB |
After Width: | Height: | Size: 68 KiB |
After Width: | Height: | Size: 441 KiB |
After Width: | Height: | Size: 102 KiB |