rabin 5 سال پیش
والد
کامیت
fd9fe9523d
4فایلهای تغییر یافته به همراه86 افزوده شده و 1 حذف شده
  1. 15 0
      database/attr.php
  2. 29 1
      database/info.php
  3. 32 0
      lib/Manage.php
  4. 10 0
      src/Api.php

+ 15 - 0
database/attr.php

@@ -92,4 +92,19 @@ return array
 		//'edit' => false,
 		//'insert' => false,
 	),
+
+	'request' => array
+	(
+		'getAttr' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'category' => array('yes', 'like'),
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => 'attr,attr_input',
+		),
+	)
 );

+ 29 - 1
database/info.php

@@ -20,6 +20,12 @@ return array
 	# 是否显示在后台菜单
 	'order' => 10,
 
+	'end' => array
+	(
+		'insert' => 'category/lib/manage.update',
+		'update' => 'category/lib/manage.update',
+	),
+
 	# 数据结构
 	'struct' => array
 	(
@@ -51,12 +57,31 @@ return array
 		(
 			'type' 		=> 'int-11',
 			'name' 		=> '上级分类',
-			'default' 	=> Dever::input('option_info_id', -1),
+			'default' 	=> -1,
 			'desc' 		=> '请选择上级分类',
 			'match' 	=> 'is_numeric',
+			'value'		=> Dever::input('option_info_id', -1),
 			'list'		=> '{info_id} > 0 ? Dever::load("category/info-one#name", {info_id}) : "父级分类"',
 		),
 
+		'top_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '顶级分类',
+			'default' 	=> -1,
+			'desc' 		=> '请选择顶级分类',
+			'match' 	=> 'is_numeric',
+		),
+
+		'level'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分类级别-1为顶级分类、2为2级分类,-1为最后一级分类',
+			'default' 	=> 1,
+			'desc' 		=> '分类级别',
+			'match' 	=> 'is_numeric',
+		),
+
 		'info'		=> array
 		(
 			'type' 		=> 'varchar-800',
@@ -138,7 +163,10 @@ return array
 			(
 				'column_id' => 'yes',
 				'info_id' => 'yes',
+				'top_id' => 'yes',
+				'level' => 'yes',
 				'id' => array('yes', '!='),
+				'info' => array('yes', 'like'),
 				'state' => 1,
 			),
 			'type' => 'all',

+ 32 - 0
lib/Manage.php

@@ -0,0 +1,32 @@
+<?php
+
+namespace Category\Lib;
+
+use Dever;
+
+class Manage
+{
+    public function update($id, $name, $data)
+    {
+        $info = Dever::param('info', $data);
+        if ($info && $info != -1) {
+            $update['top_id'] = $info[0];
+            $num = count($info)+1;
+            $update['level'] = $num;
+            $parent = Dever::param('info_id', $data);
+            $child = Dever::db('category/info')->one(array('info_id' => $id));
+            if (!$child) {
+                $update['level'] = -1;
+            }
+            Dever::db('category/info')->update(array('where_id' => $parent, 'level' => $num - 1));
+        } else {
+            $update['level'] = 1;
+            $update['top_id'] = -1;
+        }
+
+        if (isset($update)) {
+            $update['where_id'] = $id;
+            Dever::db('category/info')->update($update);
+        }
+    }
+}

+ 10 - 0
src/Api.php

@@ -153,4 +153,14 @@ class Api
         }
         return $name;
     }
+
+    # 根据顶级分类获取最低级的分类
+    public function getChild($top_id, $level = -1)
+    {
+        $where['top_id'] = $top_id;
+        $where['level'] = $level;
+        $data = Dever::db('category/info')->getList($where);
+
+        return $data;
+    }
 }