链街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.

81 lines
1.8 KiB

  1. <?php
  2. namespace App\Models\v3;
  3. use Illuminate\Database\Eloquent\SoftDeletes;
  4. use Dcat\Admin\Traits\ModelTree;
  5. use Illuminate\Database\Eloquent\Model;
  6. class Category extends Model
  7. {
  8. use ModelTree;
  9. use SoftDeletes;
  10. protected $table = 'lanzu_category';
  11. protected $dateFormat = 'U';
  12. // 父级ID字段名称,默认值为 parent_id
  13. // protected $parentColumn = 'pid';
  14. // 排序字段名称,默认值为 order
  15. protected $orderColumn = 'sort';
  16. // 标题字段名称,默认值为 title
  17. // protected $titleColumn = 'name';
  18. protected $appends = [
  19. 'cover_img_url',
  20. ];
  21. public function getCoverImgUrlAttribute($value)
  22. {
  23. $value = $value ? $value : $this->cover_img;
  24. return $this->imageUrl($value);
  25. }
  26. /**
  27. * 获取单个信息
  28. * @param int $id
  29. * @param string $field
  30. * @return string
  31. */
  32. public static function getInfo($id,$field = '*')
  33. {
  34. return self::select($field)->find($id);
  35. }
  36. /**
  37. * 获取二级分类数组
  38. * id为键,title为值
  39. * @return array
  40. */
  41. public static function getArray($where = [],$options = [])
  42. {
  43. $model = self::where('status',1)
  44. ->whereNull('deleted_at');
  45. if(count($where) > 0){
  46. $model->where($where);
  47. }
  48. $list = $model->pluck('title','id')->toArray();
  49. if(!empty($options)){
  50. return array_merge($options,$list);
  51. }else{
  52. return $list;
  53. }
  54. }
  55. /**
  56. * 处理旧图片
  57. * @param $value
  58. * @return string
  59. */
  60. public function imageUrl($value)
  61. {
  62. if(strripos($value,"http") === false){
  63. return env('OSS_IMG_HOST').'/'.$value;
  64. }else{
  65. return $value;
  66. }
  67. }
  68. }