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] : ['记录后获得个性化建议']; } }