inbox.group.list 优化:
- 移除 warehouse_id 返回字段
- 新增 store_name(StoreWarehouse.store_remask)
- express_interfaces 改为 {id,name} 对象数组
- 新增 system_express_name(wms_express.name)
- created_at/updated_at 使用 app.formatDate 格式化
- 支持 pagination 对象 + where 结构化查询(parseWhereConditions)
- keyword 虚拟字段映射为 group_name LIKE
- groupType 驼峰映射为 group_type
- 增加 specialFieldMap 声明合法字段
新增 index.loadExpressInterfaces:
- 参考 loadStores 模式,拉取仓库下快递接口下拉列表
- 支持 systemExpressCode 入参过滤
- systemMethods/index.js 注册 + methods/system.json 文档
其他:
- delivery_order_code + store_id 联合索引迁移
192 lines
6.2 KiB
JavaScript
192 lines
6.2 KiB
JavaScript
'use strict';
|
||
|
||
const MainService = require('../main');
|
||
|
||
/**
|
||
* 站内信系统方法层。
|
||
* 提供需要用户权限的内部管理接口。
|
||
*/
|
||
class InboxSystemService extends MainService {
|
||
/**
|
||
* 群管理子入口,供 /system dispatcher 按 inbox.group.* 路径访问。
|
||
* @return {{list: Function, disable: Function, update: Function, messages: Function, checkAuth: Function}}
|
||
*/
|
||
get group() {
|
||
return {
|
||
list: data => this.groupList(data),
|
||
disable: data => this.groupDisable(data),
|
||
update: data => this.groupUpdate(data),
|
||
messages: data => this.groupMessages(data),
|
||
checkAuth: (...args) => this.checkAuth(...args),
|
||
};
|
||
}
|
||
|
||
/**
|
||
* 消息管理子入口,供 /system dispatcher 按 inbox.message.* 路径访问。
|
||
* @return {{list: Function, detail: Function, thread: Function, reply: Function, stats: Function, checkAuth: Function}}
|
||
*/
|
||
get message() {
|
||
const { ctx } = this;
|
||
return {
|
||
list: data => {
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
return ctx.service.inbox.message.list({ warehouseId, ...data });
|
||
},
|
||
detail: data => {
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
return ctx.service.inbox.message.detail({ warehouseId, id: data.id });
|
||
},
|
||
thread: data => {
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
return ctx.service.inbox.message.thread({ warehouseId, id: data.id });
|
||
},
|
||
stats: data => {
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
return ctx.service.inbox.message.stats({ warehouseId, direction: data.direction });
|
||
},
|
||
checkAuth: (...args) => this.checkAuth(...args),
|
||
};
|
||
}
|
||
|
||
/**
|
||
* 生成货主绑群码。
|
||
* 委托给 systems.store.bindCode 执行:校验 StoreWarehouse 合约 → 生成12位随机码 → 缓存300秒。
|
||
* warehouseId 从 ctx.user.store_id 自动注入,绑群码缓存 key 为 chat:bind:{warehouseId}:{code}。
|
||
*
|
||
* @param {Object} data 请求数据。
|
||
* @param {number} data.storeId 货主ID。
|
||
* @param {string} [data.subType] 群子类型编码:after_sales(售后) / finance(财务) / receiving(收货)。
|
||
* @return {Promise<Object>} { code: 绑群码 }。
|
||
*/
|
||
async bindCode(data = {}) {
|
||
const { ctx } = this;
|
||
const { storeId, subType } = data;
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
|
||
return await ctx.service.systems.store.bindCode({
|
||
storeId,
|
||
warehouseId,
|
||
subType,
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 拉取当前仓库的群列表。
|
||
* warehouseId 从 ctx.user.store_id 自动注入。
|
||
*
|
||
* @param {Object} data 请求数据。
|
||
* @param {string} [data.groupType] 按群类型筛选:store / warehouse / express。
|
||
* @param {string} [data.keyword] 群名称模糊搜索。
|
||
* @param {number} [data.page] 页码。
|
||
* @param {number} [data.pageSize] 每页条数。
|
||
* @return {Promise<Object>} { total, list }。
|
||
*/
|
||
async groupList(data = {}) {
|
||
const { ctx } = this;
|
||
const { groupType, keyword, page, pageSize, pagination, where } = data;
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
|
||
return await ctx.service.systems.inbox.group.list({
|
||
warehouseId,
|
||
groupType,
|
||
keyword,
|
||
page,
|
||
pageSize,
|
||
pagination,
|
||
where,
|
||
});
|
||
}
|
||
|
||
/**
|
||
* 禁用 / 解禁群。
|
||
* warehouseId 从 ctx.user.store_id 自动注入。
|
||
*
|
||
* @param {Object} data 请求数据。
|
||
* @param {number} data.id 群记录主键ID(必填)。
|
||
* @param {number} [data.isBlocked=1] 是否禁用 1=是 0=否。
|
||
* @return {Promise<Object>} { message: 操作结果 }。
|
||
*/
|
||
async groupDisable(data = {}) {
|
||
const { ctx } = this;
|
||
const { id, isBlocked } = data;
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
|
||
await ctx.service.systems.inbox.group.disable({
|
||
id,
|
||
warehouseId,
|
||
isBlocked: isBlocked === 0 ? 0 : 1,
|
||
});
|
||
|
||
return { message: isBlocked === 0 ? '群已启用' : '群已禁用' };
|
||
}
|
||
|
||
/**
|
||
* 修改群信息。
|
||
* 支持修改 group_type / sub_type / store_id / express_interfaces / system_express_code。
|
||
* warehouseId 从 ctx.user.store_id 自动注入。
|
||
*
|
||
* @param {Object} data 请求数据。
|
||
* @param {number} data.id 群记录主键ID(必填)。
|
||
* @param {string} [data.groupType] 群类型:store / warehouse / express。
|
||
* @param {string} [data.subType] 群子类型。
|
||
* @param {number} [data.storeId] 关联货主ID。
|
||
* @param {number[]} [data.expressInterfaces] 快递接口ID数组(仅 express 生效)。
|
||
* @param {string} [data.systemExpressCode] 系统快递编码(express 时必填)。
|
||
* @return {Promise<Object>} { message: 操作结果 }。
|
||
*/
|
||
async groupUpdate(data = {}) {
|
||
const { ctx } = this;
|
||
const {
|
||
id, groupType, subType, storeId,
|
||
expressInterfaces, systemExpressCode, aiEnabled,
|
||
} = data;
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
|
||
await ctx.service.systems.inbox.group.update({
|
||
id,
|
||
warehouseId,
|
||
groupType,
|
||
subType,
|
||
storeId,
|
||
expressInterfaces,
|
||
systemExpressCode,
|
||
aiEnabled,
|
||
});
|
||
|
||
return { message: '群信息修改成功' };
|
||
}
|
||
|
||
/**
|
||
* 拉取指定群的消息列表。
|
||
* warehouseId 从 ctx.user.store_id 自动注入。
|
||
*
|
||
* @param {Object} data 请求数据。
|
||
* @param {string} data.groupId 群ID(必填)。
|
||
* @param {string} [data.direction] 消息方向筛选:inbound / outbound。
|
||
* @param {string} [data.keyword] 关键词搜索(ext_id / content)。
|
||
* @param {number} [data.page] 页码。
|
||
* @param {number} [data.pageSize] 每页条数。
|
||
* @return {Promise<Object>} { list, pagination }。
|
||
*/
|
||
async groupMessages(data = {}) {
|
||
const { ctx } = this;
|
||
const { groupId, direction, keyword, page, pageSize } = data;
|
||
const warehouseId = Number(ctx.user?.store_id || 0);
|
||
|
||
if (!groupId || typeof groupId !== 'string' || !groupId.trim()) {
|
||
throw new Error('groupId 不能为空');
|
||
}
|
||
|
||
return await ctx.service.inbox.message.list({
|
||
warehouseId,
|
||
groupId: groupId.trim(),
|
||
direction,
|
||
keyword,
|
||
page,
|
||
pageSize,
|
||
});
|
||
}
|
||
}
|
||
|
||
module.exports = InboxSystemService;
|