Goods.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. namespace app\model;
  3. use DateTimeInterface;
  4. use support\Model;
  5. class Goods extends Model
  6. {
  7. protected $table = 'goods';
  8. protected $primaryKey = 'goods_id';
  9. protected $keyType = 'string';
  10. public $incrementing = false;
  11. protected $dateFormat = 'U';
  12. const CREATED_AT = 'goods_addtimes';
  13. const UPDATED_AT = null;
  14. const LISTING_KEY_PREFIX = "GOODS:LISTING:";
  15. public function serializeDate(DateTimeInterface $date)
  16. {
  17. return $date->format('Y-m-d H:i:s');
  18. }
  19. /**
  20. * @Desc 关联分类
  21. * @Author Gorden
  22. * @Date 2024/3/28 9:36
  23. *
  24. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  25. */
  26. public function category()
  27. {
  28. return $this->hasOne(SysCategory::class, 'category_id', 'join_goods_category_id');
  29. }
  30. /**
  31. * @Desc 关联GoodsRunning
  32. * @Author Gorden
  33. * @Date 2024/3/28 10:04
  34. *
  35. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  36. */
  37. public function running()
  38. {
  39. return $this->hasOne(GoodsRunning::class, 'join_running_goods_id', 'goods_id');
  40. }
  41. public function supplier()
  42. {
  43. return $this->hasOne(Supplier::class, 'supplier_id', 'join_goods_supplier_id');
  44. }
  45. public function component()
  46. {
  47. return $this->hasMany(GoodsComponent::class,'join_component_master_goods_id','goods_id');
  48. }
  49. }