<?php

namespace App\Admin\Actions;

use App\Models\User;
use Encore\Admin\Actions\Action;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;

class CleanData extends Action
{

    protected $selector = '.clean';

    public function handle(Request $request)
    {
        // 清理用户签到
        User::where('sign', 1)->update(['sign' => 0]);

        DB::table('item_logs')->truncate();

        return $this->response()->success('清理成功')->refresh();
    }

    function dialog()
    {
        return $this->confirm('确认要清理数据么');
    }

    public function html()
    {
        return <<<HTML
        <a class="btn btn-sm btn-danger clean"><i class="fa fa-trash"></i> 清理数据</a>
HTML;
    }

}