Message.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | framework
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2014~2018 广州楚才信息科技有限公司 [ http://www.cuci.cc ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://framework.thinkadmin.top
  8. // +----------------------------------------------------------------------
  9. // | 开源协议 ( https://mit-license.org )
  10. // +----------------------------------------------------------------------
  11. // | github开源项目:https://github.com/zoujingli/framework
  12. // +----------------------------------------------------------------------
  13. namespace app\admin\controller;
  14. use library\Controller;
  15. use think\Db;
  16. /**
  17. * 系统消息管理
  18. * Class Message
  19. * @package app\admin\controller
  20. */
  21. class Message extends Controller
  22. {
  23. /**
  24. * 指定数据表
  25. * @var string
  26. */
  27. protected $table = 'SystemMessage';
  28. /**
  29. * 系统消息管理
  30. * @throws \think\Exception
  31. * @throws \think\db\exception\DataNotFoundException
  32. * @throws \think\db\exception\ModelNotFoundException
  33. * @throws \think\exception\DbException
  34. * @throws \think\exception\PDOException
  35. */
  36. public function index()
  37. {
  38. $this->title = '系统消息管理';
  39. $query = $this->_query($this->table)->like('title,desc')->equal('read_state');
  40. $query->dateBetween('create_at,read_at')->order('id desc')->page();
  41. }
  42. /**
  43. * 设置消息状态
  44. */
  45. public function read()
  46. {
  47. $this->_save($this->table, ['read_state' => '1', 'read_at' => date('Y-m-d H:i:s')]);
  48. }
  49. /**
  50. * 清理所有消息
  51. * @throws \think\Exception
  52. * @throws \think\exception\PDOException
  53. */
  54. public function clear()
  55. {
  56. if (Db::name($this->table)->whereRaw('1=1')->delete() !== false) {
  57. $this->success('系统消息清理成功!');
  58. } else {
  59. $this->error('系统消息清理失败,请稍候再试!');
  60. }
  61. }
  62. /**
  63. * 设置消息开关
  64. * @throws \think\Exception
  65. * @throws \think\exception\PDOException
  66. */
  67. public function state()
  68. {
  69. sysconf('system_message_state', sysconf('system_message_state') ? 0 : 1);
  70. if (sysconf('system_message_state')) {
  71. $this->success('系统消息提示开启成功!');
  72. } else {
  73. $this->success('系统消息提示关闭成功!');
  74. }
  75. }
  76. /**
  77. * 删除系统消息
  78. */
  79. public function remove()
  80. {
  81. $this->_delete($this->table);
  82. }
  83. }