Goods.php 1.8 KB

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