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.

174 lines
4.8 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Command;
use App\Model\BaseGame;
use App\Service\RebateService;
use Hyperf\Command\Command as HyperfCommand;
use Hyperf\Command\Annotation\Command;
use Psr\Container\ContainerInterface;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
/**
* @Command
*/
class RebateCommand extends HyperfCommand
{
/**
* @var ContainerInterface
*/
protected $container;
/**
* @var RebateService
*/
private $rebateService;
private $baseGames;
private $timeRange;
private $date;
public function __construct(ContainerInterface $container)
{
$this->container = $container;
$this->rebateService = $this->container->get(RebateService::class);
parent::__construct('rebate');
}
public function configure()
{
parent::configure();
$this->setDescription('返利');
$this->addOption('timeRange', 'T', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '时间范围', [time()-10*60, time()]);
$this->addOption('date', 'D', InputOption::VALUE_OPTIONAL, '日期', date('Y-m-d',strtotime('-1 day')));
$this->addOption('gameId', 'G', InputOption::VALUE_IS_ARRAY | InputOption::VALUE_OPTIONAL, '游戏', [11, 17, 21]);
}
public function handle()
{
$timeRange = $this->input->getOption('timeRange');
if (count($timeRange) != 2) {
return $this->line('必须时间范围', 'error');
}
if (!is_numeric($timeRange[0])) {
$timeRange[0] = strtotime($timeRange[0]);
}
if (!is_numeric($timeRange[1])) {
$timeRange[1] = strtotime($timeRange[1]);
}
if ($timeRange[0] === false || $timeRange[1] === false) {
return $this->line('时间格式错误', 'error');
} else {
$this->timeRange = $timeRange;
}
$this->date = $this->input->getOption('date');
$gameIds = $this->input->getOption('gameId');
$this->baseGames = BaseGame::whereIn('id', $gameIds)->get();
$action = $this->input->getArgument('action');
$this->$action();
}
private function initRebateGifts()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->saveRebateGifts($baseGame->id);
}
}
private function resetRebateGifts()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->saveRebateGifts($baseGame->id, true);
}
}
private function generateDaily()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateDaily($baseGame, $this->date);
}
}
private function generateSingle()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateSingle($baseGame, $this->timeRange);
}
}
private function generateSingleTimes()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateSingleTimes($baseGame, $this->timeRange);
}
}
private function generateAccumulative()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateAccumulative($baseGame, $this->timeRange);
}
}
private function generateFirstPay()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateFirstPay($baseGame, $this->timeRange);
}
}
private function generateDayAccumulative()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateDayAccumulative($baseGame, $this->date);
}
}
private function generateWeekly()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateWeekly($baseGame, $this->timeRange);
}
}
private function generateNewRole()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateNewRole($baseGame, $this->timeRange);
}
}
private function generateDailySign()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateDailySign($baseGame, $this->timeRange);
}
}
private function generateOpenSevenDay()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateOpenSevenDay($baseGame, $this->timeRange);
}
}
private function generateRoleLevel()
{
foreach ($this->baseGames as $baseGame) {
$this->rebateService->generateRoleLevel($baseGame, $this->timeRange);
}
}
protected function getArguments()
{
return [
['action', InputArgument::REQUIRED, '要执行的操作']
];
}
}