소스 검색

feat:用户端-查看申请技师记录

刘学玺 4 달 전
부모
커밋
71e238d6b5
3개의 변경된 파일88개의 추가작업 그리고 2개의 파일을 삭제
  1. 45 1
      app/Http/Controllers/Client/UserController.php
  2. 39 1
      app/Services/Client/UserService.php
  3. 4 0
      routes/api.php

+ 45 - 1
app/Http/Controllers/Client/UserController.php

@@ -205,7 +205,7 @@ class UserController extends Controller
      *     "work_years": 5,
      *     "intention_city": "杭州",
      *     "portrait_images": ["https://example.com/portrait1.jpg"],
-     *     "introduction": "专按摩师,有多年经验",
+     *     "introduction": "专��按摩师,有多年经验",
      *     "state": "auditing",
      *     "created_at": "2024-03-20 10:00:00",
      *     "updated_at": "2024-03-20 10:00:00"
@@ -291,4 +291,48 @@ class UserController extends Controller
 
         return $this->success($result, '生成成功');
     }
+
+    /**
+     * [用户]查看技师申请记录
+     *
+     * @description 获取当前用户的技师申请记录
+     *
+     * @authenticated
+     *
+     * @response 200 {
+     *   "code": 200,
+     *   "message": "获取成功",
+     *   "data": {
+     *     "id": 1,
+     *     "coach_id": 100,
+     *     "age": 25,
+     *     "mobile": "13800138000",
+     *     "gender": 1,
+     *     "work_years": 5,
+     *     "intention_city": "杭州",
+     *     "portrait_images": ["https://example.com/portrait1.jpg"],
+     *     "introduction": "专业按摩师,有多年经验",
+     *     "state": 1,
+     *     "state_text": "待审核",
+     *     "created_at": "2024-03-20 10:00:00",
+     *     "updated_at": "2024-03-20 10:00:00"
+     *   }
+     * }
+     * @response 401 {
+     *   "code": 401,
+     *   "message": "请先登录",
+     *   "data": null
+     * }
+     * @response 404 {
+     *   "code": 404,
+     *   "message": "未找到申请记录",
+     *   "data": null
+     * }
+     */
+    public function getCoachApplication()
+    {
+        $result = $this->service->getCoachApplication();
+
+        return $this->success($result);
+    }
 }

+ 39 - 1
app/Services/Client/UserService.php

@@ -509,7 +509,7 @@ class UserService
                 'qr_code' => $qrCode,
             ];
         } catch (\Exception $e) {
-            Log::error('生成邀请码失', [
+            Log::error('生成邀请码失���', [
                 'error' => $e->getMessage(),
                 'user_id' => Auth::id(),
                 'type' => $type,
@@ -609,4 +609,42 @@ class UserService
 
         return 'data:image/svg+xml;base64,'.base64_encode($qrImage);
     }
+
+    /**
+     * 获取技师申请记录
+     *
+     * 业务逻辑:
+     * 1. 获取当前用户的技师信息
+     * 2. 如果用户不是技师,返回 404
+     * 3. 获取最新的申请记录
+     *
+     * @return CoachInfoRecord 返回申请记录
+     *
+     * @throws \Illuminate\Http\Exceptions\HttpResponseException 未找到申请记录时抛出异常
+     */
+    public function getCoachApplication(): CoachInfoRecord
+    {
+        try {
+            // 1. 获取当前用户的技师信息
+            $user = $this->getAndValidateUser();
+            $coach = $user->coach;
+
+            // 2. 如果用户不是技师,返回 404
+            abort_if(! $coach, 404, '未找到申请记录');
+
+            // 3. 获取最新的申请记录
+            $application = $coach->info;
+            abort_if(! $application, 404, '未找到申请记录');
+
+            return $application;
+        } catch (\Exception $e) {
+            // 记录错误日志
+            Log::error('获取技师申请记录失败', [
+                'error' => $e->getMessage(),
+                'user_id' => Auth::id(),
+                'trace' => $e->getTraceAsString(),
+            ]);
+            throw $e;
+        }
+    }
 }

+ 4 - 0
routes/api.php

@@ -66,6 +66,9 @@ Route::prefix('client')->group(function () {
             Route::post('/apply-coach', [UserController::class, 'applyCoach']);
             // 生成邀请码
             Route::get('/invite-code', [UserController::class, 'generateInviteCode']);
+
+            // 获取技师申请记录
+            Route::get('coach/application', [UserController::class, 'getCoachApplication']);
         });
 
         // 项目相关
@@ -142,6 +145,7 @@ Route::prefix('client')->group(function () {
             Route::get('auth-url', [WechatController::class, 'getAuthUrl']);
             Route::post('callback', [WechatController::class, 'handleCallback']);
         });
+
     });
 });