chore: 重写初始提交(清空历史,整理后全量提交)

This commit is contained in:
ywxapp
2026-08-16 16:54:14 +08:00
commit 6c1a106bc1
1808 changed files with 238144 additions and 0 deletions
+141
View File
@@ -0,0 +1,141 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | 文章模型
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\articles\model;
use think\model\concern\SoftDelete;
use ywxapp\model\BaseModel;
class Article extends BaseModel
{
use SoftDelete;
protected $name = 'articles_article';
protected $deleteTime = 'delete_at';
protected $defaultSoftDelete = 0;
// 时间字段为 int 时间戳(与 install.sql 一致),开启自动维护
protected $autoWriteTimestamp = true;
protected $createTime = 'create_at';
protected $updateTime = 'update_at';
protected $type = [
'status' => 'integer',
'is_top' => 'integer',
'is_recommend' => 'integer',
'view_count' => 'integer',
'comment_count'=> 'integer',
'like_count' => 'integer',
];
// 发布中(未删除、已发布)
public function scopeNormal($query)
{
$query->where('delete_at', 0)->where('status', 1);
}
public function category()
{
return $this->belongsTo(ArticleCategory::class, 'cid', 'id')
->bind(['category_name' => 'name', 'category_alias' => 'alias']);
}
public function author()
{
return $this->belongsTo(\ywxapp\model\MemberUser::class, 'uid', 'uid')
->bind(['author_name' => 'nickname']);
}
public function tags()
{
return $this->belongsToMany(ArticleTag::class, ArticleArticleTag::class, 'tid', 'aid');
}
/**
* 列表查询(支持分类/标签/关键词)
*/
public static function listArticles(array $where = [], int $page = 1, int $size = 10, string $order = 'is_top desc, create_at desc')
{
$query = self::with(['category'])->scope('normal');
if (!empty($where['cid'])) {
$query->where('cid', $where['cid']);
}
if (!empty($where['tid'])) {
$ids = ArticleArticleTag::where('tid', $where['tid'])->column('aid');
$query->whereIn('id', $ids ?: [0]);
}
if (!empty($where['keyword'])) {
$kw = $where['keyword'];
$query->where(function ($q) use ($kw) {
$q->whereLike('title', "%{$kw}%")->whereOr('summary', 'like', "%{$kw}%");
});
}
if (!empty($where['is_recommend'])) {
$query->where('is_recommend', 1);
}
return $query->orderRaw($order)->paginate([
'list_rows' => $size,
'page' => $page,
]);
}
public static function getDetail(int $id)
{
return self::with(['category', 'tags', 'author'])
->scope('normal')
->find($id);
}
public static function prev(int $id, int $cid = 0)
{
$query = self::scope('normal')->where('id', '<', $id);
if ($cid) {
$query->where('cid', $cid);
}
return $query->order('id', 'desc')->field('id,title')->find();
}
public static function next(int $id, int $cid = 0)
{
$query = self::scope('normal')->where('id', '>', $id);
if ($cid) {
$query->where('cid', $cid);
}
return $query->order('id', 'asc')->field('id,title')->find();
}
public static function hot(int $limit = 10)
{
return self::scope('normal')
->order('view_count', 'desc')
->limit($limit)
->field('id,title,cid,view_count')
->select();
}
public static function related(int $id, int $cid = 0, int $limit = 5)
{
$query = self::scope('normal')->where('id', '<>', $id);
if ($cid) {
$query->where('cid', $cid);
}
return $query->order('create_at', 'desc')
->limit($limit)
->field('id,title,cid')
->select();
}
public static function ensureSchema(): void
{
$prefix = self::currentPrefix();
self::ensureTableFromInstall($prefix, 'articles_article');
self::ensureTableFromInstall($prefix, 'articles_article_tag');
}
}
@@ -0,0 +1,37 @@
<?php
/*
* @Author: YwxApp <ywx@ywxapp.cn>
* @Date: 2026-08-10 15:28:22
* @LastEditors: YwxApp <ywx@ywxapp.cn>
* @LastEditTime: 2026-08-12 09:42:29
* @Description:
* @FilePath: \ywxapp_dev\addon\articles\model\ArticleArticleTag.php
* @CustomString: Copyright (c) 2026 YwxApp
*/
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | 文章标签关联模型
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\articles\model;
use ywxapp\model\BaseModel;
use think\model\Pivot;
class ArticleArticleTag extends Pivot
{
protected $name = 'articles_article_tag';
public $autoWriteTimestamp = false;
public static function syncTags(int $aid, array $tagIds): void
{
self::where('aid', $aid)->delete();
$data = array_map(function ($tid) use ($aid) {
return ['aid' => $aid, 'tid' => $tid];
}, $tagIds);
if ($data) {
self::insertAll($data);
}
}
}
+93
View File
@@ -0,0 +1,93 @@
<?php
/*
* @Author: YwxApp <ywx@ywxapp.cn>
* @Date: 2026-08-10 15:28:14
* @LastEditors: YwxApp <ywx@ywxapp.cn>
* @LastEditTime: 2026-08-11 00:39:57
* @Description:
* @FilePath: \ywxapp_dev\addon\articles\model\ArticleCategory.php
* @CustomString: Copyright (c) 2026 YwxApp
*/
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | 文章分类模型
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\articles\model;
use think\model\concern\SoftDelete;
use ywxapp\model\BaseModel;
class ArticleCategory extends BaseModel
{
use SoftDelete;
protected $name = 'articles_category';
protected $deleteTime = 'delete_at';
protected $defaultSoftDelete = 0;
protected $autoWriteTimestamp = true;
protected $createTime = 'create_at';
protected $updateTime = 'update_at';
protected $type = [
'sort' => 'integer',
'status' => 'integer',
];
public function articles()
{
return $this->hasMany(Article::class, 'cid', 'id');
}
public static function allEnable()
{
return self::where('delete_at', 0)
->where('status', 1)
->order('sort', 'asc')
->order('id', 'asc')
->select();
}
public static function getByAlias(string $alias)
{
return self::where('delete_at', 0)->where('alias', $alias)->find();
}
public static function getById(int $id)
{
return self::where('delete_at', 0)->find($id);
}
public static function hasArticles(int $id): bool
{
return Article::where('delete_at', 0)->where('cid', $id)->count() > 0;
}
public static function ensureSchema(): void
{
$prefix = self::currentPrefix();
self::ensureTableFromInstall($prefix, 'articles_category');
}
/**
* 兼容旧框架 ArticleCategory::tabTree 的树形展开输出
* 插件分类为扁平结构(无 parent_id),此处直接按 sort/id 顺序输出带层级前缀的列表。
* @param iterable $arr 分类数据集
* @param int $pid 兼容参数,保留原签名
* @param int $lv 兼容参数,保留原签名
*/
public static function tabTree($arr, $pid = 0, $lv = 0)
{
$result = [];
foreach ($arr as $item) {
$data = is_array($item) ? $item : $item->toArray();
$data['lv'] = $lv + 1;
$data['title'] = str_repeat('|——', $lv + 1) . ($data['name'] ?? ($data['title'] ?? ''));
$result[] = $data;
}
return $result;
}
}
+64
View File
@@ -0,0 +1,64 @@
<?php
/*
* @Author: YwxApp <ywx@ywxapp.cn>
* @Date: 2026-08-10 15:28:26
* @LastEditors: YwxApp <ywx@ywxapp.cn>
* @LastEditTime: 2026-08-15 10:17:49
* @Description:
* @FilePath: \ywxapp_dev\addon\articles\model\ArticleComment.php
* @CustomString: Copyright (c) 2026 YwxApp
*/
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | 文章评论模型
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\articles\model;
use think\model\concern\SoftDelete;
use ywxapp\model\BaseModel;
class ArticleComment extends BaseModel
{
use SoftDelete;
protected $name = 'articles_comment';
protected $deleteTime = 'delete_at';
protected $defaultSoftDelete = 0;
protected $autoWriteTimestamp = true;
protected $createTime = 'create_at';
protected $updateTime = 'update_at';
protected $type = [
'pid' => 'integer',
'aid' => 'integer',
'uid' => 'integer',
'status' => 'integer',
'like_count'=> 'integer',
];
public function user()
{
return $this->belongsTo(\ywxapp\model\MemberUser::class, 'uid', 'uid')
->bind(['nickname', 'avatar']);
}
public static function getByArticle(int $aid, int $page = 1, int $size = 10)
{
return self::with(['user'])
->where('delete_at', 0)
->where('aid', $aid)
->where('status', 1)
->order('id', 'asc')
->paginate(['list_rows' => $size, 'page' => $page]);
}
public static function ensureSchema(): void
{
$prefix = self::currentPrefix();
self::ensureTableFromInstall($prefix, 'articles_comment');
}
}
+38
View File
@@ -0,0 +1,38 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | 文章标签模型
// +----------------------------------------------------------------------
declare (strict_types = 1);
namespace addon\articles\model;
use think\model\concern\SoftDelete;
use ywxapp\model\BaseModel;
class ArticleTag extends BaseModel
{
use SoftDelete;
protected $name = 'articles_tag';
protected $deleteTime = 'delete_at';
protected $defaultSoftDelete = 0;
protected $autoWriteTimestamp = true;
protected $createTime = 'create_at';
protected $updateTime = 'update_at';
protected $type = [];
public static function getByAlias(string $alias)
{
return self::where('delete_at', 0)->where('alias', $alias)->find();
}
public static function ensureSchema(): void
{
$prefix = self::currentPrefix();
self::ensureTableFromInstall($prefix, 'articles_tag');
}
}