OneToOneController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Etc;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use Illuminate\Pagination\LengthAwarePaginator;
  6. use Validator;
  7. class OneToOneController extends Controller
  8. {
  9. private $callApiService;
  10. public function __construct(CallApiService $callApiService)
  11. {
  12. $this->callApiService = $callApiService;
  13. }
  14. public function list()
  15. {
  16. $limit = (int)request('limit', 12);
  17. $page = (int)request('page', 1);
  18. $oneToOnePage = $this->callApiService->callApi([
  19. 'url' => 'list-type1-page',
  20. 'data' => [
  21. 'QueryVars' => [
  22. 'QueryName' => 'pro:my-page/post-list',
  23. 'SimpleFilter' => "post_code='1to1'",
  24. 'SubSimpleFilter' => "image_type = 'thumb'",
  25. 'IsntPagination' => false
  26. ],
  27. 'ListType1Vars' => [
  28. 'OrderBy' => request('sort', 'mx.created_on desc')
  29. ],
  30. 'PageVars' => [
  31. 'Limit' => $limit,
  32. 'Offset' => ($page - 1) * $limit
  33. ]
  34. ]
  35. ]);
  36. // dump($oneToOnePage);
  37. $oneToOnePage['Page'] = new LengthAwarePaginator($oneToOnePage['Page'], $oneToOnePage['PageVars']['QueryCnt'],
  38. $limit, $page, ['path' => request()->url()]);
  39. // dump($oneToOnePage);
  40. return view('views.etc.1to1-list', compact('oneToOnePage'));
  41. }
  42. public function store()
  43. {
  44. $validator = Validator::make(request()->all(), [
  45. 'post_title' => 'required',
  46. 'post_contents' => 'required',
  47. 'pc1' => 'required',
  48. 'pc2' => 'required|email'
  49. ]);
  50. if ($validator->fails()) {
  51. notify()->error(_e('Action failed'), 'Error', 'bottomRight');
  52. return redirect()->back()
  53. ->withErrors($validator)
  54. ->withInput();
  55. }
  56. $response = $this->callApiService->callApi([
  57. 'url' => 'post-act',
  58. 'data' => [
  59. 'Page' => [
  60. [
  61. 'Id' => 0,
  62. 'PostTitle' => request('post_title'),
  63. 'PostContents' => request('post_contents'),
  64. 'PostTypeId' => 6,
  65. 'Pc1' => request('pc1'),
  66. 'Pc2' => request('pc2'),
  67. 'Status' => '2',
  68. 'MemberId' => session('member')['MemberId'],
  69. ]
  70. ]
  71. ],
  72. ]);
  73. if ($this->callApiService->verifyApiError($response)) {
  74. notify()->error($response['body'], 'Error', 'bottomRight');
  75. return redirect()->back();
  76. }
  77. // notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  78. return redirect()->route('1to1.list');
  79. }
  80. public function show($id)
  81. {
  82. $listType1Book = $this->callApiService->callApi([
  83. 'url' => 'list-type1-book',
  84. 'data' => [
  85. 'Book' => [
  86. [
  87. 'QueryVars' => [
  88. 'QueryName' => 'pro:my-page/post-details',
  89. 'SimpleFilter' => "post_code='1to1' and mx.id = $id",
  90. 'IsntPagination' => true,
  91. ],
  92. 'PageVars' => [
  93. 'Limit' => 1
  94. ]
  95. ],
  96. [
  97. 'QueryVars' => [
  98. 'QueryName' => 'pro:my-page/post-details-prenext',
  99. 'SimpleFilter' => "mx.id = (select max(id) from pro_post where id < ${id} and post_type_id = 6)",
  100. 'SubSimpleFilter' => "",
  101. 'IsntPagination' => true,
  102. ],
  103. 'PageVars' => [
  104. 'Limit' => 1
  105. ]
  106. ],
  107. [
  108. 'QueryVars' => [
  109. 'QueryName' => 'pro:my-page/post-details-prenext',
  110. 'SimpleFilter' => "mx.id = (select min(id) from pro_post where id > ${id} and post_type_id = 6)",
  111. 'SubSimpleFilter' => "",
  112. 'IsntPagination' => true,
  113. ],
  114. 'PageVars' => [
  115. 'Limit' => 1
  116. ]
  117. ],
  118. ]
  119. ]
  120. ]);
  121. // dd($listType1Book);
  122. if ($this->callApiService->verifyApiError($listType1Book)) {
  123. notify()->error($listType1Book['body'], 'Error', 'bottomRight');
  124. return redirect()->back();
  125. }
  126. // dump($listType1Book);
  127. return view('views.etc.1to1-details', compact('listType1Book'));
  128. }
  129. }