修复:求婚按钮异性判断 - 统一 sex 字段格式

根因:sex 字段数据库存整数(0/1/2),但前后端判断混用了
字符串('男'/'女')导致比较永远错误。

修复三处:
1. UserController::show() - sex 返回统一转字符串(1→'男' 2→'女' 其他→'')
2. frame.blade.php - chatContext.userSex 注入时同样转字符串
3. MarriageService::propose() - 后端性别校验改用整数(1/2)比较

逻辑链路:
- 未设置性别(sex=0) → '' → x-show && userInfo.sex 为'' falsy → 按钮隐藏 ✓
- 同性(如两个男) → '男'==='男' → !== 为false → 按钮隐藏 ✓
- 异性(男+女) → '男'!=='女' → 按钮显示 ✓
This commit is contained in:
2026-03-01 16:04:32 +08:00
parent 954a078d63
commit e0c15b437e
3 changed files with 9 additions and 7 deletions
+3 -1
View File
@@ -44,7 +44,9 @@ class UserController extends Controller
$activePosition = $targetUser->activePosition?->load('position.department')->position;
$data = [
'username' => $targetUser->username,
'sex' => $targetUser->sex,
'sex' => match ((int) $targetUser->sex) {
1 => '男', 2 => '女', default => ''
},
'headface' => $targetUser->headface,
'usersf' => $targetUser->usersf,
'user_level' => $targetUser->user_level,