IndexController.php 8.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers;
  3. use App\Facades\ProApiCacheFacade;
  4. use App\Helpers\ResponseConverter;
  5. use App\Helpers\Utils;
  6. use App\Http\Controllers\Controller;
  7. use App\Services\CallApiService;
  8. use Illuminate\Http\Request;
  9. // use Illuminate\Support\Facades\Request;
  10. class IndexController extends Controller
  11. {
  12. private $callApiService;
  13. public function __construct(CallApiService $callApiService)
  14. {
  15. $this->callApiService = $callApiService;
  16. }
  17. public function index()
  18. {
  19. $connectionDevice = session()->get('ConnectionDevice');
  20. $response = ProApiCacheFacade::getCachedResponse('list-type1-book', 'list-type1/home-book');
  21. if ($this->callApiService->verifyApiError($response)) {
  22. notify()->error($response['body'], 'Error', 'bottomRight');
  23. return redirect()->back();
  24. }
  25. $widgetTaxo = $response['Book'][0]['Page'];
  26. $maMainSlider = ProApiCacheFacade::filterWidgetTaxo($widgetTaxo, 'ma-main-slider', $connectionDevice);
  27. // dd($maMainSlider);
  28. $seoHtml = Utils::getSeoHtml('main');
  29. $query = "post_type_id = 59";
  30. $limit = (int)request('limit', 36);
  31. $page = (int)request('page', 1);
  32. // 시세
  33. $mainSiseList = $this->callApiService->callApi([
  34. 'url' => 'post-page',
  35. 'data' => [
  36. 'PageVars' => [
  37. 'Query' => $query,
  38. 'Desc' => 'created_on',
  39. 'Limit' => $limit,
  40. 'Offset' => ($page - 1) * $limit
  41. ]
  42. ]
  43. ]);
  44. // dd($mainSiseList);
  45. // 유튜브
  46. $query = "(post_type_id = 40 or post_type_id = 43 or post_type_id = 46) and status ='1' and pt1 !=''";
  47. $limit = (int)request('limit', 12);
  48. $page = (int)request('page', 1);
  49. $mainYoutubeList = $this->callApiService->callApi([
  50. 'url' => 'post-page',
  51. 'data' => [
  52. 'PageVars' => [
  53. 'Query' => $query,
  54. 'Desc' => 'created_on',
  55. 'Limit' => $limit,
  56. 'Offset' => ($page - 1) * $limit
  57. ]
  58. ]
  59. ]);
  60. // dd($mainYoutubeList);
  61. // 블로그
  62. $query = "(post_type_id = 41 or post_type_id = 44 or post_type_id = 50) and status ='1'";
  63. $limit = (int)request('limit', 12);
  64. $page = (int)request('page', 1);
  65. $mainBlogList = $this->callApiService->callApi([
  66. 'url' => 'post-page',
  67. 'data' => [
  68. 'PageVars' => [
  69. 'Query' => $query,
  70. 'Desc' => 'created_on',
  71. 'Limit' => $limit,
  72. 'Offset' => ($page - 1) * $limit
  73. ]
  74. ]
  75. ]);
  76. // dd($mainBlogList);
  77. // 시세 등락 계산
  78. if (isset($mainSiseList['Page']) && !empty($mainSiseList['Page'])) {
  79. foreach ($mainSiseList['Page'] as &$sise) {
  80. if (isset($sise['Pc3'], $sise['Pc4'])) {
  81. $sise['fluctuation'] = (float)$sise['Pc3'] - (float)$sise['Pc4'];
  82. } else {
  83. $sise['fluctuation'] = 0;
  84. }
  85. }
  86. }
  87. // 블로그 post_code 만들기
  88. if (isset($mainBlogList['Page']) && !empty($mainBlogList['Page'])) {
  89. foreach ($mainBlogList['Page'] as &$mainBlog) {
  90. if (isset($mainBlog['PostTypeId'])) {
  91. switch ($mainBlog['PostTypeId']) {
  92. case 41:
  93. $mainBlog['PostCode'] = 'golf-blog';
  94. break;
  95. case 44:
  96. $mainBlog['PostCode'] = 'condo-blog';
  97. break;
  98. default:
  99. $mainBlog['PostCode'] = 'fitness-blog';
  100. }
  101. }
  102. }
  103. }
  104. if ($this->callApiService->verifyApiError($mainSiseList)) {
  105. notify()->error($mainSiseList['body'], 'Error', 'bottomRight');
  106. return redirect()->back();
  107. }
  108. if ($this->callApiService->verifyApiError($mainYoutubeList)) {
  109. notify()->error($mainYoutubeList['body'], 'Error', 'bottomRight');
  110. return redirect()->back();
  111. }
  112. if ($this->callApiService->verifyApiError($mainBlogList)) {
  113. notify()->error($mainBlogList['body'], 'Error', 'bottomRight');
  114. return redirect()->back();
  115. }
  116. return view('views.index', compact('seoHtml', 'maMainSlider', 'mainSiseList', 'mainYoutubeList' ,'mainBlogList'));
  117. }
  118. // 시세 더보기
  119. public function loadMoreSise(Request $request)
  120. {
  121. $query = "post_type_id = 59";
  122. $offset = (int) $request->query('offset', 0);
  123. $limit = (int) $request->query('limit', 5);
  124. $siseType = $request->query('siseType', 'golf');
  125. if($siseType){
  126. $query .= " and pc1='$siseType'";
  127. }
  128. $moreSiseList=$this->callApiService->callApi([
  129. 'url' => 'post-page',
  130. 'data' => [
  131. 'PageVars' => [
  132. 'Query' => $query,
  133. 'Desc' => 'created_on',
  134. 'Limit' => $limit,
  135. 'Offset' => $offset
  136. ]
  137. ]
  138. ]);
  139. // 등락 계산
  140. if (isset($moreSiseList['Page']) && !empty($moreSiseList['Page'])) {
  141. foreach ($moreSiseList['Page'] as &$sise) {
  142. if (isset($sise['Pc3'], $sise['Pc4'])) {
  143. $sise['fluctuation'] = (float)$sise['Pc3'] - (float)$sise['Pc4'];
  144. } else {
  145. $sise['fluctuation'] = 0;
  146. }
  147. }
  148. }
  149. if ($this->callApiService->verifyApiError($moreSiseList)) {
  150. notify()->error($moreSiseList['body'], 'Error', 'bottomRight');
  151. return redirect()->back();
  152. }
  153. return $moreSiseList;
  154. }
  155. // 유튜브 더보기
  156. public function loadMoreYoutube(Request $request)
  157. {
  158. $query = "(post_type_id = 40 or post_type_id = 43 or post_type_id = 46) and status ='1' and pt!=''";
  159. $offset = (int) $request->query('offset', 0);
  160. $limit = (int) $request->query('limit', 12);
  161. $mainYoutubeList=$this->callApiService->callApi([
  162. 'url' => 'post-page',
  163. 'data' => [
  164. 'PageVars' => [
  165. 'Query' => $query,
  166. 'Desc' => 'created_on',
  167. 'Limit' => $limit,
  168. 'Offset' => $offset
  169. ]
  170. ]
  171. ]);
  172. if ($this->callApiService->verifyApiError($mainYoutubeList)) {
  173. notify()->error($mainYoutubeList['body'], 'Error', 'bottomRight');
  174. return redirect()->back();
  175. }
  176. return $mainYoutubeList;
  177. }
  178. // 블로그 더보기
  179. public function loadMoreBlog(Request $request)
  180. {
  181. $query = "(post_type_id = 41 or post_type_id = 44 or post_type_id = 50) and status ='1'";
  182. $offset = (int) $request->query('offset', 0);
  183. $limit = (int) $request->query('limit', 12);
  184. $moreBlogList=$this->callApiService->callApi([
  185. 'url' => 'post-page',
  186. 'data' => [
  187. 'PageVars' => [
  188. 'Query' => $query,
  189. 'Desc' => 'created_on',
  190. 'Limit' => $limit,
  191. 'Offset' => $offset
  192. ]
  193. ]
  194. ]);
  195. // post_code 만들기
  196. if (isset($moreBlogList['Page']) && !empty($moreBlogList['Page'])) {
  197. foreach ($moreBlogList['Page'] as &$mainBlog) {
  198. if (isset($mainBlog['PostTypeId'])) {
  199. switch ($mainBlog['PostTypeId']) {
  200. case 41:
  201. $mainBlog['PostCode'] = 'golf-blog';
  202. break;
  203. case 44:
  204. $mainBlog['PostCode'] = 'condo-blog';
  205. break;
  206. default:
  207. $mainBlog['PostCode'] = 'fitness-blog';
  208. }
  209. }
  210. }
  211. }
  212. if ($this->callApiService->verifyApiError($moreBlogList)) {
  213. notify()->error($moreBlogList['body'], 'Error', 'bottomRight');
  214. return redirect()->back();
  215. }
  216. return $moreBlogList;
  217. }
  218. }