我尝试计算这种情况下的总销售价格,但它不起作用。我正确使用async.parallel吗?如何将计算结果(totalSalesResult)解析为totalSales?
async.parallel({
totalSales: function(totalSales) {
Sales.find({merchant: req.user.id}).exec(function(err, results) {
var totalShippingFees = 0;
var totalItemSales = 0;
for(var i = 0; i < results.length; i++) {
totalShippingFees += parseFloat(results[i].shippingFees);
var items = results[i].items;
for(var j = 0; j < items.length; i++) {
totalItemSales = parseFloat(items[j].sellingPrice);
}
}
var totalSalesResult = parseFloat(totalShippingFees + totalItemSales);
totalSales(null, totalSalesResult)
});
}
}, function(err, results) {
console.log(results.totalSales)
});