NoticeController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Controllers\Miniprogram;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\Notice\ManageService;
  5. use Illuminate\Http\Request;
  6. class NoticeController extends Controller
  7. {
  8. public function getAllProfile()
  9. {
  10. $uid = \App\Http\Controllers\Core\Auth::auth();
  11. $ms = new ManageService();
  12. $data = $ms->getNoticeByUser($uid);
  13. return array(
  14. 'code' => 200,
  15. 'message' => 'success',
  16. 'data' => $data
  17. );
  18. }
  19. public function getNoticeByKey(string $key)
  20. {
  21. $uid = \App\Http\Controllers\Core\Auth::auth();
  22. $ms = new ManageService();
  23. $bool = $ms->getNoticeByKey($uid, $key);
  24. return array(
  25. 'code' => 200,
  26. 'message' => 'success',
  27. 'data' => [
  28. 'isopen' => $bool
  29. ]
  30. );
  31. }
  32. /**
  33. * @param string $key
  34. * @return array
  35. * @throws \App\Exceptions\AlertException
  36. * @throws \App\Exceptions\ApiException
  37. * @deprecated Notice/GetNoticeByKeyToInt
  38. */
  39. public function getNoticeByKey2Int(string $key)
  40. {
  41. $uid = \App\Http\Controllers\Core\Auth::auth();
  42. $ms = new ManageService();
  43. $isopen = $ms->getNoticeByKey2Int($uid, $key);
  44. return array(
  45. 'code' => 200,
  46. 'message' => 'success',
  47. 'data' => [
  48. 'isopen' => $isopen
  49. ]
  50. );
  51. }
  52. /**
  53. * @param string $key
  54. * @param Request $request
  55. * @return array
  56. * @throws \App\Exceptions\AlertException
  57. * @throws \App\Exceptions\ApiException
  58. * @deprecated Notice/UpdateNoticeByKey
  59. */
  60. public function updateNoticeByKey(string $key, Request $request)
  61. {
  62. $is_open = $request->get('isopen', null);
  63. $uid = \App\Http\Controllers\Core\Auth::auth();
  64. $ms = new ManageService();
  65. $data = $ms->updateNoticeByKey($uid, $key, $is_open);
  66. return array(
  67. 'code' => 200,
  68. 'message' => 'success'
  69. );
  70. }
  71. public function updateNoticeByGroup(Request $request)
  72. {
  73. $uid = \App\Http\Controllers\Core\Auth::auth();
  74. $this->validate($request, [
  75. 'group' => 'required',
  76. 'isopen' => 'required|in:0,1'
  77. ]);
  78. $group = $request->post('group');
  79. $isopen = $request->post('isopen') ?? 0;
  80. $ms = new ManageService();
  81. $data = $ms->updateNoticeByGroup($uid, $group, $isopen);
  82. return array(
  83. 'code' => 200,
  84. 'message' => 'success'
  85. );
  86. }
  87. }