初始化文档模型的栏目选择为树形
This commit is contained in:
@@ -12,43 +12,43 @@ namespace app\model;
|
||||
/**
|
||||
* 设置模型
|
||||
*/
|
||||
class Model extends \think\Model{
|
||||
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:添加时间\r\nupdate_time:更新时间"];
|
||||
protected $type = array(
|
||||
'id' => 'integer'
|
||||
'id' => 'integer',
|
||||
);
|
||||
|
||||
protected static function onBeforeInsert($data){
|
||||
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{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}else{
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected static function onAfterInsert($data){
|
||||
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'],
|
||||
'uid' => ['name' => 'uid', 'title' => '用户UID', 'type' => 'num', 'length' => 11, 'extra' => '', 'remark' => '用户UID', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'],
|
||||
'cover_id' => ['name' => 'cover_id', 'title' => '内容封面', 'type' => 'image', 'length' => 10, 'extra' => '', 'remark' => '内容封面', 'is_show' => 1, 'is_must' => 0, 'value'=>''],
|
||||
'description' => ['name' => 'description', 'title' => '内容描述', 'type' => 'textarea', 'length' => '', 'extra' => '', 'remark' => '内容描述', 'is_show' => 1, 'is_must' => 0, 'value'=>''],
|
||||
'content' => ['name' => 'content', 'title' => '内容', 'type' => 'editor', 'length' => '', 'extra' => '', 'remark' => '内容', 'is_show' => 1, 'is_must' => 0, 'value'=>''],
|
||||
'status' => ['name' => 'status', 'title' => '数据状态', 'type' => 'select', 'length' => 2, 'extra' => "-1:删除\r\n0:禁用\r\n1:正常\r\n2:待审核\r\n3:草稿", 'remark' => '数据状态', 'is_show' => 1, 'is_must' => 1, 'value'=>'1'],
|
||||
'is_top' => ['name' => 'is_top', 'title' => '是否置顶', 'type' => 'bool', 'length' => 2, 'extra' => '', 'remark' => '是否置顶', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'],
|
||||
'view' => ['name' => 'view', 'title' => '浏览数量', 'type' => 'num', 'length' => 11, 'extra' => '', 'remark' => '浏览数量', 'is_show' => 0, 'is_must' => 1, 'value'=>'0'],
|
||||
'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'],
|
||||
'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:tree', 'remark' => '栏目', 'is_show' => 1, 'is_must' => 1, 'value' => '0'],
|
||||
'uid' => ['name' => 'uid', 'title' => '用户UID', 'type' => 'num', 'length' => 11, 'extra' => '', 'remark' => '用户UID', 'is_show' => 0, 'is_must' => 1, 'value' => '0'],
|
||||
'cover_id' => ['name' => 'cover_id', 'title' => '内容封面', 'type' => 'image', 'length' => 10, 'extra' => '', 'remark' => '内容封面', 'is_show' => 1, 'is_must' => 0, 'value' => ''],
|
||||
'description' => ['name' => 'description', 'title' => '内容描述', 'type' => 'textarea', 'length' => '', 'extra' => '', 'remark' => '内容描述', 'is_show' => 1, 'is_must' => 0, 'value' => ''],
|
||||
'content' => ['name' => 'content', 'title' => '内容', 'type' => 'editor', 'length' => '', 'extra' => '', 'remark' => '内容', 'is_show' => 1, 'is_must' => 0, 'value' => ''],
|
||||
'status' => ['name' => 'status', 'title' => '数据状态', 'type' => 'select', 'length' => 2, 'extra' => "-1:删除\r\n0:禁用\r\n1:正常\r\n2:待审核\r\n3:草稿", 'remark' => '数据状态', 'is_show' => 1, 'is_must' => 1, 'value' => '1'],
|
||||
'is_top' => ['name' => 'is_top', 'title' => '是否置顶', 'type' => 'bool', 'length' => 2, 'extra' => '', 'remark' => '是否置顶', 'is_show' => 0, 'is_must' => 1, 'value' => '0'],
|
||||
'view' => ['name' => 'view', 'title' => '浏览数量', 'type' => 'num', 'length' => 11, 'extra' => '', 'remark' => '浏览数量', 'is_show' => 0, 'is_must' => 1, 'value' => '0'],
|
||||
'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)) {
|
||||
@@ -56,7 +56,7 @@ class Model extends \think\Model{
|
||||
if ($data['is_doc']) {
|
||||
$fields[$key]['model_id'] = $data['id'];
|
||||
} else {
|
||||
if (in_array($key, array('uid', 'status', 'view', 'create_time', 'update_time'))) {
|
||||
if (in_array($key, ['uid', 'title', 'status', 'view', 'create_time', 'update_time'])) {
|
||||
$fields[$key]['model_id'] = $data['id'];
|
||||
} else {
|
||||
unset($fields[$key]);
|
||||
@@ -68,7 +68,7 @@ class Model extends \think\Model{
|
||||
return $result;
|
||||
}
|
||||
|
||||
protected static function onAfterUpdate($data){
|
||||
protected static function onAfterUpdate($data) {
|
||||
$data = $data->toArray();
|
||||
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||
$attribute_sort = json_decode($data['attribute_sort'], true);
|
||||
@@ -84,8 +84,8 @@ class Model extends \think\Model{
|
||||
}
|
||||
}
|
||||
$save = [];
|
||||
foreach($attr as $value){
|
||||
if(!empty($value)){
|
||||
foreach ($attr as $value) {
|
||||
if (!empty($value)) {
|
||||
$save = array_merge($save, $value);
|
||||
}
|
||||
}
|
||||
@@ -96,7 +96,7 @@ class Model extends \think\Model{
|
||||
return true;
|
||||
}
|
||||
|
||||
protected static function onAfterDelete($data){
|
||||
protected static function onAfterDelete($data) {
|
||||
$data = $data->toArray();
|
||||
(new Attribute())->where('model_id', $data['id'])->delete();
|
||||
$db = new \com\Datatable();
|
||||
@@ -113,7 +113,7 @@ class Model extends \think\Model{
|
||||
return strtolower($value);
|
||||
}
|
||||
|
||||
public function getGridListAttr($value, $data){
|
||||
public function getGridListAttr($value, $data) {
|
||||
$list = [];
|
||||
if ($data['list_grid'] !== '') {
|
||||
$row = explode(PHP_EOL, $data['list_grid']);
|
||||
@@ -129,7 +129,7 @@ class Model extends \think\Model{
|
||||
return $list;
|
||||
}
|
||||
|
||||
public function getAttrGroupAttr($value, $data){
|
||||
public function getAttrGroupAttr($value, $data) {
|
||||
$list = [];
|
||||
if ($data['attribute_group']) {
|
||||
$row = explode(";", $data['attribute_group']);
|
||||
|
||||
Reference in New Issue
Block a user