'use strict'; const OrderBaseService = require('./base'); class OrderIndexService extends OrderBaseService { constructor(ctx) { super(ctx); const _noNeedLogin = ''; const _noNeedRight = 'list,badgeCount,manualOutboundOrder,detail'; const _noNeedLog = 'list,badgeCount,manualOutboundOrder,detail'; const _noNeedAuth = 'list,badgeCount,manualOutboundOrder,detail'; this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth); } /** * 订单工作台总列表入口。 * @param {Object} data 请求体。 * @return {Promise} 列表与分页信息。 */ async list(data = {}) { return await this.listByModule('order', data); } /** * 手动出库入口。 * @param {Object} data 请求体。 * @return {Promise} 迁移结果。 */ async manualOutboundOrder(data = {}) { return await this.ctx.service.systems.orderDeliveryMigration.syncOutboundOrdersToDelivery(data); } /** * 获取订单工作台 8 个标签页的角标计数。 * 其中配送、异常与归档相关标签页直接返回 99+。 * @return {Promise} 角标展示值对象。 */ 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; } } module.exports = OrderIndexService;