123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384 |
- <?php
- namespace app\model;
- use DateTimeInterface;
- use support\Model;
- class Goods extends Model
- {
- protected $table = 'goods';
- protected $primaryKey = 'goods_id';
- protected $keyType = 'string';
- public $incrementing = false;
- protected $dateFormat = 'U';
- const CREATED_AT = 'goods_addtimes';
- const UPDATED_AT = 'goods_updatetimes';
- // 自动上架
- const LISTING_KEY_PREFIX = "GOODS:LISTING:ON:";
- // 自动下架
- const LISTING_OFF_KEY_PREFIX = "GOODS:LISTING:OFF:";
- public function serializeDate(DateTimeInterface $date)
- {
- return $date->format('Y-m-d H:i:s');
- }
- /**
- * @Desc 关联分类
- * @Author Gorden
- * @Date 2024/3/28 9:36
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function category()
- {
- return $this->hasOne(SysCategory::class, 'category_id', 'join_goods_category_id')
- ->select('category_id','category_name');
- }
- /**
- * @Desc 关联GoodsRunning
- * @Author Gorden
- * @Date 2024/3/28 10:04
- *
- * @return \Illuminate\Database\Eloquent\Relations\HasOne
- */
- public function running()
- {
- return $this->hasOne(GoodsRunning::class, 'join_running_goods_id', 'goods_id');
- }
- public function supplier()
- {
- return $this->hasOne(Supplier::class, 'supplier_id', 'join_goods_supplier_id');
- }
- public function component()
- {
- return $this->hasMany(GoodsComponent::class, 'join_component_master_goods_id', 'goods_id');
- }
- public function sku()
- {
- return $this->hasMany(GoodsSku::class,'join_sku_goods_id','goods_id')
- // ->where('goods_sku_status','ON')
- ->select('goods_sku_id','join_sku_goods_id','goods_sku_specs_json','goods_sku_sales_price','goods_sku_status');
- }
- public function user(){
- return $this->hasOne(SysUser::class,'user_id','creator_user_id');
- }
- public function updateUser(){
- return $this->hasOne(SysUser::class,'user_id','updator_user_id');
- }
- }
|