2026-03-23 17:10:07 +08:00

63 lines
1.9 KiB
JavaScript

'use strict';
const OrderBaseService = require('./base');
class DeliveryOrderService extends OrderBaseService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
const _noNeedRight = 'getdeliveryOrderlist';
const _noNeedLog = 'getdeliveryOrderlist';
const _noNeedAuth = 'getdeliveryOrderlist';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
async getdeliveryOrderlist(data = {}) {
try {
const warehouseId = this.ensureWarehouseId(data);
const { Op } = this.app.Sequelize;
const { DeliveryModel } = await this.getOrderModels(warehouseId);
const whereData = data.where || {};
const where = this.buildWhere(whereData, warehouseId);
const hasOutboundFilter = whereData.outbound_status !== undefined && whereData.outbound_status !== null && whereData.outbound_status !== '';
if (!hasOutboundFilter) {
where.outbound_status = { [Op.ne]: 'none' };
}
const { page, pageSize, offset } = this.getPagination(data.pagination);
const result = await DeliveryModel.findAndCountAll({
where,
attributes: [
'id',
'delivery_order_code',
'status',
'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: {
defaultOutboundFilter: !hasOutboundFilter,
},
}),
code: 200,
});
} catch (error) {
return this.fail(error.message, { code: 500 });
}
}
}
module.exports = DeliveryOrderService;