修复:求婚限制异性(前端隐藏按钮 + 后端拦截校验)

前端(user-actions.blade.php):
- 求婚按钮增加三重条件:对方未婚 + 双方性别均已填写 + 性别不同

后端(MarriageService::propose):
- 增加异性校验:两方性别必须为「男/女」且不同
- 报错:只有男女双方才能互相求婚

frame.blade.php:
- chatContext 注入 userSex(当前用户性别)供前端判断
This commit is contained in:
2026-03-01 15:34:36 +08:00
parent 877fd1935f
commit e20f94fe17
3 changed files with 18 additions and 2 deletions
+10
View File
@@ -47,6 +47,16 @@ class MarriageService
return ['ok' => false, 'message' => '不能向自己求婚!', 'marriage_id' => null];
}
// 只允许异性之间求婚
$validSexes = ['男', '女'];
if (
! in_array($proposer->sex, $validSexes, true) ||
! in_array($target->sex, $validSexes, true) ||
$proposer->sex === $target->sex
) {
return ['ok' => false, 'message' => '只有男女双方才能互相求婚,请确认双方性别设置。', 'marriage_id' => null];
}
// 检查求婚方是否在冷静期
if ($cooldownMsg = $this->checkCooldown($proposer)) {
return ['ok' => false, 'message' => $cooldownMsg, 'marriage_id' => null];