<?php

namespace App\Admin\Actions\User;

use Encore\Admin\Actions\RowAction;
use Encore\Admin\Form;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use RuLong\Identity\Models\Identity;

class UserUpgrade extends RowAction
{
    public $name = '账号升级';

    public function handle(Model $model, Request $request)
    {
        $identity_id = $request->identity_id;
        $model->identityUpdate($identity_id, 'EmptyUp');

        return $this->response()->success('升级成功')->refresh();
    }

    public function form(Model $model)
    {
        $identitys = Identity::where('id', '!=', $model->identity_id)->orderBy('id', 'asc')->pluck('title', 'id')->toArray();
        $this->text('用户名称')->disable()->value($model->info->nickname);
        $this->text('当前等级')->disable()->value($model->identity_text);
        $this->select('identity_id', '目标等级')->options($identitys);
    }

}
