SiseController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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. class SiseController extends Controller
  8. {
  9. private $callApiService;
  10. public function __construct(CallApiService $callApiService)
  11. {
  12. $this->callApiService = $callApiService;
  13. }
  14. public function index($siseType, $area=null, $memberbershipname=null)
  15. {
  16. // siseType별로 title 변수 생성
  17. switch ($siseType) {
  18. case 'golf':
  19. $title_dir = "골프";
  20. $title = "골프회원권 시세";
  21. break;
  22. case 'condo':
  23. $title_dir = "콘도";
  24. $title = "콘도회원권 시세";
  25. break;
  26. default:
  27. $title_dir = "휘트니스";
  28. $title = "휘트니스회원권 시세";
  29. }
  30. $query = "post_type_id = 59 and pc5='$siseType'";
  31. if($area){
  32. if($area != 'all'){
  33. // switch ($area) {
  34. // case '123':
  35. // $query .= " and pc2='1' or pc2='2' or pc2='3'";
  36. // break;
  37. // case '45':
  38. // $query .= " and pc2='4' or pc2='5'";
  39. // break;
  40. // default:
  41. // $query .= " and pc2='$area'";
  42. // }
  43. $query .= " and pc2='$area'";
  44. }
  45. }
  46. if($memberbershipname){
  47. $query .= " and postTitle like '%$memberbershipname%'";
  48. }
  49. $limit = (int)request('limit', 12);
  50. $page = (int)request('page', 1);
  51. // api 호출 request
  52. $siseList = $this->callApiService->callApi([
  53. 'url' => 'post-page',
  54. 'data' => [
  55. 'PageVars' => [
  56. 'Query' => $query,
  57. 'Desc' => 'created_on',
  58. 'Limit' => $limit,
  59. 'Offset' => ($page - 1) * $limit
  60. ]
  61. ]
  62. ]);
  63. // dd($siseList);
  64. // 등락 계산
  65. if (isset($siseList['Page']) && !empty($siseList['Page'])) {
  66. foreach ($siseList['Page'] as &$sise) {
  67. if (isset($sise['Pc3'], $sise['Pc4'])) {
  68. $sise['fluctuation'] = (float)$sise['Pc3'] - (float)$sise['Pc4'];
  69. } else {
  70. $sise['fluctuation'] = 0;
  71. }
  72. }
  73. }
  74. if ($this->callApiService->verifyApiError($siseList)) {
  75. notify()->error($siseList['body'], 'Error', 'bottomRight');
  76. return redirect()->back();
  77. }
  78. // pagenation
  79. $totalcnt = $siseList['PageVars']['QueryCnt'];
  80. $siseItems['Page'] = new LengthAwarePaginator(
  81. $siseList['Page'],
  82. $totalcnt,
  83. $limit,
  84. $page,
  85. ['path' => request()->url()]
  86. );
  87. return view('views.page.sise', compact('siseList', 'siseItems', 'title', "title_dir", "siseType", "area"));
  88. }
  89. }