| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409 | 
							- <?php
 
- namespace App\Admin\Controllers\Content;
 
- use App\Admin\Extensions\Form\ValidateForm;
 
- use App\Http\Controllers\Controller;
 
- use App\Models\Notice;
 
- use App\Models\NoticeCategory;
 
- use App\Models\Subsite;
 
- use App\Models\SubsiteNotice;
 
- 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;
 
- use Illuminate\Support\Facades\Cache;
 
- class NoticeController 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($id)->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 Notice);
 
-         $grid->model()->when(get_subsite_id()>0, function ($query) {
 
-             $query->where('subsite_id', get_subsite_id());
 
-         })->orderBy('sort', 'ASC')->orderBy('id', 'DESC');
 
-         $grid->id('ID');
 
-         $grid->column('标题')->display(function () {
 
-             $style="color:".$this->tit_color.';';
 
-             if ($this->tit_b=='1') {
 
-                 $style .='font-weight:bold;';
 
-             }
 
-             return '<a href="'.route(url_rewrite('AIX_noticeshow'),['id'=>$this->id]).'" target="_blank"><span style="'.$style.'">'.$this->title.'</span></a>';
 
-         })->width(400);
 
-         $grid->show_category()->category_name('所属分类');
 
-         if(get_subsite_open()){
 
-             $grid->subsite_id('所属分站')->display(function () {
 
-                 $subsites = Cache::get('subsites_list');
 
-                 if (array_has($subsites, $this->subsite_id)) {
 
-                     return $subsites[$this->subsite_id]['sitename'];
 
-                 }
 
-                 return '';
 
-             });
 
-         }
 
-         $grid->sort('排序');
 
-         $grid->click('点击量');
 
-         $grid->created_at('添加时间');
 
-         if (Admin::user()->can('content_noticemanager_noticle_create')) {
 
-             $grid->disableCreateButton(false);
 
-         }
 
-         if (Admin::user()->can('content_noticemanager_noticle_delete')) {
 
-             $grid->tools(function ($tools) {
 
-                 $tools->batch(function ($batch) {
 
-                     $batch->disableDelete(false);
 
-                 });
 
-             });
 
-         } else {
 
-             $grid->disableRowSelector();
 
-         }
 
-         $grid->actions(function ($actions) {
 
-             if (Admin::user()->can('content_noticemanager_noticle_edit')) {
 
-                 $actions->disableEdit(false);
 
-             }
 
-             if (Admin::user()->can('content_noticemanager_noticle_delete')) {
 
-                 $actions->disableDelete(false);
 
-             }
 
-         });
 
-         $grid->filter(function ($filter) {
 
-             $filter->disableIdFilter();
 
-             $filter->column(1/3, function ($filter) {
 
-                 $cate_option = NoticeCategory::all()->pluck('category_name', 'id');
 
-                 $cate_option = $cate_option->toArray();
 
-                 $cate_option = array('' => '不限') + $cate_option;
 
-                 $filter->equal('type_id', '所属分类')->select($cate_option)->default('');
 
-                 $filter->like('title', '标题');
 
-             });
 
-             $filter->column(2/3, function ($filter) {
 
-                 $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
 
-                 if ($subsites) {
 
-                     $subsites = array('' => '不限', '0' => '总站') + $subsites;
 
-                     $filter->equal('subsite_id', '所属分站')->select($subsites);
 
-                 }
 
-                 $date3 = date('Y-m-d', strtotime("-3 day"));
 
-                 $date7 = date('Y-m-d', strtotime("-7 day"));
 
-                 $date30 = date("Y-m-d", strtotime("-1 month"));
 
-                 $date180 = date("Y-m-d", strtotime("-6 month"));
 
-                 $date360 = date("Y-m-d", strtotime("-1 year"));
 
-                 $date_option = array(
 
-                     '' => '不限',
 
-                     $date3 => '三天内',
 
-                     $date7 => '一周内',
 
-                     $date30 => '一月内',
 
-                     $date180 => '半年内',
 
-                     $date360 => '一年内',
 
-                 );
 
-                 $filter->where(function ($query) {
 
-                     $query->where('created_at', '>=', "{$this->input}");}, '添加时间', 'created_at')->radio($date_option);
 
-             });
 
-         });
 
-         return $grid;
 
-     }
 
-     /**
 
-      * Make a show builder.
 
-      *
 
-      * @param mixed $id
 
-      * @return Show
 
-      */
 
-     protected function detail($id)
 
-     {
 
-         $show = new Show(Notice::findOrFail($id));
 
-         $show->id('ID');
 
-         $show->title('标题')->as(function ($title) {
 
-             return $title;
 
-         });
 
-         $show->tit_color('标题颜色')->as(function ($tit_color) {
 
-             $html = '<i style="background-color: '.$tit_color.';padding: 5px 15px;"></i>';
 
-             return $html;
 
-         })->setEscape(false);
 
-         $show->show_category("所属分类")->as(function ($show_category) {
 
-             return $show_category->category_name;
 
-         });
 
-         if(get_subsite_open()){
 
-             $show->subsite_id('所属分站')->as(function ($subsite_id) {
 
-                 if ($subsite_id) {
 
-                     $Subsite = Subsite::findOrFail($subsite_id);
 
-                     return $Subsite->sitename;
 
-                 }
 
-                 return '总站';
 
-             });
 
-         }
 
-         $show->content('内容')->setEscape(false);
 
-         $show->is_display('是否显示')->as(function ($is_display) {
 
-             return $is_display?'是':'否';
 
-         });
 
-         $show->tit_b('是否加粗')->as(function ($tit_b) {
 
-             return $tit_b?'是':'否';
 
-         });
 
-         $show->sort('排序');
 
-         $show->is_url('外部链接')->as(function ($is_url) {
 
-             return $is_url?$is_url:' ';
 
-         });
 
-         $show->seo_keywords('Keywords')->as(function ($seo_keywords) {
 
-             return $seo_keywords?$seo_keywords:' ';
 
-         });
 
-         $show->seo_description('Description')->as(function ($seo_description) {
 
-             return $seo_description?$seo_description:' ';
 
-         });
 
-         $show->created_at('添加时间');
 
-         $show->updated_at('更新时间');
 
-         return $show;
 
-     }
 
-     /**
 
-      * Make a form builder.
 
-      *
 
-      * @return Form
 
-      */
 
-     protected function form()
 
-     {
 
-         $form = new ValidateForm(new Notice);
 
-         $form->text('title', '标题')->rules('required|max:100', array('required'=>'标题不能为空。', 'max'=>'页面名称长度不能大于100个字符。'))->setWidth(4)->setMustMark();
 
-         $form->color('tit_color', '标题颜色')->default('#000000');
 
-         $cate_option = NoticeCategory::all()->pluck('category_name', 'id');
 
-         $form->select('type_id', '所属分类')->options($cate_option)->default(key($cate_option->toArray()))->setWidth(4)->setMustMark();
 
-         if (get_subsite_open()) {
 
-             if (get_subsite_id()==0) {
 
-                 $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id');
 
-             } else {
 
-                 $subsites = Subsite::where(array(array('effective','=',1),array('id','<>', get_subsite_id())))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
 
-                 $subsites['0']= '总站';
 
-                 $subsites = collect($subsites);
 
-             }
 
-             if ($subsites->isNotEmpty()  && get_subsite_id()==0) {
 
-                 $form->multipleSelect('relate_subsites', '同步分站')->options($subsites);
 
-             } else {
 
-                 $form->hidden('relate_subsites');
 
-             }
 
-         }
 
-         $form->hidden('subsite_id')->value(get_subsite_id());
 
-         $form->editor('content', '内容')->rules('required', array('required'=>'内容不能为空。'))->setMustMark();
 
-         $display_option = [
 
-             'on'  => ['value' => 1, 'text' => '是', 'color' => 'success'],
 
-             'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
 
-         ];
 
-         $form->switch('is_display', '是否显示')->states($display_option)->default('1')->setMustMark();
 
-         $form->switch('tit_b', '标题加粗')->states($display_option)->default(0)->setMustMark();
 
-         $form->number('sort', '排序')->min(1)->max(255)->default(255)->help('(数字越小越靠前)')->setMustMark();
 
-         $form->url('is_url', '外部链接')->help('(请输入包含http://或https://的完整链接)');
 
-         $form->text('seo_keywords', 'Keywords')
 
-             ->placeholder('合理设置Keywords有利于搜索引擎排名')
 
-             ->rules('max:80', array('max:Keywords不能大于80个字符。'));
 
-         $form->textarea('seo_description', 'Description')
 
-             ->placeholder('合理设置Description有利于搜索引擎排名')
 
-             ->rules('max:80', array('max'=>'Description不能大于80个字符。'));
 
-         $form->ignore(['relate_subsites']);
 
-         $form->saved(function (Form $form) {
 
-             $subsites = \Illuminate\Support\Facades\Request::input('relate_subsites');
 
-             if (empty($subsites)) {
 
-                 $subsites = [];
 
-             }
 
-             $subsites = array_merge(array(get_subsite_id()), $subsites);
 
-             $set_data = array();
 
-             foreach ($subsites as $k => $v) {
 
-                 if ($v !== null) {
 
-                     $set_data[] = array(
 
-                         'notice_id' => $form->model()->id,
 
-                         'subsite_id'=> $v
 
-                     );
 
-                 }
 
-             }
 
-             SubsiteNotice::insert($set_data);
 
-         });
 
-         return $form;
 
-     }
 
-     protected function editForm($id)
 
-     {
 
-         $form = new Form(new Notice);
 
-         $info = Notice::find($id);
 
-         $form->text('title', '标题')
 
-             ->rules('required|max:100', array('required'=>'标题不能为空。', 'max'=>'页面名称长度不能大于100个字符。'))->setWidth(4)->setMustMark();
 
-         $form->color('tit_color', '标题颜色');
 
-         $form->radio('type_id', '所属分类')->options(NoticeCategory::all()->pluck('category_name', 'id'))->setMustMark();
 
-         if ($info->subsite_id==0) {
 
-             $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id');
 
-         } else {
 
-             $subsites = Subsite::where(array(array('effective','=',1),array('id','<>', $info->subsite_id)))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
 
-             $subsites['0']= '总站';
 
-             $subsites = collect($subsites);
 
-         }
 
-         if ($subsites->isNotEmpty()  && get_subsite_id()==0) {
 
-             $relations = SubsiteNotice::where(array('notice_id'=>$id))->get()->pluck('subsite_id')->toArray();
 
-             $form->multipleSelect('relate_subsites', '同步分站')->options($subsites)->default($relations);
 
-         } else {
 
-             $form->hidden('relate_subsites');
 
-         }
 
-         $form->hidden('subsite_id')->value(get_subsite_id());
 
-         $form->editor('content', '内容')->rules('required', array('required'=>'内容不能为空。'))->setMustMark();
 
-         $display_option = [
 
-             'on'  => ['value' => 1, 'text' => '是', 'color' => 'success'],
 
-             'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
 
-         ];
 
-         $form->switch('is_display', '是否显示')->states($display_option)->setMustMark();
 
-         $form->switch('tit_b', '标题加粗')->states($display_option)->setMustMark();
 
-         $form->number('sort', '排序')->min(1)->max(255)->help('(数字越小越靠前)')->setMustMark();
 
-         $form->url('is_url', '外部链接')->help('(请输入包含http://或https://的完整链接)');
 
-         $form->text('seo_keywords', 'Keywords')
 
-             ->placeholder('合理设置Keywords有利于搜索引擎排名')
 
-             ->rules('max:80', array('max:Keywords不能大于80个字符。'));
 
-         $form->textarea('seo_description', 'Description')
 
-             ->placeholder('合理设置Description有利于搜索引擎排名')
 
-             ->rules('max:80', array('max'=>'Description不能大于80个字符。'));
 
-         $form->ignore(['relate_subsites']);
 
-         $form->saved(function (Form $form) {
 
-             $subsites = \Illuminate\Support\Facades\Request::input('relate_subsites');
 
-             if (empty($subsites)) {
 
-                 $subsites = [];
 
-             }
 
-             $subsites = array_merge(array($form->model()->subsite_id), $subsites);
 
-             SubsiteNotice::where('notice_id', $form->model()->id)->delete();
 
-             $set_data = array();
 
-             foreach ($subsites as $k => $v) {
 
-                 if ($v !== null) {
 
-                     $set_data[] = array(
 
-                         'notice_id' => $form->model()->id,
 
-                         'subsite_id'=> $v
 
-                     );
 
-                 }
 
-             }
 
-             SubsiteNotice::insert($set_data);
 
-         });
 
-         $form->footer(function ($footer) {
 
-             $footer->disableViewCheck();
 
-             $footer->disableEditingCheck();
 
-             $footer->disableCreatingCheck();
 
-             $footer->disableReset();
 
-         });
 
-         $form->tools(function (Form\Tools $tools) {
 
-             $tools->disableDelete();
 
-             $tools->disableView();
 
-         });
 
-         return $form;
 
-     }
 
-     public function update($id)
 
-     {
 
-         return $this->editForm($id)->update($id);
 
-     }
 
-     public function destroy($id)
 
-     {
 
-         $ids = array();
 
-         if ($id) {
 
-             $ids = explode(',', $id);
 
-         }
 
-         if (get_subsite_id() == 0) {
 
-             $filter_id = $id;
 
-         } else {
 
-             $seletctors = Notice::where(array('subsite_id'=>get_subsite_id()))->whereIn('id', $ids)->get()->pluck('id')->toarray();
 
-             if ($seletctors) {
 
-                 $filter_id = implode(',', $seletctors);
 
-             } else {
 
-                 $filter_id = '';
 
-             }
 
-         }
 
-         if ($filter_id) {
 
-             if ($this->form()->destroy($filter_id)) {
 
-                 $data = [
 
-                     'status'  => true,
 
-                     'message' => trans('admin.delete_succeeded'),
 
-                 ];
 
-             } else {
 
-                 $data = [
 
-                     'status'  => false,
 
-                     'message' => trans('admin.delete_failed'),
 
-                 ];
 
-             }
 
-         } else {
 
-             $data = [
 
-                 'status'  => false,
 
-                 'message' => '不能删除其它分站数据!',
 
-             ];
 
-         }
 
-         return response()->json($data);
 
-     }
 
- }
 
 
  |