Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

UsersNotice.php 5.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * 易优CMS
  4. * ============================================================================
  5. * 版权所有 2016-2028 海南赞赞网络科技有限公司,并保留所有权利。
  6. * 网站地址: http://www.eyoucms.com
  7. * ----------------------------------------------------------------------------
  8. * 如果商业用途务必到官方购买正版授权, 以免引起不必要的法律纠纷.
  9. * ============================================================================
  10. * Author: 小虎哥 <1105415366@qq.com>
  11. * Date: 2018-4-3
  12. */
  13. namespace app\user\controller;
  14. use think\Db;
  15. use think\Config;
  16. use think\Verify;
  17. use think\Page;
  18. use think\Request;
  19. /**
  20. * 消息通知
  21. */
  22. class UsersNotice extends Base
  23. {
  24. public function _initialize() {
  25. parent::_initialize();
  26. $functionLogic = new \app\common\logic\FunctionLogic;
  27. $functionLogic->validate_authorfile(1);
  28. }
  29. public function index()
  30. {
  31. $condition = array();
  32. $keywords = input('keywords/s');
  33. if (!empty($keywords)) {
  34. $condition['b.title'] = array('LIKE', "%{$keywords}%");
  35. }
  36. $is_read = input('param.is_read');
  37. if ($is_read) {
  38. $condition['a.is_read'] = $is_read == 1 ?1:0;
  39. }
  40. //查接收消息通知的会员id
  41. $users_id = $this->users_id;
  42. $condition['a.users_id'] = $users_id;
  43. $condition['a.is_del'] = 0;
  44. // 多语言
  45. $condition['a.lang'] = $this->home_lang;
  46. $count = Db::name('users_notice_read')->alias('a')->where($condition)->count('id');
  47. $Page = $pager = new Page($count, config('paginate.list_rows'));
  48. $result['data'] = Db::name('users_notice_read')
  49. ->alias('a')
  50. ->field("a.id,a.users_id,a.notice_id,a.is_read,a.is_del,b.title,b.remark,b.add_time,b.update_time")
  51. ->join("users_notice b","a.notice_id = b.id")
  52. ->where($condition)
  53. ->order('a.is_read ASC,b.add_time DESC')
  54. ->limit($Page->firstRow . ',' . $Page->listRows)
  55. ->select();
  56. $show = $Page->show();// 分页显示输出
  57. $result['delurl'] = url('user/UsersNotice/del');
  58. $result['readurl'] = url('user/UsersNotice/batch_read');
  59. $eyou = array(
  60. 'field' => $result,
  61. );
  62. $this->assign('page', $show);
  63. $this->assign('eyou', $eyou);
  64. $this->assign('pager', $pager);
  65. return $this->fetch('users_notice_index');
  66. }
  67. /**
  68. * 删除通知
  69. */
  70. public function del()
  71. {
  72. if (IS_POST) {
  73. $id_arr = input('del_id/a');
  74. $id_arr = eyIntval($id_arr);
  75. if (!empty($id_arr)) {
  76. $unread_notice = Db::name('users_notice_read')->field("id")->where(['id'=>['IN',$id_arr],'is_read'=>0])->find();
  77. if (!empty($unread_notice)) $this->error('不能删除未读消息');
  78. //将状态值改为已删除
  79. Db::name('users_notice_read')->where(['id'=>['IN',$id_arr]])->update(['is_del'=>1]);
  80. $this->success('删除成功');
  81. }
  82. }
  83. $this->error('删除失败');
  84. }
  85. /**
  86. * 批量标记为已读
  87. */
  88. public function batch_read()
  89. {
  90. if (IS_POST) {
  91. $id_arr = input('del_id/a');
  92. $id_arr = eyIntval($id_arr);
  93. $users_id = $this->users_id;
  94. if (!empty($id_arr)) {
  95. $notice_read_ids = Db::name('users_notice_read')->where(['id'=>['IN', $id_arr],'is_read'=>1])->column('id');
  96. $id_arr_unread = array_diff($id_arr, $notice_read_ids);
  97. if ($id_arr_unread) {
  98. Db::name('users_notice_read')->where(['id'=>['IN', $id_arr_unread]])->update(['is_read'=>1]);
  99. $unread_notice_num = Db::name("users")->where(['users_id' => $users_id])->value('unread_notice_num');
  100. $update_num = $unread_notice_num-count($id_arr_unread);
  101. if ($update_num>0) {
  102. Db::name("users")->where(['users_id' => $users_id])->update(['unread_notice_num'=>$update_num]);
  103. }else{
  104. Db::name("users")->where(['users_id' => $users_id])->update(['unread_notice_num'=>0]);
  105. }
  106. $this->success('操作成功');
  107. }
  108. $this->error('未选择未读消息');
  109. }
  110. $this->error('未选择消息');
  111. }
  112. }
  113. /**
  114. * 删除所有通知
  115. */
  116. public function del_all()
  117. {
  118. if (IS_POST) {
  119. $users_id = $this->users_id;
  120. $unread_notice = Db::name('users_notice_read')->field("id")->where(['users_id'=>$users_id,'is_read'=>0])->find();
  121. if ($unread_notice) $this->error('不能删除未读消息');
  122. Db::name('users_notice_read')->where(['users_id'=>$users_id])->update(['is_del'=>1]);
  123. Db::name("users")->where(['users_id' => $users_id])->update(['unread_notice_num'=> 0]);
  124. $this->success('删除成功');
  125. }
  126. $this->error('未知错误');
  127. }
  128. /**
  129. * 所有标记为已读
  130. */
  131. public function batch_read_all()
  132. {
  133. if (IS_POST) {
  134. $users_id = $this->users_id;
  135. Db::name('users_notice_read')->where(['users_id'=>$users_id])->update(['is_read'=>1]);
  136. Db::name("users")->where(['users_id' => $users_id])->update(['unread_notice_num'=> 0]);
  137. $this->success('操作成功');
  138. }
  139. $this->error('未知错误');
  140. }
  141. }