Message.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. // +----------------------------------------------------------------------
  3. // | 海豚PHP框架 [ DolphinPHP ]
  4. // +----------------------------------------------------------------------
  5. // | 版权所有 2016~2019 广东卓锐软件有限公司 [ http://www.zrthink.com ]
  6. // +----------------------------------------------------------------------
  7. // | 官方网站: http://dolphinphp.com
  8. // +----------------------------------------------------------------------
  9. namespace app\admin\controller;
  10. use app\common\builder\ZBuilder;
  11. use app\user\model\Message as MessageModel;
  12. /**
  13. * 消息控制器
  14. * @package app\admin\controller
  15. */
  16. class Message extends Admin
  17. {
  18. /**
  19. * 消息中心
  20. * @author 蔡伟明 <314013107@qq.com>
  21. * @return mixed
  22. * @throws \think\Exception
  23. * @throws \think\exception\DbException
  24. */
  25. public function index()
  26. {
  27. $data_list = MessageModel::where($this->getMap())
  28. ->where('uid_receive', UID)
  29. ->order($this->getOrder('id DESC'))
  30. ->paginate();
  31. return ZBuilder::make('table')
  32. ->setTableName('admin_message')
  33. ->addTopButton('enable', ['title' => '设置已阅读'])
  34. ->addTopButton('delete')
  35. ->addRightButton('enable', ['title' => '设置已阅读'])
  36. ->addRightButton('delete')
  37. ->addColumns([
  38. ['uid_send', '发送者', 'callback', 'get_nickname'],
  39. ['type', '分类'],
  40. ['content', '内容'],
  41. ['status', '状态', 'status', '', ['未读', '已读']],
  42. ['create_time', '发送时间', 'datetime'],
  43. ['read_time', '阅读时间', 'datetime'],
  44. ['right_button', '操作', 'btn'],
  45. ])
  46. ->addFilter('type')
  47. ->addFilter('status', ['未读', '已读'])
  48. ->setRowList($data_list)
  49. ->fetch();
  50. }
  51. /**
  52. * 设置已阅读
  53. * @param array $ids
  54. * @author 蔡伟明 <314013107@qq.com>
  55. * @throws \think\Exception
  56. * @throws \think\exception\PDOException
  57. */
  58. public function enable($ids = [])
  59. {
  60. empty($ids) && $this->error('参数错误');
  61. $map = [
  62. ['uid_receive', '=', UID],
  63. ['id', 'in', $ids]
  64. ];
  65. $result = MessageModel::where($map)
  66. ->update(['status' => 1, 'read_time' => $this->request->time()]);
  67. if (false !== $result) {
  68. $this->success('设置成功');
  69. } else {
  70. $this->error('设置失败');
  71. }
  72. }
  73. }