Advertisement.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Models;
  3. use App\Traits\ModelHelpers;
  4. use Illuminate\Database\Eloquent\Model;
  5. use Illuminate\Support\Facades\Log;
  6. class Advertisement extends Model
  7. {
  8. use ModelHelpers;
  9. //
  10. protected $table = "advertisements";
  11. protected $guarded = [];
  12. const DISPLAY_YES = 1;
  13. const DISPLAY_NO = 0;
  14. public static $displayMaps = [
  15. self::DISPLAY_NO => '未展示',
  16. self::DISPLAY_YES => '已展示',
  17. ];
  18. // 广告位
  19. public static function advertisementPositioin(){
  20. $data = [];
  21. $advertisementPositioinCategorySlug = config('systemConfig.sort.advertisement_position.slug','AdvertisementPosition');
  22. $ConfigCategory = ConfigCategory::where('slug',$advertisementPositioinCategorySlug)->first();
  23. $ConfigCategoryId = $ConfigCategory->id ?? '';
  24. if(empty($ConfigCategoryId)) {
  25. Log::error('找不到配置广告位数据');
  26. return $data;
  27. };
  28. $data = Config::where('category_id',$ConfigCategoryId)->get(['id','name','slug'])->toArray();
  29. return $data;
  30. }
  31. // 广告类型
  32. public static function advertisementType(){
  33. $data = [];
  34. $advertisementTypeCategorySlug = config('systemConfig.sort.advertisement_type.slug','AdvertisementType');
  35. $ConfigCategory = ConfigCategory::where('slug',$advertisementTypeCategorySlug)->first();
  36. $ConfigCategoryId = $ConfigCategory->id ?? '';
  37. if(empty($ConfigCategoryId)) {
  38. Log::error('找不到配置广告位数据');
  39. return $data;
  40. };
  41. $data = Config::where('category_id',$ConfigCategoryId)->get(['id','name','slug'])->toArray();
  42. return $data;
  43. }
  44. // 关联区域
  45. public function areas(){
  46. return $this->belongsTo(Area::class,'area_id','id');
  47. }
  48. }