HomePageController.php 1.7KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  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("visilbe", 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. }
  37. public function list($locale = 'tw')
  38. {
  39. $locale = $locale == "tw" ? "zh_TW" : $locale;
  40. $result = [];
  41. $webNews = News::where("visible", 1)->orderByDesc("post_date")->limit(3)->get();
  42. foreach($webNews as $item){
  43. $result["list"][] = [
  44. "id" => $item->id,
  45. "categoryId" => $item->newsCategory->id,
  46. "category" => $item->newsCategory->getTranslation("name", $locale),
  47. "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
  48. "title" => $item->getTranslation("title", $locale),
  49. ];
  50. }
  51. return Response::ok($result);
  52. }
  53. }