<?php

namespace App\Admin\Actions\Coupon;

use Encore\Admin\Actions\BatchAction;
use Illuminate\Database\Eloquent\Collection;

class BatchProfits extends BatchAction
{
    public $name = '批量打款';

    public function handle(Collection $collection)
    {
        $success = $error = 0;

        foreach ($collection as $model) {
            $res = $model->sendMoney();
            if ($res === true) {
                $success++;
            } else {
                $error++;
            }
        }

        return $this->response()->success('成功' . $success . '条,失败' . $error . '条')->refresh();
    }

    public function dialog()
    {
        $this->confirm('确定打款？');
    }

}
