From 464e5d68d22a07eacd5b24df834e3820f427bd49 Mon Sep 17 00:00:00 2001 From: lion <120344285@qq.com> Date: Thu, 22 Oct 2026 10:34:28 +0800 Subject: [PATCH] =?UTF-8?q?=E9=97=AE=E5=8D=B7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Mobile/CourseController.php | 5 ++-- .../Controllers/Mobile/UserController.php | 2 +- tests/Feature/SurveyWorkflowTest.php | 23 +++++++------------ 3 files changed, 11 insertions(+), 19 deletions(-) diff --git a/app/Http/Controllers/Mobile/CourseController.php b/app/Http/Controllers/Mobile/CourseController.php index 7236e04..4d0b91b 100755 --- a/app/Http/Controllers/Mobile/CourseController.php +++ b/app/Http/Controllers/Mobile/CourseController.php @@ -190,7 +190,7 @@ class CourseController extends CommonController if ($message = $detail->participationError($this->getUserId())) return $this->success(['id' => $detail->id, 'access_error' => $message]); $detail->schema_hash = SurveySchema::hash($detail->courseContentEvaluationAsks->toArray()); $reply = $detail->courseContentEvaluationForms()->where('user_id', $this->getUserId())->first(); - $detail->requires_profile = !\App\Services\Survey\SurveyIdentity::complete(auth('mobile')->user()); + $detail->requires_profile = trim((string) auth('mobile')->user()->mobile) === ''; if ($reply && !empty($reply->snapshot['questions'])) $detail->schema_hash = SurveySchema::hash($reply->snapshot['questions']); $detail->my_response = $reply ? [ 'title' => $reply->snapshot['title'] ?? $detail->title, @@ -488,8 +488,7 @@ class CourseController extends CommonController if ($message = $survey->participationError($this->getUserId())) return ['access_error' => $message]; if ((int) $survey->status !== 1) throw new \InvalidArgumentException('问卷未发布'); if ($survey->start_time && strtotime($survey->start_time) > time()) throw new \InvalidArgumentException('评价时间未开始'); - if (empty(auth('mobile')->user()->mobile)) throw new \InvalidArgumentException('请先绑定或注册'); - if (!\App\Services\Survey\SurveyIdentity::complete(auth('mobile')->user())) throw new \InvalidArgumentException('请先完成绑定或注册资料'); + if (trim((string) auth('mobile')->user()->mobile) === '') throw new \InvalidArgumentException('请先绑定或注册'); $reply = $survey->courseContentEvaluationForms()->where('user_id', $this->getUserId())->first(); $questions = $survey->courseContentEvaluationAsks()->with('courseContent.teacher')->orderBy('sort')->orderBy('id')->get()->toArray(); if ($reply && !empty($reply->snapshot['questions'])) $questions = $reply->snapshot['questions']; diff --git a/app/Http/Controllers/Mobile/UserController.php b/app/Http/Controllers/Mobile/UserController.php index b04fcaa..6d48f28 100755 --- a/app/Http/Controllers/Mobile/UserController.php +++ b/app/Http/Controllers/Mobile/UserController.php @@ -477,7 +477,7 @@ class UserController extends CommonController } \App\Services\SupplyDemand\Handover::verified($hasMobile); $token = $hasMobile->createToken("mobile-token")->plainTextToken; - return $this->success(['token' => $token, 'requires_profile' => !\App\Services\Survey\SurveyIdentity::complete($hasMobile)]); + return $this->success(compact('token')); } return $this->fail([ResponseCode::ERROR_BUSINESS, '校友库中还没有您的信息,请先注册']); } diff --git a/tests/Feature/SurveyWorkflowTest.php b/tests/Feature/SurveyWorkflowTest.php index adba65a..599d04e 100644 --- a/tests/Feature/SurveyWorkflowTest.php +++ b/tests/Feature/SurveyWorkflowTest.php @@ -65,29 +65,22 @@ class SurveyWorkflowTest extends TestCase return $response->json('id'); } - public function testIncompleteProfilesCannotSubmitUntilRegistrationIsComplete(): void + public function testSurveyAccessRequiresOnlyMobileEvenWhenOtherProfileFieldsAreMissing(): void { $id = $this->createQuestion(); - $complete = clone Auth::guard('mobile')->user(); $pending = new User(); $pending->forceFill(['id' => 200, 'mobile' => '13800000000']); Auth::guard('mobile')->setUser($pending); $detail = '/api/mobile/course/evaluation-detail?course_content_evaluation_id=10'; $payload = ['course_content_evaluation_id' => 10, 'answer_version' => 2, 'data' => [['id' => $id, 'value' => ['count' => 0, 'follow' => 'yes']]]]; - $this->getJson($detail)->assertJsonPath('requires_profile', true); - $this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('errmsg', '请先完成绑定或注册资料'); - $this->assertSame(0, \App\Models\CourseContentEvaluationForm::count()); - foreach (['name', 'sex', 'birthday', 'email', 'company_name', 'company_position'] as $field) { - $missing = clone $complete; - $missing->$field = null; - $this->assertFalse(\App\Services\Survey\SurveyIdentity::complete($missing)); - } - $monthOnly = clone $complete; - $monthOnly->birthday = '1990-01'; - $this->assertFalse(\App\Services\Survey\SurveyIdentity::complete($monthOnly)); - Auth::guard('mobile')->setUser($complete); $this->getJson($detail)->assertJsonPath('requires_profile', false); - $this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('user_id', 200); + $replyId = $this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('user_id', 200)->json('id'); + $pending->mobile = null; + $this->getJson($detail)->assertJsonPath('requires_profile', true); + $this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('errmsg', '请先绑定或注册'); + $pending->mobile = '13800000000'; + $this->postJson('/api/mobile/course/course-content-form', $payload)->assertJsonPath('id', $replyId); + $this->assertSame(1, \App\Models\CourseContentEvaluationForm::count()); } public function testRespondentFallbackIsSharedByListsDetailsAndExportWithoutUpdatingUsers(): void