AnnouncementRepository.php 986 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  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. ->merchant()
  16. ->whereIn('area_id', $area_ids)
  17. ->where('status', Announcement::STATUS_OK)
  18. ->orderByDesc('id')
  19. ->paginate();
  20. }
  21. /**
  22. * 获取最后一条公告
  23. * */
  24. public function byAreaIdGetLastAn($area_id)
  25. {
  26. $area_ids = array_unique([0, $area_id]);
  27. return $this->model
  28. ->merchant()
  29. ->whereIn('area_id', $area_ids)
  30. ->where('status', Announcement::STATUS_OK)
  31. ->whereDate('expiration_time', '>', Carbon::now())
  32. ->orderByDesc('id')
  33. ->first();
  34. }
  35. }