Goods.php 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. // 自动上架
  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. }
  33. /**
  34. * @Desc 关联GoodsRunning
  35. * @Author Gorden
  36. * @Date 2024/3/28 10:04
  37. *
  38. * @return \Illuminate\Database\Eloquent\Relations\HasOne
  39. */
  40. public function running()
  41. {
  42. return $this->hasOne(GoodsRunning::class, 'join_running_goods_id', 'goods_id');
  43. }
  44. public function supplier()
  45. {
  46. return $this->hasOne(Supplier::class, 'supplier_id', 'join_goods_supplier_id');
  47. }
  48. public function component()
  49. {
  50. return $this->hasMany(GoodsComponent::class, 'join_component_master_goods_id', 'goods_id');
  51. }
  52. public function sku()
  53. {
  54. return $this->hasMany(GoodsSku::class,'join_sku_goods_id','goods_id')
  55. ->select('goods_sku_id','join_sku_goods_id','goods_sku_specs_json','goods_sku_sales_price');
  56. }
  57. }