内容模型功能完成

This commit is contained in:
2020-04-01 22:20:11 +08:00
parent 85d33da0d4
commit 9dafceb2eb
32 changed files with 415 additions and 339 deletions

View File

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