<?php

namespace app\command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Output\OutputInterface;
use support\think\Db;


class Otop extends Command
{
    protected static $defaultName = 'Otop';
    protected static $defaultDescription = '结算';

    /**
     * @return void
     */
    protected function configure()
    {
        $this->addOption('user_id','u', InputArgument::OPTIONAL, 'user_id');
    }

    /**
     * @param InputInterface $input
     * @param OutputInterface $output
     * @return int
     */
    protected function execute(InputInterface $input, OutputInterface $output): int
    {
        $user_id = $input->getOption('user_id');
        if(!$user_id){
            return false;
        }
        /**
         * @var \plugin\admin\app\model\Admin $admin
         */
        $admin = \plugin\admin\app\model\Admin::where('id',$user_id)->find();
        if(!$admin){
            return false;
        }
        $totp = \OTPHP\TOTP::create($admin->totp_secret);
        cp($totp->now());
        return 1;
    }
}
