HistoryController.php 1.2KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Http\Controllers\Api;
  3. use App\Http\Controllers\Controller;
  4. use App\Models\History;
  5. use App\Supports\Response;
  6. use Carbon\Carbon;
  7. use Illuminate\Http\Request;
  8. use Illuminate\Support\Facades\DB;
  9. use Illuminate\Support\Facades\Log;
  10. /**
  11. * @group Lottery Prize
  12. */
  13. class HistoryController extends Controller
  14. {
  15. public function __construct(
  16. )
  17. {
  18. }
  19. public function list($locate = 'tw')
  20. {
  21. $locate = $locate == "tw" ? "zh_TW" : $locate;
  22. $data = History::where("visible", 1)->orderByDesc("selected_year", "desc")->orderByDesc("selected_month")->get();
  23. $yearList = History::select("selected_year", \DB::raw("concat(selected_year, '年') as lable"))->distinct()->orderBy("selected_year", "desc")->pluck('lable', 'selected_year');
  24. $result = [];
  25. $result["yearList"] = $yearList;
  26. foreach($data as $item){
  27. $result["list"][$item->selected_year][] = [
  28. "operateMonth " => $item->selected_year . "." . $item->selected_month,
  29. "title" => $item->getTranslation("title", $locate),
  30. "imgUrl" => $item->img_url_link
  31. ];
  32. }
  33. return Response::ok($result);
  34. }
  35. }