HomePageController.php 1.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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)->orderByDesc("order")->get()->map(function ($record) use (&$result, $locale){
  29. $result[] = [
  30. "imgUrl" => $record->imgUrlLink,
  31. "mobileImgUrl" => $record->mobileImgLink,
  32. "type" => $record->type,
  33. "title" => $record->getTranslation("title", $locale),
  34. "content" => $record->getTranslation("content", $locale),
  35. ];
  36. });
  37. return Response::ok($result);
  38. }
  39. public function list($locale = 'tw')
  40. {
  41. $locale = $locale == "tw" ? "zh_TW" : $locale;
  42. $result = [];
  43. $webNews = News::where("visible", 1)->orderByDesc("post_date")->limit(3)->get();
  44. foreach($webNews as $item){
  45. $result["list"][] = [
  46. "id" => $item->id,
  47. "categoryId" => $item->newsCategory->id,
  48. "category" => $item->newsCategory->getTranslation("name", $locale),
  49. "postDate" => Carbon::parse($item->post_date)->format("Y.m.d"),
  50. "title" => $item->getTranslation("title", $locale),
  51. ];
  52. }
  53. return Response::ok($result);
  54. }
  55. }