You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

97 lines
3.0 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Command;
use App\Helper\Client\Lanhuo;
use App\Model\DeviceRecord;
use App\Model\UserLoginRecord;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Hyperf\Contract\ContainerInterface;
/**
* @Command
*/
class JinlingCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
protected $admin;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
parent::__construct('jinling');
}
public function configure()
{
parent::configure();
$this->setDescription('廖金灵测试');
}
public function handle()
{
}
public function deleteUserLoginRecord() {
$gameIds = $this->getNeedDeleteGameIds();
$this->info('deleteUserLoginRecord:' . implode(',', $gameIds));
foreach ($gameIds as $gameId) {
$this->deleteUserLoginRecordByGameId($gameId);
}
}
private function getNeedDeleteGameIds() {
$gameIds = explode(',', '175,185,262,275,282,293,295,297,303,305,311,323,327,331,333,337,339,343,345,351,355,357,359,176,186,263,276,283,294,296,298,304,306,312,324,328,332,334,338,340,344,346,352,356,358,360');
return $gameIds;
}
private function deleteUserLoginRecordByGameId($gameId) {
$this->info('======= begin delete game_id ' . $gameId . ' =======');
$firstId = 0;
$hasMore = true;
do {
$this->info('delete game_id ' . $gameId . ' from id' . $firstId);
// UserLoginRecord::query()->where('game_id', $gameId)->where('id', '>=', $firstId)->limit(10000)->delete();
$record = UserLoginRecord::query()->where('game_id', $gameId)->first();
if (empty($record)) {
$hasMore = false;
} else {
$firstId = $record->id;
}
} while($hasMore);
$this->info('======= end delete game_id ' . $gameId . ' =======');
}
public function deleteDeviceRecord() {
$gameIds = $this->getNeedDeleteGameIds();
$this->info('deleteDeviceRecord:' . implode(',', $gameIds));
foreach ($gameIds as $gameId) {
$this->deleteDeviceRecordByGameId($gameId);
}
}
private function deleteDeviceRecordByGameId($gameId) {
$this->info('======= begin delete game_id ' . $gameId . ' =======');
$firstId = 0;
$hasMore = true;
do {
$this->info('delete game_id ' . $gameId . ' from id' . $firstId);
// DeviceRecord::query()->where('game_id', $gameId)->where('id', '>=', $firstId)->limit(10000)->delete();
$record = DeviceRecord::query()->where('game_id', $gameId)->first();
if (empty($record)) {
$hasMore = false;
} else {
$firstId = $record->id;
}
} while($hasMore);
$this->info('======= end delete game_id ' . $gameId . ' =======');
}
}