内容模型功能完成
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <colin@tensent.cn>
|
||||
*/
|
||||
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 <colin@tensent.cn>
|
||||
*/
|
||||
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 <colin@tensent.cn>
|
||||
*/
|
||||
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),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -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());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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 <banhuajie@163.com>
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,18 +44,16 @@ class Model extends Base {
|
||||
* @title 新增模型
|
||||
* @author huajie <banhuajie@163.com>
|
||||
*/
|
||||
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 <molong@tensent.cn>
|
||||
*/
|
||||
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 <banhuajie@163.com>
|
||||
*/
|
||||
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 <colin@tensent.cn>
|
||||
*/
|
||||
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('操作失败!');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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 <banhuajie@163.com>
|
||||
*/
|
||||
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 <colin@tensent.cn>
|
||||
*/
|
||||
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 <colin@tensent.cn>
|
||||
*/
|
||||
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 <banhuajie@163.com>
|
||||
*/
|
||||
public function miniapp() {
|
||||
public function pay() {
|
||||
return $this->fetch();
|
||||
}
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<select class="form-control" name="{$name}" id="{$name}" style="width:auto;">
|
||||
{volist name="option" id="item"}
|
||||
<option value="{$item['key']}" {if $item['key'] == $value}selected{/if}>{$item['label']}</option>
|
||||
<option value="{$item['key']}" {if $item['key'] == $value}selected{/if}>{$item['label']|raw}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
@@ -0,0 +1,5 @@
|
||||
<select class="form-control" name="{$name}" id="{$name}" style="width:auto;">
|
||||
{volist name="option" id="item"}
|
||||
<option value="{$item['key']}" {if $item['key'] == $value}selected{/if}>{$item['label']|raw}</option>
|
||||
{/volist}
|
||||
</select>
|
||||
0
app/http/form/template/kanban.html
Normal file
0
app/http/form/template/kanban.html
Normal file
6
app/http/form/template/radio.html
Normal file
6
app/http/form/template/radio.html
Normal file
@@ -0,0 +1,6 @@
|
||||
{volist name="option" id="item"}
|
||||
<div class="checkbox-nice checkbox-inline">
|
||||
<input type="radio" name="{$name}[]" id="{$name}-{$key}" value="{$key}" {if in_array($key, $value)}checked{/if}/>
|
||||
<label for="{$name}-{$key}">{$item}</label>
|
||||
</div>
|
||||
{/volist}
|
||||
@@ -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 = [];
|
||||
|
||||
33
app/http/validate/Model.php
Normal file
33
app/http/validate/Model.php
Normal file
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | SentCMS [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.tensent.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
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'],
|
||||
];
|
||||
}
|
||||
@@ -10,8 +10,11 @@
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
* 扩展模型
|
||||
*/
|
||||
class Addons extends \think\Model {
|
||||
|
||||
public static function refreshAddons(){
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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' => []],
|
||||
],
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -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'],
|
||||
];
|
||||
}
|
||||
@@ -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' => '网站导读'],
|
||||
|
||||
@@ -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) : '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user