141 lines
2.7 KiB
PHP
141 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Models\Category;
|
|
use App\Models\Favorite;
|
|
use RuLong\Order\Contracts\Orderable;
|
|
use RuLong\Panel\Models\Storage;
|
|
|
|
class Activity extends Model implements Orderable
|
|
{
|
|
const LIFE_ID = '13'; // 娱乐Id
|
|
const REC_ID = '14'; // 生活Id
|
|
static $name = [
|
|
'13' => '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 "<span style='color:green'>正常</span>";
|
|
} elseif ($this->status == -1) {
|
|
return "<span style='color:yellow'>已经结束</span>";
|
|
} elseif ($this->status === 0) {
|
|
return "<span style='color:blue'>还没开始</span>";
|
|
}
|
|
}
|
|
|
|
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');
|
|
}
|
|
|
|
}
|