Notice.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace app\admin\controller;
  3. use app\data\model\DataNotice as DataXw;
  4. use think\admin\Controller;
  5. /**
  6. * 公告
  7. * Class Xw
  8. * @package app\admin\controller\Notice
  9. */
  10. class Notice extends Controller
  11. {
  12. /**
  13. * 公告列表
  14. * @auth true
  15. * @menu true
  16. */
  17. public function index(){
  18. $this->title='公告列表';
  19. DataXw::mQuery()
  20. ->like('title')
  21. ->dateBetween('create_time')->layTable();
  22. }
  23. /**
  24. * 公告添加
  25. * @auth true
  26. * @menu true
  27. */
  28. public function add(){
  29. $this->xw_vali();
  30. DataXw::mForm('form');
  31. }
  32. /**
  33. * 公告编辑
  34. * @auth true
  35. * @menu true
  36. */
  37. public function edit(){
  38. $this->xw_vali();
  39. DataXw::mForm('form');
  40. }
  41. protected function xw_vali(){
  42. if($this->request->isPost()){
  43. $this->_vali([
  44. 'title.max:50'=>'标题过长',
  45. 'summary.require'=>'概要必须',
  46. 'summary.max:250'=>'概要最长250',
  47. 'content.require'=>'内容必须',
  48. ]);
  49. }
  50. }
  51. /**
  52. * 公告删除
  53. * @auth true
  54. * @menu true
  55. */
  56. public function remove(){
  57. $ids=$this->request->post('id');
  58. // DataXw::whereIn('id',$ids)->select()->each(function ($d){$d->delete();});
  59. DataXw::whereIn('id',$ids)->delete();
  60. $this->success('删除成功');
  61. }
  62. /**
  63. * 表单结果处理
  64. * @param boolean $state
  65. */
  66. protected function _form_result(bool $state)
  67. {
  68. if ($state) {
  69. $this->success('保存成功!',in_array($this->request->action(),['add','edit'])? 'javascript:history.back()':'');
  70. }
  71. }
  72. }