Notice.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. <?php
  2. namespace app\admin\controller;
  3. use app\admin\model\SinaNotice;
  4. use think\admin\Controller;
  5. use think\admin\service\AdminService;
  6. use think\admin\helper\QueryHelper;
  7. /**
  8. * 通知管理
  9. * Class Notice
  10. * @package app\admin\controller
  11. */
  12. class Notice extends Controller
  13. {
  14. /**
  15. * 设置默认操作表
  16. * @var string
  17. */
  18. private $table = 'SinaNotice';
  19. /**
  20. * 通知管理
  21. * @auth true
  22. * @menu true
  23. * @throws \think\db\exception\DataNotFoundException
  24. * @throws \think\db\exception\DbException
  25. * @throws \think\db\exception\ModelNotFoundException
  26. */
  27. public function index()
  28. {
  29. $this->_query(SinaNotice::class)->layTable(function () {
  30. $this->title = '通知管理';
  31. }, function (QueryHelper $query) {
  32. });
  33. }
  34. /**
  35. * 数据列表处理
  36. * @param array $data
  37. */
  38. protected function _page_filter(array &$data)
  39. {
  40. foreach ($data as &$vo) {
  41. $vo['created_at'] = date('Y-m-d H:i', $vo['created_at']);
  42. $vo['updated_at'] = date('Y-m-d H:i', $vo['updated_at']);
  43. }
  44. }
  45. /**
  46. * 添加通知
  47. * @auth true
  48. * @throws \think\db\exception\DataNotFoundException
  49. * @throws \think\db\exception\DbException
  50. * @throws \think\db\exception\ModelNotFoundException
  51. */
  52. public function add()
  53. {
  54. $this->_applyFormToken();
  55. $this->_form($this->table, 'form');
  56. }
  57. /**
  58. * 编辑通知
  59. * @auth true
  60. * @throws \think\db\exception\DataNotFoundException
  61. * @throws \think\db\exception\DbException
  62. * @throws \think\db\exception\ModelNotFoundException
  63. */
  64. public function edit()
  65. {
  66. $this->_applyFormToken();
  67. $this->_form($this->table, 'form');
  68. }
  69. /**
  70. * 表单数据处理
  71. * @param array $data
  72. * @throws \think\db\exception\DataNotFoundException
  73. * @throws \think\db\exception\DbException
  74. * @throws \think\db\exception\ModelNotFoundException
  75. */
  76. protected function _form_filter(array &$data)
  77. {
  78. if ($this->request->isPost()) {
  79. if (isset($data['id']) && $data['id'] > 0) {
  80. $data['updated_at'] = time();
  81. } else {
  82. $data['created_at'] = time();
  83. $data['updated_at'] = time();
  84. $data['created_by'] = AdminService::instance()->getUserId();
  85. }
  86. } else {
  87. }
  88. }
  89. /**
  90. * 删除通知
  91. * @auth true
  92. * @throws \think\db\exception\DbException
  93. */
  94. public function remove()
  95. {
  96. $this->_checkInput();
  97. $this->_delete($this->table);
  98. }
  99. /**
  100. * 检查输入变量
  101. */
  102. private function _checkInput()
  103. {
  104. }
  105. /**
  106. * 表单结果处理
  107. * @param bool $result
  108. */
  109. protected function _add_form_result(bool $result)
  110. {
  111. if ($result) {
  112. $id = $this->app->db->name($this->table)->getLastInsID();
  113. sysoplog('通知管理', "添加通知[{$id}]成功");
  114. }
  115. }
  116. /**
  117. * 表单结果处理
  118. * @param boolean $result
  119. */
  120. protected function _edit_form_result(bool $result)
  121. {
  122. if ($result) {
  123. $id = input('id') ?: 0;
  124. sysoplog('通知管理', "修改通知[{$id}]成功");
  125. if ($id == AdminService::instance()->getUserId()) {
  126. $this->success('通知修改成功!', 'javascript:location.reload()');
  127. } else {
  128. $this->success('通知修改成功!');
  129. }
  130. }
  131. }
  132. /**
  133. * 删除结果处理
  134. * @param boolean $result
  135. */
  136. protected function _remove_delete_result(bool $result)
  137. {
  138. if ($result) {
  139. $id = input('id') ?: 0;
  140. sysoplog('通知管理', "删除通知[{$id}]成功");
  141. }
  142. }
  143. }