Demo entry 6771748

123

   

Submitted by 4 on Nov 20, 2018 at 09:25
Language: PHP. Code size: 3.7 kB.

<?php

namespace App\Admin\Controllers;

use App\Models\Agent;
use App\Models\AgentLevel;
use App\Http\Controllers\Controller;
use Encore\Admin\Controllers\HasResourceActions;
use Encore\Admin\Form;
use Encore\Admin\Grid;
use Encore\Admin\Layout\Content;
use Encore\Admin\Show;

class AgentLevelController extends Controller
{
    use HasResourceActions;

    /**
     * Index interface.
     *
     * @param Content $content
     * @return Content
     */
    public function index(Content $content)
    {
        return $content
            ->header('代理商等级')
            ->description('列表')
            ->body($this->grid());
    }

    /**
     * Show interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function show($id, Content $content)
    {
        return $content
            ->header('操作记录')
            ->description('description')
            ->body($this->detail($id));
    }

    /**
     * Edit interface.
     *
     * @param mixed $id
     * @param Content $content
     * @return Content
     */
    public function edit($id, Content $content)
    {
        return $content
            ->header('代理商等级')
            ->description('编辑')
            ->body($this->form()->edit($id));
    }

    /**
     * Create interface.
     *
     * @param Content $content
     * @return Content
     */
    public function create(Content $content)
    {
        return $content
            ->header('创建')
            ->description('代理商等级')
            ->body($this->form());
    }

    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        $grid = new Grid(new AgentLevel);
        $grid->name('等级');
        $grid->first_min_amount('预充值(万元)')->display(function ($amount){
            return $amount/10000;
        });
        $grid->discount('享受折扣(折)');
        $grid->updated_at('操作时间');
        $grid->disableFilter();
        $grid->disableExport();
        $grid->disableRowSelector();
        $grid->actions(function ($actions) {
            $actions->disableDelete();
            $actions->disableView();
        });
        $grid->disableExport();
        return $grid;
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     * @return Show
     */
    protected function detail($id)
    {
        $show = new Show(AgentLevel::findOrFail($id));



        return $show;
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        $form = new Form(new AgentLevel);
        $form->text('name','代理商等级');
        $form->number('discount','享受折扣')->min(0)->max(10);
        $form->number('first_min_amount','预充值金额')->min(0)->max(10000000000);
        $form->tools(function (Form\Tools $tools) {
            // 去掉返回按钮
            $tools->disableView();
        });
        return $form;
    }

    public function destroy($id)
    {
        $agent=Agent::where('level_id',$id)->first();
        if($agent){
            $data = [
                'status'  => false,
                'message' => '很抱歉,您选择的等级下有代理商,无法删除!',
            ];
            return response()->json($data);
        }
        if ($this->form()->destroy($id)) {
            $data = [
                'status'  => true,
                'message' => trans('admin.delete_succeeded'),
            ];
        } else {
            $data = [
                'status'  => false,
                'message' => trans('admin.delete_failed'),
            ];
        }

        return response()->json($data);
    }


}

This snippet took 0.00 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).