后端(新增 7 控制器 + 2 服务 + 17 张表) - Prepare:排卵预测、BBT(双向体温识别)、试纸识别(规则引擎+额度)、备孕任务、同房指导 - Family:邀请码绑定(≤5)、话术库、爱心积分、私密留言、家庭健康视图 - Health:按周期阶段输出饮食/运动/睡眠/痛经四类建议 - Relation:关系测评、引导卡、冲突工具、课程下单、双人任务(联动记忆)、纪念日 - Parenting:宝宝档案、成长记录、月龄活动匹配、共育任务、育儿情绪、疫苗儿保排期 - Consult:咨询师(资质/定价/时段)、预约下单/取消、量表测评(4 套)、危机干预转介 - Setting:自定义提醒 CRUD、数据备份快照与恢复(保留 5 份) - Mood 增补急救包;Home 提醒合并自定义提醒 - 服务层:ContentService(统一内容/锁态/购买态)、AssessmentService(计分分级+危机识别) 前端(新增 8 页面) - 备孕、家人共护、健康建议、两性关系、亲子教育、心理咨询、测评执行页、情绪急救包 - 首页快捷入口扩至 8 个模块;我的页新增提醒中心与数据备份 - utils/api.js 扩至 84 个接口 数据(可重复执行脚本) - 03_modules.sql:fa_reminder/bbt/lh_test/task/family_bind/care_message/point_log/memory/ assessment(+record)/course_order/baby/growth_record/vaccine/counselor/consult_order/user_backup - 04_module_seed.sql:话术6/引导卡6/冲突3/急救4/同房3/课程6/活动6/育儿情绪4/知识7、 4 套量表、17 项疫苗儿保、3 位咨询师 验证(全部通过) - 接口全链路 82 项断言(M1–M9,含高风险测评危机干预、备份恢复) - 契约校验 84 接口 0 偏差;Vue SFC 19/19、SCSS 18/18 编译通过 - 修复 3 个真实缺陷:action 内调用 action 导致响应被劫持、coTasks 返回数组、 咨询时段跨年错误
108 行
3.3 KiB
PHP
108 行
3.3 KiB
PHP
<?php
|
||
|
||
namespace app\api\controller;
|
||
|
||
use app\common\controller\Api;
|
||
use app\common\service\ContentService;
|
||
use app\common\service\CycleService;
|
||
|
||
/**
|
||
* 健康建议接口(M5)
|
||
*
|
||
* 内容 + 规则匹配:按当前周期阶段给出 饮食 / 运动 / 睡眠 / 痛经 四类建议。
|
||
*/
|
||
class Health extends Api
|
||
{
|
||
protected $noNeedLogin = [];
|
||
protected $noNeedRight = '*';
|
||
|
||
/** 分类 → 建议类型 */
|
||
protected $categoryMap = [
|
||
'diet' => 4,
|
||
'sport' => 5,
|
||
'sleep' => 6,
|
||
'pain' => 7,
|
||
];
|
||
|
||
/**
|
||
* 建议总览
|
||
*/
|
||
public function index()
|
||
{
|
||
$userId = $this->auth->id;
|
||
$cycle = CycleService::current($userId);
|
||
$phase = $cycle['phase'] ?: 'all';
|
||
|
||
$groups = [];
|
||
foreach ($this->categoryMap as $key => $categoryId) {
|
||
$data = ContentService::lists($userId, [
|
||
'type' => 'advice',
|
||
'category_id' => $categoryId,
|
||
'phase' => $phase,
|
||
'limit' => 3,
|
||
]);
|
||
$groups[] = [
|
||
'key' => $key,
|
||
'title' => $this->title($key),
|
||
'icon' => $this->icon($key),
|
||
'list' => $data['list'],
|
||
];
|
||
}
|
||
|
||
$this->success('', [
|
||
'phase' => $phase,
|
||
'phase_text' => $cycle['phase_text'],
|
||
'has_data' => $cycle['has_data'],
|
||
'day' => $cycle['day'],
|
||
'groups' => $groups,
|
||
'tips' => $this->phaseTips($phase),
|
||
'disclaimer' => '以上内容仅供参考,不能替代医疗诊断。',
|
||
]);
|
||
}
|
||
|
||
/**
|
||
* 某一类的全部建议
|
||
* GET type=diet|sport|sleep|pain
|
||
*/
|
||
public function detail()
|
||
{
|
||
$type = $this->request->param('type', 'diet');
|
||
if (!isset($this->categoryMap[$type])) {
|
||
$this->error('类型不存在');
|
||
}
|
||
$cycle = CycleService::current($this->auth->id);
|
||
$data = ContentService::lists($this->auth->id, [
|
||
'type' => 'advice',
|
||
'category_id' => $this->categoryMap[$type],
|
||
'phase' => $cycle['phase'] ?: 'all',
|
||
'limit' => 20,
|
||
]);
|
||
$data['title'] = $this->title($type);
|
||
$data['disclaimer'] = '以上内容仅供参考,不能替代医疗诊断。';
|
||
$this->success('', $data);
|
||
}
|
||
|
||
protected function title($key)
|
||
{
|
||
$map = ['diet' => '饮食建议', 'sport' => '运动建议', 'sleep' => '睡眠建议', 'pain' => '痛经缓解'];
|
||
return isset($map[$key]) ? $map[$key] : $key;
|
||
}
|
||
|
||
protected function icon($key)
|
||
{
|
||
$map = ['diet' => '🍲', 'sport' => '🧘', 'sleep' => '🌙', 'pain' => '🌡'];
|
||
return isset($map[$key]) ? $map[$key] : '🌸';
|
||
}
|
||
|
||
protected function phaseTips($phase)
|
||
{
|
||
$map = [
|
||
'menstrual' => ['保暖优先', '补铁 + 温热饮食', '避免高强度运动'],
|
||
'follicular' => ['精力回升', '适合加量训练', '多吃优质蛋白'],
|
||
'ovulation' => ['易孕期', '注意私处清洁', '保持规律作息'],
|
||
'luteal' => ['情绪易波动', '少糖多纤维', '优先保证睡眠'],
|
||
];
|
||
return isset($map[$phase]) ? $map[$phase] : ['记录后获得个性化建议'];
|
||
}
|
||
}
|