- sign: 统一当前主体→store_id(货主方/消费方),对方→warehouse_id(仓库方/提供方) - getCounterparty: 移除 expectedRole 角色校验,仓库可签仓库、货主可签货主 - list: 拆分为 listForStore/listForWarehouse,warehouse 侧支持查询外部合作仓库 - 新增 buildListWhereByStoreId 统一按 store_id 维度构建查询条件 - 响应新增 counterparty_role / needs_my_confirm / has_qimen_config 字段
88 lines
2.7 KiB
JavaScript
88 lines
2.7 KiB
JavaScript
'use strict';
|
|
|
|
const MainService = require('../../main');
|
|
|
|
/**
|
|
* 规范签约请求入参。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Object} 复制后的请求数据。
|
|
*/
|
|
function normalizeWarehouseStorePayload(data) {
|
|
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
return {};
|
|
}
|
|
return { ...data };
|
|
}
|
|
|
|
class StoreWarehouseWarehouseService extends MainService {
|
|
constructor(ctx) {
|
|
super(ctx);
|
|
const _noNeedLogin = '';
|
|
const _noNeedRight = 'list,sign,confirmSign';
|
|
const _noNeedLog = '*';
|
|
const _noNeedAuth = 'list,sign,confirmSign';
|
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
|
}
|
|
|
|
/**
|
|
* 仓库侧获取签约列表(含外部合作仓库)。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async list(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.listForWarehouse !== 'function') {
|
|
return this.fail('获取签约列表失败', { code: 500 });
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeWarehouseStorePayload(data);
|
|
const result = await targetService.listForWarehouse(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '获取签约列表失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 仓库侧发起签约。
|
|
*/
|
|
async sign(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
if (!targetService || typeof targetService.sign !== 'function') {
|
|
return this.fail('签约失败', { code: 500 });
|
|
}
|
|
try {
|
|
const payload = normalizeWarehouseStorePayload(data);
|
|
const result = await targetService.sign(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '签约失败', { code: Number(error.code) || 500 });
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 仓库侧确认签约。
|
|
*/
|
|
async confirmSign(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
if (!targetService || typeof targetService.confirmSign !== 'function') {
|
|
return this.fail('确认签约失败', { code: 500 });
|
|
}
|
|
try {
|
|
const payload = normalizeWarehouseStorePayload(data);
|
|
const result = await targetService.confirmSign(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '确认签约失败', { code: Number(error.code) || 500 });
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = StoreWarehouseWarehouseService;
|