AdvertisementRepository.php 707 B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Repositories;
  3. use App\Models\Advertisement;
  4. use Carbon\Carbon;
  5. use Illuminate\Support\Facades\Log;
  6. class AdvertisementRepository extends BaseRepository
  7. {
  8. public function __construct(Advertisement $model)
  9. {
  10. $this->model = $model;
  11. }
  12. public function byPositionIdGetActive($position, $area_id)
  13. {
  14. $now = Carbon::now()->toDateTimeString();
  15. $area_ids = array_unique([0, $area_id]);
  16. 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();
  17. }
  18. }