IndexController.php 8.5 KB

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