This commit is contained in:
mkm 2024-02-17 18:01:44 +08:00
parent 2b900ae292
commit 3b25807f24
11 changed files with 720 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\ArticleLabelLists;
use app\admin\logic\article\ArticleLabelLogic;
use app\admin\validate\article\ArticleLabelValidate;
/**
* 文章标签控制器
* Class ArticleLabelController
* @package app\admin\controller\article
*/
class ArticleLabelController extends BaseAdminController
{
/**
* @notes 获取文章标签列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function lists()
{
return $this->dataLists(new ArticleLabelLists());
}
/**
* @notes 添加文章标签
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function add()
{
$params = (new ArticleLabelValidate())->post()->goCheck('add');
$result = ArticleLabelLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(ArticleLabelLogic::getError());
}
/**
* @notes 编辑文章标签
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function edit()
{
$params = (new ArticleLabelValidate())->post()->goCheck('edit');
$result = ArticleLabelLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(ArticleLabelLogic::getError());
}
/**
* @notes 删除文章标签
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function delete()
{
$params = (new ArticleLabelValidate())->post()->goCheck('delete');
ArticleLabelLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取文章标签详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function detail()
{
$params = (new ArticleLabelValidate())->goCheck('detail');
$result = ArticleLabelLogic::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\LabelLists;
use app\admin\logic\setting\LabelLogic;
use app\admin\validate\setting\LabelValidate;
/**
* 标签控制器
* Class LabelController
* @package app\admin\controller\setting
*/
class LabelController extends BaseAdminController
{
/**
* @notes 获取标签列表
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function lists()
{
return $this->dataLists(new LabelLists());
}
/**
* @notes 添加标签
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function add()
{
$params = (new LabelValidate())->post()->goCheck('add');
$result = LabelLogic::add($params);
if (true === $result) {
return $this->success('添加成功', [], 1, 1);
}
return $this->fail(LabelLogic::getError());
}
/**
* @notes 编辑标签
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function edit()
{
$params = (new LabelValidate())->post()->goCheck('edit');
$result = LabelLogic::edit($params);
if (true === $result) {
return $this->success('编辑成功', [], 1, 1);
}
return $this->fail(LabelLogic::getError());
}
/**
* @notes 删除标签
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function delete()
{
$params = (new LabelValidate())->post()->goCheck('delete');
LabelLogic::delete($params);
return $this->success('删除成功', [], 1, 1);
}
/**
* @notes 获取标签详情
* @return \think\response\Json
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function detail()
{
$params = (new LabelValidate())->goCheck('detail');
$result = LabelLogic::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\ArticleLabel;
use app\common\lists\ListsSearchInterface;
/**
* 文章标签列表
* Class ArticleLabelLists
* @package app\admin\listsarticle
*/
class ArticleLabelLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function setSearch(): array
{
return [
'=' => ['article_id', 'label_id'],
];
}
/**
* @notes 获取文章标签列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function lists(): array
{
return ArticleLabel::where($this->searchWhere)
->field(['id', 'article_id', 'label_id'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取文章标签数量
* @return int
* @author likeadmin
* @date 2024/02/17 14:07
*/
public function count(): int
{
return ArticleLabel::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\Label;
use app\common\lists\ListsSearchInterface;
/**
* 标签列表
* Class LabelLists
* @package app\admin\listssetting
*/
class LabelLists extends BaseAdminDataLists implements ListsSearchInterface
{
/**
* @notes 设置搜索条件
* @return \string[][]
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function setSearch(): array
{
return [
'=' => ['label_name', 'logo'],
];
}
/**
* @notes 获取标签列表
* @return array
* @throws \think\db\exception\DataNotFoundException
* @throws \think\db\exception\DbException
* @throws \think\db\exception\ModelNotFoundException
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function lists(): array
{
return Label::where($this->searchWhere)
->field(['id', 'label_name', 'logo'])
->limit($this->limitOffset, $this->limitLength)
->order(['id' => 'desc'])
->select()
->toArray();
}
/**
* @notes 获取标签数量
* @return int
* @author likeadmin
* @date 2024/02/17 13:57
*/
public function count(): int
{
return Label::where($this->searchWhere)->count();
}
}

View File

@ -0,0 +1,94 @@
<?php
namespace app\admin\logic\article;
use app\common\model\article\ArticleLabel;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 文章标签逻辑
* Class ArticleLabelLogic
* @package app\admin\logic\article
*/
class ArticleLabelLogic extends BaseLogic
{
/**
* @notes 添加文章标签
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/17 14:07
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
ArticleLabel::create([
]);
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/17 14:07
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
ArticleLabel::where('id', $params['id'])->update([
]);
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/17 14:07
*/
public static function delete(array $params): bool
{
return ArticleLabel::destroy($params['id']);
}
/**
* @notes 获取文章标签详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/17 14:07
*/
public static function detail($params): array
{
return ArticleLabel::findOrEmpty($params['id'])->toArray();
}
}

View File

@ -0,0 +1,96 @@
<?php
namespace app\admin\logic\setting;
use app\common\model\setting\Label;
use app\common\logic\BaseLogic;
use think\facade\Db;
/**
* 标签逻辑
* Class LabelLogic
* @package app\admin\logic\setting
*/
class LabelLogic extends BaseLogic
{
/**
* @notes 添加标签
* @param array $params
* @return bool
* @author likeadmin
* @date 2024/02/17 13:57
*/
public static function add(array $params): bool
{
Db::startTrans();
try {
Label::create([
'label_name' => $params['label_name'],
'logo' => $params['logo']
]);
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/17 13:57
*/
public static function edit(array $params): bool
{
Db::startTrans();
try {
Label::where('id', $params['id'])->update([
'label_name' => $params['label_name'],
'logo' => $params['logo']
]);
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/17 13:57
*/
public static function delete(array $params): bool
{
return Label::destroy($params['id']);
}
/**
* @notes 获取标签详情
* @param $params
* @return array
* @author likeadmin
* @date 2024/02/17 13:57
*/
public static function detail($params): array
{
return Label::findOrEmpty($params['id'])->toArray();
}
}

View File

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

View File

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

View File

@ -0,0 +1,22 @@
<?php
namespace app\common\model\article;
use app\common\model\BaseModel;
use think\model\concern\SoftDelete;
/**
* 文章标签模型
* Class ArticleLabel
* @package app\common\model\article
*/
class ArticleLabel extends BaseModel
{
use SoftDelete;
protected $name = 'article_label';
protected $deleteTime = 'delete_time';
}

View File

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

View File

@ -77,9 +77,9 @@ class VueApiGenerator extends BaseGenerator implements GenerateInterface
*/
public function getRouteContent()
{
$content = $this->getTableName();
$content = Str::camel($this->getTableName());
if (!empty($this->classDir)) {
$content = $this->classDir . '/' . $this->getTableName();
$content = $this->classDir . '/' . Str::camel($this->getTableName());
}
return Str::lower($content);
}