<?php

namespace App\Console\Test;

use App\Cache\UserCache;
use App\Facade\Site;
use App\Libs\TikTok\Kernel\Support\Str;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Redis;
use Illuminate\Support\Facades\Storage;
use Vinkla\Hashids\Facades\Hashids;

use function PHPSTORM_META\map;

/**
 * 测试
 */
class RegisterUserCommand extends Command
{
    /**
     * @var string
     */
    protected $signature = 'registerUser {--account=} {--pwd=} {--nickname=} {--role=}';

    /**
     * The console command description.
     *  php artisan Payment:BasePayment --bid='1'
     *
     * @var string
     */
    protected $description = '创建用户';
    private $salt = 'bXBfYXVkaW8=';


    public function __construct(
    )
    {
        parent::__construct();
    }


    /**
     * handle
     */
    public function handle()
    {
        $account = $this->option('account');
        $pwd = $this->option('pwd');
        $nickname = $this->option('nickname');
        $role = $this->option('role');
        if (!$account) dd('请输入账号');
        if (!$pwd) $pwd = $account.'123456';
        if (!$nickname) $nickname = $account;
        if (!$role) $role = 'user';
        $boolen = $this->registerUser($account, $pwd, $nickname, $role);
        if ($boolen) dd('创建用户成功!');
    }

    private function registerUser($account, $pwd, $nickname, $role) {
        $o_pass = $pwd;
        $pwd = md5($pwd.$this->salt);

        return DB::table('mp_manage_users')->insert([
            'account'       => $account,
            'nickname'      => $nickname,
            'o_pass'        => $o_pass,
            'pwd'           => $pwd,
            'role'          => $role,
            'is_enabled'    => 1,
            'created_at'    => date('Y-m-d H:i:s'),
            'updated_at'    => date('Y-m-d H:i:s'),
        ]);
    }
}
