323 lines
9.4 KiB
JavaScript
323 lines
9.4 KiB
JavaScript
'use strict';
|
|
|
|
const MainService = require('../../main');
|
|
|
|
|
|
/**
|
|
* 规范仓库配置方法入参,避免把原始引用直接传给下游服务。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Object} 复制后的请求数据。
|
|
*/
|
|
function normalizeStoreWarehousePayload(data) {
|
|
if (!data || typeof data !== 'object' || Array.isArray(data)) {
|
|
return {};
|
|
}
|
|
|
|
return { ...data };
|
|
}
|
|
|
|
class StoreWarehouseStoreService extends MainService {
|
|
/**
|
|
* 创建一个仓库配置 store 服务。
|
|
*
|
|
* @param {Object} ctx 上下文对象。
|
|
*/
|
|
constructor(ctx) {
|
|
super(ctx);
|
|
const _noNeedLogin = '';
|
|
const _noNeedRight = 'list,sign,unbind,rename,getPolicyConfig,getPolicyConfigFields,savePolicyConfig,listApiConfig,saveApiConfig,deleteQimenConfig';
|
|
const _noNeedLog = '*';
|
|
const _noNeedAuth = 'list,sign,unbind,rename,getPolicyConfig,getPolicyConfigFields,savePolicyConfig,listApiConfig,saveApiConfig,deleteQimenConfig';
|
|
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.list !== 'function') {
|
|
return this.fail('获取签约列表失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.list(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '获取签约列表失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 发起签约。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
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 = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.sign(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '签约失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 修改签约名称。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async rename(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.rename !== 'function') {
|
|
return this.fail('修改签约名称失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.rename(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '修改签约名称失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 解除签约。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async unbind(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.unbind !== 'function') {
|
|
return this.fail('解除签约失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.unbind(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '解除签约失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 人工调整面单余额。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async adjustPrintQuantity(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.adjustPrintQuantity !== 'function') {
|
|
return this.fail('人工调整面单余额失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.adjustPrintQuantity(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '人工调整面单余额失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取合约策略配置。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async getPolicyConfig(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.getPolicyConfig !== 'function') {
|
|
return this.fail('获取合约策略配置失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.getPolicyConfig(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '获取合约策略配置失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取合约策略字段信息。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async getPolicyConfigFields(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.getPolicyConfigFields !== 'function') {
|
|
return this.fail('获取合约策略字段信息失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.getPolicyConfigFields(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '获取合约策略字段信息失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 保存合约策略配置。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async savePolicyConfig(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.savePolicyConfig !== 'function') {
|
|
return this.fail('保存合约策略配置失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.savePolicyConfig(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '保存合约策略配置失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取接口配置列表。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async listApiConfig(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.listApiConfig !== 'function') {
|
|
return this.fail('获取接口配置列表失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.listApiConfig(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '获取接口配置列表失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 保存接口配置。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async saveApiConfig(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.saveApiConfig !== 'function') {
|
|
return this.fail('保存接口配置失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.saveApiConfig(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '保存接口配置失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 删除奇门接口配置。
|
|
*
|
|
* @param {Object} data 请求数据。
|
|
* @return {Promise<Object>} 统一响应结果。
|
|
*/
|
|
async deleteQimenConfig(data = {}) {
|
|
const targetService = this.service && this.service.systems && this.service.systems.storeWarehouse;
|
|
|
|
if (!targetService || typeof targetService.deleteQimenConfig !== 'function') {
|
|
return this.fail('删除接口配置失败', {
|
|
code: 500,
|
|
});
|
|
}
|
|
|
|
try {
|
|
const payload = normalizeStoreWarehousePayload(data);
|
|
const result = await targetService.deleteQimenConfig(payload);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || '删除接口配置失败', {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = StoreWarehouseStoreService;
|