6
0
Fork 0
jiqu-library-server/app/Admin/Actions/Grid/QuotaV1SendJobStart.php

60 lines
1.4 KiB
PHP

<?php
namespace App\Admin\Actions\Grid;
use App\Models\QuotaV1SendJob;
use Dcat\Admin\Actions\Response;
use Dcat\Admin\Grid\RowAction;
use Illuminate\Http\Request;
use Throwable;
class QuotaV1SendJobStart extends RowAction
{
public function title()
{
if ($this->title) {
return $this->title;
}
return '<i class="feather grid-action-icon icon-play-circle"></i> 开始任务&nbsp;&nbsp;';
}
/**
* @param Model|Authenticatable|HasPermissions|null $user
*
* @return bool
*/
protected function authorize($user): bool
{
return $user->can('dcat.admin.quota_v2_send_jobs.start');
}
/**
* Handle the action request.
*
* @param Request $request
*
* @return Response
*/
public function handle(Request $request)
{
try {
QuotaV1SendJob::findOrFail($this->getKey())->update([
'status' => QuotaV1SendJob::STATUS_DOING,
]);
} catch (Throwable $th) {
report($th);
return $this->response()->error('开始失败,'.$th->getMessage())->refresh();
}
return $this->response()->success('操作成功')->refresh();
}
/**
* @return string|array|void
*/
public function confirm()
{
return ['确认开始执行当前任务?', '确认后将针对任务金额开始分红,无法逆转。'];
}
}