| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242 | 
							- <?php
 
- namespace App\Admin\Controllers\System;
 
- use App\Http\Controllers\Controller;
 
- use App\Models\Hotword;
 
- use Encore\Admin\Controllers\HasResourceActions;
 
- use Encore\Admin\Facades\Admin;
 
- use Encore\Admin\Form;
 
- use Encore\Admin\Grid;
 
- use Encore\Admin\Layout\Content;
 
- use Encore\Admin\Show;
 
- class HotwordController 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('')
 
-             ->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->editForm()->edit($id));
 
-     }
 
-     /**
 
-      * Create interface.
 
-      *
 
-      * @param Content $content
 
-      * @return Content
 
-      */
 
-     public function create(Content $content)
 
-     {
 
-         return $content
 
-             ->header('热门关键字创建')
 
-             ->description('')
 
-             ->body($this->createForm());
 
-     }
 
-     /**
 
-      * Make a grid builder.
 
-      *
 
-      * @return Grid
 
-      */
 
-     protected function grid()
 
-     {
 
-         $grid = new Grid(new Hotword);
 
-         $grid->model()->orderBy('list_order', 'DESC')->orderBy('w_hot', 'DESC');
 
-         $grid->id('ID');
 
-         $grid->w_word('关键词')->width(150);
 
-         $grid->type('搜索类型')->width(150)->display(function () {
 
-             if ($this->type == '2') {
 
-                 return '企业搜索';
 
-             } elseif ($this->type == '3') {
 
-                 return '个人简历搜索';
 
-             } elseif ($this->type == '1') {
 
-                 return '职位搜索';
 
-             } else {
 
-                 return '资讯搜索';
 
-             }
 
-         });
 
-         $grid->w_hot('搜索次数')->width(200);
 
-         $grid->list_order('显示顺序')->editable()->width(150);
 
-         $grid->created_at('添加时间');
 
-         $grid->updated_at('更新时间');
 
-         $grid->actions(function ($actions) use ($grid) {
 
-             if (Admin::user()->can('system_hotword_edit')) {
 
-                 $actions->disableEdit(false);
 
-             }
 
-             if (Admin::user()->can('system_hotword_delete')) {
 
-                 $actions->disableDelete(false);
 
-             }
 
-             $actions->disableView();
 
-         });
 
-         $grid->filter(function ($filter) {
 
-             $type_option = ['' => '不限', '1' => '职位搜索', '2' => '企业搜索', '3' => '个人简历搜索', '4' => '资讯搜索'];
 
-             $filter->equal('type', '类型')->select($type_option)->default('');
 
-         });
 
-         if (Admin::user()->can('system_hotword_delete')) {
 
-             $grid->tools(function ($tools) {
 
-                 $tools->batch(function ($batch) {
 
-                     $batch->disableDelete(false);
 
-                 });
 
-             });
 
-             $grid->disableRowSelector(false);
 
-         }
 
-         if (Admin::user()->can('system_hotword_create')) {
 
-             $grid->disableCreateButton(false);
 
-         }
 
-         return $grid;
 
-     }
 
-     /**
 
-      * Make a show builder.
 
-      *
 
-      * @param mixed $id
 
-      * @return Show
 
-      */
 
-     protected function detail($id)
 
-     {
 
-         $show = new Show(Hotword::findOrFail($id));
 
-         $show->id('ID');
 
-         $show->w_word('关键词');
 
-         $show->type('搜索类型')->as(function ($type) {
 
-             if ($type == 2) {
 
-                 return '企业搜索';
 
-             } elseif ($type == 3) {
 
-                 return '个人简历搜索';
 
-             } elseif ($type == 1) {
 
-                 return '职位搜索';
 
-             } else {
 
-                 return '资讯搜索';
 
-             }
 
-         });
 
-         $show->w_hot('搜索次数');
 
-         $show->list_order('显示顺序');
 
-         return $show;
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function form()
 
-     {
 
-         $form = new Form(new Hotword);
 
-         $form->display('ID');
 
-         $form->display('Created at');
 
-         $form->display('Updated at');
 
-         return $form;
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function editForm()
 
-     {
 
-         $form = new Form(new Hotword);
 
-         $form->text('w_word', '关键词')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         //搜索类型
 
-         $type_arr = ['1' => '职位搜索', '2' => '企业搜索', '3' => '个人简历搜索', '4' => '资讯搜索'];
 
-         $form->select('type', '搜索类型')
 
-             ->options($type_arr)
 
-             ->rules('required', ['required' => '请选择搜索类型。'])
 
-             ->setWidth(3)
 
-             ->setMustMark();
 
-         $form->number('w_hot', '搜索次数')->min(0)->default(0);
 
-         $form->number('list_order', '显示排序')->min(0)->default(0)->help('(越大越靠前)');
 
-         return $form;
 
-     }
 
-     protected function createForm()
 
-     {
 
-         $form = new Form(new Hotword);
 
-         $form->text('w_word', '关键词')->rules([
 
-             'required',
 
-         ])->setWidth(3)->setMustMark();
 
-         //搜索类型
 
-         $type_arr = ['1' => '职位搜索', '2' => '企业搜索', '3' => '个人简历搜索', '4' => '资讯搜索'];
 
-         $form->select('type', '搜索类型')
 
-             ->options($type_arr)
 
-             ->default(key($type_arr))
 
-             ->rules('required', ['required' => '请选择搜索类型。'])
 
-             ->setWidth(3)
 
-             ->setMustMark();
 
-         $form->number('w_hot', '搜索次数')->min(0)->default(0);
 
-         $form->number('list_order', '显示排序')->min(0)->default(0)->help('(越大越靠前)');
 
-         return $form;
 
-     }
 
-     /**
 
-      * Store a newly created resource in storage.
 
-      *
 
-      * @return mixed
 
-      */
 
-     public function store()
 
-     {
 
-         return $this->createForm()->store();
 
-     }
 
-     /**
 
-      * Update the specified resource in storage.
 
-      *
 
-      * @param int $id
 
-      *
 
-      * @return \Illuminate\Http\Response|\Symfony\Component\HttpFoundation\Response
 
-      */
 
-     public function update($id)
 
-     {
 
-         return $this->editForm()->update($id);
 
-     }
 
- }
 
 
  |