first commit
This commit is contained in:
149
app/Console/Commands/Data/DashboardCacheService.php
Normal file
149
app/Console/Commands/Data/DashboardCacheService.php
Normal file
@@ -0,0 +1,149 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Data;
|
||||
|
||||
use App\Exceptions\ApiErrorException;
|
||||
use App\Models\PropertyWeb;
|
||||
use App\Models\PropertyWebWeather;
|
||||
use App\Models\vwActiveProperty;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Exception;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\App;
|
||||
use Illuminate\Support\Facades\Cache;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class DashboardCacheService extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'cron:dashboard-cache';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
public function __construct(
|
||||
Client $restClient
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->restClient = $restClient;
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : START');
|
||||
|
||||
$bookingService = App::make("App\Core\Service\BookingService");
|
||||
$propertyWebController = App::make("App\Http\Controllers\V1\PropertyWebController");
|
||||
|
||||
$vwActiveProperty = vwActiveProperty::where('commission', '>', 1)->orderBy('id')->get()->toArray();
|
||||
|
||||
|
||||
//$dashboardCountablePlaceCacheKey
|
||||
$this->info(date('Y-m-d H:i:s') . ' : $dashboardCountablePlaceCacheKey');
|
||||
foreach ($vwActiveProperty as $property) {
|
||||
|
||||
|
||||
//$dashboardCountablePlaceCacheKey
|
||||
$dashboardCountablePlaceCacheKey = md5('dashboardCountablePlace-' . $property['id']);
|
||||
|
||||
try {
|
||||
|
||||
$this->line(date('Y-m-d H:i:s') . ' : ' . $property['id'] . ' - ' . $property['name']);
|
||||
|
||||
$propertyWeb = PropertyWeb::where('property_id', $property['id'])->where('status', 1)->orderByDesc('id')->first();
|
||||
$propertyWeb = $propertyWeb ? $propertyWeb->toArray() : null;
|
||||
if (empty($propertyWeb)) {
|
||||
throw new Exception('Empty Web ID');
|
||||
}
|
||||
|
||||
$dashboardCountablePlaceParam = ['property_id' => $property['id']];
|
||||
$dashboardCountablePlace = $propertyWebController->dashboardCountablePlace($dashboardCountablePlaceParam, $propertyWeb['id']);
|
||||
|
||||
if ($dashboardCountablePlace['status']) {
|
||||
Cache::put($dashboardCountablePlaceCacheKey, $dashboardCountablePlace, 24 * 60 * 60);//1 Day
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->error(date('Y-m-d H:i:s') . ' : ' . $e->getMessage());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//$getBookingDetailedListCacheKey
|
||||
$this->info(date('Y-m-d H:i:s') . ' : GetBookingDetailedListCacheKey');
|
||||
foreach ($vwActiveProperty as $property) {
|
||||
$getBookingDetailedListCacheKey = md5('getBookingDetailedList-' . $property['id']);
|
||||
|
||||
try {
|
||||
|
||||
$this->line(date('Y-m-d H:i:s') . ' : ' . $property['id'] . ' - ' . $property['name']);
|
||||
|
||||
$getBookingDetailedListParam = ['property_id' => $property['id'], 'channel_id' => 1];
|
||||
$getBookingDetailedList = $bookingService->getBookingDetailedList($getBookingDetailedListParam);
|
||||
|
||||
if ($getBookingDetailedList['status'] == 'success') {
|
||||
|
||||
|
||||
$bookings = collect($getBookingDetailedList['data']);
|
||||
$channelBookings = $bookings->where('channel_id', '=', 1);
|
||||
$getBookingEngineBookings = $channelBookings->all();
|
||||
$paxCountArray = $channelBookings->where('status', '=', 1)->map(function ($booking) {
|
||||
$roomPaxCount = collect($booking['booking_room'])->map(function ($room) {
|
||||
return collect($room['room_pax'])->count();
|
||||
})->values()->first();
|
||||
return [
|
||||
'booking_id' => $booking['id'],
|
||||
'room_pax_count' => $roomPaxCount,
|
||||
];
|
||||
|
||||
})->values()->all();
|
||||
|
||||
$totalPaxCount = collect($paxCountArray)->sum('room_pax_count');
|
||||
|
||||
$allBookingCount = $channelBookings->count();
|
||||
$preBookingCount = $channelBookings->where('status', '=', 2)->count();
|
||||
$successBookingCount = $channelBookings->where('status', '=', 1)->count();
|
||||
|
||||
$conversionRate = $allBookingCount > 0 ? ($successBookingCount * 100) / $allBookingCount : 0;
|
||||
|
||||
$responseData['all_booking_count'] = $allBookingCount;
|
||||
$responseData['success_booking_count'] = $successBookingCount;
|
||||
$responseData['pre_booking_count'] = $preBookingCount;
|
||||
$responseData['conversion_rate'] = number_format($conversionRate, 2);
|
||||
$responseData['total_pax_count'] = $totalPaxCount;
|
||||
|
||||
Cache::put($getBookingDetailedListCacheKey, $responseData, 24 * 60 * 60);//1 Day
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
} catch (Exception $e) {
|
||||
$this->error(date('Y-m-d H:i:s') . ' : ' . $e->getMessage());
|
||||
}
|
||||
//$getBookingDetailedListCacheKey
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : FINISHED');
|
||||
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
||||
Log::error($message);
|
||||
$this->error(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' ERROR: ' . $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
128
app/Console/Commands/Data/HotelBedsList.php
Normal file
128
app/Console/Commands/Data/HotelBedsList.php
Normal file
@@ -0,0 +1,128 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Data;
|
||||
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
|
||||
|
||||
class HotelBedsList extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'cron:hotelbeds-list';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
|
||||
$hotelList = [];
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' START');
|
||||
|
||||
$baseUrl = 'https://api.hotelbeds.com';
|
||||
$apiKey = 'ddaa6y6zpf6sy8fne4n2zj7q';
|
||||
$secret = 'wc87VEfTSD';
|
||||
|
||||
$countryCode = 'TR';
|
||||
$language = 'TUR';
|
||||
$destinationCode = 'AYT';
|
||||
|
||||
$fields = ['code', 'name', 'email', 'countryCode', 'destinationCode', 'city','phones'];
|
||||
|
||||
|
||||
$chunk = 500;
|
||||
|
||||
$from = 1;
|
||||
$to = $chunk;
|
||||
|
||||
$isContinue = true;
|
||||
while ($isContinue) {
|
||||
|
||||
$xSignature = hash("sha256", $apiKey . $secret . time());
|
||||
$urlGenerate = $baseUrl . '/hotel-content-api/1.0/hotels?fields=' . implode(',', $fields) . '&countryCode=' . $countryCode . '&language=' . $language . '&from=' . $from . '&to=' . $to.'&destinationCode='.$destinationCode;
|
||||
|
||||
$this->restClient = new Client(['allow_redirects' => false]);
|
||||
|
||||
$request = $this->restClient->GET($urlGenerate, [
|
||||
'headers' => [
|
||||
'content-type' => 'application/json',
|
||||
'Api-key' => $apiKey,
|
||||
'X-Signature' => $xSignature,
|
||||
],
|
||||
'body' => null,
|
||||
]);
|
||||
Log::debug($xSignature);
|
||||
$requestResponse = $request->getBody();
|
||||
$requestResponse = json_decode($requestResponse, 1);
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : ' . $urlGenerate);
|
||||
|
||||
$from += $chunk;
|
||||
$to = $from + $chunk - 1;
|
||||
|
||||
if (empty($requestResponse['hotels'])) {
|
||||
$isContinue = false;
|
||||
}
|
||||
|
||||
foreach ($requestResponse['hotels'] as $hotel) {
|
||||
|
||||
if(!isset($hotel['email'])) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$email = mb_strtolower($hotel['email']);
|
||||
|
||||
$hotelList[$email] = [
|
||||
'code' => $hotel['code'],
|
||||
'content' => (string)uCase($hotel['name']['content']),
|
||||
'countryCode' => $hotel['countryCode'],
|
||||
'email' => $email
|
||||
];
|
||||
|
||||
foreach ($hotel['phones'] as $phone) {
|
||||
if(in_array($phone['phoneType'], ['PHONEHOTEL','PHONEMANAGEMENT'])) {
|
||||
$hotelList[$email]['phone'] = $phone['phoneNumber'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Open a file in write mode ('w')
|
||||
$fileName = $countryCode.(!empty($destinationCode) ? '-'.$destinationCode : '');
|
||||
$fp = fopen(resource_path().'/data/'.$fileName.'.csv', 'w');
|
||||
|
||||
// Loop through file pointer and a line
|
||||
foreach ($hotelList as $hotel) {
|
||||
fputcsv($fp, $hotel);
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : Total: ' . count($hotelList).' / '. $requestResponse['total']);
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' FINISHED');
|
||||
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
||||
Log::error($message);
|
||||
$this->error(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' ERROR: ' . $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
130
app/Console/Commands/Data/WeatherService.php
Normal file
130
app/Console/Commands/Data/WeatherService.php
Normal file
@@ -0,0 +1,130 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands\Data;
|
||||
|
||||
use App\Models\PropertyWeb;
|
||||
use App\Models\PropertyWebWeather;
|
||||
use Carbon\Carbon;
|
||||
use GuzzleHttp\Client;
|
||||
use Illuminate\Console\Command;
|
||||
use Exception;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class WeatherService extends Command
|
||||
{
|
||||
|
||||
protected $signature = 'cron:weather';
|
||||
|
||||
protected $description = '';
|
||||
|
||||
public function __construct(
|
||||
Client $restClient
|
||||
)
|
||||
{
|
||||
parent::__construct();
|
||||
|
||||
$this->restClient = $restClient;
|
||||
}
|
||||
|
||||
|
||||
public function handle()
|
||||
{
|
||||
try {
|
||||
|
||||
|
||||
$date = date('Y-m-d');
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' START');
|
||||
|
||||
$baseUrl = 'https://weather.visualcrossing.com/VisualCrossingWebServices/rest/services/timeline';
|
||||
$apiKey = 'GQG8FVH2C7ZZYZXS6PECE2QFX';
|
||||
|
||||
$this->restClient = new Client(['http_errors' => false]);
|
||||
|
||||
$propertyWeb = PropertyWeb::where('status', 1)
|
||||
->where('weather_active', 1)->with('property.propertyContact')
|
||||
//->where('property_id',1231)//TODO:Del
|
||||
->get()->toArray();
|
||||
|
||||
foreach ($propertyWeb as $property) {
|
||||
|
||||
|
||||
$propertyWebWeatherId = null;
|
||||
$propertyWebWeather = PropertyWebWeather::where('property_id', $property['property']['id'])->first();
|
||||
if ($propertyWebWeather) {
|
||||
$propertyWebWeatherId = $propertyWebWeather['id'];
|
||||
}
|
||||
|
||||
|
||||
$latitude = $property['property']['property_contact']['latitude'];
|
||||
$longitude = $property['property']['property_contact']['longitude'];
|
||||
if (!empty($latitude) && !empty($longitude)) {
|
||||
|
||||
$requestUrl = $baseUrl . '/' . $latitude . ',' . $longitude . '/' . $date . '?key=' . $apiKey . '&include=days&unitGroup=metric&elements=tempmax,tempmin,temp,conditions,icon';
|
||||
|
||||
$requestWeather = $this->restClient->request('GET', $requestUrl);
|
||||
|
||||
$getResponseBody = $requestWeather->getBody();
|
||||
$getResponse = $getResponseBody ? json_decode($getResponseBody, 1) : [];
|
||||
|
||||
$propertyWebWeatherParam = [
|
||||
'property_id' => $property['property']['id'],
|
||||
'date' => $date,
|
||||
'temp' => $getResponse['days'][0]['tempmax'],
|
||||
'conditions' => $getResponse['days'][0]['conditions'],
|
||||
'icon' => $getResponse['days'][0]['icon'],
|
||||
'response' => json_encode($getResponse),
|
||||
'created_by' => 1,
|
||||
'updated_by' => 1,
|
||||
];
|
||||
|
||||
if (empty($propertyWebWeatherId)) {
|
||||
|
||||
$locationUrl = 'https://geocode.maps.co/reverse?lat=' . $latitude . '&lon=' . $longitude . '&api_key=6683d9ee52e5d111344805khdf0451c';
|
||||
$requestLocation = $this->restClient->request('GET', $locationUrl);
|
||||
|
||||
$getResponseBodyLocation = $requestLocation->getBody();
|
||||
$getResponseLocation = $getResponseBodyLocation ? json_decode($getResponseBodyLocation, 1) : [];
|
||||
|
||||
|
||||
if ($getResponseLocation) {
|
||||
|
||||
$location = null;
|
||||
if(isset($getResponseLocation['address']['province'])) {
|
||||
$location = $getResponseLocation['address']['province'];
|
||||
}elseif(isset($getResponseLocation['address']['town'])) {
|
||||
$location = $getResponseLocation['address']['town'];
|
||||
}elseif(isset($getResponseLocation['address']['city'])) {
|
||||
$location = $getResponseLocation['address']['city'];
|
||||
}
|
||||
|
||||
$propertyWebWeatherParam['location'] = $location;
|
||||
$propertyWebWeatherParam['address'] = json_encode($getResponseLocation);
|
||||
}
|
||||
|
||||
PropertyWebWeather::create($propertyWebWeatherParam);
|
||||
$this->info(date('Y-m-d H:i:s') . ' : ' . $propertyWebWeatherParam['property_id'] . ' - ' . $propertyWebWeatherParam['date'] . ' : ' . $propertyWebWeatherParam['conditions']. ' : ' . $propertyWebWeatherParam['temp']);
|
||||
|
||||
} else {
|
||||
|
||||
PropertyWebWeather::where('id', $propertyWebWeatherId)->update($propertyWebWeatherParam);
|
||||
$this->line(date('Y-m-d H:i:s') . ' : ' . $propertyWebWeatherParam['property_id'] . ' - ' . $propertyWebWeatherParam['date'] . ' : ' . $propertyWebWeatherParam['conditions']. ' : ' . $propertyWebWeatherParam['temp']);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
$this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' FINISHED');
|
||||
|
||||
} catch (Exception $e) {
|
||||
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
|
||||
Log::error($message);
|
||||
$this->error(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' ERROR: ' . $message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user