我需要调用一个函数并返回结果,但它不返回结果。经过一番调查,我知道这必须要有承诺。下面是代码,我想知道如何返回结果使用承诺。
var payment = {
paymentDetails: function(data){
var order_id = data.order_id;
db.query("select o.sku,p.published_on,sp.total_sale_price as amount, o.total_cost from orders o left join product p on p.sku = o.sku and p.is_published = 1 and p.is_deleted = 0 left join supplier_product sp on sp.product_id = p.product_id and sp.is_deleted = 0 and sp.active = 1 where o.order_id = ? and o.order_status < 13",[order_id], function(err, res){
if(err) return err;
var order_details = res[0];
var payment_details = module.exports.getPaymentDetails(order_id);
});
},
getPaymentDetails: function(order_id){
db.query("select payment_type, amount, status from payment_details where payment_mode = 5 and invoice_type = 8 and status in ('success','pending_for_approval') and merchant_order_id = ?",[order_id], function(err, res){
if(err){
throw err;
} else {
return res;
}
});
}
};
module.exports = payment;
1条答案
按热度按时间c9qzyr3d1#
基于回调的方法。
现在,你可以像下面这样使用它