Category.php 3.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. */
  44. class Category extends BaseModel
  45. {
  46. use SoftDeletes;
  47. protected $table = "category";
  48. public function format(...$options)
  49. {
  50. $return = [
  51. "id" => $this->id,
  52. "name" => $this->name,
  53. "thumb" => $this->thumb,
  54. "level" => $this->level,
  55. "parent_id" => optional($this->parent)->id ?? 0,
  56. "parent_name" => optional($this->parent)->name ?? 0,
  57. "weight" => $this->weight,
  58. "index_weight" => $this->index_weight,
  59. "category_weight" => $this->category_weight,
  60. "search_weight" => $this->search_weight,
  61. ];
  62. return $return;
  63. }
  64. public function parent()
  65. {
  66. return $this->belongsTo(Category::class, "parent_id");
  67. }
  68. public function childS()
  69. {
  70. return $this->hasMany(Category::class, "parent_id", "id");
  71. }
  72. public function gcMap()
  73. {
  74. return $this->hasMany(GoodsCategoryMap::class, "category_id", "id");
  75. }
  76. }