PushController.php 3.27 KB
<?php

namespace App\Admin\Controllers;

use App\Models\Push;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Show;
use Dcat\Admin\Http\Controllers\AdminController;

class PushController extends AdminController
{
    protected $title = '推送服务';

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new Push(), function (Grid $grid) {
            $grid->column('id')->sortable();
            $grid->column('title');
            $grid->column('terminal');
            $grid->column('push_type');
            $grid->column('push_time');
            $grid->column('action_type');
            $grid->column('user_type');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');

            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new Push(), function (Show $show) {
            $show->field('id');
            $show->field('title');
            $show->field('terminal');
            $show->field('push_type');
            $show->field('push_time');
            $show->field('action_type');
            $show->field('user_type');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new Push(), function (Form $form) {
            $form->display('id');

            $form->block(8, function (Form\BlockForm $form) {
                // 设置标题
                $form->title('基本设置');
                // 显示底部提交按钮
                $form->showFooter();
                // 设置字段宽度
                $form->width(8, 3);

                $form->radio('terminal')->addElementClass('terminal')
                    ->options([1 => 'Android', 2 => 'IOS'])->default(2);

                $form->text('title')->addElementClass('title');
                $form->textarea('content')->addElementClass('push_content');

                $form->radio('push_type', '发送时间')->addElementClass('push_type')
                    ->options([1 => '立即', 2 => '定时'])->default(1)
                    ->when(2, function (Form\BlockForm $form) {
                        $form->datetime('push_time');
                    });
                $form->select('action_type')->addElementClass('action_type')
                    ->options(['打开应用', '临境', '会员介绍页', '众妙页']);

                $form->radio('user_type', '目标人群')->options([1 => '所有人', 2 => '指定用户'])->default(1)
                    ->when(2, function (Form\BlockForm $form) {
                        $form->text('user_id')->placeholder("多个用户用逗号,分开");
                    });
            });

            $form->block(4, function (Form\BlockForm $form) {
                $form->width(9, 1);
                $form->html(view('admin.form.push'));
            });

            $form->display('created_at');
            $form->display('updated_at');
        });
    }

    public function store()
    {
        dd(request()->all());
    }
}