first commit

This commit is contained in:
ExtraNetwork
2026-05-12 17:04:54 +03:00
commit e5c4b6aa13
1425 changed files with 284735 additions and 0 deletions

View File

@@ -0,0 +1,140 @@
<?php
namespace App\Console\Commands\Google;
use App\Models\PropertyWeb;
use App\Models\PropertyWebComponentMapping;
use App\Models\PropertyWebReview;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\Log;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
class GoogleReview extends Command
{
protected $signature = 'cron:google-review {--property_id=}';
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') . ' : ' . date('Y-m-d') . ' START');
$baseUrl = 'https://maps.googleapis.com/maps/api/place/details/json';
$apiKey = 'AIzaSyAPsKZ_XasAieKEhbmpOLUpArY2u2UcXuk';
$availableRating = [4,5];
$this->restClient = new Client(['http_errors' => false]);
if (!is_null($this->option('property_id'))) {
$propertyWebComponentMapping = PropertyWebComponentMapping::where('status', 1)->where('component_id', 3)->where('property_id', $this->option('property_id'))->get()->toArray();
} else {
$propertyWebComponentMapping = PropertyWebComponentMapping::where('status', 1)->where('component_id', 3)->get()->toArray();
}
foreach ($propertyWebComponentMapping as $propertyWebComponent) {
if (!isset($propertyWebComponent['parameterArray']['placeId'])) {
continue;
}
$googlePlaceId = trim($propertyWebComponent['parameterArray']['placeId']);
Log::debug('google-review: '.$googlePlaceId);
$params = [
'query' => [
'place_id' => $googlePlaceId,
'key' => $apiKey,
'fields' => 'name,rating,reviews',
'reviews_sort' => 'newest',
'reviews_no_translations' => true,
//'language' => 'tr'
]
];
$requestReview = $this->restClient->request('GET', $baseUrl, $params);
$getResponseBody = $requestReview->getBody();
$getResponse = $getResponseBody ? json_decode($getResponseBody, 1) : [];
$reviews = [];
if(isset($getResponse['result']['reviews'])) {
$reviews = collect($getResponse['result']['reviews'])->sortBy('time')->toArray();
}
foreach ($reviews as $review) {
if(!in_array(fillOnUndefined($review, 'rating'),$availableRating)) {
continue;
}
try {
$code = md5($propertyWebComponent['property_id'].'-'.$review['author_name'] . '-' . $review['time']);
$propertyWebReviewCheck = PropertyWebReview::where('code', $code)->first();
if ($propertyWebReviewCheck) {
$this->error(date('Y-m-d H:i:s') . ' : ' . $propertyWebComponent['property_id'] . ' - ' . $review['author_name'] . ' : ' . $review['rating']);
continue;
}
$propertyWebWeatherParam = [
'property_id' => $propertyWebComponent['property_id'],
'channel' => 'google',
'code' => $code,
'language_code' => fillOnUndefined($review, 'language') ? substr($review['language'],0,2) : null,
'author' => $review['author_name'],
'profile_photo' => fillOnUndefined($review, 'profile_photo_url'),
'rating' => fillOnUndefined($review, 'rating'),
'review' => fillOnUndefined($review, 'text'),
'time' => fillOnUndefined($review, 'time'),
'status' => 1,
'created_by' => 1,
'updated_by' => 1,
];
$propertyWebReviewCreate = PropertyWebReview::create($propertyWebWeatherParam);
$this->info(date('Y-m-d H:i:s') . ' : ' . $propertyWebComponent['property_id'] . ' - ' . $review['author_name'] . ' : ' . $review['rating']);
} 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);
}
}
$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);
}
}
}

View File

@@ -0,0 +1,107 @@
<?php
namespace App\Console\Commands\Google;
use App\Models\Property;
use App\Models\PropertyWeb;
use App\Models\PropertyWebComponentMapping;
use App\Models\PropertyWebReview;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\Log;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
class GoogleStaticMap extends Command
{
protected $signature = 'cron:google-static-map {--property_id=}';
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') . ' : ' . date('Y-m-d') . ' START');
$baseUrl = 'https://maps.googleapis.com/maps/api/staticmap';
$apiKey = 'AIzaSyAPsKZ_XasAieKEhbmpOLUpArY2u2UcXuk';
$imageSizes = [];
$imageSizes[] = ['name' => 'square','size' => '250x250'];
$imageSizes[] = ['name' => 'rectangle','size' => '1000x200'];
$this->restClient = new Client(['http_errors' => false]);
if (!is_null($this->option('property_id'))) {
$propertyList = Property::where('status', 1)->where('id', $this->option('property_id'))->with('propertyContact')->get()->toArray();
} else {
$propertyList = Property::where('status', 1)->where('commission','>=', 1)->with('propertyContact')->get()->toArray();
}
foreach ($propertyList as $property) {
if (!isset($property['property_contact'])) {
continue;
}
$folderPath = Config::get('app.fileSystemDriver') . '/property-map/' . $property['id'];
if(!is_dir($folderPath)) {
mkdir($folderPath);
}
foreach ($imageSizes as $imageSize) {
$imageName = 'map-'.$property['id'].'-'.$imageSize['name'].'.png';
$imagePath = Config::get('app.fileSystemDriver') . '/property-map/' . $property['id'] . '/'.$imageName;
if(is_file($imagePath)) {
$this->line(date('Y-m-d H:i:s') . ' : ' . $imageName);
continue;
}
$params = [
'center' => $property['property_contact']['latitude'] . ',' . $property['property_contact']['longitude'],
'size' => $imageSize['size'], //300x300 1000x200
'zoom' => 18,
'format' => 'png',
'scale' => 2,
'markers' => 'color:red|' . $property['property_contact']['latitude'] . ',' . $property['property_contact']['longitude'],
'key' => $apiKey,
'language' => 'en'
];
$imageUrl = $baseUrl . '?' . http_build_query($params, '', '&');
$imageSave = file_put_contents($imagePath, file_get_contents($imageUrl));
$this->info(date('Y-m-d H:i:s') . ' : ' . $imageName);
}
}
$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);
}
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace App\Console\Commands\Google;
use Illuminate\Console\Command;
use Exception;
use Illuminate\Support\Facades\Log;
use Google\Cloud\Vision\V1\ImageAnnotatorClient;
class GoogleVisioLabel extends Command
{
protected $signature = 'cron:google-visio-label';
protected $description = '';
public function __construct(
)
{
parent::__construct();
}
public function handle()
{
try {
$this->info(date('Y-m-d H:i:s') . ' : ' . date('Y-m-d') . ' START');
$googleVisionAuthentication = base_path().'/resources/data/google-vision-authentication.json';
putenv('GOOGLE_APPLICATION_CREDENTIALS='.$googleVisionAuthentication);
$imageAnnotator = new ImageAnnotatorClient();
$fileName = 'https://image.rezervasyon.com/hotel/301356/lavin-otel-10-9566879.jpg';
$fileName = 'https://image.rezervasyon.com/hotel/301356/lavin-otel-10-9566886.jpg';
$fileName = 'https://image.rezervasyon.com/hotel/301356/lavin-otel-10-9566881.jpg';
$fileName = 'https://image.rezervasyon.com/hotel/301356/lavin-otel-10-9566878.jpg';
$image = file_get_contents($fileName);
$response = $imageAnnotator->labelDetection($image);
$labels = $response->getLabelAnnotations();
$labelList = [];
if ($labels) {
foreach ($labels as $label) {
$labelList[] = [
'description' => $label->getDescription(),
'score' => $label->getScore(),
'topicality' => $label->getTopicality(),
];
}
} else {
echo('No label found' . PHP_EOL);
}
$imageAnnotator->close();
print_r($labelList);
$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);
}
}
}