NoticeController.php 4.8 KB

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