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,125 @@
<?php
namespace App\Console\Commands\PropertyTrialCheck;
use App\Core\Service\PropertyProductMappingService;
use App\Core\Service\PropertyService;
use App\Exceptions\ApiErrorException;
use Carbon\Carbon;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class PropertyTrialCheck extends Command
{
protected $signature = 'cron:property-trial-check';
protected $description = '';
private $propertyService;
public function __construct(
PropertyService $propertyService,
PropertyProductMappingService $productMappingService
)
{
parent::__construct();
$this->propertyService = $propertyService;
$this->productMappingService = $productMappingService;
}
public function handle()
{
$response = ['status' => false, 'message' => ''];
$propertySelectCriteria = [
'criteria' => [
//['field' => 'id', 'condition' => '=', 'value' => 1],
['field' => 'status', 'condition' => '=', 'value' => 1],
['field' => 'commission', 'condition' => '=', 'value' => null],
['field' => 'created_at', 'condition' => '>', 'value' => Carbon::parse('2021-10-01')->timestamp],
],
'with' => ['propertyProductMapping'],
'orderBy' => [
["field" => "id", "value" => "ASC"]
],
'take' => 100
];
$propertyData = $this->propertyService->select($propertySelectCriteria);
if ($propertyData['status'] == 'success') {
foreach ($propertyData['data'] as $property) {
if (empty($property['property_product_mapping'])) {
continue;
}
$expireDay = Carbon::now()->diff(Carbon::createFromTimestamp($property['created_at']))->days;
$this->info(date('Y-m-d H:i:s') . ' Property: ' . $property['id'] . ' - ' . $property['name'] . ' - ' . $expireDay. ' Day');
if (in_array($expireDay, [30])) {
DB::beginTransaction();
try {
$this->info(date('Y-m-d H:i:s') . ' : Property: ' . $property['id'] . ' - ' . $property['name']);
//Product remove from property
foreach ($property['property_product_mapping'] as $productMapping) {
$this->productMappingService->update($productMapping['id'], ['status' => 0]);
}
//Trial period status
$propertyData = $this->propertyService->update($property['id'], ['status' => 2]);
//Burada otel user larına mail atılabilir, trial süresi biti diye
$response['status'] = true;
} catch (ApiErrorException $e) {
$response['message'] = implode(', ', $e->getMessageArr());
} catch (Exception $e) {
$message = $e->getFile() . " " . $e->getLine() . " " . $e->getMessage();
Log::error($message);
}
if ($response['status']) {
DB::commit();
} else {
DB::rollBack();
}
}
//Expiration Check
//Product remove from property via expiration date
foreach ($property['property_product_mapping'] as $productMapping) {
if($productMapping['status'] == 1 && !is_null($productMapping['expiration_date'])) {
if(Carbon::now()->greaterThanOrEqualTo(Carbon::parse($productMapping['expiration_date']))) {
$this->productMappingService->update($productMapping['id'], ['status' => 3]);}
}
}
}
}
}
}

View File

@@ -0,0 +1,83 @@
<?php
namespace App\Console\Commands\PropertyTrialCheck;
use App\Core\Mail\TrialFirstMail;
use App\Core\Mail\TrialSecondMail;
use App\Core\Service\PropertyService;
use App\Exceptions\ApiErrorException;
use Carbon\Carbon;
use GuzzleHttp\Client;
use Illuminate\Console\Command;
use Illuminate\Mail\Mailer;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
class PropertyTrialMail extends Command
{
protected $signature = 'cron:property-trial-mail';
protected $description = '';
private $propertyService;
public function __construct(
Mailer $mailer,
PropertyService $propertyService
)
{
parent::__construct();
$this->mailer = $mailer;
$this->propertyService = $propertyService;
}
public function handle()
{
$this->info(date('Y-m-d H:i:s') . ' START');
$propertySelectCriteria = [
'criteria' => [
['field' => 'status', 'condition' => '=', 'value' => 1],
['field' => 'commission', 'condition' => '=', 'value' => null],
],
'orderBy' => [
["field" => "id", "value" => "ASC"]
],
];
$propertyData = $this->propertyService->select($propertySelectCriteria);
if ($propertyData['status'] == 'success') {
foreach ($propertyData['data'] as $property) {
$createDate = Carbon::createFromTimestamp($property['created_at'])->toDateTimeString();
$expireDay = Carbon::now()->diff(Carbon::createFromTimestamp($property['created_at']))->days;
if (in_array($expireDay, [4, 10])) {
if ($expireDay == 4) {
$this->mailer->onQueue('trialFirstMail', new TrialFirstMail(['propertyId' => $property['id']]));
$this->info(date('Y-m-d H:i:s') . ' SENT Day 4: ' . $property['id'] . ' - ' . $property['name'] . ' - ' . $createDate);
}
if ($expireDay == 10) {
$this->mailer->onQueue('trialSecondMail', new TrialSecondMail(['propertyId' => $property['id']]));
$this->info(date('Y-m-d H:i:s') . ' SENT Day 10: ' . $property['id'] . ' - ' . $property['name'] . ' - ' . $createDate);
}
}
}
}
$this->info(date('Y-m-d H:i:s') . ' FINISHED');
}
}