NoticesController.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <?php
  2. /**
  3. * ${CARET}
  4. * @file:NoticesController.php
  5. * @Created by gnitif
  6. * @Date: 2023/3/27
  7. * @Time: 11:18
  8. */
  9. namespace Modules\ContentManage\Http\Controllers\System;
  10. use Catch\Base\CatchController as Controller;
  11. use Catch\Exceptions\FailedException;
  12. use Illuminate\Contracts\Pagination\LengthAwarePaginator;
  13. use Illuminate\Http\Request;
  14. use Modules\ContentManage\Http\Requests\NoticeRequest;
  15. use Modules\ContentManage\Models\NoticeTypes;
  16. use Modules\ContentManage\Services\Notice\NoticesService;
  17. class NoticesController extends Controller
  18. {
  19. public function list(Request $request)
  20. {
  21. return NoticesService::list();
  22. }
  23. /**
  24. * 添加通知
  25. * name: addNotice
  26. * @param NoticeRequest $request
  27. * @return mixed
  28. * date 2023/03/29 14:47
  29. */
  30. public function addNotice(NoticeRequest $request)
  31. {
  32. return NoticesService::addNotice($request->all());
  33. }
  34. /**
  35. * 删除通知
  36. * name: delete
  37. * @param $id
  38. * date 2023/03/29 14:48
  39. */
  40. public function delete($id)
  41. {
  42. return NoticesService::delete($id);
  43. }
  44. /**
  45. * 获取通知详情
  46. * name: info
  47. * @param $id
  48. * @return mixed
  49. * date 2023/03/29 14:59
  50. */
  51. public function info($id)
  52. {
  53. return NoticesService::getDetail($id);
  54. }
  55. public function edit($id, Request $request)
  56. {
  57. $title = $request->input('title', '');
  58. $content = $request->input('content', '');
  59. $notice_type_id = $request->input('notice_type_id', 0);
  60. if (empty($title)) {
  61. throw new FailedException('通知标题不能为空!');
  62. }
  63. if (empty($content)) {
  64. throw new FailedException('通知内容不能为空!');
  65. }
  66. if (empty($notice_type_id)) {
  67. throw new FailedException('通知类型必填!');
  68. }
  69. $tye = NoticeTypes::where('id', $notice_type_id)->where('is_deleted', 0)->value('id');
  70. if (empty($tye)) {
  71. throw new FailedException('通知类型不正确!');
  72. }
  73. $param = [
  74. 'title' => $title,
  75. 'content' => $content,
  76. 'notice_type_id' => $notice_type_id,
  77. 'sort' => $request->input('sort',0),
  78. ];
  79. NoticesService::update($id, $param);
  80. }
  81. /**
  82. * 我的通知
  83. * name: myNotices
  84. * @param Request $request
  85. * @return LengthAwarePaginator
  86. * date 2023/03/29 23:48
  87. */
  88. public function myNotices(Request $request)
  89. {
  90. return NoticesService::myNoticesList($request->all());
  91. }
  92. /**
  93. * 已读
  94. * name: setRead
  95. * @param $id
  96. * date 2023/03/29 23:51
  97. */
  98. public function setRead($id): mixed
  99. {
  100. NoticesService::setRead($id);
  101. return response()->json(['code' => 10000, "message" => "操作成功",'data' => []]);
  102. }
  103. /**
  104. * 用户删除
  105. * name: userDel
  106. * @param $id
  107. * @return mixed
  108. * date 2023/03/29 23:55
  109. */
  110. public function userDel($id): mixed
  111. {
  112. return NoticesService::userDel($id);
  113. }
  114. /**
  115. * 阅读详情
  116. * name: detail
  117. * @param $id
  118. * date 2023/03/30 00:06
  119. */
  120. public function detail($id)
  121. {
  122. return NoticesService::detail($id);
  123. }
  124. /**
  125. * 获取通知人群选项
  126. * name: objOption
  127. * @param Request $request
  128. * date 2023/03/30 10:20
  129. */
  130. public function objOption(Request $request)
  131. {
  132. $type = $request->input('type', '2');
  133. $name = $request->input('name', '');
  134. $type = $type == "3" ? "role" : "user";
  135. return NoticesService::objOption($type, $name);
  136. }
  137. /**
  138. * home页弹窗公告
  139. * name: getPopup
  140. * date 2023/03/30 16:41
  141. */
  142. public function getPopup(){
  143. return NoticesService:: getPopup();
  144. }
  145. }