NoticeController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace Themes\Pro\modunawa\app\Http\Controllers\MyPage;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use Illuminate\Pagination\LengthAwarePaginator;
  6. class NoticeController extends Controller
  7. {
  8. private $callApiService;
  9. public function __construct(CallApiService $callApiService)
  10. {
  11. $this->callApiService = $callApiService;
  12. }
  13. public function list()
  14. {
  15. $limit = (int)request('limit', 12);
  16. $page = (int)request('page', 1);
  17. $noticePage = $this->callApiService->callApi([
  18. 'url' => 'list-type1-page',
  19. 'data' => [
  20. 'QueryVars' => [
  21. 'QueryName' => 'pro:my-page/post-list',
  22. 'SimpleFilter' => "post_code='notice' and mx.status != '0'",
  23. 'SubSimpleFilter' => "image_type = 'thumb'",
  24. 'IsntPagination' => false
  25. ],
  26. 'ListType1Vars' => [
  27. 'OrderBy' => request('sort', 'mx.created_on desc')
  28. ],
  29. 'PageVars' => [
  30. 'Limit' => $limit,
  31. 'Offset' => ($page - 1) * $limit
  32. ]
  33. ]
  34. ]);
  35. if ($this->callApiService->verifyApiError($noticePage)) {
  36. notify()->error($noticePage['body'], 'Error', 'bottomRight');
  37. return redirect()->back();
  38. }
  39. $noticePage['Page'] = new LengthAwarePaginator($noticePage['Page'], $noticePage['PageVars']['QueryCnt'],
  40. $limit, $page, ['path' => request()->url()]);
  41. return view('views.my-page.notice-list', compact('noticePage'));
  42. }
  43. public function show($id)
  44. {
  45. $listType1Book = $this->callApiService->callApi([
  46. 'url' => 'list-type1-book',
  47. 'data' => [
  48. 'Book' => [
  49. [
  50. 'QueryVars' => [
  51. 'QueryName' => 'pro:my-page/post-details',
  52. 'SimpleFilter' => "post_code='notice' and mx.id = $id",
  53. 'IsntPagination' => true,
  54. ],
  55. 'PageVars' => [
  56. 'Limit' => 1
  57. ]
  58. ],
  59. [
  60. 'QueryVars' => [
  61. 'QueryName' => 'pro:my-page/post-details-prenext',
  62. 'SimpleFilter' => "mx.id = (select max(id) from pro_post where id < ${id} and post_type_id = 1) and mx.status != '0'",
  63. 'SubSimpleFilter' => "",
  64. 'IsntPagination' => true,
  65. ],
  66. 'PageVars' => [
  67. 'Limit' => 1
  68. ]
  69. ],
  70. [
  71. 'QueryVars' => [
  72. 'QueryName' => 'pro:my-page/post-details-prenext',
  73. 'SimpleFilter' => "mx.id = (select min(id) from pro_post where id > ${id} and post_type_id = 1) and mx.status != '0'",
  74. 'SubSimpleFilter' => "",
  75. 'IsntPagination' => true,
  76. ],
  77. 'PageVars' => [
  78. 'Limit' => 1
  79. ]
  80. ],
  81. ]
  82. ]
  83. ]);
  84. if ($this->callApiService->verifyApiError($listType1Book)) {
  85. notify()->error($listType1Book['body'], 'Error', 'bottomRight');
  86. return redirect()->back();
  87. }
  88. // dump($listType1Book);
  89. return view('views.my-page.notice-details', compact('listType1Book'));
  90. }
  91. }