模型功能完善
This commit is contained in:
@@ -139,7 +139,7 @@ class Content extends Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$map['id'] = array('IN', $id);
|
$map['id'] = array('IN', $id);
|
||||||
$result = $this->model->del($map);
|
$result = $this->model->where($map)->delete();
|
||||||
|
|
||||||
if (false !== $result) {
|
if (false !== $result) {
|
||||||
return $this->success("删除成功!");
|
return $this->success("删除成功!");
|
||||||
@@ -202,6 +202,8 @@ class Content extends Admin {
|
|||||||
foreach ($rows as $key => $value) {
|
foreach ($rows as $key => $value) {
|
||||||
$fields[$field_group[$value['group_id']]][] = $value;
|
$fields[$field_group[$value['group_id']]][] = $value;
|
||||||
}
|
}
|
||||||
|
}else{
|
||||||
|
$fields = array();
|
||||||
}
|
}
|
||||||
return $fields;
|
return $fields;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -138,9 +138,6 @@ class Model extends Admin {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$model = $this->model->where($map)->find();
|
$model = $this->model->where($map)->find();
|
||||||
if ($model['table_status'] != 1 && $data['status'] == 1) {
|
|
||||||
return $this->error('数据表未创建或更新');
|
|
||||||
}
|
|
||||||
if ($model['list_grid'] == '' && $data['status'] == 1) {
|
if ($model['list_grid'] == '' && $data['status'] == 1) {
|
||||||
return $this->error('模型列表未定义');
|
return $this->error('模型列表未定义');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -54,7 +54,7 @@
|
|||||||
{/volist}
|
{/volist}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{else/}
|
{elseif isset($keyList) /}
|
||||||
{volist name="keyList" id="field"}
|
{volist name="keyList" id="field"}
|
||||||
{if $field['type'] eq 'hidden'}
|
{if $field['type'] eq 'hidden'}
|
||||||
<input type="hidden" name="{$field['name']}" value="{$info[$field['name']]|default=''}"/>
|
<input type="hidden" name="{$field['name']}" value="{$info[$field['name']]|default=''}"/>
|
||||||
|
|||||||
@@ -165,15 +165,4 @@ class Attribute extends Base{
|
|||||||
$result = $db->create();
|
$result = $db->create();
|
||||||
return $result;
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function generate($model){
|
|
||||||
$tablename = strtolower($model['name']);
|
|
||||||
//实例化一个数据库操作类
|
|
||||||
$db = new \com\Datatable();
|
|
||||||
//检查表是否存在并创建
|
|
||||||
if (!$db->CheckTable($tablename)) {
|
|
||||||
//创建新表
|
|
||||||
return $db->initTable($tablename, $model['title'], 'id')->query();
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -15,7 +15,7 @@ namespace app\common\model;
|
|||||||
class Model extends Base {
|
class Model extends Base {
|
||||||
|
|
||||||
protected $auto = ['update_time'];
|
protected $auto = ['update_time'];
|
||||||
protected $insert = ['name', 'create_time', 'status' => 0];
|
protected $insert = ['name', 'create_time', 'status' => 1, 'list_grid'=>'id:ID'];
|
||||||
protected $type = array(
|
protected $type = array(
|
||||||
'id' => 'integer',
|
'id' => 'integer',
|
||||||
'create_time' => 'integer',
|
'create_time' => 'integer',
|
||||||
@@ -23,14 +23,28 @@ class Model extends Base {
|
|||||||
);
|
);
|
||||||
|
|
||||||
protected static function init(){
|
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();
|
||||||
|
};
|
||||||
|
});
|
||||||
self::beforeUpdate(function($event){
|
self::beforeUpdate(function($event){
|
||||||
$data = $event->toArray();
|
$data = $event->toArray();
|
||||||
$attribute_sort = json_decode($data['attribute_sort'], true);
|
if (isset($data['attribute_sort']) && $data['attribute_sort']) {
|
||||||
if (!empty($attribute_sort)) {
|
$attribute_sort = json_decode($data['attribute_sort'], true);
|
||||||
foreach ($attribute_sort as $key => $value) {
|
|
||||||
db('Attribute')->where('id', 'IN', $value)->setField('group_id', $key);
|
if (!empty($attribute_sort)) {
|
||||||
foreach ($value as $k => $v) {
|
foreach ($attribute_sort as $key => $value) {
|
||||||
db('Attribute')->where('id', $v)->setField('sort', $k);
|
db('Attribute')->where('id', 'IN', $value)->setField('group_id', $key);
|
||||||
|
foreach ($value as $k => $v) {
|
||||||
|
db('Attribute')->where('id', $v)->setField('sort', $k);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,42 +94,4 @@ class Model extends Base {
|
|||||||
public function attribute() {
|
public function attribute() {
|
||||||
return $this->hasMany('Attribute');
|
return $this->hasMany('Attribute');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* 解析字段
|
|
||||||
* @param [array] $model [字段]
|
|
||||||
* @return [array] [解析后的字段]
|
|
||||||
*/
|
|
||||||
public function preFields($model) {
|
|
||||||
$fields = $model->attribute;
|
|
||||||
$groups = parse_config_attr($model['field_group']);
|
|
||||||
$field_sort = json_decode($model['field_sort'], true);
|
|
||||||
|
|
||||||
//获得数组的第一条数组
|
|
||||||
$first_key = array_keys($groups);
|
|
||||||
if (!empty($field_sort)) {
|
|
||||||
foreach ($field_sort as $key => $value) {
|
|
||||||
foreach ($value as $index) {
|
|
||||||
if (isset($fields[$index])) {
|
|
||||||
$groupfield[$key][] = $fields[$index];
|
|
||||||
unset($fields[$index]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
//未进行排序的放入第一组中
|
|
||||||
$fields[] = array('name' => 'model_id', 'type' => 'hidden'); //加入模型ID值
|
|
||||||
$fields[] = array('name' => 'id', 'type' => 'hidden'); //加入模型ID值
|
|
||||||
foreach ($fields as $key => $value) {
|
|
||||||
$groupfield[$first_key[0]][] = $value;
|
|
||||||
}
|
|
||||||
|
|
||||||
foreach ($groups as $key => $value) {
|
|
||||||
if ($groupfield[$key]) {
|
|
||||||
$data[$value] = $groupfield[$key];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return $data;
|
|
||||||
return array();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user