'use strict'; const OrderBaseService = require('./base'); class PendingOrderService extends OrderBaseService { constructor(ctx) { super(ctx); const _noNeedLogin = ''; const _noNeedRight = 'getpendingOrderlist'; const _noNeedLog = 'getpendingOrderlist'; const _noNeedAuth = 'getpendingOrderlist'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } /** * 获取待处理订单列表。 * * @param {Object} data 请求参数。 * @return {Promise} 查询结果。 */ async getpendingOrderlist(data = {}) { try { const warehouseId = this.ensureWarehouseId(data); const { Op } = this.app.Sequelize; const { DeliveryModel } = await this.getOrderModels(warehouseId); this.prepareWhereContext(data); const whereData = this.ctx.where || {}; const where = this.buildWhere(whereData, warehouseId); const hasStatusFilter = this.hasWhereValue(whereData, 'status'); const hasOutboundFilter = this.hasWhereValue(whereData, 'outbound_status'); if (!hasStatusFilter) { where.status = { [Op.in]: [ 'pedding', 'created' ] }; } if (!hasOutboundFilter) { where.outbound_status = 'none'; } const { page, pageSize, offset } = this.getPagination(data.pagination); const result = await DeliveryModel.findAndCountAll({ where, attributes: [ 'id', 'delivery_order_code', 'status', 'step', 'outbound_status', 'inspection_status', 'updated_at', 'store_id', 'warehouse_id', 'buyer_nick', 'logistics_name', ], offset, limit: pageSize, order: [[ 'updated_at', 'DESC' ], [ 'id', 'DESC' ]], raw: true, }); return this.success('ok', { data: this.buildListData(result.rows, result.count, page, pageSize, { queryInfo: { defaultPendingStatusFilter: !hasStatusFilter, defaultPendingOutboundFilter: !hasOutboundFilter, }, }), code: 200, }); } catch (error) { return this.fail(error.message, { code: 500 }); } } } module.exports = PendingOrderService;