getModel()::findOrFail($id); // 检查状态 if ((int)$record->state != TechnicianAuthStatus::AUDITING->value) { throw new \Exception('该认证已审核'); } // 更新认证记录 $record->update([ 'state' => $state, 'audit_remark' => $remark, 'auditor' => $adminId, 'audit_time' => now(), ]); // 如果审核通过,更新技师状态 if ($state == TechnicianAuthStatus::PASSED->value) { CoachUser::where('id', $record->coach_id)->update([ 'real_auth_record_id' => $record->id ]); } DB::commit(); return true; } catch (\Exception $e) { DB::rollBack(); throw $e; } } /** * 更新技师实名认证信息 * * @param int $id 认证记录ID * @param array $data 更新的数据 * @return bool * @throws \Exception */ public function updateInfo(int $id, array $data): bool { DB::beginTransaction(); try { // 获取认证记录 $record = $this->getModel()::findOrFail($id); // 准备更新数据,确保不为 null $updateData = []; if (isset($data['id_card_front_photo'])) { // 确保存储的值是有效的 JSON 格式 $updateData['id_card_front_photo'] = json_encode($data['id_card_front_photo']); } if (isset($data['id_card_back_photo'])) { // 确保存储的值是有效的 JSON 格式 $updateData['id_card_back_photo'] = json_encode($data['id_card_back_photo']); } if (isset($data['id_card_hand_photo'])) { // 确保存储的值是有效的 JSON 格式 $updateData['id_card_hand_photo'] = json_encode($data['id_card_hand_photo']); } // 确保更新数据不为空 if (empty($updateData)) { throw new \Exception('没有提供有效的更新数据'); } // 更新认证记录 $record->update($updateData); DB::commit(); return true; } catch (\Exception $e) { DB::rollBack(); throw $e; } } }