SiseController.php 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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 pc1='$siseType'";
  31. if($area){
  32. if($area != 'all'){
  33. $query .= " and pc2='$area'";
  34. }
  35. }
  36. if($memberbershipname){
  37. $query .= " and postTitle like '%$memberbershipname%'";
  38. }
  39. // dd($query);
  40. $limit = (int)request('limit', 4);
  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' => 'created_on',
  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. return view('views.page.sise', compact('siseList', 'siseItems', 'title', "title_dir", "siseType", "area"));
  79. }
  80. }