PostService.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Services;
  3. use Carbon\Carbon;
  4. class PostService
  5. {
  6. private $callApiService;
  7. public function __construct(CallApiService $callApiService)
  8. {
  9. $this->callApiService = $callApiService;
  10. }
  11. function getPostList($typeSlug, $request, $limit, $page)
  12. {
  13. $p = $request['p'] ?? '';
  14. $query = "(post_title like '%$p%' or post_contents like '%$p%' or pc1 like '%$p%')";
  15. if (isset($request['selopt1'])) {
  16. $formDt = Carbon::now()->startOfDay();
  17. $toDt = Carbon::now()->endOfDay();
  18. switch ($request['selopt1']) {
  19. case '2':
  20. $formDt->subDays(7);
  21. break;
  22. case '3':
  23. $formDt->subMonths();
  24. break;
  25. case '4':
  26. $formDt->subMonths(6);
  27. break;
  28. case '5':
  29. $formDt->subYears();
  30. break;
  31. }
  32. switch ($request['selopt3']) {
  33. case '1':
  34. $query = "(post_title like '%$p%')";
  35. break;
  36. case '2':
  37. $query = "(mem.nick_name like '%$p%')";
  38. break;
  39. }
  40. if ($request['selopt1'] > 0) {
  41. $query = "(mx.created_on between $formDt->timestamp and $toDt->timestamp) and $query";
  42. }
  43. // dump($query);
  44. }
  45. return $this->callApiService->callApi([
  46. 'url' => 'post-list-book',
  47. 'data' => [
  48. 'TypeSlug' => $typeSlug,
  49. 'PostQueryVars' => [
  50. 'QueryName' => 'pro:post/post-list-book',
  51. 'SimpleFilter' => $query
  52. ],
  53. 'PostPageVars' => [
  54. 'Limit' => $limit,
  55. 'Offset' => ($page - 1) * $limit
  56. ]
  57. ]
  58. ]);
  59. }
  60. function getPostDetailsBook($slug, $limit, $page)
  61. {
  62. return $this->callApiService->callApi([
  63. 'url' => 'post-details-book',
  64. 'data' => [
  65. 'PostSlug' => $slug,
  66. 'PostBdQueryVars' => [
  67. 'QueryName' => 'pro:post/post-bd-reply',
  68. 'SimpleFilter' => ''
  69. ],
  70. 'PostBdPageVars' => [
  71. 'Limit' => $limit,
  72. 'Offset' => ($page - 1) * $limit
  73. ]
  74. ]
  75. ]);
  76. }
  77. }