IndexController.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. $contactSuccess = session()->has('contactSuccess');
  20. $connectionDevice = session()->get('ConnectionDevice');
  21. [$oauth2InfoList, $develLoginInfo] = setupSsoClientOrLoginInfo();
  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. $maMainText = ProApiCacheFacade::filterWidgetTaxo($widgetTaxo, 'ma-main-text', $connectionDevice);
  29. $maMainSlider = ProApiCacheFacade::filterWidgetTaxo($widgetTaxo, 'ma-main-slider', $connectionDevice);
  30. $mbSubSlider = ProApiCacheFacade::filterWidgetTaxo($widgetTaxo, 'mb-sub-slider', $connectionDevice);
  31. $mbMainText = ProApiCacheFacade::filterWidgetTaxo($widgetTaxo, 'mb-main-text');
  32. $cmFooterC = ProApiCacheFacade::filterWidgetTaxo($widgetTaxo, 'cm-footer-c');
  33. date_default_timezone_set('Asia/Seoul');
  34. $today = date('Ymd');
  35. // $twoWeeksAgo = date('Ymd', strtotime('-2 weeks'));
  36. $seoHtml = Utils::getSeoHtml('main');
  37. // 가장 최근 시세 찾기
  38. $query = "post_type_id = 59";
  39. $limit = (int)request('limit', 1);
  40. $page = (int)request('page', 1);
  41. $recentSise = $this->callApiService->callApi([
  42. 'url' => 'post-page',
  43. 'data' => [
  44. 'PageVars' => [
  45. 'Query' => $query,
  46. 'Desc' => 'pc6',
  47. 'Limit' => $limit,
  48. 'Offset' => ($page - 1) * $limit
  49. ]
  50. ]
  51. ]);
  52. // dd($recentSise);
  53. $recentDate = '';
  54. foreach($recentSise['Page'] ?? [] as $recent){
  55. if ($recent) {
  56. $recentDate = $recent['Pc6'];
  57. $query .= " and Pc6 = '$recentDate'";
  58. // dd($query);
  59. }
  60. }
  61. // 메인에 뿌려질 최근 시세리스트
  62. $limit = (int)request('limit', 30);
  63. $page = (int)request('page', 1);
  64. $mainSiseList = $this->callApiService->callApi([
  65. 'url' => 'post-page',
  66. 'data' => [
  67. 'PageVars' => [
  68. 'Query' => $query,
  69. 'Asc' => 'post_title',
  70. 'Limit' => $limit,
  71. 'Offset' => ($page - 1) * $limit
  72. ]
  73. ]
  74. ]);
  75. // dd($mainSiseList);
  76. // 시세 등락 계산
  77. if (isset($mainSiseList['Page']) && !empty($mainSiseList['Page'])) {
  78. foreach ($mainSiseList['Page'] as &$sise) {
  79. if (isset($sise['Pc3'], $sise['Pc4'])) {
  80. $sise['fluctuation'] = (float)$sise['Pc3'] - (float)$sise['Pc4'];
  81. } else {
  82. $sise['fluctuation'] = 0;
  83. }
  84. }
  85. }
  86. // main yutube List
  87. $query = "(post_type_id = 40 or post_type_id = 43 or post_type_id = 46) and status ='1' and pt1 !=''";
  88. $limit = (int)request('limit', 300);
  89. $page = (int)request('page', 1);
  90. $mainYoutubeList = $this->callApiService->callApi([
  91. 'url' => 'post-page',
  92. 'data' => [
  93. 'PageVars' => [
  94. 'Query' => $query,
  95. 'Desc' => 'created_on',
  96. 'Limit' => $limit,
  97. 'Offset' => ($page - 1) * $limit
  98. ]
  99. ]
  100. ]);
  101. $youtubeTypes = [
  102. 'Page' => [
  103. 'golf' => [],
  104. 'condo' => [],
  105. 'fitness' => []
  106. ]
  107. ];
  108. foreach($mainYoutubeList['Page'] ?? [] as $mainYoutube){
  109. // dd($mainYoutube);
  110. if (isset($mainYoutube['PostTypeId'])) {
  111. $postTypeId = $mainYoutube['PostTypeId'];
  112. switch ($postTypeId) {
  113. case 40:
  114. if (count($youtubeTypes['Page']['golf']) < 3) {
  115. $youtubeTypes['Page']['golf'][] = $mainYoutube;
  116. }
  117. break;
  118. case 43:
  119. if (count($youtubeTypes['Page']['condo']) < 3) {
  120. $youtubeTypes['Page']['condo'][] = $mainYoutube;
  121. }
  122. break;
  123. case 46:
  124. if (count($youtubeTypes['Page']['fitness']) < 3) {
  125. $youtubeTypes['Page']['fitness'][] = $mainYoutube;
  126. }
  127. break;
  128. }
  129. }
  130. }
  131. // dd($youtubeTypes);
  132. // dd($mainYoutubeList);
  133. // main blog List
  134. $query = "(post_type_id = 41 or post_type_id = 44 or post_type_id = 50) and status ='1'";
  135. $limit = (int)request('limit', 12);
  136. $page = (int)request('page', 1);
  137. $mainBlogList = $this->callApiService->callApi([
  138. 'url' => 'post-page',
  139. 'data' => [
  140. 'PageVars' => [
  141. 'Query' => $query,
  142. 'Desc' => 'created_on',
  143. 'Limit' => $limit,
  144. 'Offset' => ($page - 1) * $limit
  145. ]
  146. ]
  147. ]);
  148. $blogTypes = [
  149. 'Page' => [
  150. 'golf' => [],
  151. 'condo' => [],
  152. 'fitness' => []
  153. ]
  154. ];
  155. foreach($mainBlogList['Page'] ?? [] as &$mainBlog){
  156. if (isset($mainBlog['PostTypeId'])) {
  157. $postTypeId = $mainBlog['PostTypeId'];
  158. switch ($postTypeId) {
  159. case 41:
  160. if (count($blogTypes['Page']['golf']) < 3) {
  161. $mainBlog['PostCode'] = 'golf-blog';
  162. $blogTypes['Page']['golf'][] = $mainBlog;
  163. }
  164. break;
  165. case 44:
  166. if (count($blogTypes['Page']['condo']) < 3) {
  167. $mainBlog['PostCode'] = 'condo-blog';
  168. $blogTypes['Page']['condo'][] = $mainBlog;
  169. }
  170. break;
  171. case 50:
  172. if (count($blogTypes['Page']['fitness']) < 3) {
  173. $mainBlog['PostCode'] = 'fitness-blog';
  174. $blogTypes['Page']['fitness'][] = $mainBlog;
  175. }
  176. break;
  177. }
  178. }
  179. }
  180. // dd($blogTypes);
  181. // dd($mainBlogList);
  182. if ($this->callApiService->verifyApiError($mainSiseList)) {
  183. notify()->error($mainSiseList['body'], 'Error', 'bottomRight');
  184. return redirect()->back();
  185. }
  186. if ($this->callApiService->verifyApiError($mainSiseList)) {
  187. notify()->error($mainSiseList['body'], 'Error', 'bottomRight');
  188. return redirect()->back();
  189. }
  190. if ($this->callApiService->verifyApiError($mainYoutubeList)) {
  191. notify()->error($mainYoutubeList['body'], 'Error', 'bottomRight');
  192. return redirect()->back();
  193. }
  194. if ($this->callApiService->verifyApiError($youtubeTypes)) {
  195. notify()->error($youtubeTypes['body'], 'Error', 'bottomRight');
  196. return redirect()->back();
  197. }
  198. if ($this->callApiService->verifyApiError($mainBlogList)) {
  199. notify()->error($mainBlogList['body'], 'Error', 'bottomRight');
  200. return redirect()->back();
  201. }
  202. if ($this->callApiService->verifyApiError($blogTypes)) {
  203. notify()->error($blogTypes['body'], 'Error', 'bottomRight');
  204. return redirect()->back();
  205. }
  206. return view('views.index', compact('maMainText', 'seoHtml', 'maMainSlider', 'mainSiseList', 'mainYoutubeList',
  207. 'youtubeTypes' ,'mainBlogList', 'blogTypes', 'oauth2InfoList', 'develLoginInfo'));
  208. }
  209. // 시세 더보기
  210. public function loadMoreSise(Request $request)
  211. {
  212. $today = date('ymd');
  213. // dd($today);
  214. $query = "post_type_id = 59";
  215. $offset = (int) $request->query('offset', 0);
  216. $limit = (int) $request->query('limit', 12);
  217. $siseType = $request->query('siseType', 'golf');
  218. $siseDate = $request->query('siseDate', $today);
  219. if($siseType){
  220. if($siseType != 'golf'){
  221. $query .= " and pc5='$siseType' and pc6='$siseDate'";
  222. }else{
  223. $query .= " and pc5='$siseType'";
  224. }
  225. }
  226. // dd($query);
  227. $moreSiseList=$this->callApiService->callApi([
  228. 'url' => 'post-page',
  229. 'data' => [
  230. 'PageVars' => [
  231. 'Query' => $query,
  232. 'Asc' => 'post_title',
  233. 'Limit' => $limit,
  234. 'Offset' => $offset
  235. ]
  236. ]
  237. ]);
  238. // 등락 계산
  239. if (isset($moreSiseList['Page']) && !empty($moreSiseList['Page'])) {
  240. foreach ($moreSiseList['Page'] as &$sise) {
  241. if (isset($sise['Pc3'], $sise['Pc4'])) {
  242. $sise['fluctuation'] = (float)$sise['Pc3'] - (float)$sise['Pc4'];
  243. } else {
  244. $sise['fluctuation'] = 0;
  245. }
  246. }
  247. }
  248. if ($this->callApiService->verifyApiError($moreSiseList)) {
  249. notify()->error($moreSiseList['body'], 'Error', 'bottomRight');
  250. return redirect()->back();
  251. }
  252. return $moreSiseList;
  253. }
  254. // 유튜브 더보기
  255. public function loadMoreYoutube(Request $request)
  256. {
  257. $query = "(post_type_id = 40 or post_type_id = 43 or post_type_id = 46) and status ='1' and pt!=''";
  258. $offset = (int) $request->query('offset', 0);
  259. $limit = (int) $request->query('limit', 12);
  260. $mainYoutubeList=$this->callApiService->callApi([
  261. 'url' => 'post-page',
  262. 'data' => [
  263. 'PageVars' => [
  264. 'Query' => $query,
  265. 'Desc' => 'created_on',
  266. 'Limit' => $limit,
  267. 'Offset' => $offset
  268. ]
  269. ]
  270. ]);
  271. if ($this->callApiService->verifyApiError($mainYoutubeList)) {
  272. notify()->error($mainYoutubeList['body'], 'Error', 'bottomRight');
  273. return redirect()->back();
  274. }
  275. return $mainYoutubeList;
  276. }
  277. // 블로그 더보기
  278. public function loadMoreBlog(Request $request)
  279. {
  280. $query = "(post_type_id = 41 or post_type_id = 44 or post_type_id = 50) and status ='1'";
  281. $offset = (int) $request->query('offset', 0);
  282. $limit = (int) $request->query('limit', 12);
  283. $moreBlogList=$this->callApiService->callApi([
  284. 'url' => 'post-page',
  285. 'data' => [
  286. 'PageVars' => [
  287. 'Query' => $query,
  288. 'Desc' => 'created_on',
  289. 'Limit' => $limit,
  290. 'Offset' => $offset
  291. ]
  292. ]
  293. ]);
  294. // post_code 만들기
  295. if (isset($moreBlogList['Page']) && !empty($moreBlogList['Page'])) {
  296. foreach ($moreBlogList['Page'] as &$mainBlog) {
  297. if (isset($mainBlog['PostTypeId'])) {
  298. switch ($mainBlog['PostTypeId']) {
  299. case 41:
  300. $mainBlog['PostCode'] = 'golf-blog';
  301. break;
  302. case 44:
  303. $mainBlog['PostCode'] = 'condo-blog';
  304. break;
  305. default:
  306. $mainBlog['PostCode'] = 'fitness-blog';
  307. }
  308. }
  309. }
  310. }
  311. if ($this->callApiService->verifyApiError($moreBlogList)) {
  312. notify()->error($moreBlogList['body'], 'Error', 'bottomRight');
  313. return redirect()->back();
  314. }
  315. return $moreBlogList;
  316. }
  317. }