初始化项目

This commit is contained in:
augushong
2020-08-07 23:49:50 +08:00
parent 30d8c3b64b
commit 3bc46a4b9c
304 changed files with 29675 additions and 0 deletions

33
app/model/Admin.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace app\model;
use think\Model;
/**
* @mixin think\Model
*/
class Admin extends Model
{
//
public function getAvatarAttr($value)
{
if(empty($value)){
return '/static/images/avatar.jpeg';
}
return \get_source_link($value);
}
public function getGroupAttr()
{
if(empty($this->getData('group_id'))){
return [];
}
return AdminGroup::where('id',$this->getData('group_id'))->cache(60)->find();
}
}

32
app/model/AdminGroup.php Normal file
View File

@@ -0,0 +1,32 @@
<?php
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin think\Model
*/
class AdminGroup extends Model
{
//
use SoftDelete;
protected $defaultSoftDelete = 0;
public function getPermissionsAttr($value)
{
return \explode(',',$value);
}
public function setPermissionsAttr($value)
{
if(is_array($value)){
return join(',',$value);
}
return $value;
}
}

23
app/model/AdminLog.php Normal file
View File

@@ -0,0 +1,23 @@
<?php
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin think\Model
*/
class AdminLog extends Model
{
//
use SoftDelete;
protected $defaultSoftDelete = 0;
public function admin()
{
return $this->belongsTo('Admin','admin_id');
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace app\model;
use think\Model;
/**
* 权限表
* @mixin think\Model
*/
class AdminPermission extends Model
{
//
public function getIsLogAttr($value)
{
$status = [
0=>'不记录',
1=>'记录',
];
return $status[intval($value)];
}
}

131
app/model/Category.php Normal file
View File

@@ -0,0 +1,131 @@
<?php
declare(strict_types=1);
namespace app\model;
use think\facade\Config;
use think\Model;
/**
* @mixin think\Model
*/
class Category extends Model
{
//
public static $allCategory = [];
/**
* 获取指定id下的所有分类
*
* @param string $id
* @return void
*/
public static function getListLevel($id = '',$type = 1)
{
if(empty(self::$allCategory)){
$model_list = Category::where('type',$type)->select();
self::$allCategory = array2level($model_list,0,0);
}
if(!empty($id)){
$list = [];
$in_category = [$id];
foreach (self::$allCategory as $category) {
if(in_array($category->pid,$in_category)){
$list[] = $category;
$in_category[] = $category->id;
}
}
return $list;
}
return self::$allCategory;
}
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;
}
public function getTplNameAttr($value)
{
return Config::get('view_type.category.'.$value);
}
public function getModelParentAttr()
{
$pid = $this->getData('pid');
if($pid == 0){
return $this;
}
return Category::where('id',$pid)->find();
}
// 返回除自身以外的其他的同级同类的分类
public function getModelSiblingsAttr()
{
return Category::where('pid',$this->getData('pid'))
->where('level',$this->getData('level'))
->where('id','<>',$this->getData('id'))
->select();
}
/**
* 获取同一个父元素的分类,包含自身
*
* @return void
*/
public function getModelSameParentAttr()
{
return Category::where('pid',$this->getData('pid'))
->where('level',$this->getData('level'))
->select();
}
}

29
app/model/Nav.php Normal file
View File

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

133
app/model/Post.php Normal file
View File

@@ -0,0 +1,133 @@
<?php
declare(strict_types=1);
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin think\Model
*/
class Post extends Model
{
//
public static $stausNameList = [
0=>'不发布',
1=>'发布'
];
use SoftDelete;
protected $defaultSoftDelete = 0;
public function categorys()
{
return $this->hasMany(PostCategory::class,'post_id');
}
public function tags()
{
return $this->hasMany(PostTag::class,'post_id');
}
public function setPublishTimeAttr($value)
{
return strtotime($value);
}
public function getPublishTimeTextAttr()
{
$value = $this->getData('publish_time');
return date('Y-m-d',$value);
}
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');
return $list;
}
public function getDescShortAttr()
{
$desc = $this->getData('desc');
if(strlen($desc) > 100){
$desc = mb_substr($desc,0,100).'...';
}
return $desc;
}
public function getDescListAttr()
{
$desc = $this->getData('desc');
if(empty($desc)){
return '';
}
$list = explode("\n", $desc);
return $list;
}
public function getDescHtmlAttr()
{
$desc = $this->getData('desc');
if(empty($desc)){
return '';
}
return str_replace("\n",'<br>',$desc);
}
public function getStatusNameAttr()
{
return self::$stausNameList[$this->getData('status')];
}
public function setPubishTimeAttr($value)
{
return strtotime($value);
}
public function setContentAttr($value)
{
return json_encode($value);
}
public function setContentHtmlAttr($value)
{
return trim($value);
}
public function getContentAttr($value)
{
return json_decode($value,true);
}
public function getPosterAttr($value)
{
if(empty($value)){
$value = '/static/images/avatar.jpeg';
}
return get_source_link($value);
}
}

View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace app\model;
use think\Model;
/**
* @mixin 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');
}
}

24
app/model/PostTag.php Normal file
View File

@@ -0,0 +1,24 @@
<?php
declare(strict_types=1);
namespace app\model;
use think\Model;
/**
* @mixin 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');
}
}

View File

@@ -0,0 +1,14 @@
<?php
namespace app\model;
use think\Model;
/**
* @mixin think\Model
*/
class SystemConfig extends Model
{
//
}

16
app/model/Tag.php Normal file
View File

@@ -0,0 +1,16 @@
<?php
declare(strict_types=1);
namespace app\model;
use think\Model;
/**
* @mixin think\Model
*/
class Tag extends Model
{
//
}

77
app/model/UploadFiles.php Normal file
View File

@@ -0,0 +1,77 @@
<?php
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin think\Model
*/
class UploadFiles extends Model
{
//
use SoftDelete;
protected $defaultSoftDelete = 0;
public function getSrcAttr()
{
return \get_source_link($this->getData('save_name'));
}
public function getTypeAttr($value)
{
return \config('upload_type.'.$value);
}
public function getUsedTimeAttr($value)
{
if($value == 0){
return '未使用';
}
return date('Y-m-d H:i:s',$value);
}
public function getDeleteTimeAttr($value)
{
if($value == 0){
return '未删除';
}
return date('Y-m-d H:i:s',$value);
}
public function getClearTimeAttr($value)
{
if($value == 0){
return '未清除';
}
return date('Y-m-d H:i:s',$value);
}
public function getStatusAttr($value,$data)
{
if($data['used_time'] == 0){
return '未使用(仅供预览)';
}
if($data['delete_time'] > 0){
return '已删除';
}
if($data['clear_time'] > 0){
return '已清除';
}
return '使用中';
}
public function getFileSizeAttr($value)
{
return format_size($value);
}
}

27
app/model/User.php Normal file
View File

@@ -0,0 +1,27 @@
<?php
namespace app\model;
use think\Model;
use think\model\concern\SoftDelete;
/**
* @mixin think\Model
*/
class User extends Model
{
//
use SoftDelete;
protected $defaultSoftDelete = 0;
public function getAvatarAttr($value)
{
if(empty($value)){
return '/static/images/avatar.jpeg';
}
return \get_source_link($value);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace app\model;
use think\Model;
/**
* @mixin think\Model
*/
class WxPublicAccount extends Model
{
//
public function getHeadImgAttr($value)
{
return get_source_link($value);
}
public function getQrcodeUrlAttr($value)
{
return \get_source_link($value);
}
}