chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,91 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | YwxApp [ WE CAN DO IT JUST THINK ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2026-2036 http://ywxapp.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: ywxapp<admin@ywxapp.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
declare (strict_types = 1);
|
||||
|
||||
namespace addon\docs\model;
|
||||
|
||||
use think\Model;
|
||||
|
||||
/**
|
||||
* 文档正文模型
|
||||
*
|
||||
* @author ywxapp <admin@ywxapp.cn>
|
||||
*/
|
||||
class DocsDoc extends Model
|
||||
{
|
||||
protected $name = 'docs_doc';
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'create_at';
|
||||
protected $updateTime = 'update_at';
|
||||
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'project_id' => 'integer',
|
||||
'version_id' => 'integer',
|
||||
'pid' => 'integer',
|
||||
'editor_type' => 'integer',
|
||||
'is_dir' => 'integer',
|
||||
'views' => 'integer',
|
||||
'uid' => 'integer',
|
||||
'editor_uid' => 'integer',
|
||||
'audit_status' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联所属项目
|
||||
*/
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(DocsProject::class, 'project_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 关联所属版本
|
||||
*/
|
||||
public function version()
|
||||
{
|
||||
return $this->belongsTo(DocsVersion::class, 'version_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 按项目 + 版本 + 标识查找已发布文档
|
||||
*
|
||||
* @param int $projectId 项目ID
|
||||
* @param int $versionId 版本ID
|
||||
* @param string $name 文档标识
|
||||
* @return static|null
|
||||
*/
|
||||
public static function findByName(int $projectId, int $versionId, string $name)
|
||||
{
|
||||
if ($name === '') {
|
||||
return null;
|
||||
}
|
||||
return static::where('project_id', $projectId)
|
||||
->where('version_id', $versionId)
|
||||
->where('name', $name)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
}
|
||||
|
||||
/**
|
||||
* 阅读量自增
|
||||
*
|
||||
* @param int $id 文档ID
|
||||
* @return void
|
||||
*/
|
||||
public static function addViews(int $id): void
|
||||
{
|
||||
if ($id > 0) {
|
||||
static::where('id', $id)->inc('views')->update();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user