/
proc
/
self
/
root
/
home
/
henzagold
/
server
/
app
/
Console
/
Commands
/
File Upload :
llllll
Current File: //proc/self/root/home/henzagold/server/app/Console/Commands/GetGoldPriceForPwa.php
<?php namespace App\Console\Commands; use App\Models\ConfigStatic; use Illuminate\Console\Command; use Illuminate\Support\Arr; use Illuminate\Support\Facades\Http; use Morilog\Jalali\Jalalian; class GetGoldPriceForPwa extends Command { /** * The name and signature of the console command. * * @var string */ protected $signature = 'pwa:price'; /** * The console command description. * * @var string */ protected $description = 'Command description'; /** * Create a new command instance. * * @return void */ public function __construct() { parent::__construct(); } /** * Execute the console command. * * @return int */ public function handle() { try { $responses[8] = Http::withoutVerifying()->timeout(1)->get("https://call3.tgju.org/ajax.json")->json(); } catch (\Exception $ex) { self::sendErrorToTelegram($ex); } if (isset($responses[8])) { $translations = [ "geram18" => "گرم ۱۸", "silver_999" => "نقره", "mesghal" => "مثقال", "price_dollar_rl"=> "دلار (ریال)", "sekeb" => "سکه تمام", "rob" => "ربع سکه", "nim" => "نیم سکه", "sekee_down" => "سکه طرح قدیم", "rob_down" => "ربع سکه طرح قدیم", "nim_down" => "نیم سکه طرح قدیم", ]; foreach ($responses[8]['current'] as $key => $value) { if (array_key_exists($key, $translations)) { $value['title'] = $translations[$key]; $allItems[$key] = $value; } } } ConfigStatic::where('key','gold_price_pwa')->update(['val' => $allItems]); ConfigStatic::where('key','gold_price')->update(['val' => $allItems]); //update mcode from tahesab // Execute the request and get the full Response object $response = Http::withoutVerifying() ->withHeaders(['DBName' => "tahesabDB1"]) ->withToken("S3F1P8Q4W7X5F7P5B5V5W2D3U3M1N2C5N6E3W6M1E4X4V2Y1Q3O2L6W5W3G2B8T4U2V1S1W4A4S5A1U8") ->withOptions(['stream' => true]) ->post("https://31.7.68.147:3030/", [ 'DoListMoshtari' => [1,510] ]); // Check for success (status code 200-299) if ($response->successful()) { $mainResponce = $response->json(); // Check if the JSON decoding was successful (not null or empty) if (is_array($mainResponce) || is_object($mainResponce)) { // This is the original foreach loop, now protected foreach ($mainResponce as $key => $value) { if ($key == 50){ $this->info(json_encode($value, JSON_PRETTY_PRINT)); } } } else { // The API returned a 200, but the body was not valid JSON $this->error('API response received, but the body was not valid JSON or was empty.'); $this->line($response->body()); } } else { // Request failed (e.g., 404, 500, timeout) $this->error('The request to the Tahesab API failed.'); $this->error('Status: ' . $response->status()); // You can also throw an exception here if the failure is critical } // $this->info(json_encode($mainResponce, JSON_PRETTY_PRINT)); // // $tala_ir = (int)str_replace(',', '', Http::timeout(2)->get('https://www.tala.ir/ajax/price')->json()['gold']['gold_18k']['v']) * 10; // if (!is_null($tala_ir)) { // // $service['uaj'] = Jalalian::forge(now())->format('Y/m/d - H:i:s'); //// //// // فیلتر کردن دادهها //// $filtered = Arr::except($service, [7,8,9,10,20,21,22,23,24,25,26,27,28,29]); // // // تعریف آرایه با دادههای جدید // $filtered['mesghal'] = [ // "title" => "مثقاع طلا", // "slug" => "mesghal", // "p" => "206,460,000", // "d" => "0", // "dp" => "0.0000", // "dt" => "", // "h" => "206,460,000", // "l" => "202,910,000", // "t" => "1403-09-21 12:00:00", // "updated_at" => "2024-10-10 20:11:12", // "uaj" => "1403/09/25 - 12:13" // ]; // // $filtered['geram18'] = [ // "title" => "طلای 18 عیار", // "slug" => "geram18", // "p" => number_format($tala_ir), // "d" => "0", // "dp" => "0.0000", // "dt" => "", // "h" => number_format($tala_ir), // "l" => number_format($tala_ir), // "t" => $service['uaj'], // "updated_at" => "2024-10-10 20:11:03", // "uaj" => $service['uaj'] // ]; // // $filtered['geram24'] = [ // "title" => "طلای 24 عیار", // "slug" => "geram24", // "p" => "63,542,200", // "d" => "0", // "dp" => "0.0000", // "dt" => "", // "h" => "63,542,200", // "l" => "62,449,600", // "t" => "1403-09-21 12:00:00", // "updated_at" => "2024-10-10 20:11:03", // "uaj" => "1403/09/25 - 12:12" // ]; //// dd($filtered); // اینجا را میتوانید حذف کنید پس از بررسی // // // بهروزرسانی مقدار در پایگاه داده // ConfigStatic::where('key','gold_price_pwa')->update(['val' => $filtered]); // ConfigStatic::where('key', 'gold_price')->update(['val' => json_encode($filtered)]); // return ConfigStatic::where('key','gold_price')->get(); // } } // public function handle() // { // $service = Http::get('https://api.ratebox.ir/apijson.php?token='.env('WEBSERVICE_TOKEN')) // ->json(); // if (!is_null($service)){ // $service['uaj'] = Jalalian::forge(now())->format('Y/m/d - H:i:s'); // $filtered =Arr::except($service, [7,8,9,10,20,21,22,23,24,25,26,27,28,29]); // ConfigStatic::where('key','gold_price_pwa')->update(['val' => $filtered]); // } // // } }
Copyright ©2k19 -
Hexid
|
Tex7ure