'array', 'spec' => 'array', 'tags' => 'array', ]; protected $appends = [ 'month_sales', 'cart_num', 'is_effective', 'noneffective_note', 'details_imgs_url', ]; protected function boot(): void { parent::boot(); self::addGlobalScope('normal', function (Builder $builder) { $builder->where(['on_sale' => GoodsConstants::ON_SALE_YES]); }); } public function scopeOrderByDefault($query, $sort) { return $query->orderBy('sort', $sort)->orderBy('id', $sort); } public function scopeOrderBySales($query, $sort) { return $query->orderBy('sales', $sort); } public function scopeOrderByPrice($query, $sort) { return $query->orderBy('price', $sort); } public function getCoverImgAttribute($value) { return $this->attachmentService->switchImgToAliOss($value); } 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 0; } public function getIsEffectiveAttribute() { return 1; } public function getNoneffectiveNoteAttribute() { return ''; } public function getDetailsImgsUrlAttribute() { $details_imgs = $this->details_imgs; $img_host = config('alioss.img_host').'/'; return collect($details_imgs)->map(function($item) use ($img_host){ return $img_host . $item; }); } public function store() { return $this->belongsTo(Store::class, 'store_id', 'id'); } public function carts() { return $this->morphMany(ShoppingCart::class, 'goods'); } }