'array', 'spec' => 'array', 'tags' => 'array', ]; protected $appends = [ 'month_sales', 'cart_num', 'is_effective', 'noneffective_note', 'total_seconds', ]; protected $visible = [ 'id', 'cover_img', 'name', 'original_price', 'price', 'inventory', 'store_id', 'spec', 'tags', 'sales', 'month_sales', 'cart_num', 'is_effective', 'noneffective_note', 'total_seconds', ]; protected function boot(): void { parent::boot(); self::addGlobalScope('normal', function (Builder $builder) { $builder->where(['on_sale' => GoodsConstants::ON_SALE_YES]); }); } public function getMonthSalesAttribute() { $ssdb = ApplicationContext::getContainer()->get(SSDBTask::class); return (integer)$ssdb->exec('get', SsdbKeys::GOODS_MONTH_SALES.date('YM').'_'.$this->id); } public function getCartNumAttribute() { return (integer)$this->shopCartService->check($this->id); } public function getIsEffectiveAttribute() { return 2; } public function getNoneffectiveNoteAttribute() { return '已抢光'; } public function getTotalSecondsAttribute() { return $this->attributes['expire_time'] - time(); } public function store() { return $this->belongsTo(Store::class, 'store_id', 'id'); } }