Browse Source

fixed:用户端-申请技师(添加年龄)

刘学玺 4 months ago
parent
commit
093244d740

+ 3 - 0
app/Http/Controllers/Client/UserController.php

@@ -185,6 +185,7 @@ class UserController extends Controller
      *
      * @authenticated
      *
+     * @bodyParam age integer required 年龄(18-60岁) Example: 25
      * @bodyParam mobile string required 联系电话 Example: 13800138000
      * @bodyParam gender integer required 性别(1:男/2:女) Example: 1
      * @bodyParam work_years integer required 工作年限(0-50年) Example: 5
@@ -198,6 +199,7 @@ class UserController extends Controller
      *   "data": {
      *     "id": 1,
      *     "coach_id": 100,
+     *     "age": 25,
      *     "mobile": "13800138000",
      *     "gender": 1,
      *     "work_years": 5,
@@ -242,6 +244,7 @@ class UserController extends Controller
         $validated = $request->validated();
 
         $result = $this->service->applyCoach(
+            $validated['age'],
             $validated['mobile'],
             $validated['gender'],
             $validated['work_years'],

+ 55 - 10
app/Http/Requests/Client/User/ApplyCoachRequest.php

@@ -14,31 +14,76 @@ class ApplyCoachRequest extends FormRequest
     public function rules(): array
     {
         return [
-            'mobile' => 'required|string|size:11|regex:/^1[3-9]\d{9}$/',
-            'gender' => 'required|integer|in:1,2',
-            'work_years' => 'required|integer|min:0|max:50',
-            'intention_city' => 'required|string|max:50',
-            'portrait_images' => 'required|array',
-            'portrait_images.*' => 'required|string|url|max:255',
-            'description' => 'nullable|string|max:1000',
+            'age' => [
+                'required',
+                'integer',
+                'min:18',
+                'max:60',
+            ],
+            'mobile' => [
+                'required',
+                'string',
+                'regex:/^1[3-9]\d{9}$/',
+            ],
+            'gender' => [
+                'required',
+                'integer',
+                'in:1,2',
+            ],
+            'work_years' => [
+                'required',
+                'integer',
+                'min:0',
+                'max:50',
+            ],
+            'intention_city' => [
+                'required',
+                'string',
+                'max:50',
+            ],
+            'portrait_images' => [
+                'required',
+                'array',
+                'min:1',
+                'max:6',
+            ],
+            'portrait_images.*' => [
+                'required',
+                'string',
+                'url',
+            ],
+            'description' => [
+                'nullable',
+                'string',
+                'max:1000',
+            ],
         ];
     }
 
     public function messages(): array
     {
         return [
+            'age.required' => '年龄不能为空',
+            'age.integer' => '年龄必须是整数',
+            'age.min' => '年龄不能小于18岁',
+            'age.max' => '年龄不能大于60岁',
             'mobile.required' => '手机号不能为空',
             'mobile.regex' => '手机号格式不正确',
             'gender.required' => '性别不能为空',
-            'gender.integer' => '性别必须是整数',
             'gender.in' => '性别只能是1(男)或2(女)',
             'work_years.required' => '工作年限不能为空',
             'work_years.integer' => '工作年限必须是整数',
             'work_years.min' => '工作年限不能小于0年',
             'work_years.max' => '工作年限不能超过50年',
             'intention_city.required' => '意向城市不能为空',
-            'portrait_images.required' => '形象图片不能为空',
-            'portrait_images.*.url' => '图片必须是有效的URL地址',
+            'intention_city.max' => '意向城市不能超过50个字符',
+            'portrait_images.required' => '形象照片不能为空',
+            'portrait_images.array' => '形象照片必须是数组',
+            'portrait_images.min' => '至少上传1张形象照片',
+            'portrait_images.max' => '最多上传6张形象照片',
+            'portrait_images.*.required' => '形象照片不能为空',
+            'portrait_images.*.url' => '形象照片必须是有效的URL地址',
+            'description.max' => '个人介绍不能超过1000个字符',
         ];
     }
 }

+ 8 - 9
app/Services/Client/UserService.php

@@ -217,16 +217,10 @@ class UserService
      *
      * 业务逻辑:
      * 1. 检查用户申请资格
-     *    - 验证用户是否已有技师身份
-     *    - 检查是否存在未完成的申请
      * 2. 创建或更新技师基础信息
-     *    - 首次申请:创建技师记录
-     *    - 重新申请:更新技师信息
      * 3. 创建申请记录
-     *    - 记录申请信息
-     *    - 保存形象照片
-     *    - 设置申请状态
      *
+     * @param  int  $age  年龄
      * @param  string  $mobile  联系电话
      * @param  int  $gender  性别(1:男/2:女)
      * @param  string  $work_years  工作年限
@@ -238,6 +232,7 @@ class UserService
      * @throws \Exception 申请失败时抛出异常
      */
     public function applyCoach(
+        int $age,
         string $mobile,
         int $gender,
         string $work_years,
@@ -257,6 +252,7 @@ class UserService
             // 3. 创建申请记录
             $application = $this->createCoachApplication(
                 $coach,
+                $age,
                 $mobile,
                 $gender,
                 $work_years,
@@ -377,6 +373,7 @@ class UserService
      * 3. 创建申请记录
      *
      * @param  \App\Models\Coach  $coach  技师模型
+     * @param  int  $age  年龄
      * @param  string  $mobile  联系电话
      * @param  int  $gender  性别(1:男/2:女)
      * @param  string  $work_years  工作年限
@@ -387,6 +384,7 @@ class UserService
      */
     private function createCoachApplication(
         $coach,
+        int $age,
         string $mobile,
         int $gender,
         string $work_years,
@@ -396,6 +394,7 @@ class UserService
     ): CoachInfoRecord {
         return CoachInfoRecord::create([
             'coach_id' => $coach->id,
+            'age' => $age,
             'mobile' => $mobile,
             'gender' => $gender,
             'work_years' => $work_years,
@@ -520,7 +519,7 @@ class UserService
      *
      * 业务逻辑:
      * 1. 根据类型判断邀请人身份
-     * 2. 用户类型:直接返回用信息
+     * 2. 用户类型:直接返回用���信息
      * 3. 技师类型:
      *    - 验证技师状态
      *    - 返回技师信息
@@ -604,6 +603,6 @@ class UserService
             ->encoding('UTF-8')
             ->generate($content);
 
-        return 'data:image/svg+xml;base64,' . base64_encode($qrImage);
+        return 'data:image/svg+xml;base64,'.base64_encode($qrImage);
     }
 }