'use strict'; const OrderBaseService = require('./base'); class ArchiveOrderService extends OrderBaseService { constructor(ctx) { super(ctx); const _noNeedLogin = ''; const _noNeedRight = 'getarchiveOrderlist'; const _noNeedLog = 'getarchiveOrderlist'; const _noNeedAuth = 'getarchiveOrderlist'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } /** * 获取归档订单列表。 * * @param {Object} data 请求参数。 * @return {Promise} 查询结果。 */ async getarchiveOrderlist(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); const hasOutboundFilter = this.hasWhereValue(whereData, 'outbound_status'); if (!hasOutboundFilter) { where.outbound_status = 'fin'; } const { page, pageSize, offset } = this.getPagination(data.pagination); const result = await DeliveryModel.findAndCountAll({ where, attributes: [ 'id', 'delivery_order_code', 'status', 'step', 'outbound_status', 'delivery_time', 'updated_at', 'store_id', 'warehouse_id', 'buyer_nick', 'logistics_name', ], offset, limit: pageSize, order: [[ 'delivery_time', 'DESC' ], [ 'updated_at', 'DESC' ], [ 'id', 'DESC' ]], raw: true, }); return this.success('ok', { data: this.buildListData(result.rows, result.count, page, pageSize, { queryInfo: { defaultArchiveFilter: !hasOutboundFilter, }, }), code: 200, }); } catch (error) { return this.fail(error.message, { code: 500 }); } } } module.exports = ArchiveOrderService;