AdvertisementRepository.php 814 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Advertisement;
  4. use Carbon\Carbon;
  5. class AdvertisementRepository extends BaseRepository
  6. {
  7. public function __construct(Advertisement $model)
  8. {
  9. $this->model = $model;
  10. }
  11. /**
  12. * 根据区域和位置获取广告
  13. * @param $position
  14. * @param $area_id
  15. * @return mixed
  16. * Author: Mead
  17. */
  18. public function byPositionIdGetActive($position, $area_id)
  19. {
  20. $now = Carbon::now()->toDateTimeString();
  21. $area_ids = array_unique([0, $area_id]);
  22. return $this->model->whereIn('area_id', $area_ids)->whereIn('advertisement_position_slug', $position)->where('start_time', '<=', $now)->where('end_time', '>', $now)->where('is_display', Advertisement::DISPLAY_OK)->orderBy('sort', 'desc')->get();
  23. }
  24. }