链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.0 KiB

  1. <?php
  2. namespace App\Models\v3;
  3. use Dcat\Admin\Traits\HasDateTimeFormatter;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Banners extends Model
  7. {
  8. use HasDateTimeFormatter;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_banners';
  11. protected $dateFormat = 'U';
  12. protected $appends = [
  13. 'cover_url',
  14. 'cover_type_text',
  15. 'path_type_text',
  16. 'type_text',
  17. 'status_text'
  18. ];
  19. protected $casts = [
  20. 'market_ids'=>'array',
  21. ];
  22. public static $_COVER_TYPE = [1=>'图片', 2=>'视频'];
  23. public static $_PATH_TYPE = ['page'=>'page','webview'=>'webview','applet'=>'applet'];
  24. public static $_TYPE = [1=>'首页'];
  25. public static $_STATUS = ['禁用', '正常'];
  26. public function getCoverUrlAttribute($value)
  27. {
  28. $value = $value ? $value : $this->cover;
  29. return $this->imageUrl($value);
  30. }
  31. public function getCoverTypeTextAttribute($value)
  32. {
  33. $value = $value ? $value : $this->cover_type;
  34. return isset(self::$_COVER_TYPE[$value]) ? self::$_COVER_TYPE[$value] : '';
  35. }
  36. public function getPathTypeTextAttribute($value)
  37. {
  38. $value = $value ? $value : $this->path_type;
  39. return isset(self::$_PATH_TYPE[$value]) ? self::$_PATH_TYPE[$value] : '';
  40. }
  41. public function getTypeTextAttribute($value)
  42. {
  43. $value = $value ? $value : $this->type;
  44. return isset(self::$_TYPE[$value]) ? self::$_TYPE[$value] : '';
  45. }
  46. public function getStatusTextAttribute($value)
  47. {
  48. $value = $value ? $value : $this->stauts;
  49. return isset(self::$_STATUS[$value]) ? self::$_STATUS[$value] : '';
  50. }
  51. /**
  52. * 处理旧图片
  53. * @param $value
  54. * @return string
  55. */
  56. public function imageUrl($value)
  57. {
  58. if(strripos($value,"http") === false){
  59. return config('filesystems.disks.oss.img_host').'/'.$value;
  60. }else{
  61. return $value;
  62. }
  63. }
  64. }