OneToOneController.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php
  2. namespace Themes\Pro\modunawa\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/my-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. return view('views.etc.1to1-list', compact('oneToOnePage'));
  40. }
  41. public function store()
  42. {
  43. $validator = Validator::make(request()->all(), [
  44. 'post_title' => 'required',
  45. 'post_contents' => 'required',
  46. 'pc1' => 'required',
  47. 'pc2' => 'required|email'
  48. ]);
  49. if ($validator->fails()) {
  50. notify()->error(_e('Action failed'), 'Error', 'bottomRight');
  51. return redirect()->back()
  52. ->withErrors($validator)
  53. ->withInput();
  54. }
  55. $response = $this->callApiService->callApi([
  56. 'url' => 'post-act',
  57. 'data' => [
  58. 'Page' => [
  59. [
  60. 'Id' => 0,
  61. 'PostTitle' => request('post_title'),
  62. 'PostContents' => request('post_contents'),
  63. 'PostTypeId' => 6,
  64. 'Pc1' => request('pc1'),
  65. 'Pc2' => request('pc2'),
  66. 'Status' => '2',
  67. 'MemberId' => session('member')['MemberId'],
  68. ]
  69. ]
  70. ],
  71. ]);
  72. if ($this->callApiService->verifyApiError($response)) {
  73. notify()->error($response['body'], 'Error', 'bottomRight');
  74. return redirect()->back();
  75. }
  76. notify()->success(_e('Action completed'), 'Success', 'bottomRight');
  77. return redirect()->route('1to1.list');
  78. }
  79. public function show($id)
  80. {
  81. $listType1Book = $this->callApiService->callApi([
  82. 'url' => 'list-type1-book',
  83. 'data' => [
  84. 'Book' => [
  85. [
  86. 'QueryVars' => [
  87. 'QueryName' => 'pro:my-page/my-post-details',
  88. 'SimpleFilter' => "post_code='1to1' and mx.id = $id",
  89. 'IsntPagination' => true,
  90. ],
  91. 'PageVars' => [
  92. 'Limit' => 1
  93. ]
  94. ],
  95. [
  96. 'QueryVars' => [
  97. 'QueryName' => 'pro:my-page/my-post-details-prenext',
  98. 'SimpleFilter' => "mx.id = (select max(id) from pro_post where id < ${id} and post_type_id = 6)",
  99. 'SubSimpleFilter' => "",
  100. 'IsntPagination' => true,
  101. ],
  102. 'PageVars' => [
  103. 'Limit' => 1
  104. ]
  105. ],
  106. [
  107. 'QueryVars' => [
  108. 'QueryName' => 'pro:my-page/my-post-details-prenext',
  109. 'SimpleFilter' => "mx.id = (select min(id) from pro_post where id > ${id} and post_type_id = 6)",
  110. 'SubSimpleFilter' => "",
  111. 'IsntPagination' => true,
  112. ],
  113. 'PageVars' => [
  114. 'Limit' => 1
  115. ]
  116. ],
  117. ]
  118. ]
  119. ]);
  120. // dd($listType1Book);
  121. if ($this->callApiService->verifyApiError($listType1Book)) {
  122. notify()->error($listType1Book['body'], 'Error', 'bottomRight');
  123. return redirect()->back();
  124. }
  125. // dump($listType1Book);
  126. return view('views.etc.1to1-details', compact('listType1Book'));
  127. }
  128. }