Update: 2026-06-30 21:12:26

This commit is contained in:
Hamza-Ayed
2026-06-30 21:12:26 +03:00
parent c2eab19045
commit 1ae8acad7a
14 changed files with 90 additions and 55 deletions

View File

@@ -35,7 +35,7 @@ if (empty($data) || !is_array($data)) {
}
$insertedCount = 0;
$stmt = $con->prepare("INSERT INTO scraped_competitor_prices (task_id, app_name, start_location, end_location, price_amount, currency) VALUES (?, ?, ?, ?, ?, ?)");
$stmt = $con->prepare("INSERT INTO scraped_competitor_prices (task_id, app_name, competitor_name, start_location, end_location, start_lat, start_lng, end_lat, end_lng, price_amount, price_per_km, currency, country_code) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)");
foreach ($data as $row) {
if (isset($row['status']) && $row['status'] !== 'success') {
@@ -83,7 +83,21 @@ foreach ($data as $row) {
continue;
}
if ($stmt->execute([$taskId, $appName, $startLoc, $endLoc, $amount, $currency])) {
$distanceKm = (float)($resultData['distance_km'] ?? 1);
if ($distanceKm <= 0) $distanceKm = 1;
$pricePerKm = $amount / $distanceKm;
$startLat = $resultData['start_lat'] ?? null;
$startLng = $resultData['start_lng'] ?? null;
$endLat = $resultData['end_lat'] ?? null;
$endLng = $resultData['end_lng'] ?? null;
$countryCode = 'JO'; // Default for now, as scraping is in Jordan
if ($stmt->execute([
$taskId, $appName, $appName, $startLoc, $endLoc,
$startLat, $startLng, $endLat, $endLng,
$amount, $pricePerKm, $currency, $countryCode
])) {
$insertedCount++;
} else {
echo "Failed to insert task_id: $taskId. Error: " . implode(" ", $stmt->errorInfo()) . "\n";