下面云函数功能就是通过查询条件查询数据,然后生成excel文件上传到云存储当中,问题就是上传的时候返回null!
(return await cloud.uploadFile == null'),不清楚为什么返回null,本地调试都没有问题,真机调试就出现了问题!
const cloud = require('wx-server-sdk')
cloud.init({
env: "xxx"
})
const db = cloud.database()
const _ = db.command
const xlsx = require('node-xlsx');
exports.main = async (event, context) => {
try {
let { params } = event
var newParams = {};
if (params.username && params.username !== ""){
newParams.username = params.username;
}
if (params.company && params.company !== ""){
newParams.company = params.company;
}
if (params.project && params.project !== ""){
newParams.project = params.project;
}
if (params.bigclassname && params.bigclassname !== ""){
newParams.bigclassname = params.bigclassname;
}
if (params.pddictData && params.pddictData !== ""){
newParams.orderType = params.pddictData;
}
const tasks = []
for (let i = 0; i < params.xhcs; i++) {
const promise = cloud.database().collection("demoorder").where(_.and([newParams,
{date: _.gte(new Date(params.startDate)).and(_.lte(new Date(params.endDate)))}])
).orderBy('date','desc').skip(i * 20).limit(20).get()
tasks.push(promise)
}
console.log(tasks);
let allData = await Promise.all(tasks)
let userdata = [];
for (let i = 0; i < allData.length; i++){
userdata = userdata.concat(allData[i].data);
}
dataCVS = (Date.parse(new Date()) / 1000) + ".xlsx";
let alldata = [];
let row = ['城市', '工程师', '被服务公司', '实施日期', '项目对象', '服务地址', '保修单号', '是否结单', '到场时间', '完成时间', '报销费用', '报销备注', '应收费用', '应收备注', '收费状态', '备注', '计单量', '计单量备注', '发票金额', '所属大类','订单类型','散客提成'];
alldata.push(row);
for (let key in userdata) {
let arr = [];
arr.push(userdata[key].city);
arr.push(userdata[key].username);
arr.push(userdata[key].company);
arr.push(userdata[key].date);
arr.push(userdata[key].project);
arr.push(userdata[key].address);
arr.push(userdata[key].number);
arr.push(userdata[key].isorder);
arr.push(userdata[key].arrivetime);
arr.push(userdata[key].endtime);
arr.push(userdata[key].tripmoney);
arr.push(userdata[key].tripdes);
arr.push(userdata[key].shouldmoney);
arr.push(userdata[key].shoulddes);
arr.push(userdata[key].ismoney);
arr.push(userdata[key].des);
arr.push(userdata[key].jidanliang);
arr.push(userdata[key].jidanliangdes);
arr.push(userdata[key].fapiaojine);
arr.push(userdata[key].bigclassname);
arr.push(userdata[key].orderType);
alldata.push(arr)
}
var buffer = await xlsx.build([{
name: "mySheetName",
data: alldata
}]);
return await cloud.uploadFile({
cloudPath: 'excel/' + dataCVS,
fileContent: buffer,
})
} catch (e) {
console.error(e)
return e
}
}
大佬解决了吗
我也是这个问题