Previous.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace app\home\controller;
  3. use app\common\model\PreviousModel;
  4. use app\common\model\PreviousYearModel;
  5. use app\common\model\ReservedModel;
  6. use app\home\HomeBaseController;
  7. class Previous extends HomeBaseController
  8. {
  9. public function index()
  10. {
  11. $year_id = input('year_id/d');
  12. $year_list = PreviousYearModel::order(['priority' => 'desc'])->select();
  13. if (empty($year_id)) {
  14. $year_id = $year_list[count($year_list) - 1]['id'];
  15. }
  16. return view('', [
  17. 'year_list' => $year_list,
  18. 'year_id' => $year_id,
  19. ]);
  20. }
  21. public function list()
  22. {
  23. $month = input('month/d');
  24. $year_id = input('year_id/d');
  25. if (empty($month) || empty($year_id)) {
  26. return redirect(url('index'));
  27. }
  28. $previous = PreviousModel::where('status', ReservedModel::STATUS_SHOW)
  29. ->where('year_id', $year_id)
  30. ->where('month', $month)
  31. ->order(['priority' => 'desc', 'id' => 'desc'])
  32. ->select();
  33. $previous = array_split($previous, 3);
  34. $year_list = PreviousYearModel::order(['priority' => 'desc'])->select();
  35. return view('', [
  36. 'previous' => $previous,
  37. 'year_list' => $year_list,
  38. 'year_id' => $year_id,
  39. 'month_index' => $month,
  40. 'month_list' => PreviousModel::MONTH,
  41. ]);
  42. }
  43. }