chore: 重写初始提交(清空历史,整理后全量提交)
This commit is contained in:
@@ -0,0 +1,94 @@
|
||||
<?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 DocsVersion extends Model
|
||||
{
|
||||
protected $name = 'docs_version';
|
||||
|
||||
protected $autoWriteTimestamp = true;
|
||||
protected $createTime = 'create_at';
|
||||
protected $updateTime = 'update_at';
|
||||
|
||||
protected $type = [
|
||||
'id' => 'integer',
|
||||
'project_id' => 'integer',
|
||||
'is_default' => 'integer',
|
||||
'sort' => 'integer',
|
||||
'status' => 'integer',
|
||||
];
|
||||
|
||||
/**
|
||||
* 关联所属项目
|
||||
*/
|
||||
public function project()
|
||||
{
|
||||
return $this->belongsTo(DocsProject::class, 'project_id', 'id');
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取项目下的启用版本列表
|
||||
*
|
||||
* @param int $projectId 项目ID
|
||||
* @return \think\Collection
|
||||
*/
|
||||
public static function listByProject(int $projectId)
|
||||
{
|
||||
return static::where('project_id', $projectId)
|
||||
->where('status', 1)
|
||||
->order('sort', 'asc')
|
||||
->order('id', 'asc')
|
||||
->select();
|
||||
}
|
||||
|
||||
/**
|
||||
* 解析项目的目标版本
|
||||
*
|
||||
* 优先按名称精确匹配,其次取默认版本,最后退回第一个版本。
|
||||
*
|
||||
* @param int $projectId 项目ID
|
||||
* @param string $name 版本标识,为空表示取默认
|
||||
* @return static|null
|
||||
*/
|
||||
public static function resolve(int $projectId, string $name = '')
|
||||
{
|
||||
if ($name !== '') {
|
||||
$version = static::where('project_id', $projectId)
|
||||
->where('name', $name)
|
||||
->where('status', 1)
|
||||
->find();
|
||||
if ($version) {
|
||||
return $version;
|
||||
}
|
||||
}
|
||||
|
||||
$default = static::where('project_id', $projectId)
|
||||
->where('status', 1)
|
||||
->where('is_default', 1)
|
||||
->find();
|
||||
if ($default) {
|
||||
return $default;
|
||||
}
|
||||
|
||||
return static::where('project_id', $projectId)
|
||||
->where('status', 1)
|
||||
->order('sort', 'asc')
|
||||
->order('id', 'asc')
|
||||
->find();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user