This commit is contained in:
2020-09-17 09:00:08 +08:00
commit 6366331f55
714 changed files with 167687 additions and 0 deletions

15
app/Models/Advert.php Normal file
View File

@@ -0,0 +1,15 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToCategory;
use App\Models\Traits\HasOneCover;
use App\Models\Traits\OrderByIdDesc;
use App\Scopes\SortScope;
class Advert extends Model
{
use HasOneCover,
BelongsToCategory;
}

18
app/Models/Article.php Normal file
View File

@@ -0,0 +1,18 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToCategory;
use App\Models\Traits\HasOneCover;
class Article extends Model
{
use HasOneCover, BelongsToCategory;
public function getLinkAttribute()
{
return route('article.show', $this);
}
}

90
app/Models/Category.php Normal file
View File

@@ -0,0 +1,90 @@
<?php
namespace App\Models;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
class Category extends Model
{
use AdminBuilder, ModelTree;
public const TYPE_SHOW = 'show';
public const TYPE_ARTICLE = 'article';
public const TYPE_ADVERT = 'advert';
public const TYPES = [
self::TYPE_ARTICLE => '文章列表',
self::TYPE_SHOW => '文章详情',
self::TYPE_ADVERT => '图片',
];
public function getLinkAttribute()
{
return route('category.show', $this);
}
/**
* 关联的数据
* @return [type] [description]
*/
public function relations()
{
switch ($this->type) {
case self::TYPE_SHOW:
return $this->belongsTo(Article::class);
break;
case self::TYPE_ARTICLE:
return $this->hasMany(Article::class);
break;
case self::TYPE_ADVERT:
return $this->hasMany(Advert::class);
break;
default:
return null;
}
}
public function childrens()
{
return $this->hasMany(self::class, 'parent_id');
}
public function parent()
{
return $this->hasOne(self::class, 'id', 'parent_id');
}
public function article()
{
return $this->belongsTo(Article::class);
}
/**
* Notes: 获取当前分类及子分类ID
* @Author: <C.Jason>
* @Date : 2020/4/6 3:12 下午
* @return array
*/
public function getAllChildrenId()
{
$ids = array_keys($this->buildSelectOptions([], $this->id));
array_unshift($ids, $this->id);
return $ids;
}
//查找顶级分类
public function getTop()
{
$parent = $this;
while ($parent->parent_id != 0) {
$parent = $parent->parent;
}
return $parent;
}
}

View File

@@ -0,0 +1,7 @@
<?php
namespace App\Models;
class DedeAddonarticle extends Model
{
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
class DedeArchive extends Model
{
public function info()
{
return $this->hasOne(DedeAddonarticle::class, 'aid');
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
class DedeArctype extends Model
{
use AdminBuilder, ModelTree;
}

8
app/Models/Link.php Normal file
View File

@@ -0,0 +1,8 @@
<?php
namespace App\Models;
class Link extends Model
{
//
}

22
app/Models/Model.php Normal file
View File

@@ -0,0 +1,22 @@
<?php
namespace App\Models;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Model as Eloquent;
class Model extends Eloquent
{
protected $guarded = [];
/**
* 为数组 / JSON 序列化准备日期。
*
* @param \DateTimeInterface $date
* @return string
*/
protected function serializeDate(DateTimeInterface $date)
{
return $date->format($this->dateFormat ?: 'Y-m-d H:i:s');
}
}

View File

@@ -0,0 +1,21 @@
<?php
namespace App\Models\Traits;
use App\Models\Category;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
trait BelongsToCategory
{
/**
* 关联分类表
* @author 玄尘 2020-03-05
* @return BelongsTo
*/
public function category(): BelongsTo
{
return $this->belongsTo(Category::class)->withDefault();
}
}

View File

@@ -0,0 +1,24 @@
<?php
namespace App\Models\Traits;
use Illuminate\Support\Facades\Storage;
trait HasOneCover
{
/**
* 拼接图片全地址
* @author 玄尘 2020-03-05
* @return string
*/
public function getCoverPathAttribute(): ?string
{
if ($this->cover) {
return Storage::url($this->cover);
} else {
return '';
}
}
}