开始官网模板

This commit is contained in:
augushong
2020-04-19 13:18:57 +08:00
parent 1ec8c07250
commit 9910dd3e6d
42 changed files with 1435 additions and 219 deletions

View File

@@ -20,4 +20,48 @@ class Category extends Model
// return $model_list;
return array2level($model_list,0,0);
}
public function getTitleImgAttr($value)
{
return get_source_link($value);
}
public function posts()
{
return $this->hasMany(PostCategory::class,'category_id');
}
/**
* 返回的对应的post的模型
*
* @return void
*/
public function getPostsModelListAttr()
{
$list_post_category = $this->getAttr('posts');
$list_post = [];
foreach ($list_post_category as $list_post_category) {
array_push($list_post,$list_post_category->post);
}
return $list_post;
}
/**
* 返回的对应post的数据,性能比模型要高.
*
* @return void
*/
public function getPostsListAttr()
{
$list_post_category = $this->getAttr('posts');
$list_post = array_column($list_post_category->append(['post'])->toArray(),'post');
return $list_post;
}
}

View File

@@ -1,5 +1,6 @@
<?php
declare (strict_types = 1);
declare(strict_types=1);
namespace app\model;
@@ -10,9 +11,19 @@ use think\Model;
*/
class Nav extends Model
{
//
public function getImgAttr($value)
{
return get_source_link($value);
}
public static $statusName = [
0=>'不显示',
1=>'显示'
];
//
public function getImgAttr($value)
{
return get_source_link($value);
}
public function getStatusNameAttr()
{
return self::$statusName[$this->getData('status')];
}
}

View File

@@ -33,6 +33,39 @@ class Post extends Model
return $this->hasMany(PostTag::class,'post_id');
}
public function getCategorysListAttr()
{
$list_post_categorys = $this->getAttr('categorys');
$list = array_column($list_post_categorys->append(['category'])->toArray(),'category');
$list = array2level($list,0,0);
return $list;
}
public function getTagsListAttr()
{
$list_post_tags = $this->getAttr('tags');
$list = array_column($list_post_tags->append(['tag'])->toArray(),'tag');
$list = array2level($list);
return $list;
}
public function getDescShortAttr()
{
$desc = $this->getData('desc');
if(strlen($desc) > 100){
$desc = mb_substr($desc,0,100).'...';
}
return $desc;
}
public function getStatusNameAttr()
{
return self::$stausNameList[$this->getData('status')];

View File

@@ -1,5 +1,6 @@
<?php
declare (strict_types = 1);
declare(strict_types=1);
namespace app\model;
@@ -10,5 +11,14 @@ use think\Model;
*/
class PostCategory extends Model
{
//
//
public function post()
{
return $this->belongsTo(Post::class, 'post_id');
}
public function category()
{
return $this->belongsTo(Category::class,'category_id');
}
}

View File

@@ -1,5 +1,6 @@
<?php
declare (strict_types = 1);
declare(strict_types=1);
namespace app\model;
@@ -10,5 +11,14 @@ use think\Model;
*/
class PostTag extends Model
{
//
//
public function tag()
{
return $this->belongsTo(Tag::class,'tag_id');
}
public function post()
{
return $this->belongsTo(Post::class, 'post_id');
}
}