Category.php 4.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. namespace App\Models\Goods;
  3. use App\Base\BaseModel;
  4. use Faker\Provider\Image;
  5. use Illuminate\Database\Eloquent\SoftDeletes;
  6. /**
  7. * App\Models\Goods\Category
  8. *
  9. * @property int $id
  10. * @property string $name
  11. * @property string $thumb
  12. * @property int $level 层级
  13. * @property int $parent_id 上级分类ID
  14. * @property int $weight 权重
  15. * @property int $index_weight 推荐位权重
  16. * @property int $category_weight 推荐位权重
  17. * @property int $search_weight 搜索页权重
  18. * @property \Illuminate\Support\Carbon|null $created_at
  19. * @property \Illuminate\Support\Carbon|null $updated_at
  20. * @property \Illuminate\Support\Carbon|null $deleted_at
  21. * @method static \Illuminate\Database\Eloquent\Builder|Category newModelQuery()
  22. * @method static \Illuminate\Database\Eloquent\Builder|Category newQuery()
  23. * @method static \Illuminate\Database\Query\Builder|Category onlyTrashed()
  24. * @method static \Illuminate\Database\Eloquent\Builder|Category query()
  25. * @method static \Illuminate\Database\Eloquent\Builder|Category whereCategoryWeight($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|Category whereCreatedAt($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|Category whereDeletedAt($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|Category whereId($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|Category whereIndexWeight($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder|Category whereLevel($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder|Category whereName($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder|Category whereParentId($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder|Category whereSearchWeight($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder|Category whereThumb($value)
  35. * @method static \Illuminate\Database\Eloquent\Builder|Category whereUpdatedAt($value)
  36. * @method static \Illuminate\Database\Eloquent\Builder|Category whereWeight($value)
  37. * @method static \Illuminate\Database\Query\Builder|Category withTrashed()
  38. * @method static \Illuminate\Database\Query\Builder|Category withoutTrashed()
  39. * @mixin \Eloquent
  40. * @property-read Category|null $parent
  41. * @property-read \Illuminate\Database\Eloquent\Collection|Category[] $childS
  42. * @property-read int|null $child_s_count
  43. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Goods\GoodsCategoryMap[] $gcMap
  44. * @property-read int|null $gc_map_count
  45. * @property string $en_name
  46. * @method static \Illuminate\Database\Eloquent\Builder|Category whereEnName($value)
  47. */
  48. class Category extends BaseModel
  49. {
  50. use SoftDeletes;
  51. protected $table = "category";
  52. protected $fillable = ["name", "thumb", "level", "parent_id", "weight", "index_weight", "category_weight", "search_weight"];
  53. public function format(...$options)
  54. {
  55. $return = [
  56. "id" => $this->id,
  57. "name" => $this->name,
  58. "en_name" => $this->en_name,
  59. "thumb" => $this->thumb,
  60. "level" => $this->level,
  61. "parent_id" => optional($this->parent)->id ?? 0,
  62. "parent_name" => optional($this->parent)->name ?? 0,
  63. "weight" => $this->weight,
  64. "index_weight" => $this->index_weight,
  65. "category_weight" => $this->category_weight,
  66. "search_weight" => $this->search_weight,
  67. ];
  68. return $return;
  69. }
  70. public function parent()
  71. {
  72. return $this->belongsTo(Category::class, "parent_id");
  73. }
  74. public function childS()
  75. {
  76. return $this->hasMany(Category::class, "parent_id", "id");
  77. }
  78. public function gcMap()
  79. {
  80. return $this->hasMany(GoodsCategoryMap::class, "category_id", "id");
  81. }
  82. }