ArticleController.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564
  1. <?php
  2. namespace App\Admin\Controllers\Content;
  3. use App\Admin\Extensions\Form\ValidateForm;
  4. use App\Http\Controllers\Controller;
  5. use App\Models\Article;
  6. use App\Models\ArticleCategory;
  7. use App\Models\ArticleProperty;
  8. use App\Models\Subsite;
  9. use App\Models\SubsiteArticle;
  10. use Encore\Admin\Controllers\HasResourceActions;
  11. use Encore\Admin\Facades\Admin as userAdmin;
  12. use Encore\Admin\Form;
  13. use Encore\Admin\Grid;
  14. use Encore\Admin\Layout\Content;
  15. use Encore\Admin\Show;
  16. use Illuminate\Http\Request;
  17. use Illuminate\Support\Facades\Cache;
  18. class ArticleController extends Controller
  19. {
  20. use HasResourceActions;
  21. /**
  22. * Index interface.
  23. *
  24. * @param Content $content
  25. * @return Content
  26. */
  27. public function index(Content $content)
  28. {
  29. return $content
  30. ->header('新闻列表')
  31. ->description(' ')
  32. ->body(view('admin.content.article')->with(['grid'=>$this->grid()]));
  33. }
  34. /**
  35. * Show interface.
  36. *
  37. * @param mixed $id
  38. * @param Content $content
  39. * @return Content
  40. */
  41. public function show($id, Content $content)
  42. {
  43. return $content
  44. ->header('新闻')
  45. ->description(' ')
  46. ->body($this->detail($id));
  47. }
  48. /**
  49. * Edit interface.
  50. *
  51. * @param mixed $id
  52. * @param Content $content
  53. * @return Content
  54. */
  55. public function edit($id, Content $content)
  56. {
  57. return $content
  58. ->header('新闻')
  59. ->description(' ')
  60. ->body($this->editForm($id)->edit($id));
  61. }
  62. /**
  63. * Create interface.
  64. *
  65. * @param Content $content
  66. * @return Content
  67. */
  68. public function create(Content $content)
  69. {
  70. return $content
  71. ->header('新闻')
  72. ->description(' ')
  73. ->body($this->form());
  74. }
  75. /**
  76. * Make a grid builder.
  77. *
  78. * @return Grid
  79. */
  80. protected function grid()
  81. {
  82. $grid = new Grid(new Article);
  83. $grid->model()->when(get_subsite_id()>0, function ($query) {
  84. $query->where('subsite_id', get_subsite_id());
  85. })->orderBy('list_order', 'DESC')->orderBy('created_at', 'DESC');
  86. $grid->column('新闻标题')->display(function () {
  87. $style="color:".$this->tit_color.';';
  88. if ($this->tit_b=='1') {
  89. $style .='font-weight:bold;';
  90. }
  91. $cate = ArticleCategory::where(array('id'=>$this->type_id))->first();
  92. if ($this->parent_id=='0') {
  93. $params = '?type_id=&parent_id='.$this->type_id;
  94. } else {
  95. $params = '?type_id='.$this->type_id.'&parent_id='.$this->parent_id;
  96. }
  97. $title_url = url(admin_base_path().'/content/article/index'.$params);
  98. if ($cate) {
  99. return '<a href='.$title_url.' style="color: #006699;">['.$cate->category_name.']</a> <span style="'.$style.'">'.$this->title.'</span>';
  100. } else {
  101. return '<span style="'.$style.'">'.$this->title.'</span>';
  102. }
  103. })->width(200);
  104. $grid->small_img('缩略图')->display(function () {
  105. if ($this->small_img) {
  106. return '<span class="vtip" title="<img src=\''.upload_asset($this->small_img).'\' height=120>">
  107. <img class="avatar small" src="'.upload_asset($this->small_img).'" align="absmiddle" style="width: 22px;height: 22px;">
  108. </span>';
  109. } else {
  110. return '';
  111. }
  112. });
  113. $grid->robot('添加方式');
  114. $grid->show_property()->category_name('新闻属性');
  115. if (get_subsite_open()) {
  116. $grid->subsite_id('所属分站')->display(function () {
  117. $subsites = Cache::get('subsites_list');
  118. if (array_has($subsites, $this->subsite_id)) {
  119. return $subsites[$this->subsite_id]['sitename'];
  120. }
  121. return '';
  122. });
  123. }
  124. $grid->list_order('排序');
  125. $grid->click('点击量');
  126. $grid->created_at('添加时间');
  127. //新增按钮
  128. if (userAdmin::user()->can('content_article_list_create')) {
  129. $grid->disableCreateButton(false);
  130. }
  131. //批量删除
  132. if (userAdmin::user()->can('content_article_list_delete')) {
  133. $grid->tools(function ($tools) {
  134. $tools->batch(function ($batch) {
  135. $batch->disableDelete(false);
  136. });
  137. });
  138. } else {
  139. $grid->disableRowSelector();
  140. }
  141. $grid->actions(function ($actions) {
  142. if (userAdmin::user()->can('content_article_list_delete')) {
  143. if ($actions->row['subsite_id']== get_subsite_id() || get_subsite_id()==0) {
  144. $actions->disableEdit(false);
  145. }
  146. }
  147. if (userAdmin::user()->can('content_article_list_edit')) {
  148. if ($actions->row['subsite_id']== get_subsite_id() || get_subsite_id()==0) {
  149. $actions->disableDelete(false);
  150. }
  151. }
  152. });
  153. $grid->filter(function ($filter) {
  154. $filter->disableIdFilter();
  155. $filter->equal('ID', '新闻ID');
  156. $filter->like('title', '新闻标题');
  157. $not_ids = ArticleCategory::categoryIds();
  158. if ($not_ids) {
  159. $cate_option = ArticleCategory::where('parent_id', '0')->WhereNotIn('id', $not_ids)->get()->pluck('category_name', 'id');
  160. } else {
  161. $cate_option = ArticleCategory::where('parent_id', '0')->get()->pluck('category_name', 'id');
  162. }
  163. /*$filter->where(function ($query) {
  164. $query->where('parent_id', '=', "{$this->input}")->orWhere('type_id', '=', "{$this->input}");
  165. }, '新闻分类', 'parent_id')->select($cate_option)->load('type_id', 'get_category', 'id', 'category_name');
  166. $pid = \Illuminate\Support\Facades\Request::input('parent_id');
  167. if ($pid) {
  168. $child_cates = ArticleCategory::where(array('parent_id'=>$pid))->get(['id', 'category_name'])->toArray();
  169. } else {
  170. $child_cates = array();
  171. }
  172. $pre_arr = array('id'=>'','category_name'=>'不限');
  173. array_unshift($child_cates, $pre_arr);
  174. $filter->equal('type_id', '新闻子分类')->select(collect($child_cates)->pluck('category_name', 'id'));*/
  175. /*$menuModel = config('admin.database.menu_model');
  176. $form->select('parent_id', trans('admin.parent_id'))->options($menuModel::selectOptions());*/
  177. $article_cates = ArticleCategory::selectOptions(function ($query) {
  178. return $query->orderBy('list_order', 'desc')->orderBy('created_at', 'desc');
  179. });
  180. if (array_has($article_cates, '0')) {
  181. unset($article_cates[0]);
  182. }
  183. $filter->where(function ($query) {
  184. $query->where('parent_id', '=', "{$this->input}")->orWhere('type_id', '=', "{$this->input}");
  185. }, '新闻分类', 'parent_id')->select($article_cates);
  186. $property_option = ArticleProperty::orderBy('list_order', 'DESC')->orderBy('created_at', 'DESC')->pluck('category_name', 'id');
  187. $filter->equal('property_id', '新闻属性')->select($property_option)->default('');
  188. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  189. if ($subsites) {
  190. $subsites = array('' => '不限', '0' => '总站') + $subsites;
  191. $filter->equal('subsite_id', '所属分站')->select($subsites);
  192. }
  193. $date3 = date('Y-m-d', strtotime("-3 day"));
  194. $date7 = date('Y-m-d', strtotime("-7 day"));
  195. $date30 = date("Y-m-d", strtotime("-1 month"));
  196. $date180 = date("Y-m-d", strtotime("-6 month"));
  197. $date360 = date("Y-m-d", strtotime("-1 year"));
  198. $date_option = array(
  199. '' => '不限',
  200. $date3 => '三天内',
  201. $date7 => '一周内',
  202. $date30 => '一月内',
  203. $date180 => '半年内',
  204. $date360 => '一年内',
  205. );
  206. $filter->where(function ($query) {
  207. $query->where('created_at', '>=', "{$this->input}");
  208. }, '添加时间', 'created_at')->radio($date_option);
  209. });
  210. return $grid;
  211. }
  212. public function getCategory(Request $request)
  213. {
  214. $parent_id = $request->input('q');
  215. $where = array('parent_id'=>$parent_id);
  216. $not_ids = ArticleCategory::categoryIds();
  217. if ($not_ids) {
  218. $cates = ArticleCategory::where($where)->WhereNotIn('id', $not_ids)->get(['id', 'category_name'])->toArray();
  219. } else {
  220. $cates = ArticleCategory::where($where)->get(['id', 'category_name'])->toArray();
  221. }
  222. $pre_arr = array('id'=>'','category_name'=>'不限');
  223. array_unshift($cates, $pre_arr);
  224. return collect($cates);
  225. }
  226. /**
  227. * Make a show builder.
  228. *
  229. * @param mixed $id
  230. * @return Show
  231. */
  232. protected function detail($id)
  233. {
  234. $show = new Show(Article::findOrFail($id));
  235. $show->id('ID');
  236. $show->title('标题');
  237. $show->tit_color('标题颜色')->as(function ($tit_color) {
  238. $html = '<i style="background-color: '.$tit_color.';padding: 5px 15px;"></i>';
  239. return $html;
  240. })->setEscape(false);
  241. $show->show_category("新闻分类")->as(function ($show_category) {
  242. return $show_category->category_name;
  243. });
  244. $show->small_img('缩略图')->image();
  245. if (get_subsite_open()) {
  246. $show->subsite_id('所属分站')->as(function ($subsite_id) {
  247. if ($subsite_id) {
  248. $Subsite = Subsite::findOrFail($subsite_id);
  249. return $Subsite->sitename;
  250. }
  251. return '总站';
  252. });
  253. }
  254. $show->content('内容')->setEscape(false);
  255. $show->is_display('是否显示')->as(function ($is_display) {
  256. return $is_display?'是':'否';
  257. });
  258. $show->tit_b('标题加粗')->as(function ($tit_b) {
  259. return $tit_b?'是':'否';
  260. });
  261. $show->released_at('发布日期');
  262. $show->list_order('新闻排序');
  263. $show->author('作者')->as(function ($author) {
  264. return $author?$author:'&nbsp';
  265. })->setEscape(false);
  266. $show->source('来源')->as(function ($source) {
  267. return $source?$source:'&nbsp';
  268. })->setEscape(false);
  269. $show->show_property("新闻属性")->as(function ($show_property) {
  270. return $show_property->category_name;
  271. });
  272. $show->is_url('外部链接')->as(function ($is_url) {
  273. return $is_url?$is_url:'&nbsp';
  274. })->setEscape(false);
  275. $show->seo_keywords('Keywords')->as(function ($seo_keywords) {
  276. return $seo_keywords?$seo_keywords:'&nbsp';
  277. })->setEscape(false);
  278. $show->seo_description('Description')->as(function ($seo_description) {
  279. return $seo_description?$seo_description:'&nbsp';
  280. })->setEscape(false);
  281. $show->click('点击量');
  282. $show->created_at('添加时间');
  283. $show->updated_at('更新时间');
  284. return $show;
  285. }
  286. /**
  287. * Make a form builder.
  288. *
  289. * @return Form
  290. */
  291. protected function form()
  292. {
  293. $form = new ValidateForm(new Article);
  294. $form->text('title', '新闻标题')->rules('required|max:100', array('required'=>'新闻标题不能为空。','max'=>'新闻标题长度不能大于100。'))->setWidth(4)->setMustMark();
  295. $form->color('tit_color', '标题颜色')->rules('required|regex:/^#[a-fA-F0-9]{6}$/', array('required'=>'标题颜色不能为空。','regex'=>'标题颜色格式不正确。'))->default('#000000');
  296. //$cate_option = ArticleCategory::selectOptions();
  297. $cate_option = ArticleCategory::selectOptions(function ($query) {
  298. return $query->orderBy('list_order', 'desc')->orderBy('created_at', 'desc');
  299. });
  300. unset($cate_option[0]);
  301. $form->select('type_id', '新闻分类')->options($cate_option)->default(key($cate_option))->rules('required', array('required'=>'请选择新闻分类。'))->setWidth(4)->setMustMark();
  302. $form->image('small_img', '缩略图')->uniqueName()->rules('image|mimes:jpeg,bmp,png', array('image'=>'缩略图请选择图片文件。','mimes'=>'请选择jpeg,bmp,png格式的缩略图上传。'))->setWidth(3);
  303. if (get_subsite_id()==0) {
  304. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id');
  305. } else {
  306. $subsites = Subsite::where(array(array('effective','=',1),array('id','<>', get_subsite_id())))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  307. $subsites['0']= '总站';
  308. $subsites = collect($subsites);
  309. }
  310. if ($subsites->isNotEmpty() && get_subsite_id()==0) {
  311. $form->multipleSelect('relate_subsites', '同步分站')->options($subsites);
  312. } else {
  313. $form->hidden('relate_subsites');
  314. }
  315. $form->ignore(['relate_subsites']);
  316. $form->hidden('subsite_id')->value(get_subsite_id());
  317. $form->hidden('parent_id')->value(0);
  318. $form->editor('content', '内容')->rules('required', array('required'=>'内容不能为空。'))->setMustMark();
  319. $display_option = [
  320. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  321. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  322. ];
  323. $form->switch('is_display', '是否显示')->states($display_option)->default('1')->setMustMark();
  324. $form->switch('tit_b', '标题加粗')->states($display_option)->default(0)->setMustMark();
  325. $form->date('released_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'))->default(date('Y-m-d', time()));
  326. $form->number('list_order', '新闻排序')->min(0)->default(255)->rules('required', array('required'=>'新闻排序不能为空。'))->help('(数字越大越靠前)');
  327. $form->text('author', '作者')->rules('max:20', array('max'=>'作者长度不能大于20。'))->setWidth(4);
  328. $form->text('source', '来源')->rules('max:20', array('max'=>'来源长度不能大于20。'))->setWidth(4);
  329. $cate_option = ArticleProperty::orderBy('list_order', 'DESC')->orderBy('created_at', 'DESC')->pluck('category_name', 'id');
  330. $form->select('property_id', '新闻属性')
  331. ->options($cate_option)
  332. ->default(key($cate_option->toArray()))
  333. ->rules('required', array('required'=>'请选择新闻属性。'))
  334. ->setWidth(4)
  335. ->setMustMark();
  336. $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
  337. $form->text('seo_keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
  338. $form->textarea('seo_description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
  339. $form->saving(function (Form $form) {
  340. $form->released_at = strtotime($form->released_at);
  341. $author = $form->author?$form->author:'';
  342. $source = $form->source?$form->source:'';
  343. $is_url = $form->is_url?$form->is_url:'';
  344. $seo_keywords = $form->seo_keywords?$form->seo_keywords:'';
  345. $seo_description = $form->seo_description?$form->seo_description:'';
  346. $form->author = $author;
  347. $form->source = $source;
  348. $form->is_url = $is_url;
  349. $form->seo_keywords = $seo_keywords;
  350. $form->seo_description = $seo_description;
  351. $type_info = ArticleCategory::find($form->type_id);
  352. $parent_id = $type_info->parent_id;
  353. $form->parent_id = $parent_id;
  354. });
  355. $form->saved(function (Form $form) {
  356. $subsites = \Illuminate\Support\Facades\Request::input('relate_subsites');
  357. if (empty($subsites)) {
  358. $subsites = [];
  359. }
  360. $subsites = array_merge(array(get_subsite_id()), $subsites);
  361. $set_data = array();
  362. foreach ($subsites as $k => $v) {
  363. if ($v !== null) {
  364. $set_data[] = array(
  365. 'article_id' => $form->model()->id,
  366. 'subsite_id'=> $v
  367. );
  368. }
  369. Cache::forget('article_index_list_home_'.$v); //清除缓存
  370. }
  371. SubsiteArticle::insert($set_data);
  372. });
  373. $form->footer(function ($footer) {
  374. $footer->disableViewCheck();
  375. $footer->disableEditingCheck();
  376. $footer->disableCreatingCheck();
  377. $footer->disableReset();
  378. });
  379. return $form;
  380. }
  381. protected function editForm($id)
  382. {
  383. $info = Article::find($id);
  384. $form = new ValidateForm(new Article);
  385. $form->text('title', '新闻标题')->rules('required|max:100', array('required'=>'新闻标题不能为空。','max'=>'新闻标题长度不能大于100。'))->setWidth(4)->setMustMark();
  386. $form->color('tit_color', '标题颜色')->default('#000000')->rules('required|regex:/^#[a-fA-F0-9]{6}$/', array('required'=>'标题颜色不能为空。','regex'=>'标题颜色格式不正确。'));
  387. //$cate_option = ArticleCategory::all()->pluck('category_name', 'id');
  388. //$cate_option = ArticleCategory::selectOptions();
  389. $cate_option = ArticleCategory::selectOptions(function ($query) {
  390. return $query->orderBy('list_order', 'desc')->orderBy('created_at', 'desc');
  391. });
  392. unset($cate_option[0]);
  393. $form->select('type_id', '新闻分类')->options($cate_option)->default(key($cate_option))->rules('required', array('required'=>'请选择新闻分类。'))->setWidth(4)->setMustMark();
  394. $form->image('small_img', '缩略图')->uniqueName()->rules('image|mimes:jpeg,bmp,png', array('image'=>'缩略图请选择图片文件。','mimes'=>'请选择jpeg,bmp,png格式的缩略图上传。'))->setWidth(3);
  395. if ($info->subsite_id==0) {
  396. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id');
  397. } else {
  398. $subsites = Subsite::where(array(array('effective','=',1),array('id','<>', $info->subsite_id)))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  399. $subsites['0']= '总站';
  400. $subsites = collect($subsites);
  401. }
  402. if ($subsites->isNotEmpty() && $info->subsite_id==0) {
  403. $relations = SubsiteArticle::where(array('article_id'=>$id))->get()->pluck('subsite_id')->toArray();
  404. $form->multipleSelect('relate_subsites', '同步分站')->options($subsites)->default($relations);
  405. } else {
  406. $form->hidden('relate_subsites');
  407. }
  408. $form->ignore(['relate_subsites']);
  409. $form->hidden('subsite_id')->value(get_subsite_id());
  410. $form->hidden('parent_id');
  411. $form->editor('content', '内容')->rules('required', array('required'=>'内容不能为空。'))->setMustMark();
  412. $display_option = [
  413. 'on' => ['value' => 1, 'text' => '是', 'color' => 'success'],
  414. 'off' => ['value' => 0, 'text' => '否', 'color' => 'danger'],
  415. ];
  416. $form->switch('is_display', '是否显示')->states($display_option)->setMustMark();
  417. $form->switch('tit_b', '标题加粗')->states($display_option)->setMustMark();
  418. $form->date('released_at', '发布日期')->format('YYYY-MM-DD')->rules('required|date', array('required'=>'发布日期不能为空。', 'date'=>'发布日期格式不正确。'));
  419. $form->number('list_order', '新闻排序')->min(0)->default(0)->rules('required', array('required'=>'新闻排序不能为空。'))->help('(数字越大越靠前)');
  420. $form->text('author', '作者')->rules('max:20', array('max'=>'作者长度不能大于20。'))->setWidth(3);
  421. $form->text('source', '来源')->rules('max:20', array('max'=>'来源长度不能大于20。'))->setWidth(3);
  422. $cate_option = ArticleProperty::orderBy('list_order', 'DESC')->orderBy('created_at', 'DESC')->pluck('category_name', 'id');
  423. $form->select('property_id', '新闻属性')->options($cate_option)->default(key($cate_option->toArray()))->rules('required', array('required'=>'请选择新闻属性。'))->setWidth(3)->setMustMark();
  424. $form->url('is_url', '外部链接')->rules('max:250', array('max'=>'外部链接长度不能超过250。'))->help('(请输入包含http://或https://的完整链接)');
  425. $form->text('seo_keywords', 'Keywords')->placeholder('合理设置Keywords有利于搜索引擎排名')->rules('max:80', array('max:Keywords不能大于80个字符。'));
  426. $form->textarea('seo_description', 'Description')->placeholder('合理设置Description有利于搜索引擎排名')->rules('max:80', array('max'=>'Description不能大于80个字符。'));
  427. $form->saving(function (Form $form) {
  428. if (!request()->has(Form\Field::FILE_DELETE_FLAG)) {
  429. $form->released_at = strtotime($form->released_at);
  430. $author = $form->author?$form->author:'';
  431. $source = $form->source?$form->source:'';
  432. $is_url = $form->is_url?$form->is_url:'';
  433. $seo_keywords = $form->seo_keywords?$form->seo_keywords:'';
  434. $seo_description = $form->seo_description?$form->seo_description:'';
  435. $form->author = $author;
  436. $form->source = $source;
  437. $form->is_url = $is_url;
  438. $form->seo_keywords = $seo_keywords;
  439. $form->seo_description = $seo_description;
  440. $type_info = ArticleCategory::find($form->type_id);
  441. $parent_id = $type_info->parent_id;
  442. $form->parent_id = $parent_id;
  443. }
  444. });
  445. $form->saved(function (Form $form) {
  446. if (!request()->has(Form\Field::FILE_DELETE_FLAG)) {
  447. $subsites = \Illuminate\Support\Facades\Request::input('relate_subsites');
  448. if (empty($subsites)) {
  449. $subsites = [];
  450. }
  451. $subsites = array_merge(array($form->model()->subsite_id), $subsites);
  452. SubsiteArticle::where('article_id', $form->model()->id)->delete();
  453. $set_data = array();
  454. foreach ($subsites as $k => $v) {
  455. if ($v !== null) {
  456. $set_data[] = array(
  457. 'article_id' => $form->model()->id,
  458. 'subsite_id'=> $v
  459. );
  460. }
  461. Cache::forget('article_index_list_home_'.$v); //清除缓存
  462. }
  463. SubsiteArticle::insert($set_data);
  464. }
  465. });
  466. $form->footer(function ($footer) {
  467. $footer->disableViewCheck();
  468. $footer->disableEditingCheck();
  469. $footer->disableCreatingCheck();
  470. $footer->disableReset();
  471. });
  472. $form->tools(function (Form\Tools $tools) {
  473. $tools->disableDelete();
  474. $tools->disableView();
  475. });
  476. return $form;
  477. }
  478. public function update($id)
  479. {
  480. return $this->editForm($id)->update($id);
  481. }
  482. public function destroy($id)
  483. {
  484. $ids = array();
  485. if ($id) {
  486. $ids = explode(',', $id);
  487. }
  488. if (get_subsite_id() == 0) {
  489. $filter_id = $id;
  490. } else {
  491. $seletctors = Article::where(array('subsite_id'=>get_subsite_id()))->whereIn('id', $ids)->get()->pluck('id')->toarray();
  492. if ($seletctors) {
  493. $filter_id = implode(',', $seletctors);
  494. } else {
  495. $filter_id = '';
  496. }
  497. }
  498. //获取所有分站信息
  499. $subsites = Subsite::where(array('effective'=>1))->orderBy('order', 'asc')->get()->pluck('sitename', 'id')->toArray();
  500. if ($subsites) {
  501. foreach ($subsites as $key => $val) {
  502. Cache::forget('article_index_list_home_'.$key);
  503. }
  504. }
  505. if ($filter_id) {
  506. if ($this->form()->destroy($filter_id)) {
  507. $data = [
  508. 'status' => true,
  509. 'message' => trans('admin.delete_succeeded'),
  510. ];
  511. } else {
  512. $data = [
  513. 'status' => false,
  514. 'message' => trans('admin.delete_failed'),
  515. ];
  516. }
  517. } else {
  518. $data = [
  519. 'status' => false,
  520. 'message' => '不能删除其它分站数据!',
  521. ];
  522. }
  523. return response()->json($data);
  524. }
  525. }