feat(safety): add expert skill tags and price range constraints configuration
这个提交包含在:
@@ -566,6 +566,75 @@ app.post('/api/companions/:id/audit', async (req: Request, res: Response) => {
|
||||
}
|
||||
});
|
||||
|
||||
// 大神服务单价、技能标签与资料修改 (校验价格边界与标签库规范)
|
||||
app.put('/api/companions/:id', async (req: Request, res: Response) => {
|
||||
try {
|
||||
const companionId = String(req.params.id);
|
||||
const { hourlyRate, tags, rankName, status } = req.body;
|
||||
|
||||
// 1. 读取平台配置的大神规则
|
||||
const expertRulesConfig = await repo.getPlatformConfigByKey('expert_rules');
|
||||
const rules = expertRulesConfig?.valueJson || {
|
||||
minHourlyRate: 30,
|
||||
maxHourlyRate: 500,
|
||||
maxTagsCount: 6,
|
||||
};
|
||||
|
||||
// 2. 校验服务单价上下限
|
||||
if (hourlyRate !== undefined) {
|
||||
const rateNum = Number(hourlyRate);
|
||||
if (isNaN(rateNum) || rateNum <= 0) {
|
||||
return res.status(400).json({ code: 40000, message: '服务单价必须为有效正数' });
|
||||
}
|
||||
if (rateNum < (rules.minHourlyRate || 30)) {
|
||||
return res.status(400).json({
|
||||
code: 40000,
|
||||
message: `服务单价不能低于平台最低限价 ¥${rules.minHourlyRate || 30}/小时`
|
||||
});
|
||||
}
|
||||
if (rateNum > (rules.maxHourlyRate || 500)) {
|
||||
return res.status(400).json({
|
||||
code: 40000,
|
||||
message: `服务单价不能超过平台最高限价 ¥${rules.maxHourlyRate || 500}/小时`
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 校验技能标签
|
||||
if (tags !== undefined) {
|
||||
if (!Array.isArray(tags)) {
|
||||
return res.status(400).json({ code: 40000, message: '技能标签必须为数组格式' });
|
||||
}
|
||||
const maxCount = rules.maxTagsCount || 6;
|
||||
if (tags.length > maxCount) {
|
||||
return res.status(400).json({ code: 40000, message: `技能标签最多选择或设置 ${maxCount} 个` });
|
||||
}
|
||||
// 敏感词安全校验
|
||||
const textToCheck = tags.join(' ');
|
||||
const sec = contentSecurityService.checkText(textToCheck);
|
||||
if (!sec.pass) {
|
||||
return res.status(400).json({ code: sec.code, message: sec.message });
|
||||
}
|
||||
}
|
||||
|
||||
// 4. 执行更新
|
||||
const updated = await repo.updateCompanionProfile(companionId, {
|
||||
hourlyRate: hourlyRate !== undefined ? Number(hourlyRate) : undefined,
|
||||
tags: tags !== undefined ? tags : undefined,
|
||||
rankName,
|
||||
status
|
||||
});
|
||||
|
||||
if (!updated) {
|
||||
return res.status(404).json({ code: 40400, message: '未找到指定陪伴师资料' });
|
||||
}
|
||||
|
||||
res.json({ code: 20000, data: updated, message: '陪伴师配置及标签已更新' });
|
||||
} catch (err: any) {
|
||||
res.status(400).json({ code: 40000, message: err.message });
|
||||
}
|
||||
});
|
||||
|
||||
// 5. 订单与仲裁接口 (落盘 MySQL)
|
||||
app.get('/api/orders', async (_req: Request, res: Response) => {
|
||||
try {
|
||||
|
||||
在新工单中引用
屏蔽一个用户