更新代码

This commit is contained in:
mkm 2024-02-07 14:37:31 +08:00
parent f7b813b2dd
commit 2b900ae292
14 changed files with 782 additions and 2 deletions

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\article;
use app\admin\controller\BaseAdminController;
use app\admin\lists\article\ArticleLists;
use app\admin\logic\article\ArticleLogic;
use app\admin\validate\article\ArticleValidate;
/**
* 文章控制器
* Class ArticleController
* @package app\admin\controller\article
*/
class ArticleController extends BaseAdminController
{
/**
* @notes 获取文章列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function lists()
{
return $this->dataLists(new ArticleLists());
}
/**
* @notes 添加文章
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function add()
{
$params = (new ArticleValidate())->post()->goCheck('add');
$result = ArticleLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ArticleLogic::getError());
}
/**
* @notes 编辑文章
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function edit()
{
$params = (new ArticleValidate())->post()->goCheck('edit');
$result = ArticleLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ArticleLogic::getError());
}
/**
* @notes 删除文章
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function delete()
{
$params = (new ArticleValidate())->post()->goCheck('delete');
ArticleLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取文章详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function detail()
{
$params = (new ArticleValidate())->goCheck('detail');
$result = ArticleLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,95 @@
<?php
namespace app\admin\controller\setting;
use app\admin\controller\BaseAdminController;
use app\admin\lists\setting\CategoryLists;
use app\admin\logic\setting\CategoryLogic;
use app\admin\validate\setting\CategoryValidate;
/**
* 分类表控制器
* Class CategoryController
* @package app\admin\controller\setting
*/
class CategoryController extends BaseAdminController
{
/**
* @notes 获取分类表列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function lists()
{
return $this->dataLists(new CategoryLists());
}
/**
* @notes 添加分类表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function add()
{
$params = (new CategoryValidate())->post()->goCheck('add');
$result = CategoryLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(CategoryLogic::getError());
}
/**
* @notes 编辑分类表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function edit()
{
$params = (new CategoryValidate())->post()->goCheck('edit');
$result = CategoryLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(CategoryLogic::getError());
}
/**
* @notes 删除分类表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function delete()
{
$params = (new CategoryValidate())->post()->goCheck('delete');
CategoryLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取分类表详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function detail()
{
$params = (new CategoryValidate())->goCheck('detail');
$result = CategoryLogic::detail($params);
return $this->data($result);
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\article;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\article\Article;
use app\common\lists\ListsSearchInterface;
/**
* 文章列表
* Class ArticleLists
* @package app\admin\listsarticle
*/
class ArticleLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function setSearch(): array
{
return [
'=' => ['title', 'state'],
];
}
/**
* @notes 获取文章列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function lists(): array
{
return Article::where($this->searchWhere)
->field(['id', 'title_map', 'title', 'state', 'pv', 'top', 'create_user', 'update_user'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取文章数量
* @return int
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function count(): int
{
return Article::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,65 @@
<?php
namespace app\admin\lists\setting;
use app\admin\lists\BaseAdminDataLists;
use app\common\model\setting\Category;
use app\common\lists\ListsSearchInterface;
/**
* 分类表列表
* Class CategoryLists
* @package app\admin\listssetting
*/
class CategoryLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function setSearch(): array
{
return [
'=' => ['pid', 'cate_name', 'path', 'sort', 'pic', 'is_show', 'level'],
];
}
/**
* @notes 获取分类表列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function lists(): array
{
return Category::where($this->searchWhere)
->field(['category_id', 'pid', 'cate_name', 'path', 'sort', 'pic', 'is_show', 'level'])
->limit($this->limitOffset, $this->limitLength)
->order(['category_id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取分类表数量
* @return int
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function count(): int
{
return Category::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,108 @@
<?php
namespace app\admin\logic\article;
use app\common\model\article\Article;
use app\common\logic\BaseLogic;
use app\common\model\article\ArticleContent;
use think\facade\Db;
/**
* 文章逻辑
* Class ArticleLogic
* @package app\admin\logic\article
*/
class ArticleLogic extends BaseLogic
{
/**
* @notes 添加文章
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/05 16:36
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
$res= Article::create([
'title' => $params['title'],
'state' => $params['state'],
'top' => $params['top']
]);
ArticleContent::create(['article_id'=>$res->id,'content'=>$params['content']]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑文章
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/05 16:36
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Article::where('id', $params['id'])->update([
'title_map' => $params['title_map'],
'title' => $params['title'],
'state' => $params['state'],
// 'pv' => $params['pv'],
'top' => $params['top'],
// 'create_user' => $params['create_user'],
// 'update_user' => $params['update_user']
]);
$find=ArticleContent::where('article_id',$params['id'])->find();
if($find){
ArticleContent::where('article_id',$params['id'])->update(['content'=>$params['content']]);
}else{
ArticleContent::create(['article_id'=>$params['id'],'content'=>$params['content']]);
}
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除文章
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/05 16:36
*/
public static function delete(array $params): bool
{
return Article::destroy($params['id']);
}
/**
* @notes 获取文章详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/05 16:36
*/
public static function detail($params): array
{
return Article::with('detail')->findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,108 @@
<?php
namespace app\admin\logic\setting;
use app\common\model\setting\Category;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 分类表逻辑
* Class CategoryLogic
* @package app\admin\logic\setting
*/
class CategoryLogic extends BaseLogic
{
/**
* @notes 添加分类表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/05 16:13
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Category::create([
'category_id' => $params['category_id'],
'pid' => $params['pid'],
'cate_name' => $params['cate_name'],
'path' => $params['path'],
'sort' => $params['sort'],
'pic' => $params['pic'],
'is_show' => $params['is_show'],
'level' => $params['level']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 编辑分类表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/05 16:13
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Category::where('category_id', $params['category_id'])->update([
'category_id' => $params['category_id'],
'pid' => $params['pid'],
'cate_name' => $params['cate_name'],
'path' => $params['path'],
'sort' => $params['sort'],
'pic' => $params['pic'],
'is_show' => $params['is_show'],
'level' => $params['level']
]);
Db::commit();
return true;
} catch (\Exception $e) {
Db::rollback();
self::setError($e->getMessage());
return false;
}
}
/**
* @notes 删除分类表
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/05 16:13
*/
public static function delete(array $params): bool
{
return Category::destroy($params['category_id']);
}
/**
* @notes 获取分类表详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/05 16:13
*/
public static function detail($params): array
{
return Category::findOrEmpty($params['category_id'])->toArray();
}
}

View File

@ -0,0 +1,82 @@
<?php
namespace app\admin\validate\article;
use app\common\validate\BaseValidate;
/**
* 文章验证器
* Class ArticleValidate
* @package app\admin\validate\article
*/
class ArticleValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'id' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'id' => 'id',
];
/**
* @notes 添加场景
* @return ArticleValidate
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function sceneAdd()
{
return $this->remove('id', true);
}
/**
* @notes 编辑场景
* @return ArticleValidate
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function sceneEdit()
{
return $this->only(['id']);
}
/**
* @notes 删除场景
* @return ArticleValidate
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function sceneDelete()
{
return $this->only(['id']);
}
/**
* @notes 详情场景
* @return ArticleValidate
* @author likeadmin
* @date 2024/02/05 16:36
*/
public function sceneDetail()
{
return $this->only(['id']);
}
}

View File

@ -0,0 +1,94 @@
<?php
namespace app\admin\validate\setting;
use app\common\validate\BaseValidate;
/**
* 分类表验证器
* Class CategoryValidate
* @package app\admin\validate\setting
*/
class CategoryValidate extends BaseValidate
{
/**
* 设置校验规则
* @var string[]
*/
protected $rule = [
'category_id' => 'require',
'pid' => 'require',
'cate_name' => 'require',
'path' => 'require',
'sort' => 'require',
'is_show' => 'require',
'level' => 'require',
];
/**
* 参数描述
* @var string[]
*/
protected $field = [
'category_id' => 'category_id',
'pid' => '父id',
'cate_name' => '分类名称',
'path' => '路径',
'sort' => '排序',
'is_show' => '是否显示',
'level' => '等级',
];
/**
* @notes 添加场景
* @return CategoryValidate
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function sceneAdd()
{
return $this->only(['pid','cate_name','path','sort','is_show','level']);
}
/**
* @notes 编辑场景
* @return CategoryValidate
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function sceneEdit()
{
return $this->only(['category_id','pid','cate_name','path','sort','is_show','level']);
}
/**
* @notes 删除场景
* @return CategoryValidate
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function sceneDelete()
{
return $this->only(['category_id']);
}
/**
* @notes 详情场景
* @return CategoryValidate
* @author likeadmin
* @date 2024/02/05 16:13
*/
public function sceneDetail()
{
return $this->only(['category_id']);
}
}

View File

@ -19,6 +19,7 @@ class IndexController extends BaseLikeAdminController
public function download()
{
$params = (new GenerateTableValidate())->goCheck('download');
var_dump($params);
$result = GeneratorLogic::download($params['file']);
if (false === $result) {
return $this->fail(GeneratorLogic::getError() ?: '下载失败');

View File

@ -0,0 +1,25 @@
<?php
namespace app\common\model\article;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 文章模型
* Class Article
* @package app\common\model\article
*/
class Article extends BaseModel
{
use SoftDelete;
protected $name = 'article';
protected $deleteTime = 'delete_time';
public function detail()
{
return $this->hasOne(ArticleContent::class,'article_id')->bind(['content']);
}
}

View File

@ -0,0 +1,18 @@
<?php
namespace app\common\model\article;
use app\common\model\BaseModel;
/**
* 文章内容模型
* Class Article
* @package app\common\model\article
*/
class ArticleContent extends BaseModel
{
protected $name = 'article_content';
}

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\setting;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 分类表模型
* Class Category
* @package app\common\model\setting
*/
class Category extends BaseModel
{
use SoftDelete;
protected $name = 'category';
protected $deleteTime = 'delete_time';
}

View File

@ -71,7 +71,9 @@ class UploadService
'type' => $file['type'],
'name' => $file['name'],
'uri' => FileService::getFileUrl($file['uri']),
'url' => $file['uri']
'succMap' => [
$fileInfo['name']=> $file['uri']
]
];
} catch (Exception $e) {

View File

@ -79,7 +79,7 @@ class VueApiGenerator extends BaseGenerator implements GenerateInterface
{
$content = $this->getTableName();
if (!empty($this->classDir)) {
$content = $this->classDir . '.' . $this->getTableName();
$content = $this->classDir . '/' . $this->getTableName();
}
return Str::lower($content);
}