2026-04-27 16:09:26 +08:00

111 lines
3.2 KiB
JavaScript

'use strict';
const OrderBaseService = require('./base');
class OrderIndexService extends OrderBaseService {
constructor(ctx) {
super(ctx);
const _noNeedLogin = '';
const _noNeedRight = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,detail';
const _noNeedLog = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,detail';
const _noNeedAuth = 'list,badgeCount,manualOutboundOrder,queryOrderLogs,detail';
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
}
/**
* 订单工作台总列表入口。
* @param {Object} data 请求体。
* @return {Promise<Object>} 列表与分页信息。
*/
async list(data = {}) {
return await this.listByModule('order', data);
}
/**
* 手动出库入口。
* @param {Object} data 请求体。
* @return {Promise<Object>} 迁移结果。
*/
async manualOutboundOrder(data = {}) {
return await this.ctx.service.systems.orderDeliveryMigration.syncOutboundOrdersToDelivery(data);
}
/**
* 获取订单工作台 8 个标签页的角标计数。
* 其中配送、异常与归档相关标签页直接返回 99+。
* @return {Promise<Object>} 角标展示值对象。
*/
async badgeCount() {
const warehouseId = this.getWarehouseId();
if (warehouseId === null || warehouseId === undefined || warehouseId === '') {
throw new Error('缺少当前用户仓库上下文 store_id');
}
const cacheKey = this.getBadgeCountCacheKey(warehouseId);
const cachedBadgeCount = await this.app.getCacheAsync(cacheKey);
if (cachedBadgeCount && typeof cachedBadgeCount === 'object') {
return cachedBadgeCount;
}
const [ reviewOrder, pendingOrder, outboundOrder, expectionOrder, entrustOrder ] = await Promise.all([
this.getBadgeCountByModule('reviewOrder', warehouseId),
this.getBadgeCountByModule('pendingOrder', warehouseId),
this.getBadgeCountByModule('outboundOrder', warehouseId),
this.getBadgeCountByModule('expectionOrder', warehouseId),
this.getBadgeCountByModule('entrustOrder', warehouseId),
]);
const badgeCount = {
reviewOrder,
pendingOrder,
outboundOrder,
expectionOrder,
entrustOrder,
deliveryOrder: '99+',
deliveryExpectionOrder: '99+',
archiveOrder: '99+',
};
await this.app.setCacheAsync(cacheKey, badgeCount, 30);
return badgeCount;
}
/**
* 查询订单操作日志。
* @param {Object} data 请求体。
* @param {string|number} data.id 订单ID。
* @param {number} [data.page] 页码。
* @param {number} [data.pageSize] 每页数量。
* @return {Promise<Object>} 统一 success 包装的分页结果。
*/
async queryOrderLogs(data = {}) {
const { ctx, service } = this;
const requestData = data && typeof data === 'object' ? data : {};
const { id, page, pageSize } = requestData;
try {
const result = await service.systems.operationLog.queryOrderLogs({
id,
page,
pageSize,
warehouseId: ctx.user.store_id,
});
return this.success('ok', {
data: result,
code: 200,
});
} catch (e) {
return this.success(e.message, {
code: 200,
});
}
}
}
module.exports = OrderIndexService;