更新代码,完善功能
This commit is contained in:
@@ -6,9 +6,11 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Admin;
|
||||
use app\model\Addons as AddonsM;
|
||||
use app\model\Hooks;
|
||||
|
||||
/**
|
||||
* @title 插件管理
|
||||
@@ -16,34 +18,19 @@ use app\controller\Admin;
|
||||
*/
|
||||
class Addons extends Admin {
|
||||
|
||||
protected $addons;
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
//加入菜单
|
||||
$this->getAddonsMenu();
|
||||
$this->addons = model('Addons');
|
||||
$this->hooks = db('Hooks');
|
||||
}
|
||||
/**
|
||||
* @title 插件列表
|
||||
*/
|
||||
public function index($refresh = 0) {
|
||||
public function index(AddonsM $addons, $refresh = 0) {
|
||||
if ($refresh) {
|
||||
$this->addons->refresh();
|
||||
$addons->refresh();
|
||||
}
|
||||
$list = $this->addons->order('id desc')->paginate(25, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
// 记录当前列表页的cookie
|
||||
Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||
$list = $addons->order('id desc')->paginate($this->request->pageConfig);
|
||||
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'list' => $list,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
$this->setMeta("插件管理");
|
||||
$this->assign($data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
@@ -218,22 +205,15 @@ class Addons extends Admin {
|
||||
* @title 钩子列表
|
||||
*/
|
||||
public function hooks() {
|
||||
|
||||
$map = array();
|
||||
$map = [];
|
||||
$order = "id desc";
|
||||
$list = model('Hooks')->where($map)->order($order)->paginate(10, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
|
||||
// 记录当前列表页的cookie
|
||||
Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||
$list = Hooks::where($map)->order($order)->paginate($this->request->pageConfig);
|
||||
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'list' => $list,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
$this->setMeta("钩子管理");
|
||||
$this->assign($data);
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ namespace app\controller\admin;
|
||||
|
||||
use app\model\Category as CategoryM;
|
||||
use app\model\Attribute;
|
||||
use app\model\Module;
|
||||
use app\model\Model;
|
||||
use app\controller\Admin;
|
||||
|
||||
/**
|
||||
@@ -28,7 +28,7 @@ class Category extends Admin {
|
||||
/**
|
||||
* @title 栏目列表
|
||||
*/
|
||||
public function index(CategoryM $category, Attribute $attr, Module $medule) {
|
||||
public function index(CategoryM $category, Attribute $attr, Model $model) {
|
||||
$param = $this->request->param();
|
||||
$map = [];
|
||||
|
||||
@@ -42,8 +42,8 @@ class Category extends Admin {
|
||||
$tree = new \sent\tree\Tree();
|
||||
$list = $tree->toFormatTree($list->toArray());
|
||||
}
|
||||
// $subsql = $attr->where('name', 'category_id')->fetchSql(true)->column('model_id');
|
||||
// $model_list = $medule->where('id IN ('. $subsql.')')->select();
|
||||
$subsql = $attr->where('name', 'category_id')->fetchSql(true)->column('model_id');
|
||||
$model_list = $model->where('id IN ('. $subsql.')')->select();
|
||||
|
||||
$this->data = [
|
||||
'tree' => $list,
|
||||
|
||||
@@ -8,7 +8,10 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Admin;
|
||||
use app\model\Channel as ChannelM;
|
||||
use sent\tree\Tree;
|
||||
|
||||
/**
|
||||
* @title 频道管理
|
||||
@@ -16,35 +19,27 @@ use app\controller\Admin;
|
||||
*/
|
||||
class Channel extends Admin {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 频道列表
|
||||
*/
|
||||
public function index($type = 0) {
|
||||
public function index(ChannelM $channel, $type = 0) {
|
||||
/* 获取频道列表 */
|
||||
//$map = array('status' => array('gt', -1), 'pid'=>$pid);
|
||||
$map = array('status' => array('gt', -1));
|
||||
if ($type) {
|
||||
$map['type'] = $type;
|
||||
}
|
||||
$list = db('Channel')->where($map)->order('sort asc,id asc')->column('*', 'id');
|
||||
$list = $channel->where($map)->order('sort asc,id asc')->column('*', 'id');
|
||||
|
||||
if (!empty($list)) {
|
||||
$tree = new \com\Tree();
|
||||
$tree = new Tree();
|
||||
$list = $tree->toFormatTree($list);
|
||||
}
|
||||
|
||||
config('_sys_get_channel_tree_', true);
|
||||
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'tree' => $list,
|
||||
'type' => $type,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('导航管理');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,8 @@
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\model\Client as ClientM;
|
||||
use app\controller\Admin;
|
||||
|
||||
/**
|
||||
@@ -15,71 +17,65 @@ use app\controller\Admin;
|
||||
*/
|
||||
class Client extends Admin {
|
||||
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->model = model('Client');
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 客户端列表
|
||||
*/
|
||||
public function index() {
|
||||
$list = $this->model->paginate(25, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
$data = array(
|
||||
$map = [];
|
||||
|
||||
$list = ClientM::where($map)->paginate($this->request->pageConfig);
|
||||
|
||||
$this->data = array(
|
||||
'list' => $list,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('客户端列表');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 添加客户端
|
||||
*/
|
||||
public function add(\think\Request $request) {
|
||||
public function add() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $request->param();
|
||||
$result = $this->model->validate(true)->save($data);
|
||||
$data = $this->request->param();
|
||||
|
||||
$result = ClientM::create($data);
|
||||
if (false !== $result) {
|
||||
return $this->success('成功添加', url('client/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
return $this->error('添加失败!');
|
||||
}
|
||||
} else {
|
||||
$info['appid'] = rand_string(10, 1); //八位数字appid
|
||||
$info['appsecret'] = rand_string(32); //32位数字加字母秘钥
|
||||
$data = array(
|
||||
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('添加客户端');
|
||||
return $this->fetch('add');
|
||||
return $this->fetch();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @title 编辑客户端
|
||||
*/
|
||||
public function edit(\think\Request $request) {
|
||||
public function edit() {
|
||||
if ($this->request->isPost()) {
|
||||
$data = $request->param();
|
||||
$result = $this->model->validate(true)->save($data, array('id' => $request->param('id')));
|
||||
$data = $this->request->param();
|
||||
|
||||
$result = ClientM::update($data, ['id' => $this->request->param('id')]);
|
||||
if (false !== $result) {
|
||||
return $this->success('修改添加', url('client/index'));
|
||||
} else {
|
||||
return $this->error($this->model->getError());
|
||||
}
|
||||
} else {
|
||||
$info = $this->model->where('id', $request->param('id'))->find();
|
||||
$data = array(
|
||||
$info = $ClientM::where('id', $request->param('id'))->find();
|
||||
|
||||
$this->data = array(
|
||||
'info' => $info,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta('编辑客户端');
|
||||
return $this->fetch('add');
|
||||
return $this->fetch('admin/client/add');
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -215,18 +215,17 @@ class Config extends Admin {
|
||||
/**
|
||||
* @title 主题选择
|
||||
*/
|
||||
public function themes() {
|
||||
$list = $this->model->getThemesList();
|
||||
$pc = config('pc_themes');
|
||||
$mobile = config('mobile_themes');
|
||||
$data = array(
|
||||
public function themes(ConfigM $config) {
|
||||
$list = $config->getThemesList();
|
||||
$pc = config('system_config.pc_themes');
|
||||
$mobile = config('system_config.mobile_themes');
|
||||
|
||||
$this->data = array(
|
||||
'pc' => $pc,
|
||||
'mobile' => $mobile,
|
||||
'list' => $list,
|
||||
);
|
||||
|
||||
$this->assign($data);
|
||||
$this->setMeta('主题设置');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -7,8 +7,9 @@
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\admin\controller;
|
||||
use app\common\controller\Admin;
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Admin;
|
||||
|
||||
/**
|
||||
* @title 数据库管理
|
||||
@@ -20,54 +21,55 @@ class Database extends Admin {
|
||||
* @param String $type import-还原,export-备份
|
||||
* @author 麦当苗儿 <zuojiazi@vip.qq.com>
|
||||
*/
|
||||
public function index($type = null) {
|
||||
public function index() {
|
||||
$type = $this->request->get('type', 'import');
|
||||
switch ($type) {
|
||||
/* 数据还原 */
|
||||
case 'import':
|
||||
//列出备份文件列表
|
||||
$path = config('data_backup_path');
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0755, true);
|
||||
}
|
||||
$path = realpath($path);
|
||||
$flag = \FilesystemIterator::KEY_AS_FILENAME;
|
||||
$glob = new \FilesystemIterator($path, $flag);
|
||||
|
||||
$list = array();
|
||||
foreach ($glob as $name => $file) {
|
||||
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
|
||||
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
|
||||
|
||||
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
|
||||
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
|
||||
$part = $name[6];
|
||||
|
||||
if (isset($list["{$date} {$time}"])) {
|
||||
$info = $list["{$date} {$time}"];
|
||||
$info['part'] = max($info['part'], $part);
|
||||
$info['size'] = $info['size'] + $file->getSize();
|
||||
} else {
|
||||
$info['part'] = $part;
|
||||
$info['size'] = $file->getSize();
|
||||
}
|
||||
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
|
||||
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
|
||||
$info['time'] = strtotime("{$date} {$time}");
|
||||
|
||||
$list["{$date} {$time}"] = $info;
|
||||
/* 数据还原 */
|
||||
case 'import':
|
||||
//列出备份文件列表
|
||||
$path = config('data_backup_path');
|
||||
if (!is_dir($path)) {
|
||||
mkdir($path, 0755, true);
|
||||
}
|
||||
}
|
||||
$title = '数据还原';
|
||||
break;
|
||||
/* 数据备份 */
|
||||
case 'export':
|
||||
$Db = \think\Db::connect();
|
||||
$list = $Db->query('SHOW TABLE STATUS');
|
||||
$list = array_map('array_change_key_case', $list);
|
||||
$title = '数据备份';
|
||||
break;
|
||||
default:
|
||||
return $this->error('参数错误!');
|
||||
$path = realpath($path);
|
||||
$flag = \FilesystemIterator::KEY_AS_FILENAME;
|
||||
$glob = new \FilesystemIterator($path, $flag);
|
||||
|
||||
$list = array();
|
||||
foreach ($glob as $name => $file) {
|
||||
if (preg_match('/^\d{8,8}-\d{6,6}-\d+\.sql(?:\.gz)?$/', $name)) {
|
||||
$name = sscanf($name, '%4s%2s%2s-%2s%2s%2s-%d');
|
||||
|
||||
$date = "{$name[0]}-{$name[1]}-{$name[2]}";
|
||||
$time = "{$name[3]}:{$name[4]}:{$name[5]}";
|
||||
$part = $name[6];
|
||||
|
||||
if (isset($list["{$date} {$time}"])) {
|
||||
$info = $list["{$date} {$time}"];
|
||||
$info['part'] = max($info['part'], $part);
|
||||
$info['size'] = $info['size'] + $file->getSize();
|
||||
} else {
|
||||
$info['part'] = $part;
|
||||
$info['size'] = $file->getSize();
|
||||
}
|
||||
$extension = strtoupper(pathinfo($file->getFilename(), PATHINFO_EXTENSION));
|
||||
$info['compress'] = ($extension === 'SQL') ? '-' : $extension;
|
||||
$info['time'] = strtotime("{$date} {$time}");
|
||||
|
||||
$list["{$date} {$time}"] = $info;
|
||||
}
|
||||
}
|
||||
$title = '数据还原';
|
||||
break;
|
||||
/* 数据备份 */
|
||||
case 'export':
|
||||
$Db = \think\Db::connect();
|
||||
$list = $Db->query('SHOW TABLE STATUS');
|
||||
$list = array_map('array_change_key_case', $list);
|
||||
$title = '数据备份';
|
||||
break;
|
||||
default:
|
||||
return $this->error('参数错误!');
|
||||
}
|
||||
//渲染模板
|
||||
$this->setMeta($title);
|
||||
|
||||
@@ -58,10 +58,9 @@ class Index extends Admin {
|
||||
* @title 后台退出
|
||||
* @return html
|
||||
*/
|
||||
public function logout() {
|
||||
$user = model('Member');
|
||||
$user->logout();
|
||||
$this->redirect('admin/index/login');
|
||||
public function logout(Member $user) {
|
||||
Session::delete('userInfo');
|
||||
$this->redirect('/admin/login');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,12 +86,10 @@ class Index extends Admin {
|
||||
),
|
||||
),
|
||||
);
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'keyList' => $keylist,
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("更新缓存");
|
||||
return $this->fetch('public/edit');
|
||||
return $this->fetch('admin/public/edit');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,8 +6,9 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\model\Link as LinkM;
|
||||
use app\controller\Admin;
|
||||
|
||||
/**
|
||||
@@ -19,20 +20,16 @@ class Link extends Admin {
|
||||
/**
|
||||
* @title 链接列表
|
||||
*/
|
||||
public function index() {
|
||||
public function index(LinkM $link) {
|
||||
$map = array();
|
||||
|
||||
$order = "id desc";
|
||||
$list = db('Link')->where($map)->order($order)->paginate(10, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
$list = $link->where($map)->order($order)->paginate($this->request->pageConfig);
|
||||
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'list' => $list,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
$this->assign($data);
|
||||
$this->setMeta("友情链接");
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
@@ -6,9 +6,10 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\controller\admin;
|
||||
|
||||
use app\controller\Admin;
|
||||
use app\model\Model as ModelM;
|
||||
|
||||
/**
|
||||
* @title 模型管理
|
||||
@@ -18,7 +19,6 @@ class Model extends Admin {
|
||||
public function _initialize() {
|
||||
parent::_initialize();
|
||||
$this->getContentMenu();
|
||||
$this->model = model('Model');
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -26,23 +26,17 @@ class Model extends Admin {
|
||||
* @author huajie <banhuajie@163.com>
|
||||
*/
|
||||
public function index() {
|
||||
$map = array('status' => array('gt', -1));
|
||||
$map = [];
|
||||
|
||||
$map[] = ['status', '>', '-1'];
|
||||
|
||||
$order = "id desc";
|
||||
$list = $this->model->where($map)->order($order)->paginate(10, false, array(
|
||||
'query' => $this->request->param(),
|
||||
));
|
||||
$list = ModelM::where($map)->order($order)->paginate($this->request->pageConfig);
|
||||
|
||||
$data = array(
|
||||
$this->data = array(
|
||||
'list' => $list,
|
||||
'page' => $list->render(),
|
||||
);
|
||||
|
||||
// 记录当前列表页的cookie
|
||||
Cookie('__forward__', $_SERVER['REQUEST_URI']);
|
||||
|
||||
$this->assign($data);
|
||||
$this->setMeta('模型管理');
|
||||
return $this->fetch();
|
||||
}
|
||||
|
||||
|
||||
17
app/model/Addons.php
Normal file
17
app/model/Addons.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Addons extends \think\Model {
|
||||
|
||||
}
|
||||
@@ -12,44 +12,44 @@ namespace app\model;
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Attribute {
|
||||
class Attribute extends \think\Model {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected static function init() {
|
||||
self::afterInsert(function ($data) {
|
||||
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();
|
||||
}
|
||||
});
|
||||
self::beforeUpdate(function ($data) {
|
||||
$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 init() {
|
||||
// self::afterInsert(function ($data) {
|
||||
// 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();
|
||||
// }
|
||||
// });
|
||||
// self::beforeUpdate(function ($data) {
|
||||
// $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 function getTypeTextAttr($value, $data) {
|
||||
$type = config('config_type_list');
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace app\model;
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Channel {
|
||||
class Channel extends \think\Model {
|
||||
|
||||
protected $type = array(
|
||||
'id' => 'integer',
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace app\model;
|
||||
/**
|
||||
* Client模型
|
||||
*/
|
||||
class Client {
|
||||
class Client extends \think\Model{
|
||||
protected $auto = array('update_time');
|
||||
protected $insert = array('create_time');
|
||||
|
||||
|
||||
@@ -79,4 +79,11 @@ class Config extends Model {
|
||||
}
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function getThemesList(){
|
||||
return [
|
||||
'pc' => [],
|
||||
'mobile' => []
|
||||
];
|
||||
}
|
||||
}
|
||||
17
app/model/Hooks.php
Normal file
17
app/model/Hooks.php
Normal file
@@ -0,0 +1,17 @@
|
||||
<?php
|
||||
// +----------------------------------------------------------------------
|
||||
// | OneThink [ WE CAN DO IT JUST THINK IT ]
|
||||
// +----------------------------------------------------------------------
|
||||
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com> <http://www.zjzit.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 分类模型
|
||||
*/
|
||||
class Hooks extends \think\Model {
|
||||
|
||||
}
|
||||
@@ -6,14 +6,13 @@
|
||||
// +----------------------------------------------------------------------
|
||||
// | Author: molong <molong@tensent.cn> <http://www.tensent.cn>
|
||||
// +----------------------------------------------------------------------
|
||||
|
||||
namespace app\model;
|
||||
|
||||
/**
|
||||
* 友情链接类
|
||||
* @author molong <molong@tensent.cn>
|
||||
*/
|
||||
class Link extends \app\common\model\Base {
|
||||
class Link extends \think\Model {
|
||||
|
||||
public $keyList = array(
|
||||
array('name' => 'id', 'title' => 'ID', 'type' => 'hidden'),
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace app\model;
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Module {
|
||||
class Model extends \think\Model{
|
||||
|
||||
protected $auto = ['update_time'];
|
||||
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid' => "id:ID\r\ntitle:标题\r\ncreate_time:添加时间|time_format\r\nupdate_time:更新时间|time_format"];
|
||||
@@ -22,57 +22,57 @@ class Module {
|
||||
'update_time' => 'integer',
|
||||
);
|
||||
|
||||
protected static function init() {
|
||||
self::beforeInsert(function ($event) {
|
||||
$data = $event->toArray();
|
||||
$tablename = strtolower($data['name']);
|
||||
//实例化一个数据库操作类
|
||||
$db = new \com\Datatable();
|
||||
//检查表是否存在并创建
|
||||
if (!$db->CheckTable($tablename)) {
|
||||
//创建新表
|
||||
return $db->initTable($tablename, $data['title'], 'id')->query();
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
self::afterInsert(function ($event) {
|
||||
$data = $event->toArray();
|
||||
// protected static function init() {
|
||||
// self::beforeInsert(function ($event) {
|
||||
// $data = $event->toArray();
|
||||
// $tablename = strtolower($data['name']);
|
||||
// //实例化一个数据库操作类
|
||||
// $db = new \com\Datatable();
|
||||
// //检查表是否存在并创建
|
||||
// if (!$db->CheckTable($tablename)) {
|
||||
// //创建新表
|
||||
// return $db->initTable($tablename, $data['title'], 'id')->query();
|
||||
// } else {
|
||||
// return false;
|
||||
// }
|
||||
// });
|
||||
// self::afterInsert(function ($event) {
|
||||
// $data = $event->toArray();
|
||||
|
||||
$fields = include (APP_PATH . 'admin/fields.php');
|
||||
if (!empty($fields)) {
|
||||
foreach ($fields as $key => $value) {
|
||||
if ($data['is_doc']) {
|
||||
$fields[$key]['model_id'] = $data['id'];
|
||||
} else {
|
||||
if (in_array($key, array('uid', 'status', 'view', 'create_time', 'update_time'))) {
|
||||
$fields[$key]['model_id'] = $data['id'];
|
||||
} else {
|
||||
unset($fields[$key]);
|
||||
}
|
||||
}
|
||||
}
|
||||
model('Attribute')->saveAll($fields);
|
||||
}
|
||||
return true;
|
||||
});
|
||||
self::beforeUpdate(function ($event) {
|
||||
$data = $event->toArray();
|
||||
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
$attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
// $fields = include (APP_PATH . 'admin/fields.php');
|
||||
// if (!empty($fields)) {
|
||||
// foreach ($fields as $key => $value) {
|
||||
// if ($data['is_doc']) {
|
||||
// $fields[$key]['model_id'] = $data['id'];
|
||||
// } else {
|
||||
// if (in_array($key, array('uid', 'status', 'view', 'create_time', 'update_time'))) {
|
||||
// $fields[$key]['model_id'] = $data['id'];
|
||||
// } else {
|
||||
// unset($fields[$key]);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// model('Attribute')->saveAll($fields);
|
||||
// }
|
||||
// return true;
|
||||
// });
|
||||
// self::beforeUpdate(function ($event) {
|
||||
// $data = $event->toArray();
|
||||
// if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
// $attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
|
||||
if (!empty($attribute_sort)) {
|
||||
foreach ($attribute_sort as $key => $value) {
|
||||
db('Attribute')->where('id', 'IN', $value)->setField('group_id', $key);
|
||||
foreach ($value as $k => $v) {
|
||||
db('Attribute')->where('id', $v)->setField('sort', $k);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
// if (!empty($attribute_sort)) {
|
||||
// foreach ($attribute_sort as $key => $value) {
|
||||
// db('Attribute')->where('id', 'IN', $value)->setField('group_id', $key);
|
||||
// foreach ($value as $k => $v) {
|
||||
// db('Attribute')->where('id', $v)->setField('sort', $k);
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return true;
|
||||
// });
|
||||
// }
|
||||
|
||||
protected function setAttributeSortAttr($value) {
|
||||
return $value ? json_encode($value) : '';
|
||||
Reference in New Issue
Block a user