AdPositionDispatch.php 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Modules\AdPosition\Models;
  3. use Illuminate\Database\Eloquent\Model;
  4. class AdPositionDispatch extends Model
  5. {
  6. protected $table = 'qapp_ad_position_dispatch';
  7. protected $fillable = ['title', 'ad_position_id', 'link_url', 'link_type', 'image_url', 'desc', 'type', 'content_type',
  8. 'priority', 'status', 'filter_condition', 'channel_id', 'qapp_account_id', 'start_time', 'end_time'];
  9. /**
  10. * 获取有效的广告位分配
  11. * @param $adPositionIds
  12. * @param $qappAccountId
  13. * @return array
  14. */
  15. public static function getValidPositionDispatches($adPositionIds, $qappAccountId): array
  16. {
  17. if (empty($adPositionIds) || empty($qappAccountId)) {
  18. return [];
  19. }
  20. $result = self::whereIn('ad_position_id', $adPositionIds)
  21. ->where('qapp_account_id', $qappAccountId)
  22. ->where('status', 1)
  23. ->where('start_time', '<=', date('Y-m-d H:i:s'))
  24. ->where('end_time', '>=', date('Y-m-d H:i:s'))
  25. ->orderBy('priority', 'DESC')
  26. ->orderBy('end_time', 'ASC')
  27. ->get();
  28. return $result ? $result->toArray() : [];
  29. }
  30. }