Message.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2017 https://www.sapixx.com All rights reserved.
  4. * @license Licensed (http://www.apache.org/licenses/LICENSE-2.0).
  5. * @author pillar<ltmn@qq.com>
  6. * 站内通知
  7. */
  8. namespace app\system\controller\passport;
  9. use app\common\model\SystemMemberSms;
  10. class Message extends Common{
  11. public function initialize() {
  12. parent::initialize();
  13. $this->assign('pathMaps', [['name'=>'站内通知','url'=>'javascript:;']]);
  14. }
  15. /**
  16. * @return \think\response\View
  17. * @throws \think\Exception
  18. * @throws \think\exception\DbException
  19. * @throws \think\exception\PDOException
  20. * 消息中心首页
  21. */
  22. public function index(int $type = 0){
  23. $condition = [];
  24. $condition['member_miniapp_id'] = $this->member_miniapp_id;
  25. switch ($type) {
  26. case 1:
  27. $condition['is_read'] = 0;
  28. break;
  29. case 2:
  30. $condition['is_read'] = 1;
  31. break;
  32. }
  33. SystemMemberSms::where(['member_miniapp_id' => $this->member_miniapp_id,'is_new' => 0])->update(['is_new' => 1]);
  34. $view['list'] = SystemMemberSms::where($condition)->order('create_time desc')->paginate(20);
  35. $view['type'] = $type;
  36. return view()->assign($view);
  37. }
  38. /**
  39. * @return \think\response\Json
  40. * 查看未通知信息
  41. */
  42. public function count(){
  43. $count = SystemMemberSms::where(['member_miniapp_id' => $this->member_miniapp_id,'is_new' => 0])->count();
  44. return enjson(200,'成功',$count);
  45. }
  46. /**
  47. * @param int $id
  48. * @return \think\response\Json
  49. * @throws \think\Exception
  50. * @throws \think\exception\PDOException
  51. * 设为已读
  52. */
  53. public function clean(int $id = 0){
  54. if($id > 0){
  55. $count = SystemMemberSms::where(['member_miniapp_id' => $this->member_miniapp_id,'id' => $id])->update(['is_read' => 1,'is_new' => 1]);
  56. return enjson(200,'成功',$count);
  57. }else{
  58. return enjson(204,'请稍后重试');
  59. }
  60. }
  61. /*
  62. * 删除
  63. */
  64. public function delete(){
  65. $ids = $this->request->param('ids/s');
  66. if(empty($ids)){
  67. return json(['code'=>403,'msg'=>'请选择要删除的消息']);
  68. }
  69. $result = SystemMemberSms::whereIn('id',(array)ids($ids,true))->delete();
  70. if($result){
  71. return json(['code'=>200,'msg'=>'操作成功','data'=>[]]);
  72. }else{
  73. return json(['code'=>403,'msg'=>'操作失败']);
  74. }
  75. }
  76. }