first commit

This commit is contained in:
2026-07-23 09:40:36 +08:00
commit 090abf48fa
989 changed files with 145728 additions and 0 deletions
+69
View File
@@ -0,0 +1,69 @@
{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<form class="layui-form p-page">
<h3 class="pb-2"><name></h3>
<table class="layui-table layui-table-form">
<tr>
<td class="layui-td-gray"><name>名称<font>*</font></td>
<td><input type="text" name="title" placeholder="请输入<name>名称" lay-verify="required" lay-reqText="请输入<name>名称" class="layui-input" value="{$detail.title|default=''}"></td>
<td class="layui-td-gray">父级分类<font>*</font></td>
<td>
{empty name="$detail"}
<select name="pid" lay-verify="required" lay-reqText="请选择父级分类">
<option value="0">作为顶级分类</option>
{volist name=":set_recursion(get_base_data('<model>'))" id="v"}
<option value="{$v.id}">{$v.title}</option>
{/volist}
</select>
{else/}
<select name="pid" lay-verify="required" lay-reqText="请选择父级分类">
<option value="0">作为顶级分类</option>
{volist name=":set_recursion(get_base_data('<model>'))" id="v"}
<option value="{$v.id}" {eq name="$detail.pid" value="$v.id" }selected="" {/eq}>{$v.title}</option>
{/volist}
</select>
{/empty}
</td>
<td class="layui-td-gray">排序</td>
<td><input type="text" name="sort" placeholder="请输入排序,数字" class="layui-input" value="{$detail.sort|default=''}"></td>
</tr>
<tr>
<td class="layui-td-gray"><name>描述</td>
<td colspan="5"><textarea name="desc" placeholder="请输入<name>描述,可空" class="layui-textarea">{$detail.desc|default=''}</textarea></td>
</tr>
</table>
<div class="pt-4">
<input type="hidden" name="id" value="{$detail.id|default=0}"/>
<button class="layui-btn layui-btn-normal" lay-submit="" lay-filter="webform">立即提交</button>
<button type="reset" class="layui-btn layui-btn-primary">重置</button>
</div>
</form>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
var moduleInit = ['tool'];
function gouguInit() {
var form = layui.form, tool = layui.tool;
//
form.on('submit(webform)', function (data) {
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
setTimeout(function () {
parent.location.reload();
}, 1000);
}
}
let clickbtn = $(this);
tool.post("/<module>/<controller>/add", data.field, callback,clickbtn);
return false;
});
}
</script>
{/block}
<!-- /脚本 -->
+175
View File
@@ -0,0 +1,175 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
declare (strict_types = 1);
namespace app\<module>\controller;
use app\base\BaseController;
use app\<module>\model\<Bmodel> as <Bmodel>Model;
use app\<module>\validate\<Bcontroller>Validate;
use think\exception\ValidateException;
use think\facade\Db;
use think\facade\View;
class <Bcontroller> extends BaseController
{
/**
*
*/
protected $model;
public function __construct()
{
parent::__construct(); //
$this->model = new <Bmodel>Model();
}
/**
*
*/
public function datalist()
{
if (request()->isAjax()) {
$list = $this->model->where('delete_time',0)->order('sort asc')->select();
return to_assign(0, '', $list);
}
else{
return view();
}
}
/**
*
* $id
* $is_self=1
*/
public function sonlist($id = 0, $is_self = 1)
{
$cates = $this->model->where('delete_time',0)->order('sort asc')->select()->toArray();
$cates_list = get_data_node($cates, $id);
$cates_array = array_column($cates_list, 'id');
if ($is_self == 1) {
//
$cates_array[] = $id;
}
return $cates_array;
}
/**
* /
*/
public function add()
{
$param = get_params();
if (request()->isAjax()) {
if (!empty($param['id']) && $param['id'] > 0) {
try {
validate(<Bcontroller>Validate::class)->scene('edit')->check($param);
} catch (ValidateException $e) {
//
return to_assign(1, $e->getError());
}
$cate_array = $this->sonlist($param['id']);
if (in_array($param['pid'], $cate_array)) {
return to_assign(1, '上级分类不能是该分类本身或其子分类');
}
$this->model->edit($param);
} else {
try {
validate(<Bcontroller>Validate::class)->scene('add')->check($param);
} catch (ValidateException $e) {
//
return to_assign(1, $e->getError());
}
$this->model->add($param);
}
}else{
$id = isset($param['id']) ? $param['id'] : 0;
$pid = isset($param['pid']) ? $param['pid'] : 0;
if ($id>0) {
$detail = $this->model->getById($id);
View::assign('detail', $detail);
}
View::assign('pid', $pid);
return view();
}
}
/**
*
*/
public function view($id)
{
$detail = $this->model->getById($id);
if (!empty($detail)) {
View::assign('detail', $detail);
return view();
}
else{
return view(EEEOR_REPORTING,['code'=>404,'warning'=>'找不到页面']);
}
}
/**
*
*/
public function del()
{
if (request()->isDelete()) {
$param = get_params();
$id = isset($param['id']) ? $param['id'] : 0;
$type = isset($param['type']) ? $param['type'] : 0;
$count_cate = $this->model->where(["pid"=>$id,"delete_time"=>0])->count();
if ($count_cate > 0) {
return to_assign(1, "该分类下还有子分类,无法删除");
}
$count_list = 0;
if ($count_list > 0) {
return to_assign(1, "该分类下还有内容,无法删除");
}
$this->model->delById($id,$type);
} else {
return to_assign(1, "错误的请求");
}
}
/**
*
*/
public function set()
{
if (request()->isAjax()) {
$param = get_params();
if($param['status'] == 0){
$count_cate = $this->model->where(["pid"=>$param['id'],"delete_time"=>0])->count();
if ($count_cate > 0) {
return to_assign(1, "该分类下还有子分类,无法禁用");
}
$count_list = 0;
if ($count_list > 0) {
return to_assign(1, "该分类下还有内容,无法禁用");
}
$this->model->strict(false)->field('id,status')->update($param);
add_log('disable', $param['id'], $param);
}
else if($param['status'] == 1){
$res = $this->model->strict(false)->field('id,status')->update($param);
add_log('recovery', $param['id'], $param);
}
return to_assign();
} else {
return to_assign(1, "错误的请求");
}
}
}
+121
View File
@@ -0,0 +1,121 @@
{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-page">
<div class="gg-form-bar border-t border-x" style="padding-bottom:12px">
<button class="layui-btn layui-btn-sm tool-add" type="button" data-href="/<module>/<controller>/add">+ 添加<name></button>
</div>
<table class="layui-hide" id="table_<model>" lay-filter="table_<model>"></table>
</div>
{/block}
<!-- /主体 -->
<!-- 脚本 -->
{block name="script"}
<script>
const moduleInit = ['tool'];
function gouguInit() {
var treeTable = layui.treeTable, tool = layui.tool;
layui.pageTable = treeTable.render({
elem: "#table_<model>"
,title: '<name>列表'
,url: "/<module>/<controller>/datalist"
,tree: {
customName: {name:'title'},
view: {showIcon:false},
data: {},
async: {},
callback: {}
}
,done:function(){
treeTable.expandAll('table_<model>', true); //
}
,cols: [[
{field:'id',width:80, title: 'ID号', align:'center'}
,{field: 'sort', title: '排序',align:'center', width:80}
,{field:'title', width:240, title: '分类名称'}
,{field:'pid', title: '父级ID', width:80, align:'center'}
,{field:'desc', title: '描述', }
,{field:'status', title: '状态',width:80,align:'center',templet: function(d){
var html1='<span class="green">正常</span>';
var html2='<span class="yellow">禁用</span>';
if(d.status==1){
return html1;
}
else{
return html2;
}
}}
,{width:192,title: '操作', align:'center',ignoreExport:true,templet: function(d){
var html='';
var btn='<button class="layui-btn layui-btn-xs" lay-event="add">添加子分类</button>';
var btn1='<button class="layui-btn layui-bg-blue layui-btn-xs" lay-event="edit">编辑</button>';
var btn2='<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="disable">禁用</a>';
var btn3='<a class="layui-btn layui-btn-xs" lay-event="open">启用</a>';
var btn4='<button class="layui-btn layui-bg-red layui-btn-xs" lay-event="del">删除</button>';
if(d.status==1){
html = '<div class="layui-btn-group">'+btn+btn1+btn2+btn4+'</div>';
}
else{
html = '<div class="layui-btn-group">'+btn+btn1+btn3+btn4+'</div>';
}
return html;
}
}
]]
,page:false
});
//
treeTable.on('tool(table_<model>)', function (obj) {
if (obj.event === 'add') {
tool.side("/<module>/<controller>/add?pid="+obj.data.id);
return;
}
if (obj.event === 'edit') {
tool.side("/<module>/<controller>/add?id="+obj.data.id);
return;
}
if(obj.event === 'disable'){
layer.confirm('确定要禁用该记录吗?', {icon: 3, title:'提示'}, function(index){
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
layui.pageTable.reload();
}
}
tool.post("/<module>/<controller>/set", {id:obj.data.id,status: 0}, callback);
layer.close(index);
});
}
if(obj.event === 'open'){
layer.confirm('确定要启用该记录吗?', {icon: 3, title:'提示'}, function(index){
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
layui.pageTable.reload();
}
}
tool.post("/<module>/<controller>/set", {id:obj.data.id,status:1}, callback);
layer.close(index);
});
}
if (obj.event === 'del') {
layer.confirm('确定要删除吗?', { icon: 3, title: '提示' }, function (index) {
let callback = function (e) {
layer.msg(e.msg);
if (e.code == 0) {
obj.del();
}
}
tool.delete("/<module>/<controller>/del", { id: obj.data.id }, callback);
layer.close(index);
});
}
});
}
</script>
{/block}
<!-- /脚本 -->
+115
View File
@@ -0,0 +1,115 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
namespace app\<module>\model;
use think\model;
use think\facade\Db;
class <Bmodel> extends Model
{
/**
*
* @param $where
* @param $param
*/
public function datalist($param=[],$where=[],$whereOr=[])
{
$rows = empty($param['limit']) ? get_config('app.page_size') : $param['limit'];
$order = empty($param['order']) ? 'id desc' : $param['order'];
try {
$list = self::where($where)
->where(function ($query) use($whereOr) {
if (!empty($whereOr)){
$query->whereOr($whereOr);
}
})
->order($order)->paginate(['list_rows'=> $rows]);
return $list;
} catch(\Exception $e) {
return ['code' => 1, 'data' => [], 'msg' => $e->getMessage()];
}
}
/**
*
* @param $param
*/
public function add($param)
{
$insertId = 0;
try {
$param['create_time'] = time();
$insertId = self::strict(false)->field(true)->insertGetId($param);
add_log('add', $insertId, $param);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
return to_assign(0,'操作成功',['return_id'=>$insertId]);
}
/**
*
* @param $param
*/
public function edit($param)
{
try {
$param['update_time'] = time();
self::where('id', $param['id'])->strict(false)->field(true)->update($param);
add_log('edit', $param['id'], $param);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
return to_assign(0,'操作成功',['return_id'=>$param['id']]);
}
/**
* id获取信息
* @param $id
*/
public function getById($id)
{
$info = self::find($id);
return $info;
}
/**
*
* @param $id
* @param $type
* @return array
*/
public function delById($id,$type=0)
{
if($type==0){
//
try {
$param['delete_time'] = time();
self::where('id', $id)->update(['delete_time'=>time()]);
add_log('delete', $id);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
}
else{
//
try {
self::destroy($id);
add_log('delete', $id);
} catch(\Exception $e) {
return to_assign(1, '操作失败,原因:'.$e->getMessage());
}
}
return to_assign();
}
}
+43
View File
@@ -0,0 +1,43 @@
<?php
/**
+-----------------------------------------------------------------------------------------------
* GouGuOPEN [ 左手研发,右手开源,未来可期!]
+-----------------------------------------------------------------------------------------------
* @Copyright (c) 2021~2024 http://www.gouguoa.com All rights reserved.
+-----------------------------------------------------------------------------------------------
* @Licensed 勾股OA,开源且可免费使用,但并不是自由软件,未经授权许可不能去除勾股OA的相关版权信息
+-----------------------------------------------------------------------------------------------
* @Author 勾股工作室 <hdm58@qq.com>
+-----------------------------------------------------------------------------------------------
*/
namespace app\<module>\validate;
use think\Validate;
use think\facade\Db;
class <Bcontroller>Validate extends Validate
{
//
protected function checkOne($value,$rule,$data=[])
{
$id = isset($data['id'])?$data['id']:0;
$count = Db::name('<Bmodel>')->where([['title','=',$data['title']],['id','<>',$id],['delete_time','=',0]])->count();
return $count == 0 ? true : false;
}
protected $rule = [
'title' => 'require|checkOne',
'id' => 'require',
];
protected $message = [
'title.require' => '名称不能为空',
'title.checkOne' => '同样的名称已经存在',
'id.require' => '缺少更新条件',
];
protected $scene = [
'add' => ['title'],
'edit' => ['title', 'id'],
];
}
+26
View File
@@ -0,0 +1,26 @@
{extend name="../../base/view/common/base" /}
<!-- 主体 -->
{block name="body"}
<div class="p-page">
<h3 class="pb-2"><name>详情</h3>
<table class="layui-table layui-table-form">
<tr>
<td class="layui-td-gray"><name>名称</td>
<td>{$detail.title|default=''}"></td>
<td class="layui-td-gray">父级分类</td>
<td>
{volist name=":set_recursion(get_<model>())" id="v"}
{eq name="$detail.pid" value="$v.id" }{$v.title}{/eq}
{/volist}
</td>
<td class="layui-td-gray">排序</td>
<td>{$detail.sort|default=0}</td>
</tr>
<tr>
<td class="layui-td-gray"><name>描述</td>
<td colspan="5">{$detail.desc|default=''}</td>
</tr>
</table>
</div>
{/block}
<!-- /主体 -->