Goods.php 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. <?php
  2. namespace App\Models\Goods;
  3. use App\Base\BaseModel;
  4. use Illuminate\Database\Eloquent\SoftDeletes;
  5. use Illuminate\Support\Arr;
  6. /**
  7. * App\Models\Goods\Goods
  8. *
  9. * @property int $id
  10. * @property string $name
  11. * @property array $image_list
  12. * @property array $spec 商品的规格
  13. * @property int $weight
  14. * @property string|null $desc_html
  15. * @property string|null $spec_attr_html
  16. * @property string|null $faq_html
  17. * @property \Illuminate\Support\Carbon|null $created_at
  18. * @property \Illuminate\Support\Carbon|null $updated_at
  19. * @property \Illuminate\Support\Carbon|null $deleted_at
  20. * @method static \Illuminate\Database\Eloquent\Builder|Goods newModelQuery()
  21. * @method static \Illuminate\Database\Eloquent\Builder|Goods newQuery()
  22. * @method static \Illuminate\Database\Query\Builder|Goods onlyTrashed()
  23. * @method static \Illuminate\Database\Eloquent\Builder|Goods query()
  24. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereCreatedAt($value)
  25. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereDeletedAt($value)
  26. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereDescHtml($value)
  27. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereFaqHtml($value)
  28. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereId($value)
  29. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereImageList($value)
  30. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereName($value)
  31. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereSpec($value)
  32. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereSpecAttrHtml($value)
  33. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereUpdatedAt($value)
  34. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereWeight($value)
  35. * @method static \Illuminate\Database\Query\Builder|Goods withTrashed()
  36. * @method static \Illuminate\Database\Query\Builder|Goods withoutTrashed()
  37. * @mixin \Eloquent
  38. * @property int $status 1 上架 2下架
  39. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereStatus($value)
  40. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Goods\GoodsCategoryMap[] $map
  41. * @property-read int|null $map_count
  42. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Goods\GoodsSku[] $sku
  43. * @property-read int|null $sku_count
  44. * @property-read mixed $thumb
  45. * @property int $view_total
  46. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereViewTotal($value)
  47. * @property string $sn
  48. * @property string $url_3d
  49. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereSn($value)
  50. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereUrl3d($value)
  51. * @property-read \Illuminate\Database\Eloquent\Collection|\App\Models\Goods\GoodsSpecMap[] $specMap
  52. * @property-read int|null $spec_map_count
  53. * @property array $custom
  54. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereCustom($value)
  55. * @property string $en_name
  56. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereEnName($value)
  57. * @property string|null $en_desc_html
  58. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereEnDescHtml($value)
  59. * @property string|null $en_spec_attr_html
  60. * @property string|null $en_faq_html
  61. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereEnFaqHtml($value)
  62. * @method static \Illuminate\Database\Eloquent\Builder|Goods whereEnSpecAttrHtml($value)
  63. */
  64. class Goods extends BaseModel
  65. {
  66. use SoftDeletes;
  67. protected $table = "goods";
  68. const STATUS_OK = 1;
  69. const STATUS_OFF = 2;
  70. protected $casts = [
  71. "image_list" => "array",
  72. "spec" => "array",
  73. "custom" => "array",
  74. ];
  75. public function format(...$options)
  76. {
  77. }
  78. public function map()
  79. {
  80. return $this->hasMany(GoodsCategoryMap::class, "goods_id", "id");
  81. }
  82. public function getThumbAttribute()
  83. {
  84. return Arr::first($this->image_list);
  85. }
  86. public function specMap()
  87. {
  88. return $this->hasMany(GoodsSpecMap::class, "goods_id", "id");
  89. }
  90. }