firstpush

This commit is contained in:
2020-09-09 13:38:03 +08:00
parent 38a7861abb
commit 9c6d4da51e
719 changed files with 167902 additions and 25 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;
}

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

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToCategory;
use App\Models\Traits\HasOneCover;
class Article extends Model
{
use HasOneCover, BelongsToCategory;
}

View File

@@ -0,0 +1,33 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToCategory;
use Illuminate\Support\Facades\Storage;
class ArticlePicture extends Model
{
use BelongsToCategory;
public function setPicturesAttribute($pictures)
{
if (is_array($pictures)) {
$this->attributes['pictures'] = json_encode($pictures);
}
}
public function getPicturesAttribute($pictures)
{
return json_decode($pictures, true);
}
public function getOnePicturePathAttribute(): string
{
$cover = $this->pictures;
if (empty($cover)) {
return '';
} else {
return Storage::disk('public')->url($cover[0]);
}
}
}

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

@@ -0,0 +1,57 @@
<?php
namespace App\Models;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Category extends Model
{
use AdminBuilder, ModelTree;
public const TYPES = [
'article' => '文章列表',
'show' => '文章详情',
'advert' => '广告',
'picture' => '图册',
];
public const TYPE_SHOW = 'show';
public const TYPE_ARTICLE = 'article';
public const TYPE_ADVERT = 'advert';
public const TYPE_PICTURE = 'picture';
/**
* 关联的数据
* @return [type] [description]
*/
public function relations()
{
switch ($this->type) {
case self::TYPE_SHOW:
return $this->hasOne(Article::class,'id','article_id');
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 parent(): BelongsTo
{
return $this->belongsTo(__CLASS__)->withDefault(['name' => '顶级分类']);
}
public function children(): HasMany
{
return $this->hasMany(__CLASS__, 'parent_id');
}
}

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 '';
}
}
}