68 lines
1.4 KiB
PHP
68 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Base;
|
|
use App\Http\Controllers\ApiV1Controller;
|
|
use App\Tool\ThirdApi;
|
|
use Illuminate\Support\Facades\Log;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\Redis;
|
|
|
|
class CoinInit extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'coin:init';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'init every thing need by this project.';
|
|
|
|
/**
|
|
* Create a new command instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
}
|
|
|
|
public function refresh_eth_cache()
|
|
{
|
|
$price = ThirdApi::getETHPrice();
|
|
if (is_null($price) || $price <= 0) {
|
|
Log::error("get ETH price failed. price=$price");
|
|
return;
|
|
}
|
|
|
|
$r = Redis::hSet(ApiV1Controller::K_COIN_PRICE, Base::ETH, $price);
|
|
if (is_null($r)) {
|
|
Log::error("redis error");
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Execute the console command.
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public function handle()
|
|
{
|
|
// insert ETH price
|
|
$this->refresh_eth_cache();
|
|
|
|
$price = (new ApiV1Controller())->get_cache_eth_price();
|
|
if ($price <= 0) {
|
|
Log::warning("cache ETH price failed.");
|
|
}
|
|
}
|
|
}
|