FastMovieAI 二开基线 v1.0 (完整源码)

This commit is contained in:
李建琦
2026-08-26 18:41:02 +08:00
parent fad7690c0c
commit d54584f70d
888 changed files with 105571 additions and 1 deletions
@@ -0,0 +1,10 @@
<?php
namespace plugin\article\app;
use app\Basic as AppBasic;
class Basic extends AppBasic
{
public $plugin = '/app/article/';
}
@@ -0,0 +1,516 @@
<?php
namespace plugin\article\app\admin\controller;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\Examine;
use app\expose\enum\State;
use app\expose\helper\Config;
use plugin\article\app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleClassify;
use plugin\article\app\model\PluginArticleContent;
use plugin\article\app\validate\Article;
use support\Request;
use think\facade\Db;
class AnnouncementController extends Basic
{
public function __construct()
{
$this->model = new PluginArticle();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder();
$builder->addAction('操作', [
'width' => '220px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'path' => $this->plugin . 'admin/Announcement/update',
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('缓存', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'admin/Announcement/cache',
'props' => [
'type' => 'warning',
'title' => '确定要重新缓存《{title}》公告吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'warning',
'size' => 'small'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'admin/Announcement/delete',
'props' => [
'type' => 'danger',
'title' => '确定要删除《{title}》公告吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('发布公告', [
'path' => $this->plugin . 'admin/Announcement/create',
'props' => [
'type' => 'success',
'title' => '发布公告'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder();
$formBuilder->add('title', '标题', 'input', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'placeholder' => '标题搜索',
'clearable' => true
]
]);
$formBuilder->add('state', '状态', 'select', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'options' => State::getOptions(),
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$builder->add('title', '标题', [
'props' => [
'minWidth' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'title',
'label' => '标题',
'component' => 'text',
'props' => [
'type' => 'primary',
'size' => 'small'
]
],
[
'field' => 'subtitle',
'label' => '副标题',
'component' => 'text',
'props' => [
'type' => 'info',
'size' => 'small'
]
]
]
]
]
]);
$builder->add('alias', '别名', [
'props' => [
'width' => '200px'
]
]);
$builder->add('view', '浏览量', [
'props' => [
'width' => '100px'
]
]);
$builder->add('source', '来源', [
'props' => [
'width' => '100px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => $this->plugin . 'admin/Announcement/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('sort', '排序', [
'component' => [
'name' => 'input-number',
'api' => $this->plugin . 'admin/Announcement/indexUpdateField',
'props' => [
'min' => 0,
'size' => 'small'
]
],
'props' => [
'width' => '180px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
],
[
'field' => 'release_time',
'label' => '发布'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$title = $request->get('title');
if ($title) {
$where[] = ['a.title', 'like', "%{$title}%"];
}
$where[] = ['a.alias', '=', 'announcement'];
$state = $request->get('state');
if ($state) {
$where[] = ['a.state', '=', $state];
}
$where[] = ['a.examine', '=', Examine::PASS['value']];
$list = PluginArticle::alias('a')->where($where)
->join('plugin_article_classify c', 'c.id = a.classify_id', 'LEFT')
->field('a.*,c.title as classify_title')
->order('a.id desc')->paginate($limit)->each(function ($item) {});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$validate = new Article;
try {
$validate->scene('create')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = new PluginArticle;
$PluginArticle->pid = $D['pid'];
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
$PluginArticle->keywords = $D['keywords'];
$PluginArticle->description = $D['description'];
$PluginArticle->alias = 'announcement';
$PluginArticle->view = $D['view'];
$PluginArticle->sort = $D['sort'];
$PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
$PluginArticle->examine = Examine::PASS['value'];
if ($D['release_time']) {
$PluginArticle->release_time = $D['release_time'];
} else {
$PluginArticle->release_time = date('Y-m-d H:i:s');
}
$PluginArticle->save();
$PluginArticleContent = new PluginArticleContent;
$PluginArticleContent->article_id = $PluginArticle->id;
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
$this->cacheHtml($PluginArticle->id);
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$validate = new Article;
try {
$validate->scene('update')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = PluginArticle::where(['id' => $D['id']])->find();
$PluginArticle->pid = $D['pid'];
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
$PluginArticle->keywords = $D['keywords'];
$PluginArticle->description = $D['description'];
$PluginArticle->view = $D['view'];
$PluginArticle->sort = $D['sort'];
$PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
$PluginArticle->release_time = $D['release_time'];
$PluginArticle->save();
$PluginArticleContent = PluginArticleContent::where(['article_id' => $D['id']])->find();
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
return $this->success('编辑成功');
}
$id = $request->get('id');
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c', 'c.article_id=a.id')->field('a.*,c.content')->find();
$builder = $this->getFormBuilder();
$builder->setData($PluginArticle->toArray());
return $this->resData($builder);
}
public function getFormBuilder()
{
$builder = new FormBuilder(null, null, ['size' => 'large']);
$Component = new ComponentBuilder;
$builder->add('classify_id', '所属分类', 'cascader', '', [
'required' => true,
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$builder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('subtitle', '副标题', 'input', '', [
'props' => [
'maxlength' => 200,
'show-word-limit' => true
]
]);
$builder->add('thumb', '封面', 'bundle', [], [
'props' => [
'accept' => 'image/*',
'multiple' => 5
]
]);
$builder->add('keywords', '关键词', 'input', '', [
'props' => [
'type' => 'textarea',
'maxlength' => 200,
'show-word-limit' => true,
'autosize' => [
'minRows' => 2,
'maxRows' => 4
]
]
]);
$builder->add('description', '描述', 'input', '', [
'props' => [
'type' => 'textarea',
'maxlength' => 300,
'show-word-limit' => true,
'autosize' => [
'minRows' => 3,
'maxRows' => 6
]
]
]);
$builder->add('alias', '别名', 'input', '', [
'col' => [
'xs' => 24,
'md' => 12
],
'prompt' => [
$Component->add('text', ['default' => '设置别名后可通过别名访问公告'], ['type' => 'info', 'size' => 'small'])->builder()
],
'props' => [
'maxlength' => 30,
'show-word-limit' => true
]
]);
$builder->add('view', '浏览量', 'input-number', 0, [
'col' => [
'xs' => 24,
'md' => 6
],
'props' => [
'min' => 0,
'controls' => false
]
]);
$builder->add('sort', '排序', 'input-number', 99, [
'col' => [
'xs' => 24,
'md' => 6
],
'props' => [
'min' => 0,
'controls' => false
]
]);
$builder->add('source', '来源名称', 'input', '', [
'prompt' => [
$Component->add('text', ['default' => '为空则自动读取网站应用名称'], ['type' => 'info', 'size' => 'small'])->builder()
],
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'required' => true,
'options' => State::getOptions(),
'subProps' => [
'border' => true
]
]);
$builder->add('release_time', '发布时间', 'date-picker', null, [
'prompt' => [
$Component->add('text', ['default' => '为空则自动写入当前时间'], ['type' => 'info', 'size' => 'small'])->builder()
],
'props' => [
'type' => 'datetime',
'format' => 'YYYY-MM-DD HH:mm:ss',
'value-format' => 'YYYY-MM-DD HH:mm:ss',
'placeholder' => '发布时间'
]
]);
$builder->add('content', '内容', 'wangeditor', '', [
'required' => true,
'props' => [
'class' => 'vh-60'
]
]);
return $builder;
}
public function indexUpdateState(Request $request)
{
$id = $request->post('id');
$field = $request->post('field');
$value = $request->post('value');
$model = $this->model->where(['id' => $id])->find();
if (!$model) {
return $this->fail('数据不存在');
}
$model->{$field} = $value;
if ($model->save()) {
try {
if ($value === State::NO['value']) {
$this->clearHtml($id);
} else {
$this->cacheHtml($id);
}
} catch (\Throwable $th) {
}
return $this->success();
}
return $this->fail('操作失败');
}
public function clearHtml($id)
{
$PluginArticle = PluginArticle::where(['id' => $id])->find();
$path = public_path('article/' . $id . '.html');
if (file_exists($path)) {
unlink($path);
}
if ($PluginArticle->alias) {
$path = public_path('article/' . $PluginArticle->alias . '.html');
if (file_exists($path)) {
unlink($path);
}
}
}
public function cacheHtml($id)
{
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c', 'c.article_id=a.id')->field('a.*,c.content')->find();
$config = new Config('basic', '');
if (!$PluginArticle->source) {
$PluginArticle->source = $config['web_name'];
}
if ($config['logo_use'] == 'image') {
$PluginArticle->web_logo = $config['web_logo_light'];
} else {
$PluginArticle->web_logo = '/vite.svg';
}
$PluginArticle->web_title = "{$PluginArticle->title} - {$config['web_title']}";
$html = view(base_path('plugin/article/public/template.html'), $PluginArticle->toArray(), null, '')->rawBody();
$path = public_path('article/' . $id . '.html');
file_put_contents($path, $html);
if ($PluginArticle->alias) {
$path = public_path('article/' . $PluginArticle->alias . '.html');
file_put_contents($path, $html);
}
}
public function cache(Request $request)
{
$id = $request->post('id');
$this->cacheHtml($id);
return $this->success('缓存成功');
}
}
@@ -0,0 +1,301 @@
<?php
namespace plugin\article\app\admin\controller;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\Examine;
use app\expose\enum\State;
use plugin\article\app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleClassify;
use support\Request;
use think\facade\Db;
class ClassifyController extends Basic
{
public function __construct()
{
$this->model = new PluginArticleClassify();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder([
'rowKey' => 'id',
'api' => $this->plugin.'admin/Classify/index',
'lazy' => true,
'treeProps' => [
'children' => 'children',
'hasChildren' => 'hasChildren'
]
]);
$builder->addAction('操作', [
'width' => '160px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'path' => $this->plugin . 'admin/Classify/update',
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'admin/Classify/delete',
'props' => [
'type' => 'danger',
'title' => '确定要删除《{title}》分类吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('新建分类', [
'path' => $this->plugin . 'admin/Classify/create',
'props' => [
'type' => 'success',
'title' => '新建分类'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder();
$formBuilder->add('title', '标题', 'input', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'placeholder' => '标题搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$builder->add('title', '标题', [
'props' => [
'minWidth' => '200px'
]
]);
$builder->add('alias', '别名', [
'props' => [
'width' => '200px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => $this->plugin . 'admin/Classify/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('sort', '排序', [
'component' => [
'name' => 'input-number',
'api' => $this->plugin . 'admin/Classify/indexUpdateField',
'props' => [
'min' => 0,
'size'=>'small'
]
],
'props' => [
'width' => '200px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$id = $request->get('id');
if ($id) {
$where[] = ['pid', '=', $id];
} else {
$where[] = ['pid', '=', NULL];
}
$state = $request->get('state');
if ($state) {
$where[] = ['state', '=', $state];
}
$list = PluginArticleClassify::where($where)
->order('id desc')->paginate($limit)->each(function ($item) {
$item->hasChildren = PluginArticleClassify::where(['pid' => $item->id])->count() > 0;
});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
Db::startTrans();
try {
$PluginArticleClassify = new PluginArticleClassify;
if($D['pid']){
$PluginArticleClassify->pid = $D['pid'];
}
$PluginArticleClassify->title = $D['title'];
$PluginArticleClassify->alias = $D['alias'];
$PluginArticleClassify->sort = $D['sort'];
$PluginArticleClassify->state = $D['state'];
$PluginArticleClassify->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
Db::startTrans();
try {
$PluginArticleClassify = PluginArticleClassify::where(['id' => $D['id']])->find();
if($D['pid']){
$PluginArticleClassify->pid = $D['pid'];
}else{
$PluginArticleClassify->pid = null;
}
$PluginArticleClassify->title = $D['title'];
$PluginArticleClassify->alias = $D['alias'];
$PluginArticleClassify->sort = $D['sort'];
$PluginArticleClassify->state = $D['state'];
$PluginArticleClassify->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
return $this->success('编辑成功');
}
$id = $request->get('id');
$PluginArticleClassify = PluginArticleClassify::where(['id' => $id])->find();
$builder = $this->getFormBuilder();
$builder->setData($PluginArticleClassify->toArray());
return $this->resData($builder);
}
public function getFormBuilder()
{
$builder = new FormBuilder(null,null,['size'=>'large']);
$builder->add('pid', '分类等级', 'cascader', '', [
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$builder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('alias', '别名', 'input', '', [
'col'=>[
'xs'=>24,
'md'=>12
],
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('sort', '排序', 'input-number', 99, [
'required' => true,
'col'=>[
'xs'=>24,
'md'=>12
],
'props' => [
'min' => 0,
'controls'=>false
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'required' => true,
'options' => State::getOptions(),
'subProps' => [
'border' => true
]
]);
return $builder;
}
public function delete(Request $request)
{
$id=$request->post('id');
$PluginArticleClassify = PluginArticleClassify::where(['id' => $id])->find();
if(!$PluginArticleClassify){
return $this->fail('分类不存在');
}
if(PluginArticleClassify::where(['pid' => $id])->count()){
return $this->fail('请先删除子分类');
}
if(PluginArticle::where(['classify_id' => $id])->count()){
return $this->fail('请先删除该分类下的文章');
}
if($PluginArticleClassify->delete()){
return $this->success('删除成功');
}
return $this->fail('删除失败');
}
}
@@ -0,0 +1,544 @@
<?php
namespace plugin\article\app\admin\controller;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\Examine;
use app\expose\enum\State;
use app\expose\helper\Config;
use plugin\article\app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleClassify;
use plugin\article\app\model\PluginArticleContent;
use plugin\article\app\validate\Article;
use support\Request;
use think\facade\Db;
class IndexController extends Basic
{
public function __construct()
{
$this->model = new PluginArticle();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder();
$builder->addAction('操作', [
'width' => '220px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'path' => $this->plugin . 'admin/Index/update',
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('缓存', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'admin/Index/cache',
'props' => [
'type' => 'warning',
'title' => '确定要重新缓存《{title}》文章吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'warning',
'size' => 'small'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'admin/Index/delete',
'props' => [
'type' => 'danger',
'title' => '确定要删除《{title}》文章吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('发布文章', [
'path' => $this->plugin . 'admin/Index/create',
'props' => [
'type' => 'success',
'title' => '发布文章'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder();
$formBuilder->add('title', '标题', 'input', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'placeholder' => '标题搜索',
'clearable' => true
]
]);
$formBuilder->add('classify_id', '分类等级', 'cascader', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$formBuilder->add('state', '状态', 'select', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'options' => State::getOptions(),
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$builder->add('classify_title', '分类', [
'props' => [
'width' => '120px'
]
]);
$builder->add('title', '标题', [
'props' => [
'minWidth' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'title',
'label' => '标题',
'component' => 'text',
'props' => [
'type' => 'primary',
'size' => 'small'
]
],
[
'field' => 'subtitle',
'label' => '副标题',
'component' => 'text',
'props' => [
'type' => 'info',
'size' => 'small'
]
]
]
]
]
]);
$builder->add('alias', '别名', [
'props' => [
'width' => '200px'
]
]);
$builder->add('view', '浏览量', [
'props' => [
'width' => '100px'
]
]);
$builder->add('source', '来源', [
'props' => [
'width' => '100px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => $this->plugin . 'admin/Index/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('sort', '排序', [
'component' => [
'name' => 'input-number',
'api' => $this->plugin . 'admin/Index/indexUpdateField',
'props' => [
'min' => 0,
'size'=>'small'
]
],
'props' => [
'width' => '180px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
],
[
'field' => 'release_time',
'label' => '发布'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$title = $request->get('title');
if ($title) {
$where[] = ['a.title', 'like', "%{$title}%"];
}
$classify_id = $request->get('classify_id');
if ($classify_id) {
$where[] = ['a.classify_id', '=', $classify_id];
}
$state = $request->get('state');
if ($state) {
$where[] = ['a.state', '=', $state];
}
$where[] = ['a.examine', '=', Examine::PASS['value']];
$list = PluginArticle::alias('a')->where($where)
->join('plugin_article_classify c', 'c.id = a.classify_id','LEFT')
->field('a.*,c.title as classify_title')
->order('a.id desc')->paginate($limit)->each(function ($item) {
});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$validate = new Article;
try {
$validate->scene('create')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = new PluginArticle;
$PluginArticle->pid = $D['pid'];
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
$PluginArticle->keywords = $D['keywords'];
$PluginArticle->description = $D['description'];
$PluginArticle->alias = $D['alias'];
$PluginArticle->view = $D['view'];
$PluginArticle->sort = $D['sort'];
$PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
$PluginArticle->examine = Examine::PASS['value'];
if($D['release_time']){
$PluginArticle->release_time = $D['release_time'];
}else{
$PluginArticle->release_time = date('Y-m-d H:i:s');
}
$PluginArticle->save();
$PluginArticleContent = new PluginArticleContent;
$PluginArticleContent->article_id = $PluginArticle->id;
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
$this->cacheHtml($PluginArticle->id);
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$validate = new Article;
try {
$validate->scene('update')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = PluginArticle::where(['id' => $D['id']])->find();
$PluginArticle->pid = $D['pid'];
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
$PluginArticle->keywords = $D['keywords'];
$PluginArticle->description = $D['description'];
$PluginArticle->alias = $D['alias'];
$PluginArticle->view = $D['view'];
$PluginArticle->sort = $D['sort'];
$PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
$PluginArticle->release_time = $D['release_time'];
$PluginArticle->save();
$PluginArticleContent = PluginArticleContent::where(['article_id' => $D['id']])->find();
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
return $this->success('编辑成功');
}
$id = $request->get('id');
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c','c.article_id=a.id')->field('a.*,c.content')->find();
$builder = $this->getFormBuilder();
$builder->setData($PluginArticle->toArray());
return $this->resData($builder);
}
public function getFormBuilder()
{
$builder = new FormBuilder(null,null,['size'=>'large']);
$Component = new ComponentBuilder;
$builder->add('classify_id', '所属分类', 'cascader', '', [
'required' => true,
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$builder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('subtitle', '副标题', 'input', '', [
'props' => [
'maxlength' => 200,
'show-word-limit' => true
]
]);
$builder->add('thumb', '封面', 'bundle', [], [
'props' => [
'accept' => 'image/*',
'multiple' => 5
]
]);
$builder->add('keywords', '关键词', 'input', '', [
'props' => [
'type' => 'textarea',
'maxlength' => 200,
'show-word-limit' => true,
'autosize' => [
'minRows' => 2,
'maxRows' => 4
]
]
]);
$builder->add('description', '描述', 'input', '', [
'props' => [
'type' => 'textarea',
'maxlength' => 300,
'show-word-limit' => true,
'autosize' => [
'minRows' => 3,
'maxRows' => 6
]
]
]);
$builder->add('alias', '别名', 'input', '', [
'col'=>[
'xs'=>24,
'md'=>12
],
'prompt'=>[
$Component->add('text',['default'=>'设置别名后可通过别名访问文章'],['type'=>'info','size'=>'small'])->builder()
],
'props' => [
'maxlength' => 30,
'show-word-limit' => true
]
]);
$builder->add('view', '浏览量', 'input-number', 0, [
'col'=>[
'xs'=>24,
'md'=>6
],
'props' => [
'min' => 0,
'controls'=>false
]
]);
$builder->add('sort', '排序', 'input-number', 99, [
'col'=>[
'xs'=>24,
'md'=>6
],
'props' => [
'min' => 0,
'controls'=>false
]
]);
$builder->add('source', '来源名称', 'input', '', [
'prompt'=>[
$Component->add('text',['default'=>'为空则自动读取网站应用名称'],['type'=>'info','size'=>'small'])->builder()
],
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'required' => true,
'options' => State::getOptions(),
'subProps'=>[
'border'=>true
]
]);
$builder->add('release_time', '发布时间', 'date-picker', null, [
'prompt' => [
$Component->add('text',['default'=>'为空则自动写入当前时间'],['type'=>'info','size'=>'small'])->builder()
],
'props' => [
'type' => 'datetime',
'format' => 'YYYY-MM-DD HH:mm:ss',
'value-format' => 'YYYY-MM-DD HH:mm:ss',
'placeholder' => '发布时间'
]
]);
$builder->add('content', '内容', 'wangeditor', '', [
'required' => true,
'props' => [
'class' => 'vh-60'
]
]);
return $builder;
}
public function indexUpdateState(Request $request)
{
$id = $request->post('id');
$field = $request->post('field');
$value = $request->post('value');
$model = $this->model->where(['id' => $id])->find();
if (!$model) {
return $this->fail('数据不存在');
}
$model->{$field} = $value;
if ($model->save()) {
try {
if($value===State::NO['value']){
$this->clearHtml($id);
}else{
$this->cacheHtml($id);
}
} catch (\Throwable $th) {
}
return $this->success();
}
return $this->fail('操作失败');
}
public function clearHtml($id)
{
$PluginArticle=PluginArticle::where(['id'=>$id])->find();
$path = public_path('article/'.$id.'.html');
if(file_exists($path)){
unlink($path);
}
if($PluginArticle->alias){
$path = public_path('article/'.$PluginArticle->alias.'.html');
if(file_exists($path)){
unlink($path);
}
}
}
public function cacheHtml($id)
{
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c','c.article_id=a.id')->field('a.*,c.content')->find();
$config=new Config('basic','');
if(!$PluginArticle->source){
$PluginArticle->source = $config['web_name'];
}
if($config['logo_use']=='image'){
$PluginArticle->web_logo=$config['web_logo_light'];
}else{
$PluginArticle->web_logo='/vite.svg';
}
$PluginArticle->web_title="{$PluginArticle->title} - {$config['web_title']}";
$html=view(base_path('plugin/article/public/template.html'),$PluginArticle->toArray(),null,'')->rawBody();
$path = public_path('article/'.$id.'.html');
file_put_contents($path, $html);
if($PluginArticle->alias){
$path = public_path('article/'.$PluginArticle->alias.'.html');
file_put_contents($path, $html);
}
}
public function cache(Request $request)
{
$id = $request->post('id');
$this->cacheHtml($id);
return $this->success('缓存成功');
}
}
@@ -0,0 +1,9 @@
<?php
namespace plugin\article\app\admin\middleware;
use app\expose\middleware\AdminAuth;
class Auth extends AdminAuth
{
}
@@ -0,0 +1,38 @@
<?php
namespace plugin\article\app\api\controller;
use app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleContent;
use support\Request;
class ArticleController extends Basic
{
protected $notNeedLogin = ['index', 'details'];
public function index(Request $request)
{
$alias = $request->get('key');
$article = PluginArticle::where(['alias' => $alias, 'channels_uid' => $request->channels_uid])->find();
if (!$article) {
return $this->resData('文章不存在');
}
$content = PluginArticleContent::where(['article_id' => $article->id])->find();
return $this->success('获取成功', $content->content);
}
public function details(Request $request)
{
$id = $request->get('id');
if (!$id) {
return $this->fail('文章ID不能为空');
}
$article = PluginArticle::where(['id' => $id, 'channels_uid' => $request->channels_uid])->with('content')->find();
if (!$article) {
$article = PluginArticle::where(['alias' => $id, 'channels_uid' => $request->channels_uid])->with('content')->find();
}
if (!$article) {
return $this->fail('文章不存在');
}
return $this->success('获取成功', $article);
}
}
@@ -0,0 +1,177 @@
<?php
namespace plugin\article\app\control\controller;
use app\expose\build\builder\FormBuilder;
use app\expose\enum\SubmitEvent;
use plugin\article\app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleContent;
use support\Request;
use app\expose\helper\Config;
class AgreementController extends Basic
{
public function privacy(Request $request)
{
$alias = 'privacy';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
public function user(Request $request)
{
$alias = 'user';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
public function guide(Request $request)
{
$alias = 'guide';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
public function help(Request $request)
{
$alias = 'help';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
public function points(Request $request)
{
$alias = 'points';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
public function terms(Request $request)
{
$alias = 'terms';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
public function about(Request $request)
{
$alias = 'about';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
public function cloning(Request $request)
{
$alias = 'cloning';
if ($request->method() === 'POST') {
return $this->saveAgreement($request->post(), $alias, $request->channels_uid);
}
return $this->showAgreementForm($alias);
}
protected function saveAgreement(array $data, string $alias, $channels_uid)
{
$article = PluginArticle::where(['alias' => $alias])->find();
if (!$article) {
$article = new PluginArticle;
$article->alias = $alias;
$article->channels_uid = $channels_uid;
}
$article->title = $data['title'];
$article->save();
$content = PluginArticleContent::where(['article_id' => $article->id])->find();
if (!$content) {
$content = new PluginArticleContent;
$content->article_id = $article->id;
}
$content->content = $data['content'];
$result = $content->save();
$this->cacheHtml($article->id);
if ($result) {
return $this->success('保存成功1');
} else {
return $this->fail('保存失败');
}
}
protected function showAgreementForm(string $alias)
{
$builder = $this->getFormBuilder($alias);
$article = PluginArticle::where('alias', $alias)->find();
if ($article) {
$content = PluginArticleContent::where('article_id', $article->id)->find();
$article->content = $content->content ?? '';
$builder->setData($article->toArray());
}
return $this->resData($builder);
}
protected function getFormBuilder(string $alias)
{
$builder = new FormBuilder(null, null, ['size' => 'large','submitEvent' => SubmitEvent::SILENT]);
$builder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('alias', '名称', 'input', $alias, [
'props' => [
'disabled' => true
]
]);
$builder->add('content', '内容', 'wangeditor', '', [
'required' => true,
'props' => [
'class' => 'vh-60'
]
]);
return $builder;
}
public function cacheHtml($id)
{
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c', 'c.article_id=a.id')->field('a.*,c.content')->find();
$config = new Config('basic', '');
if (!$PluginArticle->source) {
$PluginArticle->source = $config['web_name'];
}
if ($config['logo_use'] == 'image') {
$PluginArticle->web_logo = $config['web_logo_light'];
} else {
$PluginArticle->web_logo = '/vite.svg';
}
$PluginArticle->web_title = "{$PluginArticle->title} - {$config['web_title']}";
$html = view(base_path('plugin/article/public/template.html'), $PluginArticle->toArray(), null, '')->rawBody();
$path = public_path('article/' . $id . '.html');
file_put_contents($path, $html);
if ($PluginArticle->alias) {
$path = public_path('article/' . $PluginArticle->alias . '.html');
file_put_contents($path, $html);
}
}
}
@@ -0,0 +1,670 @@
<?php
namespace plugin\article\app\control\controller;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\Examine;
use app\expose\enum\State;
use app\expose\enum\SubmitEvent;
use app\expose\helper\Config;
use plugin\article\app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleClassify;
use plugin\article\app\model\PluginArticleContent;
use plugin\article\app\validate\Article;
use plugin\article\utils\enum\CrowdEnum;
use plugin\notification\app\model\PluginNotificationMessage;
use plugin\notification\app\model\PluginNotificationMessageContent;
use plugin\notification\expose\helper\Message;
use plugin\notification\utils\enum\MessageScene;
use plugin\user\app\model\PluginUser;
use support\Log;
use support\Request;
use think\facade\Db;
class AnnouncementController extends Basic
{
public function __construct()
{
$this->model = new PluginArticle();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder();
$builder->addAction('操作', [
'width' => '220px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'path' => $this->plugin . 'control/Announcement/update',
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('缓存', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'control/Announcement/cache',
'props' => [
'type' => 'warning',
'title' => '确定要重新缓存《{title}》公告吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'warning',
'size' => 'small'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'control/Announcement/delete',
'props' => [
'type' => 'danger',
'title' => '确定要删除《{title}》公告吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('发布公告', [
'path' => $this->plugin . 'control/Announcement/create',
'props' => [
'type' => 'success',
'title' => '发布公告'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder();
$formBuilder->add('title', '标题', 'input', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'placeholder' => '标题搜索',
'clearable' => true
]
]);
$formBuilder->add('state', '状态', 'select', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'options' => State::getOptions(),
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$builder->add('title', '标题', [
'props' => [
'minWidth' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'title',
'label' => '标题',
'component' => 'text',
'props' => [
'type' => 'primary',
'size' => 'small'
]
],
[
'field' => 'subtitle',
'label' => '副标题',
'component' => 'text',
'props' => [
'type' => 'info',
'size' => 'small'
]
]
]
]
]
]);
$builder->add('alias', '别名', [
'props' => [
'width' => '200px'
]
]);
$builder->add('view', '浏览量', [
'props' => [
'width' => '100px'
]
]);
$builder->add('source', '来源', [
'props' => [
'width' => '100px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => $this->plugin . 'control/Announcement/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('sort', '排序', [
'component' => [
'name' => 'input-number',
'api' => $this->plugin . 'control/Announcement/indexUpdateField',
'props' => [
'min' => 0,
'size' => 'small'
]
],
'props' => [
'width' => '180px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
],
[
'field' => 'release_time',
'label' => '发布'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$title = $request->get('title');
if ($title) {
$where[] = ['a.title', 'like', "%{$title}%"];
}
$where[] = ['a.alias', '=', 'announcement'];
$state = $request->get('state');
if ($state) {
$where[] = ['a.state', '=', $state];
}
$where[] = ['a.examine', '=', Examine::PASS['value']];
$list = PluginArticle::alias('a')->where($where)
->join('plugin_article_classify c', 'c.id = a.classify_id', 'LEFT')
->field('a.*,c.title as classify_title')
->order('a.id desc')->paginate($limit)->each(function ($item) {});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$validate = new Article;
try {
$validate->scene('create')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = new PluginArticle;
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
$PluginArticle->channels_uid = $request->channels_uid;
// $PluginArticle->keywords = $D['keywords'];
// $PluginArticle->description = $D['description'];
$PluginArticle->alias = 'announcement';
// $PluginArticle->view = $D['view'];
// $PluginArticle->sort = $D['sort'];
// $PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
$PluginArticle->push_crowd = $D['push_crowd'];
$PluginArticle->push_crowd_uids = $D['push_crowd_uids'];
$PluginArticle->examine = Examine::PASS['value'];
if ($D['release_time']) {
$PluginArticle->release_time = $D['release_time'];
} else {
$PluginArticle->release_time = date('Y-m-d H:i:s');
}
$PluginArticle->save();
$PluginArticleContent = new PluginArticleContent;
$PluginArticleContent->article_id = $PluginArticle->id;
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
$this->cacheHtml($PluginArticle->id);
// 发送通知消息
$this->sendNotification($PluginArticle, $D['content'], $request);
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$validate = new Article;
try {
$validate->scene('update')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = PluginArticle::where(['id' => $D['id']])->find();
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
// $PluginArticle->keywords = $D['keywords'];
// $PluginArticle->description = $D['description'];
// $PluginArticle->view = $D['view'];
// $PluginArticle->sort = $D['sort'];
// $PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
// $PluginArticle->release_time = $D['release_time'];
$PluginArticle->push_crowd = $D['push_crowd'];
$PluginArticle->push_crowd_uids = $D['push_crowd_uids'];
$PluginArticle->save();
$PluginArticleContent = PluginArticleContent::where(['article_id' => $D['id']])->find();
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
// 同步更新通知消息
$this->sendNotification($PluginArticle, $D['content'], $request, true);
return $this->success('编辑成功');
}
$id = $request->get('id');
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c', 'c.article_id=a.id')->field('a.*,c.content')->find();
$builder = $this->getFormBuilder();
$builder->setData($PluginArticle->toArray());
return $this->resData($builder);
}
public function getFormBuilder()
{
$builder = new FormBuilder(null, null, ['size' => 'large', 'submitEvent' => SubmitEvent::SILENT]);
$Component = new ComponentBuilder;
$builder->add('classify_id', '所属分类', 'cascader', '', [
'required' => true,
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$builder->add('push_crowd', '受众', 'select', '', [
'options' => CrowdEnum::getOptions(),
'props' => [
'clearable' => true
]
]);
$builder->add('push_crowd_uids', '受众用户', 'select', '', [
'remote' => [
'url' => $this->plugin . 'control/Announcement/getUser',
],
'props' => [
'clearable' => true,
'filterable' => true,
'multiple' => true,
'remote' => true
],
'where' => [
['push_crowd', '=', CrowdEnum::SPECIFIED['value']]
]
]);
$builder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('subtitle', '副标题', 'input', '', [
'props' => [
'maxlength' => 200,
'show-word-limit' => true
]
]);
$builder->add('thumb', '封面', 'bundle', [], [
'props' => [
'accept' => 'image/*',
'multiple' => 5
]
]);
$builder->add('sort', '排序', 'input-number', 99, [
'col' => [
'xs' => 24,
'md' => 6
],
'props' => [
'min' => 0,
'controls' => false
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'required' => true,
'options' => State::getOptions(),
'subProps' => [
'border' => true
]
]);
$builder->add('release_time', '发布时间', 'date-picker', null, [
'prompt' => [
$Component->add('text', ['default' => '为空则自动写入当前时间'], ['type' => 'info', 'size' => 'small'])->builder()
],
'props' => [
'type' => 'datetime',
'format' => 'YYYY-MM-DD HH:mm:ss',
'value-format' => 'YYYY-MM-DD HH:mm:ss',
'placeholder' => '发布时间'
]
]);
$builder->add('content', '内容', 'wangeditor', '', [
'required' => true,
'props' => [
'class' => 'vh-60'
]
]);
return $builder;
}
public function indexUpdateState(Request $request)
{
$id = $request->post('id');
$field = $request->post('field');
$value = $request->post('value');
$model = $this->model->where(['id' => $id])->find();
if (!$model) {
return $this->fail('数据不存在');
}
$model->{$field} = $value;
if ($model->save()) {
try {
if ($value === State::NO['value']) {
$this->clearHtml($id);
} else {
$this->cacheHtml($id);
}
} catch (\Throwable $th) {
}
return $this->success();
}
return $this->fail('操作失败');
}
public function clearHtml($id)
{
$PluginArticle = PluginArticle::where(['id' => $id])->find();
$path = public_path('article/' . $id . '.html');
if (file_exists($path)) {
unlink($path);
}
if (isset($PluginArticle->alias) && $PluginArticle->alias) {
$path = public_path('article/' . $PluginArticle->alias . '.html');
if (file_exists($path)) {
unlink($path);
}
}
}
public function cacheHtml($id)
{
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c', 'c.article_id=a.id')->field('a.*,c.content')->find();
$config = new Config('basic', '');
if (!$PluginArticle->source) {
$PluginArticle->source = $config['web_name'];
}
if ($config['logo_use'] == 'image') {
$PluginArticle->web_logo = $config['web_logo_light'];
} else {
$PluginArticle->web_logo = '/vite.svg';
}
$PluginArticle->web_title = "{$PluginArticle->title} - {$config['web_title']}";
$html = view(base_path('plugin/article/public/template.html'), $PluginArticle->toArray(), null, '')->rawBody();
$path = public_path('article/' . $id . '.html');
file_put_contents($path, $html);
if ($PluginArticle->alias) {
$path = public_path('article/' . $PluginArticle->alias . '.html');
file_put_contents($path, $html);
}
}
public function cache(Request $request)
{
$id = $request->post('id');
$this->cacheHtml($id);
return $this->success('缓存成功');
}
/**
* 发送通知消息
* @param PluginArticle $PluginArticle 公告对象
* @param string $content 公告内容
* @param Request $request 请求对象
* @param bool $isUpdate 是否为更新操作,更新时会同步更新已存在的消息
*/
private function sendNotification($PluginArticle, $content, $request, $isUpdate = false)
{
$uids = [];
// 获取渠道ID
$channels_uid = $request->channels_uid ?? $PluginArticle->channels_uid ?? null;
// 根据推送受众类型获取用户ID列表
if ($PluginArticle->push_crowd == CrowdEnum::ALL['value']) {
// 全部用户
$where = [];
if ($channels_uid) {
$where[] = ['channels_uid', '=', $channels_uid];
}
$users = PluginUser::where($where)->field('id')->select();
foreach ($users as $user) {
$uids[] = $user->id;
}
} elseif ($PluginArticle->push_crowd == CrowdEnum::SPECIFIED['value']) {
// 指定用户
if (!empty($PluginArticle->push_crowd_uids) && is_array($PluginArticle->push_crowd_uids)) {
$uids = $PluginArticle->push_crowd_uids;
}
}
var_dump($uids);
if (empty($uids)) {
return;
}
// 获取当前管理员ID
$form_uid = $request->uid ?? null;
// 如果是更新操作,先获取已存在的消息
$existingMessages = [];
if ($isUpdate) {
$where = [
'form_id' => $PluginArticle->id,
'scene' => MessageScene::ANNOUNCEMENT['value']
];
if ($channels_uid) {
$where['channels_uid'] = $channels_uid;
}
$messages = PluginNotificationMessage::where($where)->select();
foreach ($messages as $message) {
$existingMessages[$message->uid] = $message;
}
}
// 为每个用户发送/更新通知
foreach ($uids as $uid) {
try {
// 如果是更新操作且消息已存在,则更新消息
if ($isUpdate && isset($existingMessages[$uid])) {
$message = $existingMessages[$uid];
// 更新消息基本信息
$message->title = $PluginArticle->title;
$message->subtitle = $PluginArticle->subtitle ?? null;
if ($form_uid) {
$message->form_uid = $form_uid;
}
$message->save();
// 更新消息内容
$messageContent = PluginNotificationMessageContent::where('message_id', $message->id)->find();
if ($messageContent) {
$messageContent->content = $content;
$messageContent->save();
} else {
// 如果内容不存在,创建新内容
$messageContent = new PluginNotificationMessageContent();
$messageContent->message_id = $message->id;
$messageContent->content = $content;
$messageContent->save();
}
} else {
// 创建新消息
$Message = new Message();
if ($channels_uid) {
$Message->setChannelsUid($channels_uid);
}
$Message->setUid($uid);
if ($form_uid) {
$Message->setFormUid($form_uid);
}
$Message->setFormId($PluginArticle->id);
$Message->setScene(MessageScene::ANNOUNCEMENT['value']);
$Message->setTitle($PluginArticle->title);
$Message->setContent($content);
if ($PluginArticle->subtitle) {
$Message->setSubtitle($PluginArticle->subtitle);
}
$Message->setEffect('info');
$Message->save();
}
} catch (\Throwable $th) {
// 记录错误但不中断流程
var_dump($th->getMessage());
continue;
}
}
// 如果是更新操作,删除不再需要的消息(用户列表变化的情况)
if ($isUpdate && !empty($existingMessages)) {
$currentUids = array_flip($uids);
foreach ($existingMessages as $uid => $message) {
// 如果该用户不在新的用户列表中,删除该消息
if (!isset($currentUids[$uid])) {
try {
PluginNotificationMessageContent::where('message_id', $message->id)->delete();
$message->delete();
} catch (\Throwable $th) {
var_dump($th->getMessage());
// 记录错误但不中断流程
continue;
}
}
}
}
}
/**
* 删除指定公告的所有通知消息
* @param int $articleId 公告ID
*/
private function deleteNotificationMessages($articleId)
{
try {
// 查找该公告相关的所有通知消息
$messages = PluginNotificationMessage::where([
'form_id' => $articleId,
'scene' => MessageScene::ANNOUNCEMENT['value']
])->select();
if ($messages) {
foreach ($messages as $message) {
// 删除消息内容
PluginNotificationMessageContent::where('message_id', $message->id)->delete();
// 删除消息
$message->delete();
}
}
} catch (\Throwable $th) {
// 记录错误但不中断流程
}
}
public function getUser(Request $request)
{
$keyword = $request->get('query');
$where = [];
$where[] = ['username|nickname|mobile', 'like', "%{$keyword}%"];
$list = PluginUser::field('id as value,nickname as label')->where($where)->select();
return $this->resData($list->toArray());
}
public function delete(Request $request)
{
$id = $request->post('id');
$PluginArticle = PluginArticle::where(['id' => $id])->find();
if (!$PluginArticle) {
return $this->fail('数据不存在');
}
$PluginArticle->delete();
$this->clearHtml($id);
$this->deleteNotificationMessages($id);
return $this->success('删除成功');
}
}
@@ -0,0 +1,312 @@
<?php
namespace plugin\article\app\control\controller;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\Examine;
use app\expose\enum\State;
use plugin\article\app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleClassify;
use support\Request;
use think\facade\Db;
class ClassifyController extends Basic
{
public function __construct()
{
$this->model = new PluginArticleClassify();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder([
'rowKey' => 'id',
'api' => $this->plugin . 'control/Classify/index',
'lazy' => true,
'treeProps' => [
'children' => 'children',
'hasChildren' => 'hasChildren'
]
]);
$builder->addAction('操作', [
'width' => '160px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'path' => $this->plugin . 'control/Classify/update',
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'control/Classify/delete',
'props' => [
'type' => 'danger',
'title' => '确定要删除《{title}》分类吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('新建分类', [
'path' => $this->plugin . 'control/Classify/create',
'props' => [
'type' => 'success',
'title' => '新建分类'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder();
$formBuilder->add('title', '标题', 'input', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'placeholder' => '标题搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$builder->add('title', '标题', [
'props' => [
'minWidth' => '200px'
]
]);
$builder->add('alias', '别名', [
'props' => [
'width' => '200px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => $this->plugin . 'control/Classify/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('sort', '排序', [
'component' => [
'name' => 'input-number',
'api' => $this->plugin . 'control/Classify/indexUpdateField',
'props' => [
'min' => 0,
'size' => 'small'
]
],
'props' => [
'width' => '200px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$id = $request->get('id');
if ($id) {
$where[] = ['pid', '=', $id];
} else {
$where[] = ['pid', '=', NULL];
}
$state = $request->get('state');
if ($state) {
$where[] = ['state', '=', $state];
}
$list = PluginArticleClassify::where($where)
->order('id desc')->paginate($limit)->each(function ($item) {
$item->hasChildren = PluginArticleClassify::where(['pid' => $item->id])->count() > 0;
});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
if ($D['alias']) {
$count = PluginArticleClassify::where('alias', $D['alias'])->count();
if ($count) {
return $this->fail('别名不能重复');
}
}
Db::startTrans();
try {
$PluginArticleClassify = new PluginArticleClassify;
if ($D['pid']) {
$PluginArticleClassify->pid = $D['pid'];
}
$D['channels_uid'] = $request->channels_uid;
$PluginArticleClassify->title = $D['title'];
if ($D['alias']) {
$PluginArticleClassify->alias = $D['alias'];
}
$PluginArticleClassify->sort = $D['sort'];
$PluginArticleClassify->state = $D['state'];
$PluginArticleClassify->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
Db::startTrans();
try {
$PluginArticleClassify = PluginArticleClassify::where(['id' => $D['id']])->find();
if ($D['pid']) {
$PluginArticleClassify->pid = $D['pid'];
} else {
$PluginArticleClassify->pid = null;
}
$PluginArticleClassify->title = $D['title'];
if ($D['alias']) {
$PluginArticleClassify->alias = $D['alias'];
}
$PluginArticleClassify->sort = $D['sort'];
$PluginArticleClassify->state = $D['state'];
$PluginArticleClassify->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
return $this->success('编辑成功');
}
$id = $request->get('id');
$PluginArticleClassify = PluginArticleClassify::where(['id' => $id])->find();
$builder = $this->getFormBuilder();
$builder->setData($PluginArticleClassify->toArray());
return $this->resData($builder);
}
public function getFormBuilder()
{
$builder = new FormBuilder(null, null, ['size' => 'large']);
$builder->add('pid', '分类等级', 'cascader', '', [
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$builder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('alias', '别名', 'input', '', [
'col' => [
'xs' => 24,
'md' => 12
],
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('sort', '排序', 'input-number', 99, [
'required' => true,
'col' => [
'xs' => 24,
'md' => 12
],
'props' => [
'min' => 0,
'controls' => false
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'required' => true,
'options' => State::getOptions(),
'subProps' => [
'border' => true
]
]);
return $builder;
}
public function delete(Request $request)
{
$id = $request->post('id');
$PluginArticleClassify = PluginArticleClassify::where(['id' => $id])->find();
if (!$PluginArticleClassify) {
return $this->fail('分类不存在');
}
if (PluginArticleClassify::where(['pid' => $id])->count()) {
return $this->fail('请先删除子分类');
}
if (PluginArticle::where(['classify_id' => $id])->count()) {
return $this->fail('请先删除该分类下的文章');
}
if ($PluginArticleClassify->delete()) {
return $this->success('删除成功');
}
return $this->fail('删除失败');
}
}
@@ -0,0 +1,545 @@
<?php
namespace plugin\article\app\control\controller;
use app\expose\build\builder\ComponentBuilder;
use app\expose\build\builder\FormBuilder;
use app\expose\build\builder\TableBuilder;
use app\expose\enum\Action;
use app\expose\enum\Examine;
use app\expose\enum\State;
use app\expose\helper\Config;
use plugin\article\app\Basic;
use plugin\article\app\model\PluginArticle;
use plugin\article\app\model\PluginArticleClassify;
use plugin\article\app\model\PluginArticleContent;
use plugin\article\app\validate\Article;
use support\Request;
use think\facade\Db;
class IndexController extends Basic
{
public function __construct()
{
$this->model = new PluginArticle();
}
public function indexGetTable(Request $request)
{
$builder = new TableBuilder();
$builder->addAction('操作', [
'width' => '220px',
'fixed' => 'right'
]);
$builder->addTableAction('编辑', [
'path' => $this->plugin . 'control/Index/update',
'component' => [
'name' => 'button',
'props' => [
'type' => 'primary',
'size' => 'small'
]
]
]);
$builder->addTableAction('缓存', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'control/Index/cache',
'props' => [
'type' => 'warning',
'title' => '确定要重新缓存《{title}》文章吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'warning',
'size' => 'small'
]
]
]);
$builder->addTableAction('删除', [
'model' => Action::COMFIRM['value'],
'path' => $this->plugin . 'control/Index/delete',
'props' => [
'type' => 'danger',
'title' => '确定要删除《{title}》文章吗?'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'danger',
'size' => 'small'
]
]
]);
$builder->addHeader();
$builder->addHeaderAction('发布文章', [
'path' => $this->plugin . 'control/Index/create',
'props' => [
'type' => 'success',
'title' => '发布文章'
],
'component' => [
'name' => 'button',
'props' => [
'type' => 'success'
]
]
]);
$formBuilder = new FormBuilder();
$formBuilder->add('title', '标题', 'input', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'placeholder' => '标题搜索',
'clearable' => true
]
]);
$formBuilder->add('classify_id', '分类等级', 'cascader', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$formBuilder->add('state', '状态', 'select', '', [
'col' => [
'xs' => 24,
'sm' => 12,
'md' => 8,
'lg' => 6,
'xl' => 4
],
'options' => State::getOptions(),
'props' => [
'placeholder' => '状态搜索',
'clearable' => true
]
]);
$builder->addScreen($formBuilder);
$builder->add('id', 'ID', [
'props' => [
'width' => '80px'
]
]);
$builder->add('classify_title', '分类', [
'props' => [
'width' => '120px'
]
]);
$builder->add('title', '标题', [
'props' => [
'minWidth' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'title',
'label' => '标题',
'component' => 'text',
'props' => [
'type' => 'primary',
'size' => 'small'
]
],
[
'field' => 'subtitle',
'label' => '副标题',
'component' => 'text',
'props' => [
'type' => 'info',
'size' => 'small'
]
]
]
]
]
]);
$builder->add('alias', '别名', [
'props' => [
'width' => '200px'
]
]);
$builder->add('view', '浏览量', [
'props' => [
'width' => '100px'
]
]);
$builder->add('source', '来源', [
'props' => [
'width' => '100px'
]
]);
$builder->add('state', '状态', [
'component' => [
'name' => 'switch',
'api' => $this->plugin . 'control/Index/indexUpdateState',
'props' => [
'active-value' => State::YES['value'],
'inactive-value' => State::NO['value']
]
],
'props' => [
'width' => '160px'
]
]);
$builder->add('sort', '排序', [
'component' => [
'name' => 'input-number',
'api' => $this->plugin . 'control/Index/indexUpdateField',
'props' => [
'min' => 0,
'size'=>'small'
]
],
'props' => [
'width' => '180px'
]
]);
$builder->add('create_time', '时间', [
'props' => [
'width' => '200px'
],
'component' => [
'name' => 'table-times',
'props' => [
'group' => [
[
'field' => 'create_time',
'label' => '创建'
],
[
'field' => 'update_time',
'label' => '更新'
],
[
'field' => 'release_time',
'label' => '发布'
]
]
]
]
]);
$builder = $builder->builder();
return $this->resData($builder);
}
public function index(Request $request)
{
$limit = $request->get('limit', 10);
$where = [];
$title = $request->get('title');
if ($title) {
$where[] = ['a.title', 'like', "%{$title}%"];
}
$classify_id = $request->get('classify_id');
if ($classify_id) {
$where[] = ['a.classify_id', '=', $classify_id];
}
$state = $request->get('state');
if ($state) {
$where[] = ['a.state', '=', $state];
}
$where[] = ['a.examine', '=', Examine::PASS['value']];
$list = PluginArticle::alias('a')->where($where)
->join('plugin_article_classify c', 'c.id = a.classify_id','LEFT')
->field('a.*,c.title as classify_title')
->order('a.id desc')->paginate($limit)->each(function ($item) {
});
return $this->resData($list);
}
public function create(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$D['channels_uid'] = $request->channels_uid;
$validate = new Article;
try {
$validate->scene('create')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = new PluginArticle;
$PluginArticle->pid = $D['pid'];
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
$PluginArticle->keywords = $D['keywords'];
$PluginArticle->description = $D['description'];
$PluginArticle->alias = $D['alias'];
$PluginArticle->view = $D['view'];
$PluginArticle->sort = $D['sort'];
$PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
$PluginArticle->examine = Examine::PASS['value'];
if($D['release_time']){
$PluginArticle->release_time = $D['release_time'];
}else{
$PluginArticle->release_time = date('Y-m-d H:i:s');
}
$PluginArticle->save();
$PluginArticleContent = new PluginArticleContent;
$PluginArticleContent->article_id = $PluginArticle->id;
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
$this->cacheHtml($PluginArticle->id);
return $this->success('创建成功');
}
$builder = $this->getFormBuilder();
return $this->resData($builder);
}
public function update(Request $request)
{
if ($request->method() == 'POST') {
$D = $request->post();
$validate = new Article;
try {
$validate->scene('update')->check($D);
} catch (\Throwable $th) {
return $this->fail($th->getMessage());
}
Db::startTrans();
try {
$PluginArticle = PluginArticle::where(['id' => $D['id']])->find();
$PluginArticle->pid = $D['pid'];
$PluginArticle->title = $D['title'];
$PluginArticle->subtitle = $D['subtitle'];
$PluginArticle->thumb = $D['thumb'];
$PluginArticle->keywords = $D['keywords'];
$PluginArticle->description = $D['description'];
$PluginArticle->alias = $D['alias'];
$PluginArticle->view = $D['view'];
$PluginArticle->sort = $D['sort'];
$PluginArticle->source = $D['source'];
$PluginArticle->state = $D['state'];
$PluginArticle->release_time = $D['release_time'];
$PluginArticle->save();
$PluginArticleContent = PluginArticleContent::where(['article_id' => $D['id']])->find();
$PluginArticleContent->content = $D['content'];
$PluginArticleContent->save();
Db::commit();
} catch (\Throwable $th) {
Db::rollback();
return $this->fail($th->getMessage());
}
return $this->success('编辑成功');
}
$id = $request->get('id');
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c','c.article_id=a.id')->field('a.*,c.content')->find();
$builder = $this->getFormBuilder();
$builder->setData($PluginArticle->toArray());
return $this->resData($builder);
}
public function getFormBuilder()
{
$builder = new FormBuilder(null,null,['size'=>'large']);
$Component = new ComponentBuilder;
$builder->add('classify_id', '所属分类', 'cascader', '', [
'required' => true,
'props' => [
'options' => PluginArticleClassify::options(),
'clearable' => true,
'filterable' => true,
'props' => [
'checkStrictly' => true,
'emitPath' => false
]
]
]);
$builder->add('title', '标题', 'input', '', [
'required' => true,
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('subtitle', '副标题', 'input', '', [
'props' => [
'maxlength' => 200,
'show-word-limit' => true
]
]);
$builder->add('thumb', '封面', 'bundle', [], [
'props' => [
'accept' => 'image/*',
'multiple' => 5
]
]);
$builder->add('keywords', '关键词', 'input', '', [
'props' => [
'type' => 'textarea',
'maxlength' => 200,
'show-word-limit' => true,
'autosize' => [
'minRows' => 2,
'maxRows' => 4
]
]
]);
$builder->add('description', '描述', 'input', '', [
'props' => [
'type' => 'textarea',
'maxlength' => 300,
'show-word-limit' => true,
'autosize' => [
'minRows' => 3,
'maxRows' => 6
]
]
]);
$builder->add('alias', '别名', 'input', '', [
'col'=>[
'xs'=>24,
'md'=>12
],
'prompt'=>[
$Component->add('text',['default'=>'设置别名后可通过别名访问文章'],['type'=>'info','size'=>'small'])->builder()
],
'props' => [
'maxlength' => 30,
'show-word-limit' => true
]
]);
$builder->add('view', '浏览量', 'input-number', 0, [
'col'=>[
'xs'=>24,
'md'=>6
],
'props' => [
'min' => 0,
'controls'=>false
]
]);
$builder->add('sort', '排序', 'input-number', 99, [
'col'=>[
'xs'=>24,
'md'=>6
],
'props' => [
'min' => 0,
'controls'=>false
]
]);
$builder->add('source', '来源名称', 'input', '', [
'prompt'=>[
$Component->add('text',['default'=>'为空则自动读取网站应用名称'],['type'=>'info','size'=>'small'])->builder()
],
'props' => [
'maxlength' => 100,
'show-word-limit' => true
]
]);
$builder->add('state', '状态', 'radio', State::YES['value'], [
'required' => true,
'options' => State::getOptions(),
'subProps'=>[
'border'=>true
]
]);
$builder->add('release_time', '发布时间', 'date-picker', null, [
'prompt' => [
$Component->add('text',['default'=>'为空则自动写入当前时间'],['type'=>'info','size'=>'small'])->builder()
],
'props' => [
'type' => 'datetime',
'format' => 'YYYY-MM-DD HH:mm:ss',
'value-format' => 'YYYY-MM-DD HH:mm:ss',
'placeholder' => '发布时间'
]
]);
$builder->add('content', '内容', 'wangeditor', '', [
'required' => true,
'props' => [
'class' => 'vh-60'
]
]);
return $builder;
}
public function indexUpdateState(Request $request)
{
$id = $request->post('id');
$field = $request->post('field');
$value = $request->post('value');
$model = $this->model->where(['id' => $id])->find();
if (!$model) {
return $this->fail('数据不存在');
}
$model->{$field} = $value;
if ($model->save()) {
try {
if($value===State::NO['value']){
$this->clearHtml($id);
}else{
$this->cacheHtml($id);
}
} catch (\Throwable $th) {
}
return $this->success();
}
return $this->fail('操作失败');
}
public function clearHtml($id)
{
$PluginArticle=PluginArticle::where(['id'=>$id])->find();
$path = public_path('article/'.$id.'.html');
if(file_exists($path)){
unlink($path);
}
if($PluginArticle->alias){
$path = public_path('article/'.$PluginArticle->alias.'.html');
if(file_exists($path)){
unlink($path);
}
}
}
public function cacheHtml($id)
{
$PluginArticle = PluginArticle::alias('a')->where(['a.id' => $id])->join('plugin_article_content c','c.article_id=a.id')->field('a.*,c.content')->find();
$config=new Config('basic','');
if(!$PluginArticle->source){
$PluginArticle->source = $config['web_name'];
}
if($config['logo_use']=='image'){
$PluginArticle->web_logo=$config['web_logo_light'];
}else{
$PluginArticle->web_logo='/vite.svg';
}
$PluginArticle->web_title="{$PluginArticle->title} - {$config['web_title']}";
$html=view(base_path('plugin/article/public/template.html'),$PluginArticle->toArray(),null,'')->rawBody();
$path = public_path('article/'.$id.'.html');
file_put_contents($path, $html);
if($PluginArticle->alias){
$path = public_path('article/'.$PluginArticle->alias.'.html');
file_put_contents($path, $html);
}
}
public function cache(Request $request)
{
$id = $request->post('id');
$this->cacheHtml($id);
return $this->success('缓存成功');
}
}
@@ -0,0 +1,6 @@
<?php
/**
* Here is your custom functions.
*/
@@ -0,0 +1,42 @@
<?php
namespace plugin\article\app\model;
use app\model\Basic;
use think\model\concern\SoftDelete;
class PluginArticle extends Basic
{
use SoftDelete;
protected function getOptions(): array
{
return [
'type' => [
// 设置JSON字段的类型
'thumb' => 'json',
'push_crowd_uids' => 'json'
]
];
}
public function content()
{
return $this->hasOne(PluginArticleContent::class, 'article_id', 'id');
}
// public function getPushCrowdUidsAttr($value)
// {
// if (empty($value)) {
// return '';
// }
// return json_decode($value, true);
// }
// public function setPushCrowdUidsAttr($value)
// {
// if (empty($value)) {
// return '';
// }
// return json_encode($value, JSON_UNESCAPED_UNICODE);
// }
}
@@ -0,0 +1,33 @@
<?php
namespace plugin\article\app\model;
use app\model\Basic;
class PluginArticleClassify extends Basic
{
public static function options($pid=null)
{
if ($pid) {
$data = self::where(['pid' => $pid])->select();
} else {
$data = self::whereNull('pid')->select();
}
$options = [];
if ($data->isEmpty()) {
return $options;
}
foreach ($data as $item) {
$temp = [
'value' => $item->id,
'label' => $item->title
];
$children = self::options($item->id);
if (!empty($children)) {
$temp['children'] = $children;
}
$options[] = $temp;
}
return $options;
}
}
@@ -0,0 +1,10 @@
<?php
namespace plugin\article\app\model;
use app\model\Basic;
class PluginArticleContent extends Basic
{
// protected $pk='token_id';
}
@@ -0,0 +1,34 @@
<?php
namespace plugin\article\app\validate;
use app\expose\validate\Validate;
class Article extends Validate
{
protected $rule = [
'classify_id'=>'require',
'title'=>'require',
'subtitle'=>'length:0,200',
'thumb'=>'array',
'keywords'=>'length:0,200',
'description'=>'length:0,300',
'alias'=>'alphaDash|length:0,30',
'content'=>'require'
];
protected $message = [
'classify_id.require' => '请选择分类',
'title.require' => '请输入标题',
'subtitle.length' => '副标题长度不能超过200个字符',
'thumb.array' => '缩略图格式错误',
'keywords.length' => '关键词长度不能超过200个字符',
'description.length' => '描述长度不能超过300个字符',
'alias.alphaDash' => '别名只能是字母、数字、下划线和破折号',
'alias.length' => '别名长度不能超过30个字符',
'content.require' => '请输入内容'
];
protected $scene = [
'agreement' => ['title','alias','content'],
];
}