'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;