liufumingren e73a311076 ok
2026-04-11 17:09:06 +08:00

84 lines
2.4 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

'use strict';
const OrderBaseService = require('../order/base');
/**
* 系统方法层:storage.stockout(非订单出库单接口包装层)。
*/
class StorageStockoutService extends OrderBaseService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
const _noNeedRight = 'list,toOrder,listItems';
const _noNeedLog = 'list,toOrder,listItems';
const _noNeedAuth = 'list,toOrder,listItems';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
async list(data = {}) {
try {
const warehouseId = this.ensureWarehouseId(data);
const { DeliveryModel } = await this.getOrderModels(warehouseId);
this.prepareWhereContext(data);
const whereData = this.ctx.where || {};
const where = this.buildWhere(whereData, warehouseId);
// 默认只查询订单类型为 STOCKOUT 的出库单
if (!whereData.order_type && !where.order_type) {
where.order_type = 'STOCKOUT';
}
const { page, pageSize, offset } = this.getPagination(data.pagination);
const result = await DeliveryModel.findAndCountAll({
where,
offset,
limit: pageSize,
order: [[ 'updated_at', 'DESC' ], [ 'id', 'DESC' ]],
raw: true,
});
return this.success('ok', {
data: this.buildListData(result.rows, result.count, page, pageSize),
code: 200,
});
} catch (error) {
return this.fail(error.message, { code: 500 });
}
}
async toOrder() {
return this.fail('占位接口,暂未开放', { code: 405, placeholder: true });
}
async listItems(data = {}) {
try {
const warehouseId = this.ensureWarehouseId(data);
const { DeliveryModel, OrderItemsModel } = await this.getOrderModels(warehouseId);
const where = this.getOrderLocatorWhere(data, warehouseId);
const order = await DeliveryModel.findOne({
where,
attributes: [ 'id', 'delivery_order_code' ],
raw: true,
});
if (!order) {
return this.fail('订单不存在', { code: 404 });
}
const items = await OrderItemsModel.findAll({
where: { order_id: order.id },
order: [[ 'id', 'ASC' ]],
raw: true,
});
return this.success('ok', {
data: { order, items },
code: 200,
});
} catch (error) {
return this.fail(error.message, { code: 500 });
}
}
}
module.exports = StorageStockoutService;