43 lines
1.1 KiB
JavaScript
43 lines
1.1 KiB
JavaScript
'use strict';
|
||
|
||
const MainService = require('../../main');
|
||
|
||
/**
|
||
* 业务逻辑层:quick.waybill(运单号快速查询)。
|
||
*/
|
||
class QuickWaybillService extends MainService {
|
||
/**
|
||
* 根据运单号查询有效订单ID。
|
||
* 仅查询 wms_order_express 表中 status=1 的记录。
|
||
*
|
||
* @param {Object} params 查询参数。
|
||
* @param {string} params.waybill_code 运单号,不可为空。
|
||
* @return {Promise<Object>} 包含 order_id 的对象。
|
||
* @throws {Error} 当 waybill_code 为空或未找到匹配记录时抛出业务错误。
|
||
*/
|
||
async toOrder({ waybill_code: waybillCode }) {
|
||
const { ctx } = this;
|
||
|
||
if (!waybillCode || !String(waybillCode).trim()) {
|
||
this.throwError('运单号不能为空');
|
||
}
|
||
|
||
const record = await ctx.model.OrderExpress.findOne({
|
||
where: {
|
||
waybill_code: String(waybillCode).trim(),
|
||
status: 1,
|
||
},
|
||
attributes: [ 'order_id' ],
|
||
raw: true,
|
||
});
|
||
|
||
if (!record) {
|
||
this.throwError('未找到该运单号对应的订单');
|
||
}
|
||
|
||
return { order_id: record.order_id };
|
||
}
|
||
}
|
||
|
||
module.exports = QuickWaybillService;
|