diff --git a/app/service/systems/store_warehouse.js b/app/service/systems/store_warehouse.js index c981ea4..bdd2561 100644 --- a/app/service/systems/store_warehouse.js +++ b/app/service/systems/store_warehouse.js @@ -1324,9 +1324,12 @@ class SettingStoreWarehouseService extends Service { const authStatus = Number(item.auth_status || 0); const currentIsWarehouse = !!(currentSubject && currentSubject.isWarehouse); + const subjectId = currentSubject ? Number(currentSubject.id) : 0; - // 当前主体始终在 store_id 方(货主方/消费方),对方始终在 warehouse_id 方(仓库方/提供方) - const counterparty = item.warehouse; + // 根据当前主体在 store_id 还是 warehouse_id 判定对方主体(兼容新旧签约数据) + const subjectIsStore = subjectId > 0 && subjectId === Number(item.store_id || 0); + const subjectIsWarehouse = subjectId > 0 && subjectId === Number(item.warehouse_id || 0); + const counterparty = subjectIsStore ? item.warehouse : item.store; const counterpartyRole = counterparty && counterparty.project === 'warehouse' ? 'warehouse' : 'store'; const storeName = item.store_remask || (item.store && item.store.company_name ? item.store.company_name : ''); @@ -1369,8 +1372,8 @@ class SettingStoreWarehouseService extends Service { applied_by: item.applied_by ? Number(item.applied_by) : null, reviewed_by: item.reviewed_by ? Number(item.reviewed_by) : null, ended_by: item.ended_by ? Number(item.ended_by) : null, - remask: currentIsWarehouse ? (item.store_remask || '') : (item.warehouse_remask || ''), - use_status: currentIsWarehouse + remask: subjectIsWarehouse ? (item.store_remask || '') : (item.warehouse_remask || ''), + use_status: subjectIsWarehouse ? Number(item.warehouse_use_status || 0) : Number(item.store_use_status || 0), warehouse_use_status: Number(item.warehouse_use_status || 0), @@ -1430,9 +1433,9 @@ class SettingStoreWarehouseService extends Service { } /** - * 货主侧查询签约关系列表。 + * 货主侧查询签约关系列表(兼容新旧签约数据)。 * - * 当前货主主体在 store_id 方,对方仓库在 warehouse_id 方。 + * 使用 OR 查询 store_id / warehouse_id 两边,确保新旧签约数据都能被正确展示。 * * @param {Object} [data={}] 请求参数。 * @return {Promise} 接口响应对象。 @@ -1444,7 +1447,49 @@ class SettingStoreWarehouseService extends Service { const page = this.normalizePage(data.page, 'page', 1, 1000000); const pageSize = this.normalizePage(data.page_size || data.pageSize, 'page_size', 20, 200); const offset = (page - 1) * pageSize; - const where = this.buildListWhereByStoreId(data, currentSubject); + + // OR 查询两边,兼容新旧签约数据 + const where = { + [Op.or]: [ + { store_id: currentSubject.id }, + { warehouse_id: currentSubject.id }, + ], + }; + + const relationId = this.resolveRelationId(data); + if (relationId) { + where.id = relationId; + } + + const counterpartyId = this.toPositiveNumber(data.counterparty_id || data.warehouse_id, 'counterparty_id', { allowEmpty: true }); + if (counterpartyId) { + // 对方可能在 store_id 或 warehouse_id,两边都过滤 + where[Op.and] = where[Op.and] || []; + where[Op.and].push({ + [Op.or]: [ + { store_id: counterpartyId, warehouse_id: currentSubject.id }, + { warehouse_id: counterpartyId, store_id: currentSubject.id }, + ], + }); + } + + const authStatus = this.normalizeAuthStatus(data.auth_status); + if (authStatus !== null) { + where.auth_status = authStatus; + } + + const rawUseStatus = data.use_status !== undefined ? data.use_status : data.store_use_status; + if (rawUseStatus !== undefined && rawUseStatus !== null && rawUseStatus !== '') { + // 同时过滤 store_use_status 和 warehouse_use_status + where[Op.and] = where[Op.and] || []; + where[Op.and].push({ + [Op.or]: [ + { store_use_status: Number(rawUseStatus), store_id: currentSubject.id }, + { warehouse_use_status: Number(rawUseStatus), warehouse_id: currentSubject.id }, + ], + }); + } + const keyword = typeof data.keyword === 'string' ? data.keyword.trim() : ''; if (keyword) { @@ -1507,9 +1552,9 @@ class SettingStoreWarehouseService extends Service { } /** - * 仓库侧查询签约关系列表。 + * 仓库侧查询签约关系列表(兼容新旧签约数据)。 * - * 当前仓库主体在 store_id 方(消费方),对方(可能是仓库或货主)在 warehouse_id 方(提供方)。 + * 使用 OR 查询 store_id / warehouse_id 两边,确保新旧签约数据都能被正确展示。 * 支持查询仓库与外部合作仓库的关系。 * * @param {Object} [data={}] 请求参数。 @@ -1522,7 +1567,49 @@ class SettingStoreWarehouseService extends Service { const page = this.normalizePage(data.page, 'page', 1, 1000000); const pageSize = this.normalizePage(data.page_size || data.pageSize, 'page_size', 20, 200); const offset = (page - 1) * pageSize; - const where = this.buildListWhereByStoreId(data, currentSubject); + + // OR 查询两边,兼容新旧签约数据 + const where = { + [Op.or]: [ + { store_id: currentSubject.id }, + { warehouse_id: currentSubject.id }, + ], + }; + + const relationId = this.resolveRelationId(data); + if (relationId) { + where.id = relationId; + } + + const counterpartyId = this.toPositiveNumber(data.counterparty_id || data.warehouse_id, 'counterparty_id', { allowEmpty: true }); + if (counterpartyId) { + // 对方可能在 store_id 或 warehouse_id,两边都过滤 + where[Op.and] = where[Op.and] || []; + where[Op.and].push({ + [Op.or]: [ + { store_id: counterpartyId, warehouse_id: currentSubject.id }, + { warehouse_id: counterpartyId, store_id: currentSubject.id }, + ], + }); + } + + const authStatus = this.normalizeAuthStatus(data.auth_status); + if (authStatus !== null) { + where.auth_status = authStatus; + } + + const rawUseStatus = data.use_status !== undefined ? data.use_status : data.store_use_status; + if (rawUseStatus !== undefined && rawUseStatus !== null && rawUseStatus !== '') { + // 同时过滤 store_use_status 和 warehouse_use_status + where[Op.and] = where[Op.and] || []; + where[Op.and].push({ + [Op.or]: [ + { store_use_status: Number(rawUseStatus), store_id: currentSubject.id }, + { warehouse_use_status: Number(rawUseStatus), warehouse_id: currentSubject.id }, + ], + }); + } + const keyword = typeof data.keyword === 'string' ? data.keyword.trim() : ''; if (keyword) {