diff --git a/app/controller/Upload.php b/app/controller/Upload.php index 05e86683..10e7b59d 100644 --- a/app/controller/Upload.php +++ b/app/controller/Upload.php @@ -9,6 +9,7 @@ namespace app\controller; use think\facade\Session; +use think\facade\Filesystem; class Upload extends Base { @@ -17,8 +18,52 @@ class Upload extends Base { protected function initialize() { } + public function upload(){ + $upload_type = $this->request->get('filename', 'images', 'trim'); + $config = $this->$upload_type(); + // 获取表单上传文件 例如上传了001.jpg + $file = request()->file('file'); + try { + validate(['file'=>'filesize:10240|fileExt:jpg|image:200,200,jpg']) + ->check([$file]); + $data['status'] = 1; + $data['info'] = $this->save($file, $upload_type); + } catch (think\exception\ValidateException $e) { + $data['status'] = 0; + $data['info'] = $e->getMessage(); + } + return json($data); + } + + protected function images(){ + return []; + } + public function ueditor(){ $data = new \com\Ueditor(Session::get('userInfo.uid')); echo $data->output(); } + + protected function save($file, $upload_type){ + $data = []; + $savename = Filesystem::disk('public')->putFile($upload_type, $file, 'md5'); + + $data['create_time'] = $file->getATime(); //最后访问时间 + $data['savename'] = $file->getBasename(); //获取无路径的basename + $data['c_time'] = $file->getCTime(); //获取inode修改时间 + $data['ext'] = $file->getExtension(); //文件扩展名 + $data['name'] = $file->getFilename(); //获取文件名 + $data['m_time'] = $file->getMTime(); //获取最后修改时间 + $data['owner'] = $file->getOwner(); //文件拥有者 + $data['savepath'] = $file->getPath(); //不带文件名的文件路径 + $data['url'] = $data['path'] = '/uploads/' . $savename; //全路径 + $data['size'] = $file->getSize(); //文件大小,单位字节 + $data['is_file'] = $file->isFile(); //是否是文件 + $data['is_execut'] = $file->isExecutable(); //是否可执行 + $data['is_readable'] = $file->isReadable(); //是否可读 + $data['is_writable'] = $file->isWritable(); //是否可写 + $data['md5'] = md5_file($file->getPathname()); + $data['sha1'] = sha1_file($file->getPathname()); + return $data; + } } \ No newline at end of file diff --git a/app/controller/admin/Addons.php b/app/controller/admin/Addons.php index 77207caf..b1be8afe 100644 --- a/app/controller/admin/Addons.php +++ b/app/controller/admin/Addons.php @@ -20,11 +20,13 @@ class Addons extends Base { /** * @title 插件列表 */ - public function index(AddonsM $addons, $refresh = 0) { + public function index($refresh = 0) { + $map = []; if ($refresh) { - $addons->refresh(); + AddonsM::refreshAddons(); } - $list = $addons->order('id desc')->paginate($this->request->pageConfig); + + $list = AddonsM::where($map)->order('id desc')->paginate($this->request->pageConfig); $this->data = array( 'list' => $list, @@ -49,17 +51,16 @@ class Addons extends Base { return $this->error($this->addons->getError()); } } else { - $hooks = db('Hooks')->field('name,description')->select(); - $this->assign('Hooks', $hooks); - $hook = db('Hooks')->field(true)->select(); - foreach ($hook as $key => $value) { - $addons_opt[$value['name']] = $value['name']; - } - $addons_opt = array(array('type' => 'select', 'opt' => $addons_opt)); - if (!is_writable(SENT_ADDON_PATH)) { - return $this->error('您没有创建目录写入权限,无法使用此功能'); - } - $this->setMeta("添加插件"); + // $hooks = db('Hooks')->field('name,description')->select(); + // $this->assign('Hooks', $hooks); + // $hook = db('Hooks')->field(true)->select(); + // foreach ($hook as $key => $value) { + // $addons_opt[$value['name']] = $value['name']; + // } + // $addons_opt = array(array('type' => 'select', 'opt' => $addons_opt)); + // if (!is_writable(SENT_ADDON_PATH)) { + // return $this->error('您没有创建目录写入权限,无法使用此功能'); + // } return $this->fetch(); } } @@ -220,7 +221,6 @@ class Addons extends Base { * @title 添加钩子 */ public function addhook() { - $hooks = model('Hooks'); if ($this->request->isPost()) { $result = $hooks->change(); if ($result !== false) { @@ -229,13 +229,10 @@ class Addons extends Base { return $this->error($hooks->getError()); } } else { - $keylist = $hooks->getaddons(); - $data = array( - 'keyList' => $keylist, + $this->data = array( + 'keyList' => Hooks::$keylist, ); - $this->assign($data); - $this->setMeta('编辑钩子'); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } diff --git a/app/controller/admin/Attribute.php b/app/controller/admin/Attribute.php index 9f9b2e50..c3d3fadf 100644 --- a/app/controller/admin/Attribute.php +++ b/app/controller/admin/Attribute.php @@ -24,25 +24,6 @@ class Attribute extends Base { public function initialize() { parent::initialize(); $this->getContentMenu(); - // $this->model = model('Attribute'); - // //遍历属性列表 - // foreach (get_attribute_type() as $key => $value) { - // $this->attr[$key] = $value[0]; - // } - // $this->validate_rule = array( - // 0 => '请选择', - // 'regex' => '正则验证', - // 'function' => '函数验证', - // 'unique' => '唯一验证', - // 'length' => '长度验证', - // 'in' => '验证在范围内', - // 'notin' => '验证不在范围内', - // 'between' => '区间验证', - // 'notbetween' => '不在区间验证', - // ); - // $this->auto_type = array(0 => '请选择', 'function' => '函数', 'field' => '字段', 'string' => '字符串'); - // $this->the_time = array(0 => '请选择', '3' => '始 终', '1' => '新 增', '2' => '编 辑'); - // $this->field = $this->getField(); } /** @@ -67,22 +48,25 @@ class Attribute extends Base { * @title 创建字段 * @author colin */ - public function add($model_id = '') { + public function add(AttributeModel $attribute) { if ($this->request->isPost()) { - $result = $this->model->validate('attribute.add')->save($this->request->param()); + $data = $this->request->post(); + $result = $attribute->save($data); if (false !== $result) { - return $this->success("创建成功!", url('Attribute/index', array('model_id' => $model_id))); + return $this->success("创建成功!", url('/admin/attribute/index', ['model_id' => $data['model_id']])); } else { - return $this->error($this->model->getError()); + return $this->error('创建失败!'); } } else { - $data = array( + $model_id = $this->request->param('model_id', 0); + if (!$model_id) { + return $this->error('非法操作!'); + } + $this->data = array( 'info' => array('model_id' => $model_id), - 'fieldGroup' => $this->field, + 'fieldGroup' => AttributeModel::getfieldList(), ); - $this->assign($data); - $this->setMeta('添加字段'); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } @@ -90,23 +74,22 @@ class Attribute extends Base { * @title 编辑字段 * @author colin */ - public function edit($id = '', $model_id = '') { + public function edit(AttributeModel $attribute, $id = '', $model_id = '') { if ($this->request->isPost()) { - $result = $this->model->validate('attribute.edit')->save($this->request->param(), array('id' => $id)); + $data = $this->request->post(); + $result = $attribute->exists(true)->save($data); if ($result) { - return $this->success("修改成功!", url('Attribute/index', array('model_id' => $model_id))); + return $this->success("修改成功!", url('/admin/attribute/index', ['model_id' => $model_id])); } else { - return $this->error($this->model->getError()); + return $this->error('修改失败!'); } } else { - $info = db('Attribute')->find($id); - $data = array( + $info = AttributeModel::find($id); + $this->data = array( 'info' => $info, - 'fieldGroup' => $this->field, + 'fieldGroup' => AttributeModel::getfieldList(), ); - $this->assign($data); - $this->setMeta('编辑字段'); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } @@ -115,47 +98,19 @@ class Attribute extends Base { * @var delattr 是否删除字段表里的字段 * @author colin */ - public function del(\think\Request $request) { - $id = $request->param('id'); - $model_id = $request->param('model_id'); + public function del() { + $id = $this->request->param('id'); + $model_id = $this->request->param('model_id'); if (!$id) { return $this->error("非法操作!"); } - $result = $this->model->del($id, $model_id); + $result = AttributeModel::find($id)->delete(); if ($result) { return $this->success("删除成功!"); } else { return $this->error($this->model->getError()); } } - - //字段编辑所需字段 - protected function getField() { - return array( - '基础' => array( - array('name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'), - array('name' => 'model_id', 'title' => 'model_id', 'help' => '', 'type' => 'hidden'), - array('name' => 'name', 'title' => '字段名', 'help' => '英文字母开头,长度不超过30', 'type' => 'text'), - array('name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'type' => 'text'), - array('name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => $this->attr, 'help' => ''), - array('name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'), - array('name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'), - array('name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'), - array('name' => 'remark', 'title' => '字段备注', 'help' => '用于表单中的提示', 'type' => 'text'), - array('name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => array('1' => '始终显示', '2' => '新增显示', '3' => '编辑显示', '0' => '不显示'), 'value' => 1), - array('name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => array('0' => '否', '1' => '是')), - ), - '高级' => array( - array('name' => 'validate_type', 'title' => '验证方式', 'type' => 'select', 'option' => $this->validate_rule, 'help' => ''), - array('name' => 'validate_rule', 'title' => '验证规则', 'help' => '根据验证方式定义相关验证规则', 'type' => 'text'), - array('name' => 'error_info', 'title' => '出错提示', 'type' => 'text', 'help' => ''), - array('name' => 'validate_time', 'title' => '验证时间', 'help' => '英文字母开头,长度不超过30', 'type' => 'select', 'option' => $this->the_time, 'help' => ''), - array('name' => 'auto_type', 'title' => '自动完成方式', 'help' => '英文字母开头,长度不超过30', 'type' => 'select', 'option' => $this->auto_type, 'help' => ''), - array('name' => 'auto_rule', 'title' => '自动完成规则', 'help' => '根据完成方式订阅相关规则', 'type' => 'text'), - array('name' => 'auto_time', 'title' => '自动完成时间', 'help' => '英文字母开头,长度不超过30', 'type' => 'select', 'option' => $this->the_time), - ), - ); - } } \ No newline at end of file diff --git a/app/controller/admin/Base.php b/app/controller/admin/Base.php index ef97f954..5205dad0 100644 --- a/app/controller/admin/Base.php +++ b/app/controller/admin/Base.php @@ -78,7 +78,7 @@ class Base extends BaseC { //菜单设置 $this->getMenu(); - View::assign('meta_title', $this->getCurrentTitle()); + View::assign('meta_title', isset($this->data['meta_title']) ? $this->data['meta_title'] : $this->getCurrentTitle()); } } diff --git a/app/controller/admin/Category.php b/app/controller/admin/Category.php index 33c393dc..d4ae5c74 100644 --- a/app/controller/admin/Category.php +++ b/app/controller/admin/Category.php @@ -145,11 +145,7 @@ class Category extends Base { if (!$child->isEmpty()) { return $this->error('请先删除该分类下的子分类'); } - //判断该分类下有没有内容 - // $document_list = db('Document')->where(array('category_id' => $id))->field('id')->select(); - // if (!empty($document_list)) { - // return $this->error('请先删除该分类下的文章(包含回收站)'); - // } + //删除该分类信息 $result = CategoryM::where('id', $id)->delete(); if ($result !== false) { @@ -160,11 +156,13 @@ class Category extends Base { } /** - * 操作分类初始化 + * 移动/合并分类 * @param string $type * @author huajie */ public function operate($type = 'move', $from = '') { + $map = []; + $map[] = ['status', '=', 1]; //检查操作参数 if ($type == 'move') { $operate = '移动'; @@ -176,24 +174,19 @@ class Category extends Base { if (empty($from)) { return $this->error('参数错误!'); + }else{ + $map[] = ['id', '<>', $from]; } + //获取分类 - $map = array('status' => 1, 'id' => array('neq', $from)); - $list = db('Category')->where($map)->field('id,pid,title')->select(); - //移动分类时增加移至根分类 - if ($type == 'move') { - //不允许移动至其子孙分类 - $list = tree_to_list(list_to_tree($list)); + $list = CategoryM::where($map)->field('id,pid,title')->select(); - $pid = db('Category')->getFieldById($from, 'pid'); - $pid && array_unshift($list, array('id' => 0, 'title' => '根分类')); - } - - $this->assign('type', $type); - $this->assign('operate', $operate); - $this->assign('from', $from); - $this->assign('list', $list); - $this->setMeta($operate . '分类'); + $this->data = [ + 'type' => $type, + 'operate' => $operate, + 'from' => $from, + 'list' => $list + ]; return $this->fetch(); } diff --git a/app/controller/admin/Model.php b/app/controller/admin/Model.php index b0838058..3edf4448 100644 --- a/app/controller/admin/Model.php +++ b/app/controller/admin/Model.php @@ -44,18 +44,16 @@ class Model extends Base { * @title 新增模型 * @author huajie */ - public function add(\think\Request $request) { + public function add(ModelM $model) { if ($this->request->isPost()) { - $result = $this->model->validate('Model.add')->save($request->post()); + $data = $this->request->post(); + $result = $model->save($data); if (false !== $result) { - //记录行为 - action_log('add_model', 'model', $result, session('auth_user.uid')); - $this->success('创建成功!', url('admin/model/index')); + $this->success('创建成功!', url('/admin/model/index')); } else { - return $this->error($this->model->getError() ? $this->model->getError() : '模型标识为保留名称!'); + return $this->error('创建失败!'); } } else { - $this->setMeta('新增模型'); return $this->fetch(); } } @@ -64,22 +62,22 @@ class Model extends Base { * @title 编辑模型 * @author molong */ - public function edit(\think\Request $request) { + public function edit(ModelM $model) { if ($this->request->isPost()) { - $result = $this->model->validate('Model.edit')->save($request->post(), array('id' => $request->post('id'))); + $data = $this->request->post(); + + $result = $model->exists(true)->save($data); if (false !== $result) { - //记录行为 - action_log('update_model', 'model', $request->post('id'), session('auth_user.uid')); - $this->success('更新成功!', url('admin/model/index')); + $this->success('更新成功!', url('/admin/model/index')); } else { - return $this->error($this->model->getError()); + return $this->error('修改失败'); } } else { - $info = ModelM::find($request->param('id')); + $info = ModelM::find($this->request->param('id')); $field_group = parse_config_attr($info['attribute_group']); //获取字段列表 - $rows = Attribute::where('model_id', $request->param('id'))->where('is_show', 1)->order('group_id asc, sort asc')->select(); + $rows = Attribute::where('model_id', $this->request->param('id'))->where('is_show', 1)->order('group_id asc, sort asc')->select(); if ($rows) { // 梳理属性的可见性 foreach ($rows as $key => $field) { @@ -105,11 +103,17 @@ class Model extends Base { * @author huajie */ public function del() { - $result = $this->model->del(); + $id = $this->request->param('id', 0); + + if (!$id) { + return $this->error('非法操作!'); + } + + $result = ModelM::find($id)->delete(); if ($result) { return $this->success('删除模型成功!'); } else { - return $this->error($this->mdoel->getError()); + return $this->error('删除失败!'); } } @@ -126,24 +130,23 @@ class Model extends Base { * @title 更新数据 * @author colin */ - public function status(\think\Request $request) { - $map['id'] = $request->param('id'); + public function status() { + $id = $this->request->param('id', 0); + $status = $this->request->param('status', 0); - $data['status'] = $request->param('status'); - - if (null == $map['id'] || null == $data['status']) { - return $this->error('参数不正确!'); + if (!$id) { + return $this->error('非法操作!'); } + $model = ModelM::where('id', $id)->find(); - $model = $this->model->where($map)->find(); - if ($model['list_grid'] == '' && $data['status'] == 1) { + if ($model['list_grid'] == '' && $status == 1) { return $this->error('模型列表未定义'); } - $result = $this->model->where($map)->update($data); + $result = ModelM::update(['status' => $status], ['id'=>$id]); if (false !== $result) { return $this->success('状态设置成功!'); } else { - return $this->error($this->model->getError()); + return $this->error('操作失败!'); } } } \ No newline at end of file diff --git a/app/controller/admin/Wechat.php b/app/controller/admin/Wechat.php index 4581539e..1ffa1d6d 100644 --- a/app/controller/admin/Wechat.php +++ b/app/controller/admin/Wechat.php @@ -12,83 +12,73 @@ namespace app\controller\admin; use app\model\Wechat as WechatM; /** - * @title 微信公众号 - * @description 微信公众号管理 + * @title 微信模块 + * @description 微信公众号、小程序管理 */ class Wechat extends Base { /** - * @title 公众号列表 + * @title 微信列表 * @author huajie */ public function index() { - // $map = array('status' => array('gt', -1)); + $map = []; - // $order = "id desc"; - // //获取列表数据 - // $list = WechatM::where($map)->order($order)->paginate(10, false, array( - // 'query' => $this->request->param(), - // )); + $order = "id desc"; + //获取列表数据 + $list = WechatM::where($map)->order($order)->paginate($this->request->pageConfig); $this->data = array( - 'list' => [], + 'list' => $list, 'page' => '', ); return $this->fetch(); } /** - * @title 新建用户行为 + * @title 添加微信 * @author colin */ public function add() { - $model = model('Action'); if ($this->request->isPost()) { - $data = input('post.'); - $result = $model->save($data); + $data = $this->request->post(); + $result = WechatM::create($data); if (false != $result) { - action_log('add_action', 'Action', $result, session('user_auth.uid')); - return $this->success('添加成功!', url('index')); + return $this->success('添加成功!', url('/admin/wechat/index')); } else { - return $this->error($model->getError()); + return $this->error('添加失败!'); } } else { - $data = array( - 'keyList' => $model->fieldlist, + $this->data = array( + 'keyList' => WechatM::$fieldlist ); - $this->assign($data); - $this->setMeta("添加行为"); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } /** - * @title 编辑用户行为 + * @title 修改微信 * @author colin */ public function edit($id = null) { - $model = model('Action'); if ($this->request->isPost()) { - $data = input('post.'); - $result = $model->save($data, array('id' => $data['id'])); + $data = $this->request->post(); + $result = WechatM::update($data, ['id' => $data['id']]); if ($result !== false) { - action_log('edit_action', 'Action', $id, session('user_auth.uid')); - return $this->success('编辑成功!', url('index')); + return $this->success('编辑成功!', url('/admin/wechat/index')); } else { - return $this->error($model->getError()); + return $this->error('修改失败!'); } } else { - $info = $model::where(array('id' => $id))->find(); + $info = WechatM::find($id); if (!$info) { return $this->error("非法操作!"); } - $data = array( + $this->data = array( 'info' => $info, - 'keyList' => $model->fieldlist, + 'keyList' => WechatM::$fieldlist ); - $this->assign($data); - $this->setMeta("编辑行为"); - return $this->fetch('public/edit'); + return $this->fetch('admin/public/edit'); } } @@ -136,7 +126,7 @@ class Wechat extends Base { * @title 小程序列表 * @author huajie */ - public function miniapp() { + public function pay() { return $this->fetch(); } /** diff --git a/app/http/form/template/bind.html b/app/http/form/template/bind.html index 855755ea..6d06e904 100644 --- a/app/http/form/template/bind.html +++ b/app/http/form/template/bind.html @@ -1,5 +1,5 @@ \ No newline at end of file diff --git a/app/http/form/template/bool.html b/app/http/form/template/bool.html index e69de29b..6d06e904 100644 --- a/app/http/form/template/bool.html +++ b/app/http/form/template/bool.html @@ -0,0 +1,5 @@ + \ No newline at end of file diff --git a/app/http/form/template/kanban.html b/app/http/form/template/kanban.html new file mode 100644 index 00000000..e69de29b diff --git a/app/http/form/template/radio.html b/app/http/form/template/radio.html new file mode 100644 index 00000000..91e6b50c --- /dev/null +++ b/app/http/form/template/radio.html @@ -0,0 +1,6 @@ +{volist name="option" id="item"} +
+ + +
+{/volist} \ No newline at end of file diff --git a/app/http/validate/Content.php b/app/http/validate/Content.php index 7b1ea1c5..855ca1c2 100644 --- a/app/http/validate/Content.php +++ b/app/http/validate/Content.php @@ -22,6 +22,13 @@ class Content extends Validate{ $param = Request::param(); $map = []; + $map[] = ['model_id', '=', $param['model_id']]; + if ($param['function'] == 'add') { + $map[] = ['is_show', 'IN', [1, 2]]; + }else if ($param['function'] == 'edit') { + $map[] = ['is_show', 'IN', [1, 3]]; + } + $attr = Attribute::where($map)->select(); $rule = []; $message = []; diff --git a/app/http/validate/Model.php b/app/http/validate/Model.php new file mode 100644 index 00000000..debadb3f --- /dev/null +++ b/app/http/validate/Model.php @@ -0,0 +1,33 @@ + +// +---------------------------------------------------------------------- +namespace app\http\validate; + +use think\Validate; + +/** + * 菜单验证 + */ +class Model extends Validate{ + protected $rule = [ + 'title' => 'require', + 'name' => 'require|unique:Model|alpha', + ]; + + protected $message = [ + 'title.require' => '模型名称必须', + 'name.require' => '模型标识必须', + 'name.unique' => '模型标识已存在', + 'name.alpha' => '模型标识必须为字母', + ]; + + protected $scene = [ + 'adminadd' => ['title', 'name'], + 'adminedit' => ['title'], + ]; +} \ No newline at end of file diff --git a/app/model/Addons.php b/app/model/Addons.php index 2f87670c..355280c6 100644 --- a/app/model/Addons.php +++ b/app/model/Addons.php @@ -10,8 +10,11 @@ namespace app\model; /** - * 分类模型 + * 扩展模型 */ class Addons extends \think\Model { + public static function refreshAddons(){ + + } } \ No newline at end of file diff --git a/app/model/Attribute.php b/app/model/Attribute.php index cd67c113..433df2fd 100644 --- a/app/model/Attribute.php +++ b/app/model/Attribute.php @@ -9,6 +9,9 @@ namespace app\model; use think\facade\Config; +use think\facade\Db; +use sent\tree\Tree; +use app\model\Model as Models; /** * 设置模型 @@ -19,46 +22,49 @@ class Attribute extends \think\Model { 'id' => 'integer', ); - protected static function onAfterInsert($model){ - // if ($data['model_id']) { - // $name = db('Model')->where('id', $data['model_id'])->value('name'); - // $db = new \com\Datatable(); - // $attr = $data->toArray(); - // $model_attr = array( - // 'model_id' => $data['model_id'], - // 'attr_id' => $data->id, - // 'group_id' => 0, - // 'is_add_table' => 1, - // 'is_show' => $data['is_show'], - // 'is_must' => $data['is_must'], - // 'sort' => 0, - // ); - // $attr['after'] = db('Attribute')->where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name'); - // return $db->columField(strtolower($name), $attr)->query(); - // } - } - - protected static function onAfterUpdate($model){ - // $attr = $data->toArray(); - // $attr['action'] = 'CHANGE'; - // $attr['oldname'] = db('Attribute')->where('id', $attr['id'])->value('name'); - // if ($attr['id']) { - // $name = db('Model')->where('id', $attr['model_id'])->value('name'); - // $db = new \com\Datatable(); - // return $db->columField(strtolower($name), $attr)->query(); - // } else { - // return false; - // } - } - - protected static function onAfterDelete($model){ - $tablename = strtolower($tablename); - //删除模型表中字段 - $db = new \com\Datatable(); - if (!$db->CheckField($tablename, $info['name'])) { - return true; + protected static function onAfterInsert($data){ + $data = $data->toArray(); + if ($data['model_id']) { + $db = new \com\Datatable(); + $name = Models::where('id', $data['model_id'])->value('name'); + $data['after'] = self::where('name', '<>', $data['name'])->where('model_id', $data['model_id'])->order('id desc')->value('name'); + return $db->columField(strtolower($name), $data)->query(); + } + } + + protected static function onAfterUpdate($data){ + $data = $data->toArray(); + if ($data['model_id']) { + $tablename = Models::where('id', $data['model_id'])->value('name'); + + //删除模型表中字段 + $db = new \com\Datatable(); + if ($db->CheckField($tablename, $data['name'])) { + $data['action'] = 'CHANGE'; + } + $result = $db->columField(strtolower($tablename), $data)->query(); + return $result; + }else{ + return false; + } + } + + protected static function onAfterDelete($data){ + $data = $data->toArray(); + if ($data['model_id']) { + $tablename = Models::where('id', $data['model_id'])->value('name'); + + //删除模型表中字段 + $db = new \com\Datatable(); + if (!$db->CheckField($tablename, $data['name'])) { + $result = true; + }else{ + $result = $db->delField($tablename, $data['name'])->query(); + } + return $result; + }else{ + return false; } - $result = $db->delField($tablename, $info['name'])->query(); } protected function getTypeTextAttr($value, $data) { @@ -71,14 +77,44 @@ class Attribute extends \think\Model { } protected function getOptionAttr($value, $data){ + $list = []; if ($data == '') { - return []; + return $list; } - if (in_array($data['type'], ['checkbox', 'radio', 'select', 'bool'])) { - # code... + if (in_array($data['type'], ['checkbox', 'radio', 'select'])) { + $row = explode(PHP_EOL, $data['extra']); + foreach ($row as $k => $val) { + if (strrpos($val, ":")) { + list($key, $label) = explode(":", $val); + $list[] = ['key' => $key, 'label' => $label]; + }else{ + $list[] = ['key' => $k, 'label' => $val]; + } + } + }elseif($data['type'] == 'bool'){ + $list = [['key'=>0,'label'=>'禁用'],['key'=>1,'label'=>'启用']]; }elseif($data['type'] == 'bind'){ - + if (strrpos($data['extra'], ":")) { + $extra = explode(":", $data['extra']); + $row = Db::name($extra[0])->select()->toArray(); + if ($extra[1] == 'tree') { + $row = (new Tree())->toFormatTree($row); + foreach ($row as $val) { + $list[] = ['key'=>$val['id'], 'label'=>$val['title_show']]; + } + }else{ + foreach ($row as $val) { + $list[] = ['key'=>$val['id'], 'label'=>$val['title']]; + } + } + }else{ + $row = Db::name($data['extra'])->select()->toArray(); + foreach ($row as $val) { + $list[] = ['key'=>$val['id'], 'label'=>$val['title']]; + } + } } + return $list; } public static function getField($model, $ac = "add"){ @@ -93,7 +129,7 @@ class Attribute extends \think\Model { $map[] = ['is_show', 'IN', [1, 3]]; } - $row = self::where('model_id', $model['id']) + $row = self::where($map) ->select() ->append(['option']) ->toArray(); @@ -107,4 +143,33 @@ class Attribute extends \think\Model { return $list; } + + public static function getfieldList(){ + return [ + '基础' => [ + ['name' => 'id', 'title' => 'id', 'help' => '', 'type' => 'hidden'], + ['name' => 'model_id', 'title' => 'model_id', 'help' => '', 'type' => 'hidden'], + ['name' => 'name', 'title' => '字段名', 'help' => '英文字母开头,长度不超过30', 'type' => 'text'], + ['name' => 'title', 'title' => '字段标题', 'help' => '请输入字段标题,用于表单显示', 'type' => 'text'], + ['name' => 'type', 'title' => '字段类型', 'help' => '用于表单中的展示方式', 'type' => 'select', 'option' => Config::get('config.config_type_list'), 'help' => ''], + ['name' => 'length', 'title' => '字段长度', 'help' => '字段的长度值', 'type' => 'text'], + ['name' => 'extra', 'title' => '参数', 'help' => '布尔、枚举、多选字段类型的定义数据', 'type' => 'textarea'], + ['name' => 'value', 'title' => '默认值', 'help' => '字段的默认值', 'type' => 'text'], + ['name' => 'remark', 'title' => '字段备注', 'help' => '用于表单中的提示', 'type' => 'text'], + ['name' => 'is_show', 'title' => '是否显示', 'help' => '是否显示在表单中', 'type' => 'select', 'option' => [ + ['key'=>'1', 'label' => '始终显示'], ['key'=>'2', 'label' => '新增显示'], ['key'=>'3', 'label' => '编辑显示'], ['key'=>'0', 'label' => '不显示'] + ], 'value' => 1], + ['name' => 'is_must', 'title' => '是否必填', 'help' => '用于自动验证', 'type' => 'select', 'option' => [['key'=>'0', 'label' => '否'], ['key'=>'1', 'label' => '是']]], + ], + '高级' => [ + ['name' => 'validate_type', 'title' => '验证方式', 'type' => 'select', 'option' => [], 'help' => ''], + ['name' => 'validate_rule', 'title' => '验证规则', 'help' => '根据验证方式定义相关验证规则', 'type' => 'text'], + ['name' => 'error_info', 'title' => '出错提示', 'type' => 'text', 'help' => ''], + ['name' => 'validate_time', 'title' => '验证时间', 'help' => '英文字母开头,长度不超过30', 'type' => 'select', 'option' => [], 'help' => ''], + ['name' => 'auto_type', 'title' => '自动完成方式', 'help' => '英文字母开头,长度不超过30', 'type' => 'select', 'option' => [], 'help' => ''], + ['name' => 'auto_rule', 'title' => '自动完成规则', 'help' => '根据完成方式订阅相关规则', 'type' => 'text'], + ['name' => 'auto_time', 'title' => '自动完成时间', 'help' => '英文字母开头,长度不超过30', 'type' => 'select', 'option' => []], + ], + ]; + } } \ No newline at end of file diff --git a/app/model/Hooks.php b/app/model/Hooks.php index f44cab9a..0b892fac 100644 --- a/app/model/Hooks.php +++ b/app/model/Hooks.php @@ -14,4 +14,10 @@ namespace app\model; */ class Hooks extends \think\Model { + public static $keylist = [ + ['name' => 'name', 'title' => '钩子名称', 'type' => 'text', 'help' => '需要在程序中先添加钩子,否则无效'], + ['name' => 'description', 'title' => '钩子描述', 'type' => 'text', 'help' => '钩子的描述信息'], + ['name' => 'type_text', 'title' => '钩子类型', 'type' => 'select', 'option' => '', 'help' => '钩子的描述信息'], + ['name' => 'addons', 'title' => '插件排序', 'type' => 'kanban'], + ]; } \ No newline at end of file diff --git a/app/model/Link.php b/app/model/Link.php index 777611b5..4a37b896 100644 --- a/app/model/Link.php +++ b/app/model/Link.php @@ -20,7 +20,7 @@ class Link extends \think\Model { public static $keyList = [ ['name' => 'id', 'title' => 'ID', 'type' => 'hidden'], ['name' => 'title', 'title' => '友链标题', 'type' => 'text', 'help' => ''], - ['name' => 'url', 'title' => 'URL链接', 'type' => 'text', 'help' => ''], + ['name' => 'url', 'title' => 'URL链接', 'type' => 'text', 'help' => '连接格式如:https://www.tensent.cn'], ['name' => 'ftype', 'title' => '友链类别', 'type' => 'select', 'option' => [ ['key'=>'1', 'label' => '常用链接'], ['key'=>'2', 'label' => '网站导读'], diff --git a/app/model/Model.php b/app/model/Model.php index addcd1fb..fa495c76 100644 --- a/app/model/Model.php +++ b/app/model/Model.php @@ -20,9 +20,23 @@ class Model extends \think\Model{ 'id' => 'integer' ); - protected static function onAfterInsert($model){ - $data = $model->getDate(); + protected static function onBeforeInsert($data){ + if ($data['name'] && $data['title']) { + $db = new \com\Datatable(); + //检查表是否存在并创建 + if (!$db->CheckTable($data['name'])) { + //创建新表 + return $db->initTable($data['name'], $data['title'], 'id')->query(); + }else{ + return false; + } + }else{ + return false; + } + } + protected static function onAfterInsert($data){ + $data = $data->toArray(); $fields = [ 'title'=> ['name' => 'title', 'title' => '标题', 'type' => 'text', 'length' => 200, 'extra' => '', 'remark' => '标题', 'is_show' => 1, 'is_must' => 1, 'value'=>''], 'category_id' => ['name' => 'category_id', 'title' => '栏目', 'type' => 'bind', 'length' => 10, 'extra' => 'category', 'remark' => '栏目', 'is_show' => 1, 'is_must' => 1, 'value'=>'0'], @@ -36,6 +50,7 @@ class Model extends \think\Model{ 'update_time' => ['name' => 'update_time', 'title' => '更新时间', 'type' => 'datetime', 'length' => 11, 'extra' => '', 'remark' => '更新时间', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'], 'create_time' => ['name' => 'create_time', 'title' => '添加时间', 'type' => 'datetime', 'length' => 11, 'extra' => '', 'remark' => '添加时间', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'], ]; + $result = false; if (!empty($fields)) { foreach ($fields as $key => $value) { if ($data['is_doc']) { @@ -48,13 +63,12 @@ class Model extends \think\Model{ } } } - (new Attribute())->saveAll($fields); + $result = (new Attribute())->saveAll($fields); } - return true; + return $result; } - protected static function onAfterUpdate($model){ - $data = $model->getDate(); + protected static function onAfterUpdate($data){ if (isset($data['attribute_sort']) && $data['attribute_sort']) { $attribute_sort = json_decode($data['attribute_sort'], true); @@ -73,6 +87,16 @@ class Model extends \think\Model{ return true; } + protected static function onAfterDelete($data){ + $data = $data->toArray(); + (new Attribute())->where('model_id', $data['id'])->delete(); + $db = new \com\Datatable(); + if ($db->CheckTable($data['name'])) { + $result = $db->delTable($data['name'])->query(); + } + return $result; + } + protected function setAttributeSortAttr($value) { return $value ? json_encode($value) : ''; } diff --git a/config/filesystem.php b/config/filesystem.php index 965297e8..8ac3ea57 100755 --- a/config/filesystem.php +++ b/config/filesystem.php @@ -13,9 +13,9 @@ return [ // 磁盘类型 'type' => 'local', // 磁盘路径 - 'root' => app()->getRootPath() . 'public/storage', + 'root' => app()->getRootPath() . 'public/uploads', // 磁盘路径对应的外部URL路径 - 'url' => '/storage', + 'url' => '/uploads', // 可见性 'visibility' => 'public', ], diff --git a/extend/com/Datatable.php b/extend/com/Datatable.php index 635cb336..7a17c0cd 100644 --- a/extend/com/Datatable.php +++ b/extend/com/Datatable.php @@ -9,6 +9,7 @@ namespace com; use think\facade\Config; +use think\facade\Env; use think\facade\Db; /** @@ -50,8 +51,8 @@ class Datatable { */ public function __construct() { //创建DB对象 - $this->prefix = Config::get('database.prefix'); - $this->model_table_prefix = Config::get('model_table_prefix'); + $this->prefix = Env::get('database.prefix'); + $this->model_table_prefix = Config::get('model_table_prefix') ? Config::get('model_table_prefix') : ''; } /** @@ -123,7 +124,7 @@ class Datatable { if ($field_attr['action'] == 'ADD') { $this->sql = "ALTER TABLE `{$field_attr['table']}` ADD `{$field_attr['name']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}' {$field_attr['after']}"; } elseif ($field_attr['action'] == 'CHANGE') { - $field_attr['oldname'] = (isset($attr['oldname']) && $attr['oldname']) ? $attr['oldname'] : ''; + $field_attr['oldname'] = (isset($attr['oldname']) && $attr['oldname']) ? $attr['oldname'] : $attr['name']; $this->sql = "ALTER TABLE `{$field_attr['table']}` CHANGE `{$field_attr['oldname']}` `{$field_attr['name']}` {$field_attr['type']}{$field_attr['length']} {$field_attr['is_null']} {$field_attr['default']} COMMENT '{$field_attr['comment']}'"; } diff --git a/public/template/default/front/index_index.html b/public/template/default/front/index_index.html index 9340259c..99486dc9 100644 --- a/public/template/default/front/index_index.html +++ b/public/template/default/front/index_index.html @@ -27,7 +27,6 @@ html, body {background-color: #fff; color: #636b6f; font-family: 'Raleway', sans
SentCMS网站管理系统
-{:ad('index', [])}
- 新 增 - + 新 增 +
@@ -35,8 +35,8 @@ {$item['description']} {$item['type_text']} - 编辑 - 删除 + 编辑 + 删除 {/volist} diff --git a/view/admin/addons/index.html b/view/admin/addons/index.html index 86b21a9d..6b2361ac 100644 --- a/view/admin/addons/index.html +++ b/view/admin/addons/index.html @@ -9,9 +9,9 @@

{$meta_title}

- 更 新 - 新 增 - + 更 新 + 新 增 +
@@ -43,15 +43,15 @@ {$item['version']} {if !$item['isinstall']} - 安装 + 安装 {else/} - 卸载 + 卸载 {if $item['status']} - 禁用 + 禁用 {else/} - 启用 + 启用 {/if} - 设置 + 设置 {/if} diff --git a/view/admin/attribute/index.html b/view/admin/attribute/index.html index e0504d8d..e8faa573 100644 --- a/view/admin/attribute/index.html +++ b/view/admin/attribute/index.html @@ -6,9 +6,9 @@

{$meta_title}

@@ -35,8 +35,8 @@ {$item['length']} {$item['value']} - 编辑 - 删除 + 编辑 + 删除 {/volist} @@ -48,17 +48,4 @@
{/block} {block name="script"} - - {/block} \ No newline at end of file diff --git a/view/admin/category/edit.html b/view/admin/category/edit.html index 2061c7cd..1c47f5b7 100644 --- a/view/admin/category/edit.html +++ b/view/admin/category/edit.html @@ -17,7 +17,7 @@
-
+ -
- -
- -
-
-
- -
- -
-
diff --git a/view/admin/category/operate.html b/view/admin/category/operate.html index 4e51b688..19240738 100644 --- a/view/admin/category/operate.html +++ b/view/admin/category/operate.html @@ -4,7 +4,7 @@
-

{$operate}分类

+

{$meta_title}分类

diff --git a/view/admin/link/index.html b/view/admin/link/index.html index cd175516..1ce60861 100644 --- a/view/admin/link/index.html +++ b/view/admin/link/index.html @@ -37,8 +37,8 @@ {$item['create_time']} {$item['update_time']} - 编辑 - 删除 + 编辑 + 删除 {/volist} diff --git a/view/admin/model/index.html b/view/admin/model/index.html index 1813d962..15cc6f20 100644 --- a/view/admin/model/index.html +++ b/view/admin/model/index.html @@ -8,7 +8,6 @@
新 增 -
@@ -37,7 +36,7 @@ {$item['id']} {$item['name']} - {$item['title']} + {$item['title']} {$item.create_time} @@ -51,7 +50,7 @@ 字段 - {$item['status'] ? '禁用' : '启用'} + {$item['status'] ? '禁用' : '启用'} 编辑 删除 数据 diff --git a/view/admin/public/header.html b/view/admin/public/header.html index 9aca6c77..bed1f922 100644 --- a/view/admin/public/header.html +++ b/view/admin/public/header.html @@ -13,7 +13,7 @@