Notice.php 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. <?php
  2. namespace App\Http\Controllers\Api\Process;
  3. use App\Http\Controllers\Api\Api;
  4. use App\Http\Requests\Api\Process\Notices as Request;
  5. use App\Models\Api\Process\Notices as NoticesModel;
  6. /**
  7. * 通知服务
  8. * @author: 唐远望
  9. * @version: 1.0
  10. * @date: 2026-03-30
  11. */
  12. class Notice extends Api
  13. {
  14. /**
  15. * 列表
  16. * @author: 唐远望
  17. * @version: 1.0
  18. * @date: 2026-03-30
  19. */
  20. public function list(Request $Request, NoticesModel $NoticesModel)
  21. {
  22. $user_info = $this->checkLogin();
  23. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  24. $user_id = $user_info['uid'];
  25. $company_id = $user_info['company_id'];
  26. // 验证规则
  27. $Request->scene('list')->validate();
  28. $map = [];
  29. // 权限判断
  30. $map['company_id'] = $company_id;
  31. $map['custom_uid'] = $user_id;
  32. // 接收参数
  33. $status = request('status');
  34. $limit = request('limit', config('page_num', 10));
  35. $start_time = request('start_time', '');
  36. $end_time = request('end_time', '');
  37. // 时间条件
  38. if ($start_time) $map[] = ['insert_time', '>=', strtotime($start_time . ' 00:00:00')];
  39. if ($end_time) $map[] = ['insert_time', '<=', strtotime($end_time . ' 23:59:59')];
  40. if (!is_null($status)) $map[] = ['status', '=', $status];
  41. // 查询系统用户
  42. $result = $NoticesModel->where($map)->orderByDesc('id')->paginate($limit);
  43. // 告知结果
  44. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => $result]);
  45. }
  46. /**
  47. * 修改状态
  48. * @author: 唐远望
  49. * @version: 1.0
  50. * @date: 2026-03-30
  51. */
  52. public function set_status(Request $request, NoticesModel $NoticesModel)
  53. {
  54. $user_info = $this->checkLogin();
  55. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  56. $user_id = $user_info['uid'];
  57. $company_id = $user_info['company_id'];
  58. // 验证参数
  59. $request->scene('set_status')->validate();
  60. $map = [];
  61. // 权限判断
  62. $map['company_id'] = $company_id;
  63. $map['custom_uid'] = $user_id;
  64. // 设置状态
  65. $id = request('id', 0);
  66. $status = request('status', 0);
  67. $map[] = ['id', '=', $id];
  68. // 查询用户
  69. $oldData = $NoticesModel->where($map)->first();
  70. // 如果用户不存在
  71. if (!$oldData) return json_send(['code' => 'error', 'msg' => '通知消息记录不存在']);
  72. // 执行修改
  73. $result = $NoticesModel->where($map)->update(['status' => $status, 'update_time' => time()]);
  74. // 提示新增失败
  75. if (!$result) return json_send(['code' => 'error', 'msg' => '设置失败']);
  76. // 告知结果
  77. return json_send(['code' => 'success', 'msg' => '设置成功', 'data' => '']);
  78. }
  79. /**
  80. * 消息数统计
  81. * @author: 唐远望
  82. * @version: 1.0
  83. * @date: 2026-03-30
  84. */
  85. public function message_count(Request $Request, NoticesModel $NoticesModel)
  86. {
  87. $user_info = $this->checkLogin();
  88. if (!$user_info) return json_send(['code' => 'error', 'msg' => '请先登录']);
  89. $user_id = $user_info['uid'];
  90. $company_id = $user_info['company_id'];
  91. // 验证规则
  92. $Request->scene('message_count')->validate();
  93. $map = [];
  94. // 权限判断
  95. $map['company_id'] = $company_id;
  96. $map['custom_uid'] = $user_id;
  97. $map[] = ['status', '=', 0];
  98. // 查询系统用户
  99. $unread_count = $NoticesModel->where($map)->orderByDesc('id')->count();
  100. // 告知结果
  101. return json_send(['code' => 'success', 'msg' => '获取成功', 'data' => ['unread_count' => $unread_count]]);
  102. }
  103. }