Files

186 lines
6.0 KiB
PHP

<?php
// backend/bot/seed_kazan.php
// Populates the `kazan` table with default pricing for Jordan, Syria, and Egypt if missing
require_once __DIR__ . '/../core/bootstrap.php';
require_once __DIR__ . '/../functions.php';
try {
$con = Database::get('main');
echo "Connected to database.\n";
} catch (Exception $e) {
die("Database connection failed: " . $e->getMessage() . "\n");
}
$defaultPricing = [
[
'country' => 'Jordan',
'currency' => 'JOD',
'kazanPercent' => '10',
'fuelPrice' => '1.0',
'startPrice' => '0.35',
'speedPrice' => '0.22',
'comfortPrice' => '0.29',
'ladyPrice' => '0.25',
'electricPrice' => '0.26',
'vanPrice' => '0.33',
'deliveryPrice' => '0.20',
'mishwarVipPrice' => '0.31',
'fixedPrice' => '0.22',
'awfarPrice' => '0.19',
'normalMinPrice' => '0.05',
'peakMinPrice' => '0.06',
'lateMinPrice' => '0.05',
'adminId' => 'system'
],
[
'country' => 'JO',
'currency' => 'JOD',
'kazanPercent' => '10',
'fuelPrice' => '1.0',
'startPrice' => '0.35',
'speedPrice' => '0.22',
'comfortPrice' => '0.29',
'ladyPrice' => '0.25',
'electricPrice' => '0.26',
'vanPrice' => '0.33',
'deliveryPrice' => '0.20',
'mishwarVipPrice' => '0.31',
'fixedPrice' => '0.22',
'awfarPrice' => '0.19',
'normalMinPrice' => '0.05',
'peakMinPrice' => '0.06',
'lateMinPrice' => '0.05',
'adminId' => 'system'
],
[
'country' => 'Syria',
'currency' => 'SYP',
'kazanPercent' => '10',
'fuelPrice' => '12000',
'startPrice' => '1000',
'speedPrice' => '500',
'comfortPrice' => '650',
'ladyPrice' => '550',
'electricPrice' => '600',
'vanPrice' => '750',
'deliveryPrice' => '450',
'mishwarVipPrice' => '700',
'fixedPrice' => '500',
'awfarPrice' => '425',
'normalMinPrice' => '100',
'peakMinPrice' => '115',
'lateMinPrice' => '100',
'adminId' => 'system'
],
[
'country' => 'Egypt',
'currency' => 'EGP',
'kazanPercent' => '10',
'fuelPrice' => '15',
'startPrice' => '10',
'speedPrice' => '3.0',
'comfortPrice' => '4.0',
'ladyPrice' => '3.3',
'electricPrice' => '3.6',
'vanPrice' => '4.5',
'deliveryPrice' => '2.7',
'mishwarVipPrice' => '4.2',
'fixedPrice' => '3.0',
'awfarPrice' => '2.5',
'normalMinPrice' => '0.5',
'peakMinPrice' => '0.6',
'lateMinPrice' => '0.5',
'adminId' => 'system'
],
[
'country' => 'EG',
'currency' => 'EGP',
'kazanPercent' => '10',
'fuelPrice' => '15',
'startPrice' => '10',
'speedPrice' => '3.0',
'comfortPrice' => '4.0',
'ladyPrice' => '3.3',
'electricPrice' => '3.6',
'vanPrice' => '4.5',
'deliveryPrice' => '2.7',
'mishwarVipPrice' => '4.2',
'fixedPrice' => '3.0',
'awfarPrice' => '2.5',
'normalMinPrice' => '0.5',
'peakMinPrice' => '0.6',
'lateMinPrice' => '0.5',
'adminId' => 'system'
]
];
$sqlInsert = "INSERT INTO kazan (
country, currency, kazanPercent, fuelPrice, startPrice,
speedPrice, comfortPrice, ladyPrice, electricPrice, vanPrice,
deliveryPrice, mishwarVipPrice, fixedPrice, awfarPrice,
normalMinPrice, peakMinPrice, lateMinPrice, adminId
) VALUES (
:country, :currency, :kazanPercent, :fuelPrice, :startPrice,
:speedPrice, :comfortPrice, :ladyPrice, :electricPrice, :vanPrice,
:deliveryPrice, :mishwarVipPrice, :fixedPrice, :awfarPrice,
:normalMinPrice, :peakMinPrice, :lateMinPrice, :adminId
) ON DUPLICATE KEY UPDATE
currency = VALUES(currency),
startPrice = VALUES(startPrice),
speedPrice = VALUES(speedPrice),
comfortPrice = VALUES(comfortPrice),
ladyPrice = VALUES(ladyPrice),
electricPrice = VALUES(electricPrice),
vanPrice = VALUES(vanPrice),
deliveryPrice = VALUES(deliveryPrice),
mishwarVipPrice = VALUES(mishwarVipPrice),
fixedPrice = VALUES(fixedPrice),
awfarPrice = VALUES(awfarPrice),
normalMinPrice = VALUES(normalMinPrice),
peakMinPrice = VALUES(peakMinPrice),
lateMinPrice = VALUES(lateMinPrice)";
$stmt = $con->prepare($sqlInsert);
foreach ($defaultPricing as $row) {
try {
$stmt->execute($row);
echo "Successfully seeded/updated kazan pricing for: {$row['country']}\n";
} catch (Exception $e) {
echo "Error seeding kazan for {$row['country']}: " . $e->getMessage() . "\n";
}
}
echo "Kazan seeding completed.\n";
// Also ensure ride_chat_logs table exists in main DB and ride DB
$sqlCreateChat = "CREATE TABLE IF NOT EXISTS `ride_chat_logs` (
`id` bigint UNSIGNED NOT NULL AUTO_INCREMENT,
`ride_id` int NOT NULL,
`sender_id` varchar(111) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`receiver_id` varchar(111) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`sender_type` enum('passenger','driver') CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`message_content` text CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
PRIMARY KEY (`id`),
KEY `idx_ride_id` (`ride_id`),
KEY `idx_created_at` (`created_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;";
try {
$con->exec($sqlCreateChat);
echo "Successfully created/verified `ride_chat_logs` table in main DB.\n";
} catch (Exception $e) {
echo "Error creating `ride_chat_logs` in main DB: " . $e->getMessage() . "\n";
}
try {
$con_ride = Database::get('ride');
$con_ride->exec($sqlCreateChat);
echo "Successfully created/verified `ride_chat_logs` table in ride DB.\n";
} catch (Exception $e) {
echo "Error creating `ride_chat_logs` in ride DB: " . $e->getMessage() . "\n";
}