AnnouncementRepository.php 936 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Announcement;
  4. use Carbon\Carbon;
  5. class AnnouncementRepository extends BaseRepository
  6. {
  7. public function __construct(Announcement $model)
  8. {
  9. $this->model = $model;
  10. }
  11. public function byAreaIdGetAns($area_id)
  12. {
  13. $area_ids = array_unique([0, $area_id]);
  14. return $this->model
  15. ->whereIn('area_id', $area_ids)
  16. ->where('status', Announcement::STATUS_OK)
  17. ->orderByDesc('id')
  18. ->paginate();
  19. }
  20. /**
  21. * 获取最后一条公告
  22. * */
  23. public function byAreaIdGetLastAn($area_id)
  24. {
  25. $area_ids = array_unique([0, $area_id]);
  26. return $this->model
  27. ->whereIn('area_id', $area_ids)
  28. ->where('status', Announcement::STATUS_OK)
  29. ->whereDate('expiration_time', '>', Carbon::now())
  30. ->orderByDesc('id')
  31. ->first();
  32. }
  33. }