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;
|
$docUrls[$k] = $u;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* ================== حفظ المدخلات الخام قبل AI ================== */
|
||||||
|
$userInputJson = json_encode([
|
||||||
|
'driver' => $data,
|
||||||
|
'car' => $car,
|
||||||
|
]);
|
||||||
|
|
||||||
/* ================== AI PROCESSING START ================== */
|
/* ================== AI PROCESSING START ================== */
|
||||||
$apiKey = getenv("GEMINI_API_KEY");
|
$apiKey = getenv("GEMINI_API_KEY");
|
||||||
|
$aiRawText = null;
|
||||||
if ($apiKey) {
|
if ($apiKey) {
|
||||||
$promptBase = '
|
$promptBase = '
|
||||||
You are a highly secure AI Assistant specialized in analyzing identification and driver documents.
|
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);
|
$aiData = json_decode($response, true);
|
||||||
$textRaw = $aiData['candidates'][0]['content']['parts'][0]['text'] ?? '';
|
$textRaw = $aiData['candidates'][0]['content']['parts'][0]['text'] ?? '';
|
||||||
$textRaw = trim(preg_replace('/```json|```/', '', $textRaw));
|
$textRaw = trim(preg_replace('/```json|```/', '', $textRaw));
|
||||||
|
$aiRawText = $textRaw; // حفظ الـ JSON الخام من Gemini
|
||||||
$json = json_decode($textRaw, true);
|
$json = json_decode($textRaw, true);
|
||||||
|
|
||||||
if ($json && isset($json['status']) && strtolower($json['status']) === 'failure') {
|
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,
|
name_arabic, issue_date, expiry_date, license_categories,
|
||||||
address, licenseIssueDate, status, birthdate, site,
|
address, licenseIssueDate, status, birthdate, site,
|
||||||
first_name, last_name, accountBank, bankCode,
|
first_name, last_name, accountBank, bankCode,
|
||||||
employmentType, maritalStatus, fullNameMaritial, expirationDate,
|
employmentType, ai_data, user_input, maritalStatus,
|
||||||
created_at, updated_at
|
fullNameMaritial, expirationDate, created_at, updated_at
|
||||||
) VALUES (
|
) VALUES (
|
||||||
:id, :phone, :email, :pwd, :gender, :license_type, :national_number,
|
:id, :phone, :email, :pwd, :gender, :license_type, :national_number,
|
||||||
:name_arabic, :issue_date, :expiry_date, :license_categories,
|
:name_arabic, :issue_date, :expiry_date, :license_categories,
|
||||||
:address, :licenseIssueDate, :status, :birthdate, :site,
|
:address, :licenseIssueDate, :status, :birthdate, :site,
|
||||||
:first_name, :last_name, :accountBank, :bankCode,
|
:first_name, :last_name, :accountBank, :bankCode,
|
||||||
:employmentType, :maritalStatus, :fullNameMaritial, :expirationDate,
|
:employmentType, :ai_data, :user_input, :maritalStatus,
|
||||||
NOW(), NOW()
|
:fullNameMaritial, :expirationDate, NOW(), NOW()
|
||||||
)
|
)
|
||||||
";
|
";
|
||||||
$insD = $con->prepare($sqlDriver);
|
$insD = $con->prepare($sqlDriver);
|
||||||
@@ -424,7 +432,7 @@ $pwdHashed = password_hash($rawSecret, PASSWORD_DEFAULT);
|
|||||||
':license_categories' => !empty($data['license_categories']) ? $data['license_categories'] : 'B',
|
':license_categories' => !empty($data['license_categories']) ? $data['license_categories'] : 'B',
|
||||||
':address' => $data['address'],
|
':address' => $data['address'],
|
||||||
':licenseIssueDate' => !empty($data['licenseIssueDate']) ? $data['licenseIssueDate'] : '2020-01-01',
|
':licenseIssueDate' => !empty($data['licenseIssueDate']) ? $data['licenseIssueDate'] : '2020-01-01',
|
||||||
':status' => !empty($data['status']) ? $data['status'] : 'yet',
|
':status' => 'pending_review',
|
||||||
':birthdate' => $data['birthdate'],
|
':birthdate' => $data['birthdate'],
|
||||||
':site' => !empty($data['site']) ? $data['site'] : 'demascus',
|
':site' => !empty($data['site']) ? $data['site'] : 'demascus',
|
||||||
':first_name' => $data['first_name'],
|
':first_name' => $data['first_name'],
|
||||||
@@ -432,6 +440,8 @@ $pwdHashed = password_hash($rawSecret, PASSWORD_DEFAULT);
|
|||||||
':accountBank' => 'yet',
|
':accountBank' => 'yet',
|
||||||
':bankCode' => 'yet',
|
':bankCode' => 'yet',
|
||||||
':employmentType' => !empty($data['employmentType']) ? $data['employmentType'] : 'yet',
|
':employmentType' => !empty($data['employmentType']) ? $data['employmentType'] : 'yet',
|
||||||
|
':ai_data' => $aiRawText ?: null,
|
||||||
|
':user_input' => $userInputJson ?: null,
|
||||||
':maritalStatus' => !empty($data['maritalStatus']) ? $data['maritalStatus'] : 'yet',
|
':maritalStatus' => !empty($data['maritalStatus']) ? $data['maritalStatus'] : 'yet',
|
||||||
':fullNameMaritial' => !empty($data['fullNameMaritial']) ? $data['fullNameMaritial'] : 'yet',
|
':fullNameMaritial' => !empty($data['fullNameMaritial']) ? $data['fullNameMaritial'] : 'yet',
|
||||||
':expirationDate' => !empty($data['expirationDate']) ? $data['expirationDate'] : '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',
|
`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',
|
`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,
|
`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,
|
`maritalStatus` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
|
||||||
`fullNameMaritial` varchar(255) DEFAULT NULL,
|
`fullNameMaritial` varchar(255) DEFAULT NULL,
|
||||||
`expirationDate` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
|
`expirationDate` varchar(50) CHARACTER SET utf8mb3 COLLATE utf8mb3_general_ci DEFAULT NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user