<?php

namespace Modules\Mall\Http\Controllers\Admin\Action\Shop;

use Encore\Admin\Actions\Response;
use Encore\Admin\Actions\RowAction;
use Modules\Mall\Models\Shop;

class Open extends RowAction
{

    public $name = '开启店铺';

    public function handle(Shop $shop): Response
    {
        try {
            if ($shop->open()) {
                return $this->response()->success('店铺开启成功')->refresh();
            } else {
                return $this->response()->error('店铺开启失败')->refresh();
            }
        } catch (\Exception $exception) {
            return $this->response()->error($exception->getMessage())->refresh();
        }
    }

    public function dialog()
    {
        $this->confirm('确定开启店铺吗？');
    }

}
