feat(consult): 咨询改为在线预约表单 + 新增 SDS/SAS/16PF 付费心理测评

一、心理咨询(M9)
- 前端不再选咨询师时段,改为「分类 + 表单」:11 类(婚恋/青少年/职场人际/情绪疏导/
  人生卡点/成长迷茫/脱单指导/分手挽回/社恐咨询/抑郁焦虑/情绪压力)
- 表单字段:称呼、手机号(11 位校验)、方便联系时间、困扰描述(≥5 字),提交后由咨询助理联系
- 支持查看/取消我的预约;同一用户 10 分钟内防重复提交
- 新增表 fa_consult_booking(含跟进状态与备注),后台可跟进

二、心理测评(付费)
- 新增三个付费量表:抑郁自评 SDS(20 题,1-4 级 + 10 道反向题,标准分=粗分×1.25 取整)、
  焦虑自评 SAS(20 题,5 道反向题)、卡特尔 16PF 简版(48 题 / 16 维度,三选项)
- 华东:测评需付费,未付费拦截并返回 need_pay;新增 fa_assessment_order 订单表与下单接口
- 计分:标准分分级(正常/轻度/中度/重度)+ 16PF 维度剖面(1-10 分、高/中/低解读)
- 风险识别:SDS 自伤条目高分或重度 → risk_flag + 危机热线
- 结果页新增 16PF 16 维条形剖面与「预约咨询师解读」入口

三、管理端
- 新增后台模块:心理预约(分类/状态/备注跟进)、测评订单(支付状态可改)
- ManageConfig 增加对应字段配置;菜单脚本 db/06_consult_assessment.sql(可重复执行)
- fa_assessment 增加 price 字段;测评列表/详情接口返回价格与购买状态

四、验证(全绿)
- 咨询+测评专项:54 项断言(分类、表单校验、防重复、脱敏、取消、题库、付费拦截、
  下单、付费后 SDS=62/轻度、SAS=56/轻度、16PF 16 维满分、危机干预)
- 前台接口 78 项、后台自检 33 项(28 模块)、契约 0 偏差、Vue 20/20、SCSS 19/19、无 emoji
这个提交包含在:
linda
2026-11-06 16:00:52 +08:00
父节点 56f5f60aa5
当前提交 3baa52e95a
共有 15 个文件被更改,包括 1623 次插入 和 644 次删除

查看文件

@@ -132,10 +132,14 @@ bbt = r.get("data") or {}
check("体温曲线含今日", any(x.get("temperature") == 36.62 for x in (bbt.get("list") or [])), f"{bbt.get('count')} 天")
r = call("/api/prepare/lhtest", {"test_type": "lh", "log_date": str(today), "level": 3}, "POST")
lh = r.get("data") or {}
check("试纸识别", lh.get("result") == "strong", lh.get("result_text"))
check("识别置信度", (lh.get("confidence") or 0) > 80, str(lh.get("confidence")))
check("额度扣减", (lh.get("quota") or {}).get("used", 0) >= 1, str((lh.get("quota") or {}).get("used")))
if r.get("code") == 1:
lh = r.get("data") or {}
check("试纸识别", lh.get("result") == "strong", lh.get("result_text"))
check("识别置信度", (lh.get("confidence") or 0) > 80, str(lh.get("confidence")))
check("额度扣减", (lh.get("quota") or {}).get("used", 0) >= 1, str((lh.get("quota") or {}).get("used")))
else:
# 免费额度用尽(每月 5 次)时应给出明确提示,属预期行为
check("试纸识别额度控制", ("用完" in (r.get("msg") or "")) or ("会员" in (r.get("msg") or "")), r.get("msg"))
r = call("/api/prepare/taskSave", {"title": "预约孕前检查", "scope": "prepare", "category": "check"}, "POST")
check("备孕任务新增", r.get("code") == 1, r.get("msg"))
@@ -239,51 +243,61 @@ r = call("/api/parenting/courses")
check("育儿课程", len((r.get("data") or {}).get("list") or []) >= 3)
print("=" * 72)
print("8. M9 心理咨询与测评")
print("8. M9 心理咨询(预约表单)+ 心理测评")
r = call("/api/consult/index")
con = r.get("data") or {}
check("咨询总览", "counselors" in con and "crisis" in con)
check("咨询师≥3", len(con.get("counselors") or []) >= 3)
counselor = (con.get("counselors") or [{}])[0]
check("咨询师含资质/价格/时段", bool(counselor.get("cert_verify")) and bool(counselor.get("slots")))
import re as _re
_slot = (counselor.get("slots") or [""])[0]
check("时段为完整时间格式", bool(_re.match(r"^\d{4}-\d{2}-\d{2} \d{2}:\d{2}$", _slot)), _slot)
check("咨询总览", "categories" in con and "bookings" in con and "assessments" in con)
check("咨询分类 11 个", len(con.get("categories") or []) == 11, f"{len(con.get('categories') or [])} 个")
check("危机信息含热线", "12356" in ((con.get("crisis") or {}).get("text") or ""))
r = call("/api/consult/orderCreate", {
"counselor_id": counselor.get("id"),
"mode": "video",
"start_time": (datetime.datetime.now() + datetime.timedelta(days=2)).strftime("%Y-%m-%d 15:00"),
# 清理历史待处理预约,保证可重复执行
for b in (con.get("bookings") or []):
if b.get("status") in ("pending", "contacted"):
call("/api/consult/bookingCancel", {"id": b["id"]}, "POST")
r = call("/api/consult/booking", {
"name": "小满", "mobile": "13900002222", "category": "emotion",
"prefer_time": "工作日 19:00-21:00", "description": "最近工作压力大,睡眠不好,想找人聊聊",
}, "POST")
order = r.get("data") or {}
check("咨询预约", bool(order.get("order_no")), order.get("order_no"))
consult_id = order.get("order_id", 0)
r = call("/api/consult/orders")
check("预约列表", len((r.get("data") or {}).get("list") or []) >= 1)
r = call("/api/consult/cancel", {"id": consult_id}, "POST")
check("取消预约", r.get("code") == 1)
booking = r.get("data") or {}
check("提交咨询预约", r.get("code") == 1 and bool(booking.get("id")), r.get("msg"))
check("预约分类中文", booking.get("category") == "情绪疏导", str(booking.get("category")))
booking_id = booking.get("id", 0)
r = call("/api/consult/bookings")
blist = (r.get("data") or {}).get("list") or []
check("我的预约列表", any(x.get("id") == booking_id for x in blist), f"{len(blist)} 条")
if blist:
check("手机号脱敏", "****" in (blist[0].get("mobile") or ""))
r = call("/api/consult/bookingCancel", {"id": booking_id}, "POST")
check("取消预约", r.get("code") == 1, r.get("msg"))
# 测评:PMS(低风险)
r = call("/api/consult/assessments", {"scope": "mood"})
alist = (r.get("data") or {}).get("list") or []
codes = {a.get("code"): a for a in alist}
check("量表列表含 SDS", "dep_sds" in codes)
check("量表列表含 SAS", "anx_sas" in codes)
check("量表列表含 16PF", "pf16" in codes)
sds = codes.get("dep_sds") or {}
check("SDS 需付费 29.9", sds.get("need_pay") is True and abs((sds.get("price") or 0) - 29.9) < 0.01, f"¥{sds.get('price')}")
check("SDS 题数 20", sds.get("questions") == 20, str(sds.get("questions")))
r = call("/api/consult/assessmentDetail", {"id": sds.get("id")})
detail = r.get("data") or {}
check("SDS 题库加载", len(detail.get("items") or []) == 20 and len(detail.get("options") or []) == 4)
# 免费量表(PMS)计分仍正常
pms = next((a for a in alist if a.get("code") == "pms"), None)
check("量表列表含 PMS", pms is not None)
check("免费量表 PMS 存在", pms is not None)
if pms:
r = call("/api/consult/assessmentDetail", {"id": pms["id"]})
detail = r.get("data") or {}
check("量表题目加载", len(detail.get("questions") or []) == 5 and len(detail.get("options") or []) == 5)
r = call("/api/consult/assessmentSubmit", {"id": pms["id"], "answers": json.dumps([0, 1, 1, 0, 1])}, "POST")
res = r.get("data") or {}
check("测评计分", res.get("score") == 3, str(res.get("score")))
check("测评结果分级", res.get("result") == "low", res.get("result_text"))
check("测评含免责声明", "仅供参考" in (res.get("disclaimer") or ""))
check("PMS 计分 3", res.get("score") == 3, str(res.get("score")))
check("PMS 分级 low", res.get("result") == "low", str(res.get("result")))
# 测评:产后情绪(高风险 → 危机干预)
# 产后情绪高风险 → 危机干预
pdp = next((a for a in alist if a.get("code") == "pdp"), None)
if not pdp:
r2 = call("/api/consult/assessments", {"scope": "parenting"})
pdp = next((a for a in ((r2.get("data") or {}).get("list") or []) if a.get("code") == "pdp"), None)
check("量表列表含产后筛查", pdp is not None)
if pdp:
r = call("/api/consult/assessmentSubmit", {"id": pdp["id"], "answers": json.dumps([3, 3, 3, 3, 3])}, "POST")
res = r.get("data") or {}