- express_interface 新增 is_enabled 字段(1=启用, 0=停用) - expressInterface service 支持 is_enabled 筛选与编辑 - express 运单分配跳过停用接口 + 取消状态订单过滤 - 迁移: 20260724100000-add-is-enabled-to-wms-express-interface
368 lines
11 KiB
JavaScript
368 lines
11 KiB
JavaScript
'use strict';
|
|
|
|
const MainService = require('../../main');
|
|
|
|
class expressInterfaceService extends MainService {
|
|
/**
|
|
* 初始化快递接口管理模块的权限配置。
|
|
*
|
|
* @param {Egg.Context} ctx 上下文对象
|
|
*/
|
|
constructor(ctx) {
|
|
super(ctx);
|
|
const _noNeedLogin = '';
|
|
const _noNeedRight = 'list,listByWarehousePlatformCode,create,update,delete';
|
|
const _noNeedLog = '*';
|
|
const _noNeedAuth = 'list,listByWarehousePlatformCode,create,update,delete';
|
|
this.systemInit(_noNeedLogin, _noNeedRight, _noNeedLog, _noNeedAuth);
|
|
}
|
|
|
|
/**
|
|
* 调用快递接口系统服务。
|
|
*
|
|
* @param {string} methodName 系统服务方法名
|
|
* @param {Object} data 请求参数
|
|
* @param {string} defaultMessage 默认错误信息
|
|
* @return {Promise<Object>} 统一返回结果
|
|
*/
|
|
async callSystemExpressInterface(methodName, data, defaultMessage) {
|
|
const { service } = this;
|
|
|
|
try {
|
|
const result = await service.systems.setting.expressInterface[methodName](data);
|
|
return this.success('ok', result);
|
|
} catch (error) {
|
|
return this.fail(error.message || defaultMessage, {
|
|
code: Number(error.code) || 500,
|
|
});
|
|
}
|
|
}
|
|
|
|
/**
|
|
* 获取快递接口列表。
|
|
*
|
|
* @param {Object} data 请求参数
|
|
* @return {Promise<Object>} 列表结果
|
|
*/
|
|
async list(data = {}) {
|
|
const {
|
|
where = {},
|
|
pagination: inputPagination,
|
|
page,
|
|
page_size: pageSize,
|
|
pageSize: camelPageSize,
|
|
...rest
|
|
} = data || {};
|
|
|
|
const pagination = {
|
|
...(inputPagination && typeof inputPagination === 'object' ? inputPagination : {}),
|
|
};
|
|
if (page !== undefined) {
|
|
pagination.page = page;
|
|
}
|
|
|
|
const resolvedPageSize = pageSize !== undefined ? pageSize : camelPageSize;
|
|
if (resolvedPageSize !== undefined) {
|
|
pagination.pageSize = resolvedPageSize;
|
|
}
|
|
|
|
const payload = {
|
|
...rest,
|
|
where,
|
|
pagination,
|
|
};
|
|
|
|
this.prepareWhereContext(payload, {
|
|
specialFieldMap: {
|
|
id: {
|
|
field: 'id',
|
|
},
|
|
name: {
|
|
field: 'name',
|
|
},
|
|
express_code: {
|
|
field: 'express_code',
|
|
},
|
|
platform_code: {
|
|
field: 'platform_code',
|
|
},
|
|
sender_name: {
|
|
field: 'sender_name',
|
|
},
|
|
sender_tel: {
|
|
field: 'sender_tel',
|
|
},
|
|
viewer: {
|
|
field: 'viewer',
|
|
},
|
|
client_id: {
|
|
field: 'client_id',
|
|
},
|
|
share_id: {
|
|
field: 'share_id',
|
|
},
|
|
site_code: {
|
|
field: 'site_code',
|
|
},
|
|
product_type: {
|
|
field: 'product_type',
|
|
},
|
|
shop_name: {
|
|
field: 'shop_name',
|
|
},
|
|
is_enabled: {
|
|
field: 'is_enabled',
|
|
},
|
|
quickWhere: {
|
|
bucket: 'quick',
|
|
},
|
|
},
|
|
});
|
|
|
|
return await this.callSystemExpressInterface('list', payload, '获取快递接口列表失败');
|
|
}
|
|
|
|
/**
|
|
* 按仓库与平台代码查询快递接口全量记录。
|
|
*
|
|
* @param {Object} data 请求参数
|
|
* @return {Promise<Object>} 查询结果
|
|
*/
|
|
async listByWarehousePlatformCode(data = {}) {
|
|
return await this.callSystemExpressInterface('listByWarehousePlatformCode', data, '获取快递接口查询失败');
|
|
}
|
|
|
|
/**
|
|
* 创建快递接口。
|
|
*
|
|
* @param {Object} data 请求参数
|
|
* @return {Promise<Object>} 创建结果
|
|
*/
|
|
async create(data = {}) {
|
|
const {
|
|
name,
|
|
express_code: expressCode,
|
|
expressCode: camelExpressCode,
|
|
sys_express_code: sysExpressCode,
|
|
sysExpressCode: camelSysExpressCode,
|
|
platform_code: platformCode,
|
|
platformCode: camelPlatformCode,
|
|
weight_type: weightType,
|
|
weightType: camelWeightType,
|
|
address,
|
|
town_name: townName,
|
|
townName: camelTownName,
|
|
ispickup: isPickup,
|
|
isPickup: camelIsPickup,
|
|
shipperno: shipperNo,
|
|
shipperNo: camelShipperNo,
|
|
template_url: templateUrl,
|
|
templateUrl: camelTemplateUrl,
|
|
ext_data: extData,
|
|
extData: camelExtData,
|
|
template_id: templateId,
|
|
templateId: camelTemplateId,
|
|
paymode,
|
|
payMode,
|
|
brandno,
|
|
brandNo,
|
|
providertype,
|
|
providerType,
|
|
providerid,
|
|
providerId,
|
|
...rest
|
|
} = data || {};
|
|
|
|
const payload = {
|
|
...rest,
|
|
};
|
|
|
|
if (name !== undefined) {
|
|
payload.name = name;
|
|
}
|
|
if (expressCode !== undefined || camelExpressCode !== undefined) {
|
|
payload.express_code = expressCode !== undefined ? expressCode : camelExpressCode;
|
|
}
|
|
if (platformCode !== undefined || camelPlatformCode !== undefined) {
|
|
payload.platform_code = platformCode !== undefined ? platformCode : camelPlatformCode;
|
|
}
|
|
if (sysExpressCode !== undefined || camelSysExpressCode !== undefined) {
|
|
payload.sys_express_code = sysExpressCode !== undefined ? sysExpressCode : camelSysExpressCode;
|
|
}
|
|
if (weightType !== undefined || camelWeightType !== undefined) {
|
|
payload.weight_type = weightType !== undefined ? weightType : camelWeightType;
|
|
}
|
|
if (address !== undefined) {
|
|
payload.address = address;
|
|
}
|
|
if (townName !== undefined || camelTownName !== undefined) {
|
|
payload.town_name = townName !== undefined ? townName : camelTownName;
|
|
}
|
|
if (isPickup !== undefined || camelIsPickup !== undefined) {
|
|
payload.ispickup = isPickup !== undefined ? isPickup : camelIsPickup;
|
|
}
|
|
if (shipperNo !== undefined || camelShipperNo !== undefined) {
|
|
payload.shipperno = shipperNo !== undefined ? shipperNo : camelShipperNo;
|
|
}
|
|
if (templateUrl !== undefined || camelTemplateUrl !== undefined) {
|
|
payload.template_url = templateUrl !== undefined ? templateUrl : camelTemplateUrl;
|
|
}
|
|
if (extData !== undefined || camelExtData !== undefined) {
|
|
payload.ext_data = extData !== undefined ? extData : camelExtData;
|
|
}
|
|
if (templateId !== undefined || camelTemplateId !== undefined) {
|
|
payload.template_id = templateId !== undefined ? templateId : camelTemplateId;
|
|
}
|
|
if (paymode !== undefined || payMode !== undefined) {
|
|
payload.paymode = paymode !== undefined ? paymode : payMode;
|
|
}
|
|
if (brandno !== undefined || brandNo !== undefined) {
|
|
payload.brandno = brandno !== undefined ? brandno : brandNo;
|
|
}
|
|
if (providertype !== undefined || providerType !== undefined) {
|
|
payload.providertype = providertype !== undefined ? providertype : providerType;
|
|
}
|
|
if (providerid !== undefined || providerId !== undefined) {
|
|
payload.providerid = providerid !== undefined ? providerid : providerId;
|
|
}
|
|
|
|
return await this.callSystemExpressInterface('create', payload, '创建快递接口失败');
|
|
}
|
|
|
|
/**
|
|
* 修改快递接口。
|
|
*
|
|
* @param {Object} data 请求参数
|
|
* @return {Promise<Object>} 修改结果
|
|
*/
|
|
async update(data = {}) {
|
|
const {
|
|
id,
|
|
interface_id: interfaceId,
|
|
interfaceId: camelInterfaceId,
|
|
name,
|
|
express_code: expressCode,
|
|
expressCode: camelExpressCode,
|
|
sys_express_code: sysExpressCode,
|
|
sysExpressCode: camelSysExpressCode,
|
|
platform_code: platformCode,
|
|
platformCode: camelPlatformCode,
|
|
weight_type: weightType,
|
|
weightType: camelWeightType,
|
|
address,
|
|
town_name: townName,
|
|
townName: camelTownName,
|
|
ispickup: isPickup,
|
|
isPickup: camelIsPickup,
|
|
shipperno: shipperNo,
|
|
shipperNo: camelShipperNo,
|
|
template_url: templateUrl,
|
|
templateUrl: camelTemplateUrl,
|
|
ext_data: extData,
|
|
extData: camelExtData,
|
|
platform_shop_id: platformShopId,
|
|
platformShopId: camelPlatformShopId,
|
|
template_id: templateId,
|
|
templateId: camelTemplateId,
|
|
paymode,
|
|
payMode,
|
|
brandno,
|
|
brandNo,
|
|
providertype,
|
|
providerType,
|
|
providerid,
|
|
providerId,
|
|
is_enabled: isEnabledSnake,
|
|
isEnabled: isEnabledCamel,
|
|
...rest
|
|
} = data || {};
|
|
|
|
const payload = {
|
|
...rest,
|
|
};
|
|
|
|
payload.id = id !== undefined ? id : (interfaceId !== undefined ? interfaceId : camelInterfaceId);
|
|
if (name !== undefined) {
|
|
payload.name = name;
|
|
}
|
|
if (expressCode !== undefined || camelExpressCode !== undefined) {
|
|
payload.express_code = expressCode !== undefined ? expressCode : camelExpressCode;
|
|
}
|
|
if (platformCode !== undefined || camelPlatformCode !== undefined) {
|
|
payload.platform_code = platformCode !== undefined ? platformCode : camelPlatformCode;
|
|
}
|
|
if (sysExpressCode !== undefined || camelSysExpressCode !== undefined) {
|
|
payload.sys_express_code = sysExpressCode !== undefined ? sysExpressCode : camelSysExpressCode;
|
|
}
|
|
if (weightType !== undefined || camelWeightType !== undefined) {
|
|
payload.weight_type = weightType !== undefined ? weightType : camelWeightType;
|
|
}
|
|
if (address !== undefined) {
|
|
payload.address = address;
|
|
}
|
|
if (townName !== undefined || camelTownName !== undefined) {
|
|
payload.town_name = townName !== undefined ? townName : camelTownName;
|
|
}
|
|
if (isPickup !== undefined || camelIsPickup !== undefined) {
|
|
payload.ispickup = isPickup !== undefined ? isPickup : camelIsPickup;
|
|
}
|
|
if (shipperNo !== undefined || camelShipperNo !== undefined) {
|
|
payload.shipperno = shipperNo !== undefined ? shipperNo : camelShipperNo;
|
|
}
|
|
if (templateUrl !== undefined || camelTemplateUrl !== undefined) {
|
|
payload.template_url = templateUrl !== undefined ? templateUrl : camelTemplateUrl;
|
|
}
|
|
if (extData !== undefined || camelExtData !== undefined) {
|
|
payload.ext_data = extData !== undefined ? extData : camelExtData;
|
|
}
|
|
if (platformShopId !== undefined || camelPlatformShopId !== undefined) {
|
|
payload.platform_shop_id = platformShopId !== undefined ? platformShopId : camelPlatformShopId;
|
|
}
|
|
if (templateId !== undefined || camelTemplateId !== undefined) {
|
|
payload.template_id = templateId !== undefined ? templateId : camelTemplateId;
|
|
}
|
|
if (paymode !== undefined || payMode !== undefined) {
|
|
payload.paymode = paymode !== undefined ? paymode : payMode;
|
|
}
|
|
if (brandno !== undefined || brandNo !== undefined) {
|
|
payload.brandno = brandno !== undefined ? brandno : brandNo;
|
|
}
|
|
if (providertype !== undefined || providerType !== undefined) {
|
|
payload.providertype = providertype !== undefined ? providertype : providerType;
|
|
}
|
|
if (providerid !== undefined || providerId !== undefined) {
|
|
payload.providerid = providerid !== undefined ? providerid : providerId;
|
|
}
|
|
if (isEnabledSnake !== undefined || isEnabledCamel !== undefined) {
|
|
payload.is_enabled = isEnabledSnake !== undefined ? isEnabledSnake : isEnabledCamel;
|
|
}
|
|
|
|
return await this.callSystemExpressInterface('update', payload, '更新快递接口失败');
|
|
}
|
|
|
|
/**
|
|
* 删除快递接口。
|
|
*
|
|
* @param {Object} data 请求参数
|
|
* @return {Promise<Object>} 删除结果
|
|
*/
|
|
async delete(data = {}) {
|
|
const {
|
|
id,
|
|
interface_id: interfaceId,
|
|
interfaceId: camelInterfaceId,
|
|
...rest
|
|
} = data || {};
|
|
|
|
const payload = {
|
|
...rest,
|
|
};
|
|
|
|
payload.id = id !== undefined ? id : (interfaceId !== undefined ? interfaceId : camelInterfaceId);
|
|
|
|
return await this.callSystemExpressInterface('delete', payload, '删除快递接口失败');
|
|
}
|
|
}
|
|
|
|
module.exports = expressInterfaceService;
|