add ai_data + user_input to driver table, status=pending_review, save raw Gemini response
This commit is contained in:
@@ -156,8 +156,15 @@ try {
|
||||
$docUrls[$k] = $u;
|
||||
}
|
||||
|
||||
/* ================== حفظ المدخلات الخام قبل AI ================== */
|
||||
$userInputJson = json_encode([
|
||||
'driver' => $data,
|
||||
'car' => $car,
|
||||
]);
|
||||
|
||||
/* ================== AI PROCESSING START ================== */
|
||||
$apiKey = getenv("GEMINI_API_KEY");
|
||||
$aiRawText = null;
|
||||
if ($apiKey) {
|
||||
$promptBase = '
|
||||
You are a highly secure AI Assistant specialized in analyzing identification and driver documents.
|
||||
@@ -269,6 +276,7 @@ Therefore, do NOT assume a specific field is on the front or the back of a card.
|
||||
$aiData = json_decode($response, true);
|
||||
$textRaw = $aiData['candidates'][0]['content']['parts'][0]['text'] ?? '';
|
||||
$textRaw = trim(preg_replace('/```json|```/', '', $textRaw));
|
||||
$aiRawText = $textRaw; // حفظ الـ JSON الخام من Gemini
|
||||
$json = json_decode($textRaw, true);
|
||||
|
||||
if ($json && isset($json['status']) && strtolower($json['status']) === 'failure') {
|
||||
@@ -398,15 +406,15 @@ $pwdHashed = password_hash($rawSecret, PASSWORD_DEFAULT);
|
||||
name_arabic, issue_date, expiry_date, license_categories,
|
||||
address, licenseIssueDate, status, birthdate, site,
|
||||
first_name, last_name, accountBank, bankCode,
|
||||
employmentType, maritalStatus, fullNameMaritial, expirationDate,
|
||||
created_at, updated_at
|
||||
employmentType, ai_data, user_input, maritalStatus,
|
||||
fullNameMaritial, expirationDate, created_at, updated_at
|
||||
) VALUES (
|
||||
:id, :phone, :email, :pwd, :gender, :license_type, :national_number,
|
||||
:name_arabic, :issue_date, :expiry_date, :license_categories,
|
||||
:address, :licenseIssueDate, :status, :birthdate, :site,
|
||||
:first_name, :last_name, :accountBank, :bankCode,
|
||||
:employmentType, :maritalStatus, :fullNameMaritial, :expirationDate,
|
||||
NOW(), NOW()
|
||||
:employmentType, :ai_data, :user_input, :maritalStatus,
|
||||
:fullNameMaritial, :expirationDate, NOW(), NOW()
|
||||
)
|
||||
";
|
||||
$insD = $con->prepare($sqlDriver);
|
||||
@@ -424,7 +432,7 @@ $pwdHashed = password_hash($rawSecret, PASSWORD_DEFAULT);
|
||||
':license_categories' => !empty($data['license_categories']) ? $data['license_categories'] : 'B',
|
||||
':address' => $data['address'],
|
||||
':licenseIssueDate' => !empty($data['licenseIssueDate']) ? $data['licenseIssueDate'] : '2020-01-01',
|
||||
':status' => !empty($data['status']) ? $data['status'] : 'yet',
|
||||
':status' => 'pending_review',
|
||||
':birthdate' => $data['birthdate'],
|
||||
':site' => !empty($data['site']) ? $data['site'] : 'demascus',
|
||||
':first_name' => $data['first_name'],
|
||||
@@ -432,6 +440,8 @@ $pwdHashed = password_hash($rawSecret, PASSWORD_DEFAULT);
|
||||
':accountBank' => 'yet',
|
||||
':bankCode' => 'yet',
|
||||
':employmentType' => !empty($data['employmentType']) ? $data['employmentType'] : 'yet',
|
||||
':ai_data' => $aiRawText ?: null,
|
||||
':user_input' => $userInputJson ?: null,
|
||||
':maritalStatus' => !empty($data['maritalStatus']) ? $data['maritalStatus'] : 'yet',
|
||||
':fullNameMaritial' => !empty($data['fullNameMaritial']) ? $data['fullNameMaritial'] : 'yet',
|
||||
':expirationDate' => !empty($data['expirationDate']) ? $data['expirationDate'] : 'yet',
|
||||
|
||||
@@ -404,6 +404,8 @@ CREATE TABLE `driver` (
|
||||
`accountBank` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'yet',
|
||||
`bankCode` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci NOT NULL DEFAULT 'CIB',
|
||||
`employmentType` varchar(255) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
|
||||
`ai_data` json DEFAULT NULL COMMENT 'بيانات Gemini المستخرجة من الصور',
|
||||
`user_input` json DEFAULT NULL COMMENT 'البيانات الخام التي أدخلها السائق في الفورم',
|
||||
`maritalStatus` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
|
||||
`fullNameMaritial` varchar(255) DEFAULT NULL,
|
||||
`expirationDate` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
|
||||
|
||||
Reference in New Issue
Block a user