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 次删除

查看文件

@@ -85,7 +85,8 @@ $modules = [
'family_bind' => '家人绑定', 'care_message' => '沟通留言', 'point_log' => '爱心积分',
'memory' => '纪念日', 'course_order' => '课程订单',
'baby' => '宝宝档案', 'growth_record' => '成长记录', 'vaccine' => '疫苗与儿保',
'counselor' => '咨询师', 'consult_order' => '咨询订单', 'assessment' => '量表管理', 'assessment_record' => '测评记录',
'counselor' => '咨询师', 'consult_order' => '咨询订单', 'consult_booking' => '心理预约',
'assessment' => '量表管理', 'assessment_record' => '测评记录', 'assessment_order' => '测评订单',
'member_plan' => '会员套餐', 'member_order' => '会员订单', 'user_setting' => '隐私与提醒', 'user_backup' => '数据备份',
];

查看文件

@@ -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 {}

查看文件

@@ -0,0 +1,223 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""花期 APP · 心理咨询预约 + 付费心理测评 全链路验证
前置:
export HQ_TEST_ACCOUNT=demo HQ_TEST_PASSWORD=demo123456
可选:
export HQ_ASSESSMENT_PAID=1 # 已在后台把测评订单置为 paid 后,验证计分链路
用法:
python3 scripts/verify/consult_assessment_test.py
"""
import json
import os
import sys
import urllib.error
import urllib.parse
import urllib.request
BASE = os.environ.get("HQ_API_BASE", "https://huaqiapp.gzyakj.com.cn")
ACCOUNT = os.environ.get("HQ_TEST_ACCOUNT", "")
PASSWORD = os.environ.get("HQ_TEST_PASSWORD", "")
PAID_READY = os.environ.get("HQ_ASSESSMENT_PAID", "") == "1"
TOKEN = ""
PASSED = []
FAILED = []
if not ACCOUNT or not PASSWORD:
print("请先设置 HQ_TEST_ACCOUNT / HQ_TEST_PASSWORD")
sys.exit(2)
def call(path, params=None, method="GET", auth=True):
url = BASE + path
data = None
if method == "GET" and params:
url += "?" + urllib.parse.urlencode(params)
elif method == "POST":
data = urllib.parse.urlencode(params or {}).encode()
req = urllib.request.Request(url, data=data, method=method)
req.add_header("Accept", "application/json")
if auth and TOKEN:
req.add_header("token", TOKEN)
try:
with urllib.request.urlopen(req, timeout=25) as resp:
return json.loads(resp.read().decode("utf-8"))
except urllib.error.HTTPError as e:
return {"code": -e.code, "msg": e.read().decode("utf-8", "ignore")[:200]}
except Exception as e:
return {"code": -1, "msg": str(e)}
def check(name, cond, detail=""):
if cond:
PASSED.append(name)
print(f" ✅ {name}" + (f" {detail}" if detail else ""))
else:
FAILED.append(f"{name} {detail}")
print(f" ❌ {name} {detail}")
print("=" * 72)
print("0. 登录")
r = call("/api/user/login", {"account": ACCOUNT, "password": PASSWORD}, "POST", auth=False)
info = (r.get("data") or {}).get("userinfo") or {}
TOKEN = info.get("token", "")
check("登录成功", bool(TOKEN))
print("=" * 72)
print("1. 咨询分类(免登录)")
r = call("/api/consult/categories", auth=False)
cats = (r.get("data") or {}).get("list") or []
names = [c.get("name") for c in cats]
check("分类 11 个", len(cats) == 11, f"{len(cats)} 个")
for expect in ["婚恋咨询", "青少年心理", "职场人际", "情绪疏导", "人生卡点", "成长迷茫",
"脱单指导", "分手挽回", "社恐咨询", "抑郁焦虑", "情绪压力"]:
check(f"分类含「{expect}」", expect in names)
print("=" * 72)
print("2. 预约表单校验")
r = call("/api/consult/booking", {"name": "", "mobile": "13800000000", "category": "love",
"prefer_time": "工作日 19:00", "description": "最近压力很大"}, "POST")
check("缺少称呼被拦截", r.get("code") == 0, r.get("msg"))
r = call("/api/consult/booking", {"name": "小满", "mobile": "1390000", "category": "love",
"prefer_time": "工作日 19:00", "description": "最近压力很大"}, "POST")
check("手机号格式校验", r.get("code") == 0, r.get("msg"))
r = call("/api/consult/booking", {"name": "小满", "mobile": "13900001111", "category": "unknown",
"prefer_time": "工作日 19:00", "description": "最近压力很大"}, "POST")
check("非法分类被拦截", r.get("code") == 0, r.get("msg"))
r = call("/api/consult/booking", {"name": "小满", "mobile": "13900001111", "category": "love",
"prefer_time": "工作日 19:00", "description": "最近压力很大"}, "POST")
data = r.get("data") or {}
check("提交预约成功", r.get("code") == 1 and bool(data.get("id")), r.get("msg"))
booking_id = data.get("id", 0)
check("返回分类中文", data.get("category") == "婚恋咨询", str(data.get("category")))
check("返回联系提示", bool(data.get("notice")))
r = call("/api/consult/booking", {"name": "小满", "mobile": "13900001111", "category": "emotion",
"prefer_time": "明天上午", "description": "重复提交测试"}, "POST")
check("10 分钟内重复提交被拦截", r.get("code") == 0, r.get("msg"))
print("=" * 72)
print("3. 我的预约")
r = call("/api/consult/bookings")
list_ = (r.get("data") or {}).get("list") or []
check("预约列表含新记录", any(x.get("id") == booking_id for x in list_), f"{len(list_)} 条")
if list_:
first = list_[0]
check("手机号脱敏", "****" in (first.get("mobile") or ""), first.get("mobile"))
check("状态文案", first.get("status_text") in ("待联系", "已联系", "已完成", "已取消"), first.get("status_text"))
r = call("/api/consult/bookingCancel", {"id": booking_id}, "POST")
list_ = (r.get("data") or {}).get("list") or []
check("取消预约", any(x.get("id") == booking_id and x.get("status") == "canceled" for x in list_), r.get("msg"))
print("=" * 72)
print("4. 心理测评列表(付费)")
r = call("/api/consult/assessments", {"scope": "mood"})
scales = (r.get("data") or {}).get("list") or []
by_code = {s.get("code"): s for s in scales}
for code, title, price, count in [("dep_sds", "抑郁自评量表(SDS)", 29.9, 20),
("anx_sas", "焦虑自评量表(SAS)", 29.9, 20),
("pf16", "卡特尔十六种人格因素测验(16PF 简版)", 59.9, 48)]:
s = by_code.get(code)
check(f"量表存在:{code}", s is not None)
if s:
check(f" {code} 需付费", s.get("need_pay") is True and abs((s.get("price") or 0) - price) < 0.01,
f"¥{s.get('price')}")
check(f" {code} 题数 {count}", s.get("questions") == count, str(s.get("questions")))
if not PAID_READY:
check(f" {code} 未购买锁定", s.get("paid") is False and s.get("locked") is True)
else:
check(f" {code} 已购买解锁", s.get("paid") is True)
print("=" * 72)
print("5. 题库与选项")
sid = by_code.get("dep_sds", {}).get("id")
r = call("/api/consult/assessmentDetail", {"id": sid})
d = r.get("data") or {}
check("SDS 题库加载", len(d.get("items") or []) == 20 and len(d.get("options") or []) == 4)
check("SDS 选项为 1-4 级", [o.get("value") for o in d.get("options") or []] == [1, 2, 3, 4])
check("SDS 含计分类型", d.get("scale") == "SDS")
pf = by_code.get("pf16", {})
r = call("/api/consult/assessmentDetail", {"id": pf.get("id")})
pd = r.get("data") or {}
check("16PF 题库 48 题", len(pd.get("items") or []) == 48)
check("16PF 三选项", len(pd.get("options") or []) == 3)
check("16PF 16 个维度", len(pd.get("dims") or {}) == 16)
print("=" * 72)
if not PAID_READY:
print("6. 未付费拦截")
answers20 = [1] * 20
r = call("/api/consult/assessmentSubmit", {"id": sid, "answers": json.dumps(answers20)}, "POST")
check("未付费提交被拒绝", r.get("code") == 0, r.get("msg"))
need_pay = (r.get("data") or {}).get("need_pay") if isinstance(r.get("data"), dict) else None
check("返回 need_pay 标记", need_pay == 1 or "付费" in (r.get("msg") or ""), str(need_pay))
print("=" * 72)
print("7. 下单")
r = call("/api/consult/assessmentOrder", {"id": sid}, "POST")
order = r.get("data") or {}
check("测评订单创建", bool(order.get("order_no")) and order.get("need_pay") is True, order.get("order_no"))
check("订单金额正确", abs((order.get("amount") or 0) - 29.9) < 0.01, str(order.get("amount")))
else:
print("6. 已付费(跳过未付费拦截断言)")
print("7. 已付费(跳过下单断言)")
order = {}
if not PAID_READY:
print("=" * 72)
print("⏸ 未设置 HQ_ASSESSMENT_PAID=1,跳过计分链路(请先在后台把该订单置为已支付)")
print(f" 订单号:{order.get('order_no')}")
else:
print("=" * 72)
print("8. 付费后计分(SDS / SAS / 16PF)")
r = call("/api/consult/assessments", {"scope": "mood"})
paid_list = {s.get("code"): s for s in ((r.get("data") or {}).get("list") or [])}
check("SDS 已解锁", paid_list.get("dep_sds", {}).get("paid") is True)
# SDS:全部选第 1 个选项(值 1)→ 粗分 47 → 标准分 59(轻度)
r = call("/api/consult/assessmentSubmit", {"id": sid, "answers": json.dumps([0] * 20)}, "POST")
res = r.get("data") or {}
check("SDS 提交成功", r.get("code") == 1, r.get("msg"))
check("SDS 标准分 62", res.get("score") == 62, str(res.get("score")))
check("SDS 分级 mild", res.get("result") == "mild", str(res.get("result")))
check("SDS 含建议与免责", bool(res.get("advice")) and "仅供参考" in (res.get("disclaimer") or ""))
# SDS 风险:第 19 题选最高(自伤念头)→ risk_flag
risky = [0] * 20
risky[18] = 3
r = call("/api/consult/assessmentSubmit", {"id": sid, "answers": json.dumps(risky)}, "POST")
res = r.get("data") or {}
check("SDS 高风险触发危机干预", res.get("risk_flag") == 1 and bool((res.get("crisis") or {}).get("hotlines")))
# SAS:全部选第 2 个选项(值 2)→ 粗分 40 → 标准分 50(轻度)
sas_id = paid_list.get("anx_sas", {}).get("id")
r = call("/api/consult/assessmentSubmit", {"id": sas_id, "answers": json.dumps([1] * 20)}, "POST")
res = r.get("data") or {}
check("SAS 标准分 56", res.get("score") == 56, str(res.get("score")))
check("SAS 分级 mild", res.get("result") == "mild", str(res.get("result")))
# 16PF:全选 A(值 2)→ 每维度 6 分 → 标准分 10
pf_id = paid_list.get("pf16", {}).get("id")
r = call("/api/consult/assessmentSubmit", {"id": pf_id, "answers": json.dumps([0] * 48)}, "POST")
res = r.get("data") or {}
check("16PF 提交成功", r.get("code") == 1, r.get("msg"))
check("16PF 16 维剖面", len(res.get("dims") or []) == 16)
check("16PF 维度满分 10", all(d.get("score") == 10 for d in (res.get("dims") or [])), str((res.get("dims") or [{}])[0]))
check("16PF 含主导特质文案", "最突出的特质" in (res.get("result_text") or ""), res.get("result_text"))
print("=" * 72)
print(f"通过 {len(PASSED)} 项,失败 {len(FAILED)} 项")
if FAILED:
for f in FAILED:
print(" ❌ " + f)
sys.exit(1)
print("🎉 咨询预约 + 付费心理测评 全链路验证通过")