first commit

This commit is contained in:
2020-09-14 14:29:29 +08:00
commit 3ac390f68f
767 changed files with 166582 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;
}

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

@@ -0,0 +1,48 @@
<?php
namespace App\Models;
use App\Models\Traits\BelongsToCategory;
use App\Models\Traits\HasOneCover;
class Article extends Model
{
use HasOneCover, BelongsToCategory;
public function get_content_cover()
{
preg_match("/<img.*?src=\"([^\"]+)\"[^>].*?>/isU", str_ireplace("\\", "", $this->content), $matches);
if (isset($matches[1])) {
return $matches[1];
} else {
return '';
}
}
/**
* Notes: 获取一个默认图片
* @Author: 玄尘
* @Date : 2020/6/3 16:29
* @return mixed|string
*/
public function get_one_cover()
{
if ($this->cover_path) {
$path = $this->cover_path;
} else {
$path = $this->get_content_cover();
if ($path) {
$this->cover = str_replace("/storage", "", $path);
$this->save();
$path = config('app.url') . $path;
}
}
return $path;
}
}

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

@@ -0,0 +1,72 @@
<?php
namespace App\Models;
use Encore\Admin\Traits\AdminBuilder;
use Encore\Admin\Traits\ModelTree;
class Category extends Model
{
use AdminBuilder, ModelTree;
public const TYPES = [
'article' => '文章列表',
'show' => '文章详情',
'advert' => '广告',
];
public const TYPE_SHOW = 'show';
public const TYPE_ARTICLE = 'article';
public const TYPE_ADVERT = 'advert';
/**
* 关联的数据
* @return [type] [description]
*/
public function relations()
{
switch ($this->type) {
case self::TYPE_SHOW:
return $this->hasOne(Article::class)->where('id',$this->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 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;
}
}

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