Goods.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. <?php
  2. namespace App\Models;
  3. use DateTimeInterface;
  4. use Illuminate\Database\Eloquent\Model;
  5. /**
  6. * 商家商品表
  7. */
  8. class Goods extends Model
  9. {
  10. /**
  11. * The table associated with the model.
  12. *
  13. * @var string
  14. */
  15. protected $table = 'goods';
  16. /**
  17. * The primary key associated with the table.
  18. *
  19. * @var string
  20. */
  21. protected $primaryKey = 'id';
  22. /**
  23. * Indicates if the model should be timestamped.
  24. *
  25. * @var bool
  26. */
  27. public $timestamps = true;
  28. /**
  29. * 不能被批量赋值的属性
  30. *
  31. * @var array
  32. */
  33. protected $guarded = ['id', 'updated_at', 'created_at'];
  34. private $statusEnum=[
  35. 1=>'上架中',
  36. 2=>'已下架',
  37. 3=>'已售罄',
  38. ];
  39. /**
  40. * 为数组 / JSON 序列化准备日期。
  41. *
  42. * @param DateTimeInterface $date
  43. * @return string
  44. */
  45. protected function serializeDate(DateTimeInterface $date)
  46. {
  47. return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
  48. }
  49. /**
  50. * 序列化数据字典
  51. */
  52. function initializeModel(){
  53. if($this->{'status'}!==null){
  54. $this->{'status_str'}=empty($this->statusEnum[$this->{'status'}])?'无':$this->statusEnum[$this->{'status'}];
  55. }
  56. }
  57. }