Update: 2026-06-21 18:58:05

This commit is contained in:
Hamza-Ayed
2026-06-21 18:58:13 +03:00
parent b492b5076b
commit e73be65a72
8755 changed files with 92977 additions and 99 deletions

View File

@@ -17,7 +17,12 @@ try {
// =========================================================
// 1. Security & Configuration
$SECRET_KEY = getenv('BOT_SECRET_KEY') ?: 'SIRO_BOT_SUPER_SECRET_123';
$SECRET_KEY = getenv('BOT_SECRET_KEY');
if (!$SECRET_KEY) {
http_response_code(500);
echo json_encode(['status' => 'failure', 'message' => 'Server configuration error: BOT_SECRET_KEY not set in environment']);
exit;
}
$ALLOWED_DEVICES = ['SHAM_CASH_BOT_01', 'PRICE_SCRAPER_BOT_01'];
$method = $_SERVER['REQUEST_METHOD'];
@@ -123,23 +128,25 @@ if ($method === 'GET') {
$end_lat = (float)($result_data['end_lat'] ?? 0);
$end_lng = (float)($result_data['end_lng'] ?? 0);
$pricePerKm = $distance_km > 0 ? ($price / $distance_km) : 0.0;
$country_code = $result_data['country_code'] ?? 'SY';
// 1. Save to MySQL
$stmt = $con->prepare("
INSERT INTO competitor_prices
(app_name, start_lat, start_lng, end_lat, end_lng, distance_km, price)
VALUES (?, ?, ?, ?, ?, ?, ?)
(competitor_name, from_latitude, from_longitude, to_latitude, to_longitude, distance_km, total_price, price_per_km, country_code)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)
");
$stmt->execute([$app_name, $start_lat, $start_lng, $end_lat, $end_lng, $distance_km, $price]);
$stmt->execute([$app_name, (string)$start_lat, (string)$start_lng, (string)$end_lat, (string)$end_lng, $distance_km, $price, $pricePerKm, $country_code]);
// 2. Save to Redis (Calculate Price Per KM)
if ($distance_km > 0 && $price > 0) {
$pricePerKm = $price / $distance_km;
// Store in Redis (Main) to be used by Pricing Engine
// Store recent 50 prices for the app
$redis->lpush("competitor:price_history:$app_name", $pricePerKm);
$redis->ltrim("competitor:price_history:$app_name", 0, 49);
error_log("[Bot Worker] Price Check $app_name: Dist $distance_km, Price $price");
error_log("[Bot Worker] Price Check $app_name: Dist $distance_km, Price $price, Country $country_code");
}
} else {
// It's a payment task