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
@@ -0,0 +1,128 @@
<?php
// +----------------------------------------------------------------------
// | YwxApp [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | 文章CMS后台分类管理
// +----------------------------------------------------------------------
declare(strict_types=1);
namespace addon\articles\controller\backend;
use think\facade\Request;
use think\facade\View;
use think\Validate;
use ywxapp\controller\BackendBase;
use addon\articles\model\ArticleCategory;
use addon\articles\library\ArticleSchema;
class Category extends BackendBase
{
/**
* Summary of needLogin
* @var array
*/
protected $noNeedLogin = [];
/**
* Summary of needRight
* @var array
*/
protected $noNeedVerify = [];
protected function initialize()
{
parent::initialize();
ArticleSchema::ensure();
}
/**
* 显示资源列表
*
* @param \think\Request $request
* @return \think\Response
*/
public function index()
{
$page = $this->request->param('page', 1);
$size = $this->request->param('size', 15);
if ($this->request->isAjax()) {
$data = ArticleCategory::paginate([
'page' => $page,
'list_rows' => $size,
]);
$this->result->success($data->items());
}
$this->view->assign('title', '登录');
return $this->view->fetch('category/index');
}
public function save()
{
if (Request::isPost()) {
$data = Request::post();
$data['status'] = isset($data['status']) ? 1 : 0;
$validate = new Validate([
'name|名称' => 'require|max:50',
'alias|别名' => 'require|max:50',
]);
if (!$validate->check($data)) {
$this->result->error($validate->getError());
}
ArticleCategory::create($data);
$this->result->success();
}
}
public function edit($id = null)
{
$category = ArticleCategory::find($id);
if (!$category) {
return redirect('/articles/backend/category');
}
return View::fetch('category/edit', ['category' => $category]);
}
public function update($id = 0)
{
$data = Request::post();
$id = $id ?: (int) ($data['id'] ?? 0);
$data['update_at'] = time();
$data['status'] = isset($data['status']) ? 1 : 0;
$validate = new Validate([
'name|名称' => 'require|max:50',
'alias|别名' => 'require|max:50',
]);
if (!$validate->check($data)) {
return json(['code' => 0, 'msg' => $validate->getError()]);
}
if ($id) {
$category = ArticleCategory::find($id);
if (!$category) {
return json(['code' => 0, 'msg' => '分类不存在']);
}
$category->save($data);
} else {
$data['create_at'] = time();
ArticleCategory::create($data);
}
return json(['code' => 0, 'msg' => '保存成功', 'url' => '/articles/backend/category']);
}
public function delete($id = 0)
{
$id = $id ?: (int) Request::post('id', 0);
$category = ArticleCategory::find($id);
if ($category) {
if (ArticleCategory::hasArticles($id)) {
return json(['code' => 0, 'msg' => '该分类下还有文章,无法删除']);
}
$category->delete();
return json(['code' => 0, 'msg' => '已删除']);
}
return json(['code' => 0, 'msg' => '分类不存在']);
}
}