文件
huaqiapp/server/application/api/controller/Setting.php
linda 5ea1b461f3 feat: 花期 V1.0 纵向切片(暖色调设计系统 + 周期/情绪/会员全链路)
前端(uni-app · Vue3)
- 设计系统:uni.scss 品牌令牌(花红 #E8604C / 蜜橙 #F5A65B / 暖米白 #FFF9F5),
  App.vue 全局原子类(卡片/按钮/胶囊/单元格/空态/进度)
- 页面:登录、首页(聚合)、周期(花瓣日历+当日记录+预测+概览)、情绪(记录+趋势+日记+疗愈)、
  我的(资料/会员/隐私/提醒)、健康报告、会员套餐、内容详情
- 组件:hq-tabbar(自定义底栏)、bloom-calendar(阶段日历)
- 基础层:utils/{config,request,store,api,date}.js(统一 token、401 处理、接口集中定义)

后端(FastAdmin / ThinkPHP 5.0)
- 新增 api 控制器:Home / Cycle / Mood / Content / Member / Setting,User 增补 detail、updateprofile
- 新增服务层:CycleService(四阶段计算、预测、月历、汇总)、MemberService(权益判定)
- 新增表:fa_cycle / fa_cycle_log / fa_symptom_tag / fa_mood_log / fa_content /
  fa_content_category / fa_member_plan / fa_member_order / fa_user_setting
- 初始化数据:20 个症状标签、28 条内容(心语/科普/知识/食谱/运动/睡眠/痛经/冥想)、3 档会员

验证(全部通过)
- 接口全链路 48 项断言(登录→周期→首页→情绪→内容→会员→设置→资料)
- 前后端契约静态校验 24 个接口 0 偏差
- Vue SFC 编译 11/11、SCSS 编译 10/10
- 验证脚本见 scripts/verify/,报告见 docs/04-前端设计系统与联调验证.md
2026-11-05 22:54:02 +08:00

130 行
4.1 KiB
PHP

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

<?php
namespace app\api\controller;
use app\common\controller\Api;
use think\Db;
/**
* 隐私与提醒设置(M6)
*/
class Setting extends Api
{
protected $noNeedLogin = [];
protected $noNeedRight = '*';
protected $defaultRemind = [
'period' => true, // 经期前提醒
'ovulation' => true, // 排卵日提醒
'record' => true, // 每日记录提醒
'care' => true, // 关怀提醒(家人共护)
'time' => '21:00',
];
/**
* 读取设置
*/
public function index()
{
$setting = Db::name('user_setting')->where('user_id', $this->auth->id)->find();
if (!$setting) {
$setting = [
'app_lock' => 'none',
'local_only' => 0,
'remind_json' => json_encode($this->defaultRemind),
];
}
$remind = json_decode($setting['remind_json'], true) ?: $this->defaultRemind;
$remind = array_merge($this->defaultRemind, $remind);
$this->success('', [
'app_lock' => $setting['app_lock'],
'has_lock_code' => !empty($setting['app_lock_value']),
'local_only' => (int)$setting['local_only'],
'remind' => $remind,
]);
}
/**
* 保存设置
* POST app_lock=none|password|biometric, app_lock_code=1234, local_only=0|1, remind={"period":true,...}
*/
public function save()
{
$userId = $this->auth->id;
$exist = Db::name('user_setting')->where('user_id', $userId)->find();
$data = ['updatetime' => time()];
$appLock = $this->request->post('app_lock', null);
if ($appLock !== null) {
if (!in_array($appLock, ['none', 'password', 'biometric'])) {
$this->error('应用锁类型不正确');
}
$data['app_lock'] = $appLock;
}
$code = (string)$this->request->post('app_lock_code', '');
if ($code !== '') {
if (!preg_match('/^\d{4,6}$/', $code)) {
$this->error('应用锁密码需为 4-6 位数字');
}
// 仅存哈希,不落明文
$data['app_lock_value'] = md5($code . 'huāqī');
}
$localOnly = $this->request->post('local_only', null);
if ($localOnly !== null) {
$data['local_only'] = (int)!!$localOnly;
}
$remind = $this->readRemind();
if ($remind !== null) {
$merged = array_merge($this->defaultRemind, array_intersect_key($remind, $this->defaultRemind));
if (isset($merged['time']) && !preg_match('/^\d{2}:\d{2}$/', $merged['time'])) {
$merged['time'] = '21:00';
}
$data['remind_json'] = json_encode($merged, JSON_UNESCAPED_UNICODE);
}
if ($exist) {
Db::name('user_setting')->where('id', $exist['id'])->update($data);
} else {
$data['user_id'] = $userId;
$data['createtime'] = time();
Db::name('user_setting')->insert($data);
}
$this->success('已保存');
}
/**
* 读取提醒配置:支持 remind_xxx 独立字段(推荐,兼容 request filter)与 remind JSON
* @return array|null
*/
protected function readRemind()
{
$keys = ['period', 'ovulation', 'record', 'care', 'time'];
$result = [];
$hasField = false;
foreach ($keys as $key) {
$value = $this->request->post('remind_' . $key, null);
if ($value !== null) {
$hasField = true;
$result[$key] = $key === 'time' ? (string)$value : (bool)(int)$value;
}
}
if ($hasField) {
return $result;
}
// 兼容 JSON 传参(注意:全局 filter 会把引号转义,需还原)
$json = $this->request->post('remind', null);
if ($json === null || $json === '') {
return null;
}
$arr = is_array($json) ? $json : json_decode(htmlspecialchars_decode((string)$json, ENT_QUOTES), true);
return is_array($arr) ? $arr : null;
}
}