128 lines
4.2 KiB
PHP
128 lines
4.2 KiB
PHP
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Admin\Actions\Grid\QuotaV1SendJobStart;
|
|
use App\Admin\Renderable\QuotaV1SendLogTable;
|
|
use App\Admin\Repositories\QuotaV1SendJob;
|
|
use App\Models\QuotaV1SendJob as QuotaV1SendJobModel;
|
|
use Dcat\Admin\Admin;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Layout\Content;
|
|
use Dcat\Admin\Show;
|
|
|
|
class QuotaV1SendJobController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
$builder = QuotaV1SendJob::with('administrator');
|
|
return Grid::make($builder, function (Grid $grid) {
|
|
$grid->column('id')->sortable();
|
|
$grid->column('amount')->display(function ($value) {
|
|
return bcdiv($value, 100, 2);
|
|
})->prepend('¥');
|
|
$grid->column('administrator.name');
|
|
$grid->column('status')->using(QuotaV1SendJobModel::$statusText)->dot([
|
|
0=>'primary',
|
|
1=> 'warning',
|
|
2=>'success',
|
|
]);
|
|
$grid->column('remarks');
|
|
$grid->column('created_at')->sortable();
|
|
|
|
$grid->model()->orderBy('created_at', 'desc');
|
|
|
|
/** 操作 **/
|
|
//新增
|
|
if (Admin::user()->can('dcat.admin.quota_v1_send_jobs.create')) {
|
|
$grid->disableCreateButton(false);
|
|
$grid->enableDialogCreate();
|
|
}
|
|
//修改
|
|
$grid->showQuickEditButton(Admin::user()->can('dcat.admin.quota_v1_send_jobs.edit'));
|
|
//删除以及自定义操作
|
|
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
|
if ($actions->row->status === 0) {
|
|
$actions->disableDelete(Admin::user()->cannot('dcat.admin.quota_v1_send_jobs.destroy'));
|
|
if (Admin::user()->can('dcat.admin.quota_v1_send_jobs.start')) {
|
|
$actions->append(new QuotaV1SendJobStart());
|
|
}
|
|
} else {
|
|
if (Admin::user()->can('dcat.admin.quota_v1_send_jobs.log_list')) {
|
|
$actions->append('<a href="'.admin_route('quota_v1_send_jobs.log_list', ['job'=>$actions->row]).'"><i class="fa fa-eye"></i> 发放记录</a>');
|
|
}
|
|
}
|
|
});
|
|
|
|
/** 查询 **/
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->panel();
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new QuotaV1SendJob(), function (Show $show) {
|
|
$show->field('id');
|
|
$show->field('administrator_id');
|
|
$show->field('amount');
|
|
$show->field('status');
|
|
$show->field('remarks');
|
|
$show->field('created_at');
|
|
$show->field('updated_at');
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new QuotaV1SendJob(), function (Form $form) {
|
|
$form->display('id');
|
|
if ($form->isCreating()) {
|
|
$form->currency('amount')->symbol('¥')->customFormat(function ($amount) {
|
|
return bcdiv($amount, 100, 2);
|
|
})->saving(function ($amount) {
|
|
return bcmul($amount, 100);
|
|
})->required();
|
|
} else {
|
|
$form->currency('amount')->symbol('¥')->customFormat(function ($amount) {
|
|
return bcdiv($amount, 100, 2);
|
|
})->saving(function ($amount) {
|
|
return bcmul($amount, 100);
|
|
})->disable();
|
|
}
|
|
|
|
$form->text('remarks');
|
|
|
|
$form->display('created_at');
|
|
$form->display('updated_at');
|
|
});
|
|
}
|
|
|
|
public function logList(Content $content, QuotaV1SendJobModel $job)
|
|
{
|
|
return $content->header(__('quota-v1-send-job.labels.quota-v1-send-jobs'))
|
|
->description($job->id)
|
|
->body(QuotaV1SendLogTable::grid($job->id));
|
|
}
|
|
}
|