Lae/app/Console/Commands/GetUser.php

78 lines
2.0 KiB
PHP
Raw Normal View History

2022-09-28 05:13:24 +00:00
<?php
namespace App\Console\Commands;
2022-11-06 11:28:22 +00:00
use App\Models\Balance;
2022-09-28 05:13:24 +00:00
use App\Models\Host;
2022-11-06 11:28:22 +00:00
use App\Models\User;
2022-09-28 05:13:24 +00:00
use Illuminate\Console\Command;
class GetUser extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'user {email_or_id}';
2022-09-28 05:13:24 +00:00
/**
* The console command description.
*
* @var string
*/
protected $description = '获取一个用户的信息,交易记录,余额,主机,服务器,工单。';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
2022-12-11 11:47:30 +00:00
* @return int
2022-09-28 05:13:24 +00:00
*/
2023-01-10 13:42:27 +00:00
public function handle(): int
2022-09-28 05:13:24 +00:00
{
//
$email_or_id = $this->argument('email_or_id');
2023-01-10 13:42:27 +00:00
$user = (new User)->where('email', $email_or_id)->orWhere('id', $email_or_id)->orWhere('name', $email_or_id)->first();
2022-09-28 05:13:24 +00:00
2023-01-10 13:42:27 +00:00
// $transaction = new Transaction();
2022-09-28 05:13:24 +00:00
$this->warn('用户基本信息');
2023-02-07 09:04:11 +00:00
$this->info('用户 ID: '.$user->id);
$this->info('名称: '.$user->name);
$this->info('邮箱: '.$user->email);
$this->info('余额:'.$user->balance.' 元');
2022-09-28 05:13:24 +00:00
$this->warn('前 10 条充值记录');
2023-01-10 13:42:27 +00:00
$balances = (new Balance)->where('user_id', $user->id)->whereNotNull('paid_at')->latest()->limit(10)->get();
2022-09-28 05:13:24 +00:00
// 倒序输出
foreach (array_reverse($balances->toArray()) as $balance) {
2023-02-07 09:04:11 +00:00
$this->info('['.$balance['paid_at'].'] 支付方式: '.$balance['payment'].' 金额:'.$balance['amount'].' 元');
2022-09-28 05:13:24 +00:00
}
$this->warn('前 10 个主机');
2023-01-10 13:42:27 +00:00
$hosts = (new Host)->where('user_id', $user->id)->with('module')->latest()->limit(10)->get();
2022-09-28 05:13:24 +00:00
// 倒序
foreach (array_reverse($hosts->toArray()) as $host) {
2023-02-07 09:04:11 +00:00
$this->info('['.$host['module']['name'].']('.$host['price'].' 元) '.$host['name']);
2022-09-28 05:13:24 +00:00
}
2022-11-19 14:42:47 +00:00
return 0;
2022-09-28 05:13:24 +00:00
}
}