2021-05-20 16:53:34 +08:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace App\Command;
|
|
|
|
|
2021-07-30 23:23:48 +08:00
|
|
|
use App\Model\UsersFriend;
|
2021-08-27 22:55:42 +08:00
|
|
|
use App\Repository\ExampleRepository;
|
2021-05-20 16:53:34 +08:00
|
|
|
use Hyperf\Command\Command as HyperfCommand;
|
|
|
|
use Hyperf\Command\Annotation\Command;
|
|
|
|
use Psr\Container\ContainerInterface;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @Command
|
|
|
|
*/
|
|
|
|
class TestCommand extends HyperfCommand
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var ContainerInterface
|
|
|
|
*/
|
|
|
|
protected $container;
|
|
|
|
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
$this->container = $container;
|
|
|
|
|
|
|
|
parent::__construct('test:command');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function configure()
|
|
|
|
{
|
|
|
|
parent::configure();
|
|
|
|
$this->setDescription('Hyperf Demo Command');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function handle()
|
|
|
|
{
|
2021-08-28 16:11:38 +08:00
|
|
|
$repository = di()->get(ExampleRepository::class);
|
|
|
|
|
2021-08-28 23:41:01 +08:00
|
|
|
$repository->case5();
|
2021-08-28 16:11:38 +08:00
|
|
|
|
2021-07-28 23:42:21 +08:00
|
|
|
//$api = config('juhe_api.ip');
|
|
|
|
//$options = [];
|
|
|
|
//$client = di()->get(ClientFactory::class)->create($options);
|
|
|
|
//$params = [
|
|
|
|
// 'ip' => '47.105.180.123',
|
|
|
|
// 'key' => $api['key'],
|
|
|
|
//];
|
|
|
|
//
|
|
|
|
//$address = '';
|
|
|
|
//$response = $client->get($api['api'] . '?' . http_build_query($params));
|
|
|
|
//if ($response->getStatusCode() == 200) {
|
|
|
|
// $result = json_decode($response->getBody()->getContents(), true);
|
|
|
|
// if ($result['resultcode'] == 200) {
|
|
|
|
// unset($result['result']['Isp']);
|
|
|
|
// $address = join(' ', $result['result']);
|
|
|
|
// }
|
|
|
|
//}
|
|
|
|
//
|
|
|
|
//var_dump($address);
|
2021-05-20 16:53:34 +08:00
|
|
|
}
|
2021-07-30 23:23:48 +08:00
|
|
|
|
|
|
|
|
|
|
|
// 更新好友表数据
|
|
|
|
public function updateData()
|
|
|
|
{
|
|
|
|
$max = UsersFriend::max('id');
|
|
|
|
UsersFriend::where('id', '<=', $max)->chunk(1000, function ($rows) {
|
|
|
|
$arr = [];
|
|
|
|
foreach ($rows as $row) {
|
|
|
|
$arr[] = [
|
|
|
|
'user_id' => $row->friend_id,
|
|
|
|
'friend_id' => $row->user_id,
|
|
|
|
'status' => 1,
|
|
|
|
'remark' => '',
|
|
|
|
'updated_at' => date('Y-m-d H:i:s'),
|
|
|
|
'created_at' => date('Y-m-d H:i:s'),
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
UsersFriend::insert($arr);
|
|
|
|
});
|
|
|
|
}
|
2021-05-20 16:53:34 +08:00
|
|
|
}
|