js 外部获取then里面的值
service
async getOrderList(where) { return new Promise((resolve, reject)=>{ CargoOrderCommonModel.findAndCountAll({ //offset, //limit: parseInt(req.query.limit) || 20, include: [ { model: CargoOrderModel, attributes: ['cupboard', 'cupboard_num', 'pkg', 'kgs'] } ], where: where, order: [['create_time', 'DESC']] }).then(function (result) { resolve(result.rows); }).catch(err => { reject(err); }) });
controller
async getOrderList(req, res) { let where = {} if (req.body.pick_up_time_begin && req.body.pick_up_time_end) { where = { pick_up_time: { [Op.between]: [req.body.pick_up_time_begin, req.body.pick_up_time_end] }, is_delete: 0 } } const resp = await orderService.getOrderList(where) res.send({ code: 200, msg: "请求数据成功", data: resp }) }