const db = uniCloud.database()
const dbCmd = db.command
exports.getBillRecordList = async (data) => {
const {
billId,
page_size,
page_index,
} = data
// 数据没有限制,表中有什么返回什么
const collection = await db.collection('fcy-user-bill-record').orderBy('date', 'desc').where({
billId: billId,
dataState: 0,
}).get();
// 获取列表
let start = page_index * page_size
let res = await db.collection('fcy-user-bill-record').orderBy('date', 'desc').where({
billId: billId,
dataState: 0,
}).skip(start).limit(page_size).get();
let Y = null;
let M = null;
let userInfo = null;
for (var i = 0; i < res.data.length; i++) {
let record = res.data[i];
let date = new Date(record.date);
let dateY = date.getFullYear();
let dateM = parseFloat(date.getMonth() + 1 < 10 ? '0' + (date.getMonth() + 1) : date.getMonth() + 1);
var year2 = 0;
let pd = false;
if (i == 0) {
// console.log('获取账单记录1:', JSON.stringify(M));
// console.log('获取账单记录1:', JSON.stringify(dateM));
pd = true;
Y = dateY;
M = dateM;
} else {
// console.log('获取账单记录2:', JSON.stringify(M));
// console.log('获取账单记录2:', JSON.stringify(dateM));
if (Y != dateY || M != dateM) {
console.log('不同!!!:', JSON.stringify(dateM));
pd = true;
Y = dateY;
M = dateM;
}
}
console.log('aaaaaaa:', record);
if (userInfo == null || userInfo._id != record.userId) {
// 数据没有限制,表中有什么返回什么
const userDB = await db.collection('fcy-user').doc(record.userId).field({
'avatarUrl': true,
'nickName': true,
'name': true,
}).get();
userInfo = userDB.data[0];
res.data[i].recordUser = userDB.data[0];
} else {
res.data[i].recordUser = userInfo;
}
// console.log('ssssssss:');
if (pd) {
// 本月第一天日期
var begin = new Date(Y + '-' + M + '-01 00: 00: 00').getTime();
// 本月最后一天日期
var month2 = 0;
if (M + 2 > 12) {
month2 = 1;
year2 = Y + 1;
} else {
month2 = M + 1;
year2 = Y;
}
var end = new Date(year2 + '-' + month2 + '-01 00: 00: 00').getTime() - 1000;
// console.log('获取账单记录3:', JSON.stringify(begin));
// console.log('获取账单记录3:', JSON.stringify(end));
const mDB = await db.collection('fcy-user-bill-record').orderBy('date', 'desc').where({
billId: billId,
date: dbCmd.gte(begin).and(dbCmd.lte(end)),
dataState: 0,
}).get();
let expend = 0;
let income = 0;
for (var j = 0; j < mDB.data.length; j++) {
let item = mDB.data[j];
switch (item.recordType) {
case '103':
income += Number(item.value1) * Number(item.value3) * Number(item.value2);
break;
case '104':
expend += Number(item.value3) * Number(item.value4);
break;
case '105':
switch (item.value1) {
case 0:
expend += Number(item.value3);
break;
case 1:
income += Number(item.value2) * Number(item.value3);
break;
}
break;
case '106':
expend += Number(item.value2);
break;
case '107':
expend += Number(item.value1);
break;
case '108':
expend += Number(item.value1);
break;
case '0':
expend += Number(item.value1) * Number(item.value2);
break;
case '1':
income += Number(item.value1) * Number(item.value2);
break;
default:
break;
}
}
res.data[i].mStatistics = {
expend: parseFloat(expend).toFixed(2),
income: parseFloat(income).toFixed(2)
};
}
}
console.log('获取账单记录3:', JSON.stringify(res.data));
return {
code: 0,
msg: '',
data: res.data
};
}
春夏秋冬 (作者)
嗯呢 感谢
2020-12-01 15:38