diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 808a260..9cb0687 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -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, diff --git a/app/Services/MarriageService.php b/app/Services/MarriageService.php index 106580d..7c7b984 100644 --- a/app/Services/MarriageService.php +++ b/app/Services/MarriageService.php @@ -47,12 +47,12 @@ class MarriageService return ['ok' => false, 'message' => '不能向自己求婚!', 'marriage_id' => null]; } - // 只允许异性之间求婚 - $validSexes = ['男', '女']; + // 只允许异性之间求婚(sex 字段:1=男 2=女 0=未设置) + $validSexes = [1, 2]; if ( - ! in_array($proposer->sex, $validSexes, true) || - ! in_array($target->sex, $validSexes, true) || - $proposer->sex === $target->sex + ! in_array((int) $proposer->sex, $validSexes, true) || + ! in_array((int) $target->sex, $validSexes, true) || + (int) $proposer->sex === (int) $target->sex ) { return ['ok' => false, 'message' => '只有男女双方才能互相求婚,请确认双方性别设置。', 'marriage_id' => null]; } diff --git a/resources/views/chat/frame.blade.php b/resources/views/chat/frame.blade.php index 9c79676..9c718a7 100644 --- a/resources/views/chat/frame.blade.php +++ b/resources/views/chat/frame.blade.php @@ -31,7 +31,7 @@ roomId: {{ $room->id }}, userId: {{ $user->id }}, username: "{{ $user->username }}", - userSex: "{{ $user->sex }}", + userSex: "{{ match ((int) $user->sex) {1 => '男',2 => '女',default => ''} }}", userLevel: {{ $user->user_level }}, superLevel: {{ $superLevel }}, levelKick: {{ $levelKick }},