更新代码,完善功能

This commit is contained in:
2020-02-18 14:50:57 +08:00
parent 31fd944b9c
commit 8bc0f7534b
36 changed files with 283 additions and 280 deletions

17
app/model/Addons.php Normal file
View 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 {
}

View File

@@ -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');

View File

@@ -12,7 +12,7 @@ namespace app\model;
/**
* 设置模型
*/
class Channel {
class Channel extends \think\Model {
protected $type = array(
'id' => 'integer',

View File

@@ -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');

View File

@@ -79,4 +79,11 @@ class Config extends Model {
}
return $data;
}
public function getThemesList(){
return [
'pc' => [],
'mobile' => []
];
}
}

17
app/model/Hooks.php Normal file
View 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 {
}

View File

@@ -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'),

View File

@@ -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) : '';