Goods.php 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 = 'goods_updatetimes';
  14. // 自动上架
  15. const LISTING_KEY_PREFIX = "GOODS:LISTING:ON:";
  16. // 自动下架
  17. const LISTING_OFF_KEY_PREFIX = "GOODS:LISTING:OFF:";
  18. public function serializeDate(DateTimeInterface $date)
  19. {
  20. return $date->format('Y-m-d H:i:s');
  21. }
  22. /**
  23. * @Desc 关联分类
  24. * @Author Gorden
  25. * @Date 2024/3/28 9:36
  26. *
  27. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  28. */
  29. public function category()
  30. {
  31. return $this->hasOne(SysCategory::class, 'category_id', 'join_goods_category_id')
  32. ->select('category_id', 'category_name');
  33. }
  34. public function detail()
  35. {
  36. return $this->hasOne(GoodsDetail::class, 'join_detail_goods_id', 'goods_id');
  37. }
  38. /**
  39. * @Desc 关联GoodsRunning
  40. * @Author Gorden
  41. * @Date 2024/3/28 10:04
  42. *
  43. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  44. */
  45. public function running()
  46. {
  47. return $this->hasOne(GoodsRunning::class, 'join_running_goods_id', 'goods_id');
  48. }
  49. public function supplier()
  50. {
  51. return $this->hasOne(Supplier::class, 'supplier_id', 'join_goods_supplier_id');
  52. }
  53. public function component()
  54. {
  55. return $this->hasMany(GoodsComponent::class, 'join_component_master_goods_id', 'goods_id');
  56. }
  57. public function sku()
  58. {
  59. return $this->hasMany(GoodsSku::class, 'join_sku_goods_id', 'goods_id')
  60. // ->where('goods_sku_status','ON')
  61. ->select('goods_sku_id', 'join_sku_goods_id', 'goods_sku_specs_json', 'goods_sku_sales_price', 'goods_sku_status', 'goods_sku_storage_json');
  62. }
  63. public function skuOne()
  64. {
  65. return $this->hasOne(GoodsSku::class, 'join_sku_goods_id', 'goods_id')
  66. ->select('goods_sku_id', 'join_sku_goods_id', 'goods_sku_specs_json', 'goods_sku_sales_price', 'goods_sku_status', 'goods_sku_storage_json');
  67. }
  68. public function user()
  69. {
  70. return $this->hasOne(SysUser::class, 'user_id', 'creator_user_id');
  71. }
  72. public function updateUser()
  73. {
  74. return $this->hasOne(SysUser::class, 'user_id', 'updator_user_id');
  75. }
  76. }