You've already forked guangan
办事指南分类
This commit is contained in:
@ -24,7 +24,7 @@ class Category extends Controller
|
|||||||
$this->title = '栏目列表';
|
$this->title = '栏目列表';
|
||||||
CmsCategory::mQuery()->layTable(function () {
|
CmsCategory::mQuery()->layTable(function () {
|
||||||
}, static function (QueryHelper $query) {
|
}, static function (QueryHelper $query) {
|
||||||
$query->equal('status')->like('name');
|
$query->equal(['status', 'pid'])->like('name');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ class Category extends Controller
|
|||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$this->title = '添加栏目';
|
$this->title = '添加栏目';
|
||||||
|
$this->pid = $this->request->param('pid', 1, 'intval');
|
||||||
CmsCategory::mForm('form');
|
CmsCategory::mForm('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -52,6 +53,7 @@ class Category extends Controller
|
|||||||
{
|
{
|
||||||
$this->title = '编辑栏目';
|
$this->title = '编辑栏目';
|
||||||
$this->id = $this->request->param('id', 0, 'intval'); //当前栏目ID
|
$this->id = $this->request->param('id', 0, 'intval'); //当前栏目ID
|
||||||
|
$this->pid = $this->request->param('pid', 1, 'intval');
|
||||||
CmsCategory::mForm('form');
|
CmsCategory::mForm('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,6 +80,9 @@ class Category extends Controller
|
|||||||
if ($articles_count > 0) {
|
if ($articles_count > 0) {
|
||||||
$this->error("该栏目下有文章,不能删除!");
|
$this->error("该栏目下有文章,不能删除!");
|
||||||
}
|
}
|
||||||
|
if ($id <= 2) {
|
||||||
|
$this->error("该栏目为根栏目,不能删除!");
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
namespace plugin\cms\controller;
|
namespace plugin\cms\controller;
|
||||||
|
|
||||||
|
use plugin\cms\model\CmsCategory;
|
||||||
use plugin\cms\model\CmsTutorial;
|
use plugin\cms\model\CmsTutorial;
|
||||||
use think\admin\Controller;
|
use think\admin\Controller;
|
||||||
use think\admin\helper\QueryHelper;
|
use think\admin\helper\QueryHelper;
|
||||||
@ -30,23 +31,25 @@ class Tutorial extends Controller
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* 添加办事指南
|
* 添加办事指南
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function add()
|
public function add()
|
||||||
{
|
{
|
||||||
$this->title = '添加办事指南';
|
$this->title = '添加办事指南';
|
||||||
|
$this->cates = CmsCategory::query()->where("pid", "=", 1)->select(); // 获取分类列表
|
||||||
|
$this->cate_ids = [];
|
||||||
CmsTutorial::mForm('form');
|
CmsTutorial::mForm('form');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 编辑办事指南
|
* 编辑办事指南
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit()
|
||||||
{
|
{
|
||||||
$this->title = '编辑办事指南';
|
$this->title = '编辑办事指南';
|
||||||
$this->id = $this->request->param('id');
|
$this->id = $this->request->param('id');
|
||||||
CmsTutorial::mForm('form');
|
$this->cates = CmsCategory::query()->where("pid", "=", 1)->select(); // 获取分类列表
|
||||||
|
$this->cate_ids = CmsTutorial::find($this->id)->category_ids; // 获取当前分类ID
|
||||||
|
CmsTutorial::mForm('form', "id");
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -84,4 +87,18 @@ class Tutorial extends Controller
|
|||||||
'sort.between:0,9999' => '排序值必须为0~9999之间!',
|
'sort.between:0,9999' => '排序值必须为0~9999之间!',
|
||||||
]), 'id');
|
]), 'id');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 表单数据过滤
|
||||||
|
*/
|
||||||
|
protected function _form_result(bool $state, array $post)
|
||||||
|
{
|
||||||
|
if ($this->request->isPost()) {
|
||||||
|
// 处理分类数据
|
||||||
|
$tutorial = CmsTutorial::find($post['id']);
|
||||||
|
if ($state) {
|
||||||
|
$tutorial->category_ids = input('post.category_ids/a', []);;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -6,5 +6,31 @@ use think\admin\Model;
|
|||||||
|
|
||||||
class CmsTutorial extends Model
|
class CmsTutorial extends Model
|
||||||
{
|
{
|
||||||
|
/**
|
||||||
|
* 定义与分类的多对多关系
|
||||||
|
*/
|
||||||
|
public function categories()
|
||||||
|
{
|
||||||
|
return $this->belongsToMany(CmsCategory::class, CmsTutorialCategory::class, 'cid', 'tid');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取分类ID列表
|
||||||
|
*/
|
||||||
|
public function getCategoryIdsAttr()
|
||||||
|
{
|
||||||
|
return $this->categories()->column('id');
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCategoryIdsAttr($value)
|
||||||
|
{
|
||||||
|
if ($this->isExists()) {
|
||||||
|
$this->categories()->detach();
|
||||||
|
if (is_array($value)) {
|
||||||
|
foreach ($value as $cid) {
|
||||||
|
$this->categories()->attach($cid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
24
plugs/think-plugs-cms/src/model/CmsTutorialCategory.php
Normal file
24
plugs/think-plugs-cms/src/model/CmsTutorialCategory.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace plugin\cms\model;
|
||||||
|
|
||||||
|
use think\model\Pivot;
|
||||||
|
|
||||||
|
class CmsTutorialCategory extends Pivot
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* 关联分类模型
|
||||||
|
*/
|
||||||
|
public function category()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(CmsCategory::class, 'cid', 'id');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 关联办事指南模型
|
||||||
|
*/
|
||||||
|
public function tutorial()
|
||||||
|
{
|
||||||
|
return $this->belongsTo(CmsTutorial::class, 'tid', 'id');
|
||||||
|
}
|
||||||
|
}
|
@ -9,6 +9,7 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>-->
|
</div>-->
|
||||||
|
<input type="hidden" name="pid" value="{$pid|default=0}">
|
||||||
|
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">栏目名称</label>
|
<label class="layui-form-label">栏目名称</label>
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
<form class="layui-form layui-card" action="{:sysuri()}" data-auto="true" method="post" autocomplete="off" data-table-id="articleTable">
|
<form class="layui-form layui-card" action="{:sysuri()}" data-auto="true" method="post" autocomplete="off" data-table-id="articleTable">
|
||||||
<div class="layui-row">
|
<div class="layui-row">
|
||||||
|
<div class="layui-form-item label-required-prev">
|
||||||
|
<span class="help-label"><b>绑定分类</b>Category</span>
|
||||||
|
<select class="layui-select" name="category_ids[]" lay-search multiple>
|
||||||
|
{foreach $cates as $cate}
|
||||||
|
<option value="{$cate.id}" {in name="$cate.id" value="$cate_ids"}selected{/in}>{$cate.name}</option>
|
||||||
|
{/foreach}
|
||||||
|
</select>
|
||||||
|
<span class="help-block"><b>必选,</b>请选择所属分类</span>
|
||||||
|
</div>
|
||||||
<div class="layui-form-item">
|
<div class="layui-form-item">
|
||||||
<label class="layui-form-label">办事指南标题</label>
|
<label class="layui-form-label">办事指南标题</label>
|
||||||
<div class="layui-input-block">
|
<div class="layui-input-block">
|
||||||
|
Reference in New Issue
Block a user