HomePageController.php 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Http\Requests\RegistEPaperRequest;
  5. use App\Models\Banner;
  6. use App\Models\EpaperSubscription;
  7. use App\Models\HomepageToTop;
  8. use App\Models\News;
  9. use App\Models\Setting;
  10. use App\Supports\Response;
  11. use Carbon\Carbon;
  12. use Illuminate\Http\Request;
  13. use Illuminate\Support\Facades\DB;
  14. use Illuminate\Support\Facades\Log;
  15. /**
  16. * @group Lottery Prize
  17. */
  18. class HomePageController extends Controller
  19. {
  20. public function __construct(
  21. )
  22. {
  23. }
  24. public function banners($locale = 'tw')
  25. {
  26. $locale = $locale == "tw" ? "zh_TW" : $locale;
  27. $result = [];
  28. $banners = Banner::where("visible", true)->get()->map(function ($record) use (&$result, $locale){
  29. $result[] = [
  30. "imgUrl" => $record->imgUrlLink,
  31. "mobileImgUrl" => $record->mobileImgLink,
  32. "title" => $record->getTranslation("title", $locale),
  33. "content" => $record->getTranslation("content", $locale),
  34. ];
  35. });
  36. return Response::ok($result);
  37. }
  38. public function list($locale = 'tw')
  39. {
  40. $locale = $locale == "tw" ? "zh_TW" : $locale;
  41. $result = [];
  42. $webNews = News::where("visible", 1)->orderByDesc("post_date")->limit(3)->get();
  43. foreach($webNews as $item){
  44. $result["list"][] = [
  45. "id" => $item->id,
  46. "categoryId" => $item->newsCategory->id,
  47. "category" => $item->newsCategory->getTranslation("name", $locale),
  48. "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
  49. "title" => $item->getTranslation("title", $locale),
  50. ];
  51. }
  52. return Response::ok($result);
  53. }
  54. }