<?php

namespace App\Community\Actions\Vaccine;

use App\Models\Order;
use App\Models\User;
use Encore\Admin\Actions\RowAction;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class OrderCance extends RowAction
{
    public $name = '取消订单';

    public function handle(Model $model)
    {
        $id = $this->row->id;
        DB::beginTransaction();
        try {
            //退还余额
            $res = Order::orderCancel($id);
            DB::commit();
        } catch ( \Exception $e){
            dd($e->getMessage());
            DB::rollBack();
            return $this->response()->error('操作失败!');
        }

        if($res){
            return $this->response()->success('操作成功!')->refresh();
        }
        return $this->response()->error('操作失败!');
    }

}
