Goods.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  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. // ->where('goods_sku_status','ON')
  57. ->select('goods_sku_id','join_sku_goods_id','goods_sku_specs_json','goods_sku_sales_price','goods_sku_status');
  58. }
  59. public function user(){
  60. return $this->hasOne(SysUser::class,'user_id','creator_user_id');
  61. }
  62. public function updateUser(){
  63. return $this->hasOne(SysUser::class,'user_id','updator_user_id');
  64. }
  65. }