SiseController.php 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. <?php
  2. namespace Themes\kbgolf\pro\app\Http\Controllers\Page;
  3. use App\Http\Controllers\Controller;
  4. use App\Services\CallApiService;
  5. use Illuminate\Pagination\LengthAwarePaginator;
  6. use Illuminate\Http\Request;
  7. use Illuminate\Support\Facades\Log;
  8. class SiseController extends Controller
  9. {
  10. private $callApiService;
  11. public function __construct(CallApiService $callApiService)
  12. {
  13. $this->callApiService = $callApiService;
  14. }
  15. public function index($siseType, $area=null, $memberbershipname=null)
  16. {
  17. // siseType별로 title 변수 생성
  18. switch ($siseType) {
  19. case 'golf':
  20. $title_dir = "골프";
  21. $title = "골프회원권 시세";
  22. break;
  23. case 'condo':
  24. $title_dir = "콘도";
  25. $title = "콘도회원권 시세";
  26. break;
  27. default:
  28. $title_dir = "휘트니스";
  29. $title = "휘트니스회원권 시세";
  30. }
  31. $query = "post_type_id = 59 and pc5='$siseType'";
  32. if($area){
  33. if($area != 'all'){
  34. $query .= " and pc2='$area'";
  35. }
  36. }
  37. if($memberbershipname){
  38. $query .= " and postTitle like '%$memberbershipname%'";
  39. }
  40. $limit = (int)request('limit', 10);
  41. $page = (int)request('page', 1);
  42. // api 호출 request
  43. $siseList = $this->callApiService->callApi([
  44. 'url' => 'post-page',
  45. 'data' => [
  46. 'PageVars' => [
  47. 'Query' => $query,
  48. 'Desc' => 'post_title',
  49. 'Limit' => $limit,
  50. 'Offset' => ($page - 1) * $limit
  51. ]
  52. ]
  53. ]);
  54. // dd($siseList);
  55. // 등락 계산
  56. if (isset($siseList['Page']) && !empty($siseList['Page'])) {
  57. foreach ($siseList['Page'] as &$sise) {
  58. if (isset($sise['Pc3'], $sise['Pc4'])) {
  59. $sise['fluctuation'] = (float)$sise['Pc3'] - (float)$sise['Pc4'];
  60. } else {
  61. $sise['fluctuation'] = 0;
  62. }
  63. }
  64. }
  65. if ($this->callApiService->verifyApiError($siseList)) {
  66. notify()->error($siseList['body'], 'Error', 'bottomRight');
  67. return redirect()->back();
  68. }
  69. // pagenation
  70. // $totalcnt = $siseList['PageVars']['QueryCnt'];
  71. // $siseItems['Page'] = new LengthAwarePaginator(
  72. // $siseList['Page'],
  73. // $totalcnt,
  74. // $limit,
  75. // $page,
  76. // ['path' => request()->url()]
  77. // );
  78. // dd($siseItems['Page']);
  79. return view('views.page.sise', compact('siseList', 'title', "title_dir", "siseType", "area"));
  80. }
  81. public function loadScrollSise(Request $request)
  82. {
  83. $today = date('ymd');
  84. $limit = (int) $request->query('limit', 400);
  85. $page = (int) $request->query('page', 1);
  86. $siseType = $request->query('siseType', "golf");
  87. $areaType = $request->query('areaType', "all");
  88. $siseDate = $request->query('siseDate', $today);
  89. $query = "post_type_id = 59 ";
  90. if($areaType != 'all'){
  91. $query .= "and pc5='$siseType' and pc2='$areaType' and pc6='$siseDate'";
  92. }else{
  93. $query .= "and pc5='$siseType' and pc6='$siseDate'";
  94. }
  95. // Log::info('More Sise List:',$siseDate );
  96. $moreSiseList=$this->callApiService->callApi([
  97. 'url' => 'post-page',
  98. 'data' => [
  99. 'PageVars' => [
  100. 'Query' => $query,
  101. 'Asc' => 'post_title',
  102. 'Limit' => $limit,
  103. 'Offset' => ($page - 1) * $limit
  104. ]
  105. ]
  106. ]);
  107. // 등락 계산
  108. if (isset($moreSiseList['Page']) && !empty($moreSiseList['Page'])) {
  109. foreach ($moreSiseList['Page'] as &$sise) {
  110. if (isset($sise['Pc3'], $sise['Pc4'])) {
  111. $sise['fluctuation'] = (float)$sise['Pc3'] - (float)$sise['Pc4'];
  112. } else {
  113. $sise['fluctuation'] = 0;
  114. }
  115. }
  116. }
  117. if ($this->callApiService->verifyApiError($moreSiseList)) {
  118. notify()->error($moreSiseList['body'], 'Error', 'bottomRight');
  119. return redirect()->back();
  120. }
  121. return $moreSiseList;
  122. }
  123. }