更新内核

This commit is contained in:
2016-11-18 11:14:26 +08:00
parent 9074eb1d89
commit 860da138c9
36 changed files with 754 additions and 330 deletions

View File

@@ -66,13 +66,13 @@ class InitHook {
$route[$value['name'] . "/index"] = "index/content/index?model=" . $value['name'];
$route[$value['name'] . "/list/:id"] = "index/content/lists?model=" . $value['name'];
$route[$value['name'] . "/detail/:id"] = "index/content/detail?model_id=" . $value['id'];
$route["/list/:id"] = "index/content/category";
$route["user/" . $value['name'] . "/index"] = "user/content/index?model_id=" . $value['id'];
$route["user/" . $value['name'] . "/add"] = "user/content/add?model_id=" . $value['id'];
$route["user/" . $value['name'] . "/edit"] = "user/content/edit?model_id=" . $value['id'];
$route["user/" . $value['name'] . "/del"] = "user/content/del?model_id=" . $value['id'];
$route["user/" . $value['name'] . "/status"] = "user/content/status?model_id=" . $value['id'];
}
$route["list/:id"] = "index/content/category";
\think\Route::rule($route);
}
}

View File

@@ -148,7 +148,7 @@ class Admin extends Base {
$pid = db('menu')->where("pid !=0 AND url like '%{$hover_url}%'")->value('pid');
$id = db('menu')->where("pid = 0 AND url like '%{$hover_url}%'")->value('id');
$pid = $pid ? $pid : $id;
if ($hover_url == 'admin/content' || $hover_url == 'admin/attribute') {
if (strtolower($hover_url) == 'admin/content' || strtolower($hover_url) == 'admin/attribute') {
//内容管理菜单
$pid = db('menu')->where("pid =0 AND url like '%admin/category%'")->value('id');
}

View File

@@ -14,11 +14,17 @@ namespace app\common\model;
*/
class Base extends \think\Model{
protected $param;
protected $type = array(
'id' => 'integer',
'cover_id' => 'integer',
);
public function initialize(){
parent::initialize();
$this->param = \think\Request::instance()->param();
}
/**
* 数据修改
* @return [bool] [是否成功]

View File

@@ -14,11 +14,11 @@ namespace app\common\model;
*/
class Content extends Base{
//protected $name = "page";
protected $dao;
protected $auto = array("update_time");
protected $insert = array("create_time");
protected $type = array(
'id' => 'integer',
'cover_id' => 'integer',
@@ -37,27 +37,59 @@ class Content extends Base{
}
public function extend($name){
$this->name = $name;
$this->dao = db($name);
return $this;
}
public function detail($id){
public function lists($map, $order){
$list = $this->dao->where($map)->order($order)->paginate(15, false, array(
'query' => $this->param,
));
return $list;
}
public function detail($id, $map = array()){
$map['id'] = $id;
$this->data = $this->db()->where($map)->find();
$this->data = $this->dao->where($map)->find();
return $this->data;
}
public function del($map){
return $this->dao->where($map)->delete();
}
public function change(){
$data = input('post.');
if ($data['id']) {
$result = $this->save($data,array('id'=>$data['id']));
$data = $this->param;
if (isset($data['id']) && $data['id']) {
$where['id'] = $data['id'];
}
if (!empty($data)) {
// 数据自动验证
if (!$this->validateData($data)) {
return false;
}
// 数据对象赋值
foreach ($data as $key => $value) {
$this->setAttr($key, $value, $data);
}
if (!empty($where)) {
$this->isUpdate = true;
}
}
// 数据自动完成
$this->autoCompleteData($this->auto);
// 自动写入更新时间
if ($this->autoWriteTimestamp && $this->updateTime) {
$this->setAttr($this->updateTime, null);
}
if ($this->isUpdate) {
$result = $this->dao->update($this->data, $where);
}else{
$result = $this->save($data);
$result = $this->dao->insert($this->data);
}
return $result;
}
public function del($map){
return $this->where($map)->delete();
}
}

View File

@@ -12,7 +12,7 @@ namespace app\common\model;
/**
* 设置模型
*/
class Document extends \think\Model{
class Document extends Base{
protected $fk = 'doc_id';
protected $pk = 'id';
@@ -72,9 +72,18 @@ class Document extends \think\Model{
public function extend($name){
$name = strtoupper($name);
$this->join('__DOCUMENT_' . $name . '__', $this->fk . '=' . $this->pk, 'LEFT');
$this->dao = $this->db()->alias('d')
->join('__DOCUMENT_' . $name . '__ dc', 'dc.' . $this->fk . '= d.' . $this->pk, 'RIGHT');
return $this;
}
public function lists($map, $order){
$list = $this->dao->where($map)->order($order)->paginate(15, false, array(
'query' => $this->param,
));
return $list;
}
public function change(){
/* 获取数据对象 */
$data = \think\Request::instance()->post();