'recreation', '14' => 'life', ]; protected $dates = [ 'start_time', 'end_time', ]; public function gifts() { return $this->hasMany(ActivityGift::class); } public function storage() { return $this->belongsTo(Storage::class)->withDefault(); } public function getStatusAttribute() { //未开始 if ($this->start_time > now()) { return 0; } //已结束 if ($this->end_time < now()) { return -1; } if ($this->start_time <= now() && $this->end_time >= now()) { return 1; } } public function getStatusTextAttribute() { if ($this->status == 1) { return "正常"; } elseif ($this->status == -1) { return "已经结束"; } elseif ($this->status === 0) { return "还没开始"; } } public function category() { return $this->belongsTo(Category::class)->withDefault(); } public function seller() { return $this->belongsTo(Seller::class)->withDefault(); } public function getTypeAttribute() { $cids = Category::whereNotIN('id', [1, 2])->pluck('parent_id', 'id'); $id = $this->category_id; while ($cids[$id] ?? '') { $id = $cids[$id]; if ($id == self::LIFE_ID || $id == self::REC_ID) { return self::$name[$id]; } } return '1'; } public function getStartAtAttribute() { return $this->start_time; } public function getEndAtAttribute() { return $this->end_time; } public function getTitle() { return $this->title . '-' . $this->price; } public function getPrice() { return $this->price; } public function getScore() { return 0; } public function getStock() { return 0; } public function getSellerPrice() { return $this->price; } public function deductStock($stock) { } public function addStock($stock) { } public function getStorage() { return $this->storage; } public function getFavoriteAttribute() { return Favorite::isFavorite($this->id, 'Activity'); } }