PolicyController.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. <?php
  2. namespace Themes\Pro\modunawa\app\Http\Controllers;
  3. use App\Helpers\File;
  4. use App\Http\Controllers\Controller;
  5. use App\Services\CallApiService;
  6. class PolicyController extends Controller
  7. {
  8. private $callApiService;
  9. public function __construct(CallApiService $callApiService)
  10. {
  11. $this->callApiService = $callApiService;
  12. }
  13. public function index()
  14. {
  15. $limit = (int)request('limit', 10);
  16. $page = (int)request('page', 1);
  17. $policyPage = $this->callApiService->callApi([
  18. 'url' => 'simple-join-page',
  19. 'data' => [
  20. 'QueryVars' => [
  21. 'QueryName' => 'post-member-user',
  22. 'SimpleFilter' => "post_type_id = 11 and mx.status = '0'"
  23. ],
  24. 'PageVars' => [
  25. 'Desc' => 'Id',
  26. 'Limit' => $limit,
  27. 'Offset' => ($page - 1) * $limit
  28. ]
  29. ]
  30. ]);
  31. // dd($policyPage);
  32. $policy = $policyPage['Page'][0];
  33. if (empty($policy)) {
  34. notify()->error(__('이용약관이 존재하지 않습니다'), 'Error', 'bottomRight');
  35. return redirect()->back();
  36. }
  37. if (empty($policy['PostSlug'])) {
  38. $key = $policy['Id'];
  39. } else {
  40. $key = $policy['PostSlug'];
  41. }
  42. return redirect()->route('policy.show', $key);
  43. }
  44. public function show($slug)
  45. {
  46. $postPick = $this->pickPost([ 'PostSlug' => $slug ]);
  47. if ($this->callApiService->verifyApiError($postPick)) {
  48. $postPick = $this->pickPost([ 'Id' => (int)$slug ]);
  49. }
  50. if ($this->callApiService->verifyApiError($postPick)) {
  51. return redirect()->back();
  52. }
  53. $post = $postPick['Page'][0];
  54. if ($post['Status'] === '1') {
  55. notify()->error(__('이용약관이 존재하지 않습니다'), 'Error', 'bottomRight');
  56. return redirect()->back();
  57. }
  58. $policyPage = $this->callApiService->callApi([
  59. 'url' => 'simple-join-page',
  60. 'data' => [
  61. 'QueryVars' => [
  62. 'QueryName' => 'post-member-user',
  63. 'SimpleFilter' => "post_type_id = 11 and mx.status = '0'"
  64. ],
  65. 'PageVars' => [
  66. 'Desc' => 'Id',
  67. 'Limit' => 9999,
  68. 'Offset' => 0
  69. ]
  70. ]
  71. ]);
  72. $currKey = collect($policyPage['Page'])->search(function($policy) use ($post) {
  73. return $policy['Id'] === $post['Id'];
  74. });
  75. $title = __('이용약관');
  76. // dd($post);
  77. //dd(count($policyPage['Page']));
  78. return view('views.policy-or-privacy', compact('policyPage', 'currKey', 'post', 'title'));
  79. }
  80. public function pickPost($page)
  81. {
  82. return $this->callApiService->callApi([
  83. 'url' => 'post-pick',
  84. 'data' => [
  85. 'Page' => [ $page ],
  86. ]
  87. ]);
  88. }
  89. }