NASER fix some issues
This commit is contained in:
Executable → Regular
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use Illuminate\Console\Command;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Support\Facades\Http;
|
||||
use App\Http\Controllers\Site\ReportController ;
|
||||
|
||||
// مدل محصول خود را ایمپورت کنید
|
||||
|
||||
class UpdateProductStatus extends Command
|
||||
{
|
||||
/**
|
||||
* نام دستور که در زمانبندی استفاده میشود
|
||||
*/
|
||||
protected $signature = 'product:update-status';
|
||||
|
||||
/**
|
||||
* توضیحات دستور
|
||||
*/
|
||||
protected $description = 'Updates product prices and auto closes/opens products';
|
||||
|
||||
public function handle()
|
||||
{
|
||||
// منطق توابع خود را اینجا بیاورید
|
||||
// اگر توابع در کلاس دیگری هستند، آن کلاس را صدا بزنید یا کد را اینجا کپی کنید
|
||||
|
||||
$this->info('Starting update...');
|
||||
// \Illuminate\Support\Facades\Log::info("handle at: " . now());
|
||||
|
||||
// 1. Get Price Logic
|
||||
|
||||
$RPrices =Http::timeout(40)->get('http://212.23.201.173:8381/price_list', [])->json();
|
||||
|
||||
try{
|
||||
$cooper =Http::timeout(40)->get('https://www.livedata.ir/main/static/p.json', [])->json();
|
||||
if(isset($cooper['s_301006']) && isset($cooper['s_200103'])){
|
||||
$CP = (($cooper['s_301006']/1000000)*$cooper['s_200103'])*10;
|
||||
// Cnt::where('key', 'cu_price')
|
||||
}
|
||||
}catch (\Exception $e){}
|
||||
$products = Product::with([])->whereNotNull('reading_method')->get();
|
||||
$current_time = now()->format('H:i:s');
|
||||
|
||||
foreach ($products as $product) {
|
||||
foreach ($RPrices as $RPrice) {
|
||||
$show = ($current_time >= $product->auto_open_at && $current_time <= $product->auto_close_at);
|
||||
|
||||
if ($product->reading_method == $RPrice['name']) {
|
||||
$p = Product::where('id', $product->id)->update([
|
||||
'price' => $RPrice['price'],
|
||||
'price_profit' => $RPrice['profit'],
|
||||
]);
|
||||
|
||||
if($product->bubble== 1){
|
||||
$ReportController = new ReportController();
|
||||
$liquidGold= $ReportController->lastPrice();
|
||||
$p = Product::find($product->id);
|
||||
|
||||
$p->amount = $RPrice['price'] / $liquidGold['price'];
|
||||
$p->show = $show;
|
||||
$p->save();
|
||||
|
||||
}
|
||||
}
|
||||
if($product->reading_method == 'مس' && $CP){
|
||||
$p = Product::where('id', $product->id)->update([
|
||||
'price' => $CP,
|
||||
'show' => $show,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
// 2. Auto Close/Open Logic
|
||||
// $this->auto_close_open(); -> کد داخل این تابع را اینجا قرار دهید
|
||||
// \Illuminate\Support\Facades\Log::info("handle end at: " . now());
|
||||
|
||||
$this->info('Product statuses updated successfully.');
|
||||
}
|
||||
}
|
||||
Executable → Regular
+14
@@ -20,6 +20,20 @@ class Kernel extends ConsoleKernel
|
||||
protected function schedule(Schedule $schedule)
|
||||
{
|
||||
// $schedule->command('inspire')->hourly();
|
||||
$schedule->call(function () {
|
||||
// حلقه برای اجرای 6 بار در یک دقیقه (هر 10 ثانیه)
|
||||
for ($i = 0; $i < 6; $i++) {
|
||||
// \Illuminate\Support\Facades\Log::info("Update process ran at: " . now());
|
||||
|
||||
// فراخوانی کامند ما
|
||||
\Illuminate\Support\Facades\Artisan::call('product:update-status');
|
||||
|
||||
// 10 ثانیه صبر کن (به جز دور آخر که نیاز نیست اسکریپت باز بماند)
|
||||
if ($i < 5) {
|
||||
sleep(10);
|
||||
}
|
||||
}
|
||||
})->everyMinute()->name('update_products_every_20s')->withoutOverlapping();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Executable → Regular
Reference in New Issue
Block a user