IndexController.php 12 KB

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