119 lines
3.9 KiB
PHP
Executable File
119 lines
3.9 KiB
PHP
Executable File
<?php
|
||
|
||
namespace App\Admin\Controllers;
|
||
|
||
use App\Admin\Repositories\Coin;
|
||
use Dcat\Admin\Form;
|
||
use Dcat\Admin\Grid;
|
||
use Dcat\Admin\Show;
|
||
use Dcat\Admin\Http\Controllers\AdminController;
|
||
|
||
class CoinController extends AdminController
|
||
{
|
||
/**
|
||
* Make a grid builder.
|
||
*
|
||
* @return Grid
|
||
*/
|
||
protected function grid()
|
||
{
|
||
return Grid::make(new Coin(), function (Grid $grid) {
|
||
$grid->column('id')->sortable();
|
||
$grid->column('name');
|
||
$grid->column('type')->display(function ($type) {
|
||
return \App\Models\Coin::TYPE[$type];
|
||
});
|
||
// $grid->column('longitude');
|
||
// $grid->column('latitude');
|
||
$grid->column('address', '地址');
|
||
$grid->column('status')->bool();
|
||
$grid->column('is_unlock')->bool();
|
||
$grid->column('updated_at')->sortable();
|
||
|
||
$grid->column('二维码')->modal(function ($modal) {
|
||
$modal->title('二维码');//模态框标题
|
||
// $modal->icon('feather icon-eye');//按钮图标
|
||
|
||
$code = json_encode([
|
||
'id' => $this->id,
|
||
'token' => md5(json_encode([
|
||
'id' => $this->id,
|
||
'type' => $this->type,
|
||
'longitude' => $this->longitude,
|
||
'latitude' => $this->latitude,
|
||
])),
|
||
]);
|
||
|
||
$base64Image = (new \chillerlan\QRCode\QRCode())->render($code);
|
||
|
||
return view('qrcode', ['code' => $base64Image]);//配置view,传入自定义参数
|
||
});
|
||
|
||
$grid->filter(function (Grid\Filter $filter) {
|
||
// $filter->panel();
|
||
// $filter->expand();
|
||
$filter->equal('id');
|
||
$filter->equal('name');
|
||
$filter->equal('type')->select(\App\Models\Coin::TYPE);
|
||
});
|
||
$grid->model()->orderBy('id', 'desc');
|
||
|
||
$grid->actions(function (Grid\Displayers\Actions $actions) {
|
||
$actions->append('<a href="/admin/clues?coin_id=' . $actions->getKey() . '">线索</a>');
|
||
});
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Make a show builder.
|
||
*
|
||
* @param mixed $id
|
||
*
|
||
* @return Show
|
||
*/
|
||
protected function detail($id)
|
||
{
|
||
return Show::make($id, new Coin(), function (Show $show) {
|
||
$show->field('id');
|
||
$show->field('name');
|
||
$show->field('type')->using(\App\Models\Coin::TYPE);
|
||
if ($show->model()->type == \App\Models\Coin::TYPE_JIN) {
|
||
$show->field('is_true')->using(\App\Models\Coin::IS_TRUE);
|
||
$show->field('amount', '橡果数');
|
||
}
|
||
$show->field('longitude');
|
||
$show->field('latitude');
|
||
$show->field('address', '地址');
|
||
$show->field('status')->using(\App\Models\Coin::STATUS);
|
||
$show->field('is_unlock')->using(\App\Models\Coin::IS_UNLOCK);
|
||
$show->field('created_at');
|
||
$show->field('updated_at');
|
||
});
|
||
}
|
||
|
||
/**
|
||
* Make a form builder.
|
||
*
|
||
* @return Form
|
||
*/
|
||
protected function form()
|
||
{
|
||
return Form::make(new Coin(), function (Form $form) {
|
||
$form->text('name');
|
||
$form->radio('type')->options(\App\Models\Coin::TYPE)->default(\App\Models\Coin::TYPE_TONG)->when(\App\Models\Coin::TYPE_JIN, function (Form $form) {
|
||
$form->switch('is_true');
|
||
$form->number('amount', '橡果数');
|
||
});
|
||
$form->text('longitude');
|
||
$form->text('latitude');
|
||
$form->switch('status');
|
||
$form->text('address', '地址');
|
||
$form->saving(function (Form $form) {
|
||
if ($form->type != \App\Models\Coin::TYPE_JIN) {
|
||
$form->is_true = \App\Models\Coin::IS_TRUE_YES;
|
||
}
|
||
});
|
||
});
|
||
}
|
||
}
|