0
0

更新代码

This commit is contained in:
2020-08-04 10:09:42 +08:00
parent 6118b5b63b
commit c2ac5d964e
478 changed files with 34410 additions and 0 deletions

140
app/Models/Activity.php Normal file
View File

@@ -0,0 +1,140 @@
<?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');
}
}