Jelajahi Sumber

fixed:技师端-优化实名认证

刘学玺 4 bulan lalu
induk
melakukan
b34e8c46ab

+ 7 - 7
app/Http/Controllers/Coach/AccountController.php

@@ -86,10 +86,10 @@ class AccountController extends Controller
      * @authenticated
      *
      * @bodyParam real_name string required 姓名(2-20个字符) Example: 张三
-     * @bodyParam id_card string required 身份证号(18位) Example: 370602199001011234
-     * @bodyParam id_card_front_photo string required 身份证正面照片 Example: http://example.com/front.jpg
-     * @bodyParam id_card_back_photo string required 身份证反面照片 Example: http://example.com/back.jpg
-     * @bodyParam id_card_hand_photo string required 手持身份证照片 Example: http://example.com/hold.jpg
+     * @bodyParam id_card string nullable 身份证号(18位) Example: 370602199001011234
+     * @bodyParam id_card_front_photo string required 身份证正面照片 Example: base64或其他格式的图片数据
+     * @bodyParam id_card_back_photo string required 身份证反面照片 Example: base64或其他格式的图片数据
+     * @bodyParam id_card_hand_photo string required 手持身份证照片 Example: base64或其他格式的图片数据
      *
      * @response {
      *  "message": "实名认证信息提交成功"
@@ -105,7 +105,7 @@ class AccountController extends Controller
     /**
      * [账户]获取技师信息
      *
-     * @description ��取技师的基本信息、资质信息和实名信息
+     * @description 取技师的基本信息、资质信息和实名信息
      *
      * @authenticated
      *
@@ -185,7 +185,7 @@ class AccountController extends Controller
     /**
      * [账户]获取技师位置信息
      *
-     * @description ��取技师的当前位置和常用位置信息
+     * @description 取技师的当前位置和常用位置信息
      *
      * @authenticated
      *
@@ -268,7 +268,7 @@ class AccountController extends Controller
             'time_ranges.min' => '至少设置一个时间段',
             'time_ranges.*.start_time.required' => '开始时间不能为空',
             'time_ranges.*.start_time.regex' => '开始时间格式错误,应为HH:mm格式',
-            'time_ranges.*.end_time.required' => '结���时间不能为空',
+            'time_ranges.*.end_time.required' => '结时间不能为空',
             'time_ranges.*.end_time.regex' => '结束时间格式错误,应为HH:mm格式',
         ]);
 

+ 8 - 14
app/Http/Requests/Coach/SubmitRealNameRequest.php

@@ -15,15 +15,10 @@ class SubmitRealNameRequest extends FormRequest
     {
         return [
             'real_name' => 'required|string|min:2|max:20',
-            'id_card' => [
-                'required',
-                'string',
-                'size:18',
-                'regex:/^[1-9]\d{5}(19|20)\d{2}(0[1-9]|1[0-2])(0[1-9]|[12]\d|3[01])\d{3}[\dX]$/',
-            ],
-            'id_card_front_photo' => 'required|url|max:255',
-            'id_card_back_photo' => 'required|url|max:255',
-            'id_card_hand_photo' => 'required|url|max:255',
+            'id_card' => 'nullable|string|size:18',
+            'id_card_front_photo' => 'required|string|max:2048',
+            'id_card_back_photo' => 'required|string|max:2048',
+            'id_card_hand_photo' => 'required|string|max:2048',
         ];
     }
 
@@ -31,17 +26,16 @@ class SubmitRealNameRequest extends FormRequest
     {
         return [
             'real_name.required' => '姓名不能为空',
+            'real_name.string' => '姓名必须是字符串',
             'real_name.min' => '姓名不能少于2个字符',
             'real_name.max' => '姓名不能超过20个字符',
-            'id_card.required' => '身份证号不能为空',
             'id_card.size' => '身份证号必须是18位',
-            'id_card.regex' => '身份证号格式不正确',
             'id_card_front_photo.required' => '身份证正面照片不能为空',
-            'id_card_front_photo.url' => '身份证正面照片必须是有效的URL地址',
+            'id_card_front_photo.max' => '身份证正面照片数据过大',
             'id_card_back_photo.required' => '身份证反面照片不能为空',
-            'id_card_back_photo.url' => '身份证反面照片必须是有效的URL地址',
+            'id_card_back_photo.max' => '身份证反面照片数据过大',
             'id_card_hand_photo.required' => '手持身份证照片不能为空',
-            'id_card_hand_photo.url' => '手持身份证照片必须是有效的URL地址',
+            'id_card_hand_photo.max' => '手持身份证照片数据过大',
         ];
     }
 }

+ 42 - 11
app/Services/Coach/AccountService.php

@@ -93,7 +93,7 @@ class AccountService
 
             // 检查是否有待审核的记录,避免重复提交
             $pendingRecord = $this->hasPendingRecord($user->coach, 'qual');
-            // abort_if($pendingRecord, 422, '已有待审核的资质信息记录');
+            abort_if($pendingRecord, 422, '已有待审核的资质信息记录');
 
             // 创建新的资质审核记录,设置为待审核状态
             $record = $user->coach->qualRecords()->create([
@@ -128,33 +128,64 @@ class AccountService
 
     /**
      * 提交实名认证信息
+     * 包括姓名、身份证号(可选)和三张身份证照片的提交和审核
+     *
+     * 业务流程:
+     * 1. 验证技师信息存在性
+     * 2. 检查是否有待审核的记录
+     * 3. 创建新的实名认证记录
+     * 4. 清除相关缓存
+     *
+     * 注意事项:
+     * - 同一时间只能有一条待审核记录
+     * - 审核不通过可以重新提交
+     * - 所有图片数据不限制格式
+     * - 身份证号为可选字段
+     * - 敏感信息会进行脱敏处理
+     *
+     * @param User $user 当前认证用户
+     * @param array $data 实名认证数据,包含:
+     *        - real_name: string 真实姓名
+     *        - id_card: string|null 身份证号(可选)
+     *        - id_card_front_photo: string 身份证正面照片
+     *        - id_card_back_photo: string 身份证反面照片
+     *        - id_card_hand_photo: string 手持身份证照片
+     * @return array 返回结果
+     * @throws \Exception 当验证失败或保存失败时抛出异常
      */
     public function submitRealName($user, array $data)
     {
+        // 开启数据库事务
         DB::beginTransaction();
         try {
+            // 验证技师信息是否存在
+            abort_if(!$user->coach, 404, '技师信息不存在');
 
-            abort_if(! $user->coach, 404, '技师信息不存在');
-
-            // 检查是否有待审核的记录
+            // 检查是否有待审核的记录,避免重复提交
             $pendingRecord = $this->hasPendingRecord($user->coach, 'real');
             abort_if($pendingRecord, 422, '已有待审核的实名认证信息');
 
-            // 创建实名认证信息
+            // 创建新的实名认证记录,设置为待审核状态
             $record = $user->coach->realRecords()->create(array_merge($data, [
                 'state' => TechnicianAuthStatus::AUDITING->value,
             ]));
 
-            // 清除技师信息缓存
+            // 清除技师信息缓存,确保数据一致性
             $this->clearCoachCache($user->coach->id);
 
+            // 提交事务
             DB::commit();
 
+            // 记录成功日志(注意:敏感信息需要脱敏)
             $this->logInfo('技师提交实名认证信息成功', $user, $this->maskSensitiveData($data));
 
+            // 返回成功结果
             return ['message' => '实名认证信息提交成功'];
         } catch (\Exception $e) {
+            // 发生异常时回滚事务
             DB::rollBack();
+
+            // 记录错误日志(注意:敏感信息需要脱敏)
             $this->logError('提交实名认证信息失败', $user, $this->maskSensitiveData($data), $e);
             throw $e;
         }
@@ -341,7 +372,7 @@ class AccountService
         try {
             // 验证经纬度参数
             if (! is_numeric($latitude) || ! is_numeric($longitude)) {
-                throw new \Exception('无���的经纬度坐标');
+                throw new \Exception('无的经纬度坐标');
             }
 
             // 验证位置类型
@@ -500,7 +531,7 @@ class AccountService
      */
     private function validateAndSortTimeRanges(array $timeRanges): array
     {
-        // 验证时���段数组
+        // 验证时段数组
         abort_if(empty($timeRanges), 400, '必须至少设置一个时间段');
 
         // 验证每个时间段格式并转换为分钟数进行比较
@@ -797,7 +828,7 @@ class AccountService
 
             return false;
         } catch (\Exception $e) {
-            Log::error('检查排班时间异���', [
+            Log::error('检查排班时间异', [
                 'coach_id' => $coachId,
                 'error' => $e->getMessage(),
             ]);
@@ -929,9 +960,9 @@ class AccountService
     }
 
     /**
-     * 检查是否存在审核记录
+     * 检查是否存在��审核记录
      *
-     * @param CoachUser $coach 技师���
+     * @param CoachUser $coach 技师象
      * @param string $type 记录类型(info|qual|real)
      * @return bool
      */