RefundController.php 3.0 KB

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