rabin 5 years ago
parent
commit
90ec210503
5 changed files with 355 additions and 5 deletions
  1. 75 0
      database/cate.php
  2. 58 5
      database/file.php
  3. 69 0
      database/file_tag.php
  4. 96 0
      database/tag.php
  5. 57 0
      src/Manage.php

+ 75 - 0
database/cate.php

@@ -0,0 +1,75 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'cate',
+    # 显示给用户看的名称
+    'lang' => '分类管理',
+    'order' => 1,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'        => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '分类名称',
+            'default'   => '',
+            'desc'      => '分类名称',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '创建时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'  => 'date',
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        //'excel'   => true,
+        //'delete' => false,
+        //'edit' => false,
+        //'insert' => false,
+    ),
+
+    # 默认值
+    'default' => array
+    (
+        'col' => 'name,state,cdate',
+        'value' => array
+        (
+            '"默认分类",1,' . time(),
+        ),
+    ),
+);

+ 58 - 5
database/file.php

@@ -11,6 +11,10 @@ $option = array
 	1 => '启用',
 	2 => '关闭',
 );
+$cate = function()
+{
+	return Dever::db('upload/cate')->state();
+};
 
 return array
 (
@@ -19,6 +23,26 @@ return array
 	# 显示给用户看的名称
 	'lang' => '文件管理',
 	'order' => 9,
+	'end' => array
+	(
+		//'insert' => 'upload/manage.add_tag',
+		//'update' => 'upload/manage.add_tag',
+	),
+
+	/*
+	# 同步更新另外一个或多个表的数据
+	'sync' => array
+	(
+		'upload/file_tag' => array
+		(
+			# 更新另外一个表的字段 => 本表的字段
+			'where' => array('file_id', 'id'),
+			# 要更新的数据
+			'update' => array('tag_id' => 'tag'),
+			# 同步更新的类型,delete为先删再插入,update为先查询是否存在,存在直接更新,不存在则插入, only为仅更新
+			'type' => 'delete',
+		)
+	),*/
 	# 数据结构
 	'struct' => array
 	(
@@ -55,6 +79,34 @@ return array
 			'list'		=> true,
 		),
 
+		'cate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属分类',
+			'default' 	=> '1',
+			'desc' 		=> '分类',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $cate,
+			'update'	=> 'select',
+			'search'	=> 'select',
+			//'control'	=> 'type',
+			//'list'		=> true,
+		),
+
+		'tag'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '标签',
+			'default' 	=> '',
+			'desc' 		=> '标签',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'autocomplete' => array('upload/manage.search_tag?json=1', 'id', 'upload/manage.search_tag_by_ids'),
+			//'control'	=> 'type',
+			//'list'		=> true,
+		),
+
 		'key'		=> array
 		(
 			'type' 		=> 'varchar-32',
@@ -73,7 +125,8 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '请输入后缀名',
 			'match' 	=> 'is_string',
-			'list'		=> true,
+			'list_name'	=> '文件信息',
+			'list'		=> 'Dever::load("upload/manage.file", {id})',
 		),
 		
 		'file'		=> array
@@ -83,7 +136,7 @@ return array
 			'default' 	=> '',
 			'desc' 		=> '请输入访问路径',
 			'match' 	=> 'is_string',
-			'list'		=> true,
+			//'list'		=> true,
 		),
 		
 		'width'		=> array
@@ -93,7 +146,7 @@ return array
 			'default' 	=> '0',
 			'desc' 		=> '请输入宽度',
 			'match' 	=> 'option',
-			'list'		=> true,
+			//'list'		=> true,
 		),
 		
 		'height'		=> array
@@ -103,7 +156,7 @@ return array
 			'default' 	=> '0',
 			'desc' 		=> '请输入高度',
 			'match' 	=> 'option',
-			'list'		=> true,
+			//'list'		=> true,
 		),
 		
 		'size'		=> array
@@ -113,7 +166,7 @@ return array
 			'default' 	=> '0',
 			'desc' 		=> '请输入大小',
 			'match' 	=> 'option',
-			'list'		=> true,
+			//'list'		=> true,
 		),
 		
 		'state'		=> array

+ 69 - 0
database/file_tag.php

@@ -0,0 +1,69 @@
+<?php
+/*
+|--------------------------------------------------------------------------
+| file_tag
+|--------------------------------------------------------------------------
+*/
+
+return array
+(
+    # 表名
+    'name' => 'file_tag',
+    # 显示给用户看的名称
+    'lang' => '文件标签关联表',
+    'menu' => false,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'list'      => true,
+        ),
+        
+        'file_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '文件id',
+            'default'   => '',
+            'desc'      => '文件id',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'tag_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '标签id',
+            'default'   => '',
+            'desc'      => '标签id',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '录入时间',
+            'match'     => array('is_numeric', DEVER_TIME),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    # request 请求接口定义
+    'request' => array
+    (
+        
+    )
+);

+ 96 - 0
database/tag.php

@@ -0,0 +1,96 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'tag',
+    # 显示给用户看的名称
+    'lang' => '标签管理',
+    'order' => 1,
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            //'list'        => true,
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-300',
+            'name'      => '名称',
+            'default'   => '',
+            'desc'      => '名称',
+            'match'     => 'option',
+            'update'    => 'text',
+            'list'      => true,
+        ),
+
+        'state'     => array
+        (
+            'type'      => 'tinyint-1',
+            'name'      => '状态',
+            'default'   => '1',
+            'desc'      => '请选择状态',
+            'match'     => 'is_numeric',
+        ),
+        
+        'cdate'     => array
+        (
+            'type'      => 'int-11',
+            'name'      => '创建时间',
+            'match'     => array('is_numeric', time()),
+            'desc'      => '',
+            # 只有insert时才生效
+            'insert'    => true,
+            //'search'  => 'date',
+            'list'      => 'date("Y-m-d H:i:s", {cdate})',
+        ),
+    ),
+
+    'manage' => array
+    (
+        //'excel'   => true,
+        //'delete' => false,
+        //'edit' => false,
+        //'insert' => false,
+    ),
+
+    'request' => array
+    (
+        'getDataByIds' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'id' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id' => 'desc'),
+            'col' => '*',
+        ),
+        'search' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'name' => array('yes', 'like'),
+                'id' => array('yes', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('id', 'desc'),
+            'col' => '*,name as value,name as label|id',//这里为了做autocomplete进行测试,必须输出value和label
+        ),
+    )
+
+);

+ 57 - 0
src/Manage.php

@@ -0,0 +1,57 @@
+<?php
+namespace Upload\Src;
+
+use Dever;
+
+class Manage
+{
+    public function search_tag()
+    {
+        $name = Dever::input('term');
+        $param['name'] = $name;
+
+        $data = Dever::db('upload/tag')->search($param);
+
+        if ($data) {
+            return $data;
+        } else {
+            return array
+            (
+                0 => array('id' => -1, 'value' => '没有找到您搜索的数据', 'label' => '没有找到您搜索的数据'),
+            );
+        }
+    }
+
+    public function search_tag_by_ids($id)
+    {
+        $data = Dever::db('upload/tag')->search($id);
+
+        return $data;
+    }
+
+    public function add_tag($id, $name, $data)
+    {
+        $tag = Dever::param('tag', $data);
+
+        if ($tag) {
+            $temp = explode(',', $tag);
+            foreach ($temp as $k => $v) {
+                $info = Dever::db('upload/tag')->one(array('name' => $v));
+                if (!$info) {
+                    Dever::db('upload/tag')->insert(array('name' => $v));
+                }
+            }
+        }
+    }
+
+    public function file($id)
+    {
+        $info = Dever::db('upload/file')->one($id);
+
+        $table = array();
+
+        $table['文件'] = $info['file'];
+
+        return Dever::table($table);
+    }
+}