rabin 2 years ago
parent
commit
a9692bda43
11 changed files with 1344 additions and 184 deletions
  1. 53 23
      database/category.php
  2. 61 115
      database/category_attr.php
  3. 144 0
      database/category_attr_search.php
  4. 153 0
      database/category_attr_value.php
  5. 67 23
      database/info.php
  6. 141 0
      database/info_attr.php
  7. 85 0
      database/unit.php
  8. 18 0
      lib/Manage.php
  9. 578 0
      src/Attr.php
  10. 20 23
      src/Category.php
  11. 24 0
      src/Unit.php

+ 53 - 23
database/category.php

@@ -11,7 +11,7 @@ return array
 	# 表名
 	# 表名
 	'name' => 'category',
 	'name' => 'category',
 	# 显示给用户看的名称
 	# 显示给用户看的名称
-	'lang' => '商品分类',
+	'lang' => '属性分类设置',
 	# 是否显示在后台菜单
 	# 是否显示在后台菜单
 	'order' => 10,
 	'order' => 10,
 
 
@@ -31,7 +31,6 @@ return array
 			'default' 	=> '',
 			'default' 	=> '',
 			'desc' 		=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
-			'order'		=> 'asc',
 			'list'		=> true,
 			'list'		=> true,
 		),
 		),
 
 
@@ -48,31 +47,33 @@ return array
 			'edit'		=> true,
 			'edit'		=> true,
 		),
 		),
 
 
-		'category'		=> array
+		'parent'		=> array
 		(
 		(
 			'type' 		=> 'varchar-800',
 			'type' 		=> 'varchar-800',
 			'name' 		=> '上级分类',
 			'name' 		=> '上级分类',
-			'default' 	=> Dever::input('option_category', -1),
+			'default' 	=> Dever::input('option_parent', -1),
 			'desc' 		=> '请选择上级分类',
 			'desc' 		=> '请选择上级分类',
 			'match' 	=> 'is_string',
 			'match' 	=> 'is_string',
 			'update'	=> 'linkage',
 			'update'	=> 'linkage',
 			'linkage' 	=> 'id=' . Dever::input('where_id'),
 			'linkage' 	=> 'id=' . Dever::input('where_id'),
 			'option'	=> Dever::url('category.get', 'product'),
 			'option'	=> Dever::url('category.get', 'product'),
-			//'list'		=> 'Dever::load("product/api.string", "{category}")',
+			//'list'		=> 'Dever::load("product/api.string", "{parent}")',
 		),
 		),
 
 
-		'category_id'		=> array
+		'parent_id'		=> array
 		(
 		(
 			'type' 		=> 'int-11',
 			'type' 		=> 'int-11',
 			'name' 		=> '上级分类',
 			'name' 		=> '上级分类',
 			'default' 	=> -1,
 			'default' 	=> -1,
 			'desc' 		=> '请选择上级分类',
 			'desc' 		=> '请选择上级分类',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
-			'value'		=> Dever::input('option_category_id', -1),
-			'list'		=> '{category_id} > 0 ? Dever::load("product/category-one#name", {category_id}) : "父级分类"',
+			'value'		=> Dever::input('option_parent_id', -1),
+			//'list'		=> '{parent_id} > 0 ? Dever::load("product/category-one#name", {parent_id}) : "父级分类"',
+			'list_name'	=> '属性',
+			'list'		=> 'Dever::load("product/attr.getInfoByCate", {id})',
 		),
 		),
 
 
-		'top_category_id'		=> array
+		'top_parent_id'		=> array
 		(
 		(
 			'type' 		=> 'int-11',
 			'type' 		=> 'int-11',
 			'name' 		=> '顶级分类',
 			'name' 		=> '顶级分类',
@@ -81,6 +82,19 @@ return array
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 		),
 		),
 
 
+		/*
+		'product-category_attr'=> array
+		(
+			'name' 		=> '属性设置',
+			'default' 	=> '',
+			'desc' 		=> '请先选择属性分类',
+			'match' 	=> 'option',
+			# 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
+			'sync'		=> array('id', 'category_id'),
+			# 根据category字段的值,获取product/attr.search接口的内容
+			'update'	=> array(1),
+		),*/
+
 		'level'		=> array
 		'level'		=> array
 		(
 		(
 			'type' 		=> 'int-11',
 			'type' 		=> 'int-11',
@@ -90,6 +104,20 @@ return array
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 		),
 		),
 
 
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '分类标识-该标识一般为前台样式名称,选填项',
+			'default' 	=> '',
+			'desc' 		=> '标识',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+			//'edit'		=> true,
+			'tab'		=> 1,
+		),
+
 		'icon'		=> array
 		'icon'		=> array
 		(
 		(
 			'type' 		=> 'varchar-150',
 			'type' 		=> 'varchar-150',
@@ -187,13 +215,15 @@ return array
 
 
 	'manage' => array
 	'manage' => array
 	(
 	(
-		'lang' => 'name',
-		//'tab' => array('基础设置', '前端样式'),
+		//'lang' => 'name',
+		'tab' => array('基础设置', '前端样式'),
 		# 列表页的类型
 		# 列表页的类型
 		'list_type' => 'tree',
 		'list_type' => 'tree',
 		'list_button' => array
 		'list_button' => array
 		(
 		(
-			'add' => array('新增子分类', '"{category}" == -1 ? "category&option_category={id}" : "category&option_category={category},{id}"'),
+			'add' => array('新增子分类', '"{parent}" == -1 ? "category&option_parent={id}" : "category&option_parent={parent},{id}"'),
+
+			'list' => array('属性设置', '"category_attr&search_option_category_id={id}&oper_table=category"'),
 		),
 		),
 	),
 	),
 
 
@@ -206,7 +236,7 @@ return array
 			'option' => array
 			'option' => array
 			(
 			(
 				'ids' => array('yes-id', 'in'),
 				'ids' => array('yes-id', 'in'),
-				'category_id' => -1,
+				'parent_id' => -1,
 				'state' => 1,
 				'state' => 1,
 			),
 			),
 			'type' => 'all',
 			'type' => 'all',
@@ -219,17 +249,17 @@ return array
 			# 匹配的正则或函数 选填项
 			# 匹配的正则或函数 选填项
 			'option' => array
 			'option' => array
 			(
 			(
-				'category_id' => 'yes',
-				'top_category_id' => 'yes',
+				'parent_id' => 'yes',
+				'top_parent_id' => 'yes',
 				'level' => 'yes',
 				'level' => 'yes',
-				'category_id_in' => array('yes-category_id', 'in'),
+				'parent_id_in' => array('yes-parent_id', 'in'),
 				'id' => array('yes', '!='),
 				'id' => array('yes', '!='),
-				'category' => array('yes', 'like'),
+				'parent' => array('yes', 'like'),
 				'state' => 1,
 				'state' => 1,
 			),
 			),
 			'type' => 'all',
 			'type' => 'all',
 			'order' => array('reorder' => 'desc', 'id' => 'asc'),
 			'order' => array('reorder' => 'desc', 'id' => 'asc'),
-			'col' => '*|category_id|',
+			'col' => '*|parent_id|',
 		),
 		),
 
 
 		'getList' => array
 		'getList' => array
@@ -237,12 +267,12 @@ return array
 			# 匹配的正则或函数 选填项
 			# 匹配的正则或函数 选填项
 			'option' => array
 			'option' => array
 			(
 			(
-				'category_id' => 'yes',
-				'top_category_id' => 'yes',
+				'parent_id' => 'yes',
+				'top_parent_id' => 'yes',
 				'level' => 'yes',
 				'level' => 'yes',
-				'category_id_in' => array('yes-category_id', 'in'),
+				'parent_id_in' => array('yes-parent_id', 'in'),
 				'id' => array('yes', '!='),
 				'id' => array('yes', '!='),
-				'category' => array('yes', 'like'),
+				'parent' => array('yes', 'like'),
 				'state' => 1,
 				'state' => 1,
 			),
 			),
 			'type' => 'all',
 			'type' => 'all',
@@ -255,7 +285,7 @@ return array
 			# 匹配的正则或函数 选填项
 			# 匹配的正则或函数 选填项
 			'option' => array
 			'option' => array
 			(
 			(
-				'category_id' => 'yes',
+				'parent_id' => 'yes',
 				'id' => array('yes', '!='),
 				'id' => array('yes', '!='),
 				'state' => 1,
 				'state' => 1,
 			),
 			),

+ 61 - 115
database/category_attr.php

@@ -1,6 +1,6 @@
 <?php
 <?php
 
 
-$col = 'id,name,is_must,is_sell,sell_type,sell_compute,sell_value,`type`,data_type,`match`,`unit`,ename,icon,color,bgcolor,list_reorder,search_reorder,view_reorder,cate_id,state';
+$col = 'id,name,is_must,`type`,data_type,`match`,`unit`,ename,icon,color,bgcolor,list_reorder,search_reorder,view_reorder,cate_id,state';
 $type = array
 $type = array
 (
 (
 	1 => '数字输入框',
 	1 => '数字输入框',
@@ -24,26 +24,6 @@ $is_must = array
 	2 => '选填项',
 	2 => '选填项',
 );
 );
 
 
-$is_sell = array
-(
-	1 => '普通属性',
-	2 => '销售属性',
-);
-
-$sell_type = array
-(
-	1 => '组合',
-	2 => '单选',
-	3 => '输入',
-);
-
-$sell_compute = array
-(
-	1 => '相乘',
-	2 => '相加',
-	3 => '相减',
-);
-
 $data_type = array
 $data_type = array
 (
 (
 	1 => '数字',
 	1 => '数字',
@@ -93,12 +73,10 @@ return array
 	# 是否显示在后台菜单
 	# 是否显示在后台菜单
 	'order' => 10,
 	'order' => 10,
 	'menu'	=> false,
 	'menu'	=> false,
-	'sell_type' => $sell_type,
-	'sell_compute' => $sell_compute,
 	'end' => array
 	'end' => array
     (
     (
-        'insert' => 'product/lib/manage.attrUpdate',
-        'update' => 'product/lib/manage.attrUpdate',
+        'insert' => 'product/lib/manage.updateAttr',
+        'update' => 'product/lib/manage.updateAttr',
     ),
     ),
 
 
 	# 数据结构
 	# 数据结构
@@ -137,6 +115,7 @@ return array
 			'desc' 		=> '分类',
 			'desc' 		=> '分类',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'hidden',
 			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_category_id'),
 			//'list'		=> '{category_id} > 0 ? Dever::load("product/category-one#name", {category_id}) : "未选择"',
 			//'list'		=> '{category_id} > 0 ? Dever::load("product/category-one#name", {category_id}) : "未选择"',
 			'tab'		=> 0,
 			'tab'		=> 0,
 		),
 		),
@@ -155,72 +134,19 @@ return array
 			'tab'		=> 0,
 			'tab'		=> 0,
 		),
 		),
 
 
-		'is_sell'	  => array
-		(
-			'type' 		=> 'tinyint-1',
-			'name' 		=> '是否销售属性-销售属性将可以配置价格',
-			'default' 	=> '1',
-			'desc' 		=> '属性类型',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'radio',
-			'option'	=> $is_sell,
-			'search'	=> 'select',
-			'list'		=> true,
-			//'edit'		=> true,
-			'control'	=> 'is_sell',
-		),
-
-		'sell_type'	  => array
-		(
-			'type' 		=> 'tinyint-1',
-			'name' 		=> '销售属性类型-组合类型将会生成不同的SKU组合价格,根据不同的SKU组合生成总价和库存;单选类型将生成单独的属性价格,将影响总价,可单独设置库存;输入类型一般为输入尺寸,需要单独设置影响总价的方式;具体价格都需要在商品中设置',
-			'default' 	=> '1',
-			'desc' 		=> '销售属性类型',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'radio',
-			'option'	=> $sell_type,
-			//'search'	=> 'select',
-			'show'		=> 'is_sell=2',
-			'control'	=> 'sell_type',
-		),
-
-		'sell_compute'	  => array
-		(
-			'type' 		=> 'tinyint-1',
-			'name' 		=> '计算方式-如输入类型设置了宽度和高度,总价需要平米来计算,这里选择相乘即可',
-			'default' 	=> '1',
-			'desc' 		=> '销售属性类型',
-			'match' 	=> 'is_numeric',
-			'update'	=> 'radio',
-			'option'	=> $sell_compute,
-			//'search'	=> 'select',
-			'show'		=> 'sell_type=3',
-		),
-
-		'sell_value' => array
-		(
-			'type' 		=> 'varchar-50',
-			'name' 		=> '价格起始值-同样是平米为例,这里输入10的话,就是大于10平米时开始加价,具体加价多少需要在商品中设置',
-			'default' 	=> '0',
-			'desc' 		=> '价格起始值',
-			'match' 	=> 'is_string',
-			'update'	=> 'text',
-			'show'		=> 'sell_type=3',
-		),
-
 		'type'	  => array
 		'type'	  => array
 		(
 		(
 			'type' 		=> 'tinyint-11',
 			'type' 		=> 'tinyint-11',
-			'name' 		=> '后台录入类型-配置录入类型后可以在后台商品管理中的属性设置进行设置',
+			'name' 		=> '录入类型-配置录入类型后可以在商品录入时进行属性设置',
 			'default' 	=> '1',
 			'default' 	=> '1',
-			'desc' 		=> '后台录入类型',
+			'desc' 		=> '录入类型',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'radio',
 			'update'	=> 'radio',
 			'option'	=> $type,
 			'option'	=> $type,
 			//'search'	=> 'select',
 			//'search'	=> 'select',
 			//'list'		=> true,
 			//'list'		=> true,
-			'show'		=> 'is_sell=1',
 			'control'	=> 'type',
 			'control'	=> 'type',
+			'tab'		=> 0,
 		),
 		),
 
 
         'data_type'	  => array
         'data_type'	  => array
@@ -236,6 +162,7 @@ return array
 			//'list'		=> true,
 			//'list'		=> true,
 			'control' 	=> 'data_type',
 			'control' 	=> 'data_type',
 			'show'      => 'type=2',
 			'show'      => 'type=2',
+			'tab'		=> 0,
 		),
 		),
 
 
 		'match'		=> array
 		'match'		=> array
@@ -250,88 +177,80 @@ return array
 			//'list'		=> true,
 			//'list'		=> true,
 			//'edit'		=> true,
 			//'edit'		=> true,
 			'show'		=> array('data_type' => 3),
 			'show'		=> array('data_type' => 3),
-		),
-
-		'hr2'		=> array
-		(
-			'name' 		=> '排序规则',
-			'class'		=> '',//本项必须填写
-			'attr'		=> '',
+			'tab'		=> 0,
 		),
 		),
 
 
 		'list_reorder'	  => array
 		'list_reorder'	  => array
 		(
 		(
 			'type' 		=> 'int-11',
 			'type' 		=> 'int-11',
-			'name' 		=> '列表页排序-设置该属性在前台列表页中的排序,数字越大越靠前,如果为负数或者0,则不加入到列表页中。',
+			'name' 		=> '列表页排序-设置该属性在列表页中的排序,数字越大越靠前,如果为负数或者0,则不加入到列表页中。',
 			'default' 	=> '1',
 			'default' 	=> '1',
 			'desc' 		=> '是否作为搜索条件',
 			'desc' 		=> '是否作为搜索条件',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'text',
 			'update'	=> 'text',
 			'show'      => 'type=1,2,7,9,10,11,12',
 			'show'      => 'type=1,2,7,9,10,11,12',
-			'search'	=> 'order',
-			'order'		=> 'desc',
+			//'search'	=> 'order',
+			//'order'		=> 'desc',
 			'edit'		=> true,
 			'edit'		=> true,
 			//'list'		=> true,
 			//'list'		=> true,
+			'tab'		=> 2,
 		),
 		),
 
 
 		'search_reorder'	  => array
 		'search_reorder'	  => array
 		(
 		(
 			'type' 		=> 'int-11',
 			'type' 		=> 'int-11',
-			'name' 		=> '搜索条件排序-设置前台搜索条件中的排序,数字越大越靠前,如果为负数或者0,则不加入到搜索条件中。',
+			'name' 		=> '搜索条件排序-设置搜索条件中的排序,数字越大越靠前,如果为负数或者0,则不加入到搜索条件中。',
 			'default' 	=> '1',
 			'default' 	=> '1',
 			'desc' 		=> '是否作为搜索条件',
 			'desc' 		=> '是否作为搜索条件',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'text',
 			'update'	=> 'text',
 			'show'      => 'type=1,2,7,9,10,11,12',
 			'show'      => 'type=1,2,7,9,10,11,12',
-			'search'	=> 'order',
-			'order'		=> 'desc',
+			//'search'	=> 'order',
+			//'order'		=> 'desc',
 			'edit'		=> true,
 			'edit'		=> true,
 			//'list'		=> true,
 			//'list'		=> true,
+			'tab'		=> 2,
 		),
 		),
 
 
 		'view_reorder'	  => array
 		'view_reorder'	  => array
 		(
 		(
 			'type' 		=> 'int-11',
 			'type' 		=> 'int-11',
-			'name' 		=> '详情页排序-设置该属性在前台详情页中的排序,数字越大越靠前,如果为负数或者0,则不加入到详情页中。',
+			'name' 		=> '详情页排序-设置该属性在详情页中的排序,数字越大越靠前,如果为负数或者0,则不加入到详情页中。',
 			'default' 	=> '1',
 			'default' 	=> '1',
 			'desc' 		=> '详情页排序',
 			'desc' 		=> '详情页排序',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 			'update'	=> 'text',
 			'update'	=> 'text',
 			//'show'      => 'type=1,2,7,9,10,11,12',
 			//'show'      => 'type=1,2,7,9,10,11,12',
-			'search'	=> 'order',
-			'order'		=> 'desc',
+			//'search'	=> 'order',
+			//'order'		=> 'desc',
 			'edit'		=> true,
 			'edit'		=> true,
 			//'list'		=> true,
 			//'list'		=> true,
+			'tab'		=> 2,
 		),
 		),
 
 
-		'hr3'		=> array
-		(
-			'name' 		=> '扩展设置',
-			'class'		=> '',//本项必须填写
-			'attr'		=> '',
-		),
-
-		'unit'		=> array
+		'key'		=> array
 		(
 		(
 			'type' 		=> 'varchar-150',
 			'type' 		=> 'varchar-150',
-			'name' 		=> '单位-填写属性单位,选填项',
+			'name' 		=> '标识-该标识一般为前台样式名称,选填项',
 			'default' 	=> '',
 			'default' 	=> '',
-			'desc' 		=> '单位',
+			'desc' 		=> '标识',
 			'match' 	=> 'option',
 			'match' 	=> 'option',
 			'update'	=> 'text',
 			'update'	=> 'text',
+			//'search'	=> 'fulltext',
+			//'list'		=> true,
+			//'edit'		=> true,
+			'tab'		=> 1,
 		),
 		),
 
 
-		'ename'		=> array
+		'unit'		=> array
 		(
 		(
 			'type' 		=> 'varchar-150',
 			'type' 		=> 'varchar-150',
-			'name' 		=> '英文标识-该标识一般为前台样式名称,选填项',
+			'name' 		=> '单位-填写属性单位,选填项',
 			'default' 	=> '',
 			'default' 	=> '',
-			'desc' 		=> '英文名称',
+			'desc' 		=> '单位',
 			'match' 	=> 'option',
 			'match' 	=> 'option',
 			'update'	=> 'text',
 			'update'	=> 'text',
-			//'search'	=> 'fulltext',
-			//'list'		=> true,
-			//'edit'		=> true,
+			'tab'		=> 1,
 		),
 		),
 
 
 		'icon'		=> array
 		'icon'		=> array
@@ -343,6 +262,7 @@ return array
 			'match' 	=> 'option',
 			'match' 	=> 'option',
 			'update'	=> 'image',
 			'update'	=> 'image',
 			'key'		=> 1,
 			'key'		=> 1,
+			'tab'		=> 1,
 		),
 		),
 
 
 		'color'		=> array
 		'color'		=> array
@@ -353,6 +273,7 @@ return array
 			'desc' 		=> '字体颜色',
 			'desc' 		=> '字体颜色',
 			'match' 	=> 'option',
 			'match' 	=> 'option',
 			'update'	=> 'color',
 			'update'	=> 'color',
+			'tab'		=> 1,
 		),
 		),
 
 
 		'bgcolor'		=> array
 		'bgcolor'		=> array
@@ -363,6 +284,7 @@ return array
 			'desc' 		=> '背景颜色',
 			'desc' 		=> '背景颜色',
 			'match' 	=> 'option',
 			'match' 	=> 'option',
 			'update'	=> 'color',
 			'update'	=> 'color',
+			'tab'		=> 1,
 		),
 		),
 		
 		
 		'state'		=> array
 		'state'		=> array
@@ -389,12 +311,23 @@ return array
 
 
 	'manage' => array
 	'manage' => array
 	(
 	(
+		'lang' => 'name,unit',
 		'tab' => array('基本配置', '扩展设置', '排序规则'),
 		'tab' => array('基本配置', '扩展设置', '排序规则'),
+
+		'insert' => false,
+        'edit' => false,
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+
 		# 列表
 		# 列表
 		'list_button' => array
 		'list_button' => array
 		(
 		(
-			'list1' => array('属性值设置', '"value&project=attr&search_type=4&search_option_info_id={id}&oper_table=info&oper_project=attr"' , '{type} > 9'),
-			'list2' => array('搜索值设置', '"search&project=attr&search_type=4&search_option_info_id={id}&oper_table=info&oper_project=attr"' , '{type} == 1 || {type} == 9'),
+			'fast' => array('编辑'),
+
+			'list1' => array('属性值设置', '"category_attr_value&search_type=4&search_option_category_id={category_id}&search_option_attr_id={id}&oper_table=category_attr&top_table=category"' , '{type} > 9'),
+			'list2' => array('搜索值设置', '"category_attr_search&search_type=4&search_option_attr_id={id}&search_option_category_id={category_id}&oper_table=category_attr&top_table=category"' , '{type} == 1 || {type} == 9'),
 		),
 		),
 	),
 	),
 
 
@@ -468,6 +401,19 @@ return array
 			'col' => $col. '|id',
 			'col' => $col. '|id',
 		),
 		),
 
 
+		'getCateAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'category_id' => array('yes', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('list_reorder`+`search_reorder`+`view_reorder' => 'desc', 'id' => 'desc'),
+			'col' => '*',
+		),
+
 		/*
 		/*
 		'getSearch' => array
 		'getSearch' => array
 		(
 		(

+ 144 - 0
database/category_attr_search.php

@@ -0,0 +1,144 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'category_attr_search',
+    # 显示给用户看的名称
+    'lang' => '搜索值设置',
+    # 是否显示在后台菜单
+    'order' => 9,
+    'menu'  => false,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'list'      => true,
+        ),
+
+        'category_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分类',
+			'default' 	=> '-1',
+			'desc' 		=> '分类',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_category_id'),
+		),
+
+        'attr_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '属性id',
+            'default'   => '1',
+            'desc'      => '属性id',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_attr_id'),
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-1000',
+            'name'      => '搜索名称-如设置为100万以下',
+            'default'   => '',
+            'desc'      => '搜索名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'value'      => array
+        (
+            'type'      => 'varchar-1000',
+            'name'      => '搜索值-直接输入要搜索的值即可,也可以设置为公式,如{v}<=100,{v}为当前值,如果是区间输入框,则{s}为区间最小值,{e}为区间最大值',
+            'default'   => '',
+            'desc'      => '搜索值',
+            'match'     => 'is_string',
+            'update'    => 'textarea',
+            'search'    => 'fulltext',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'reorder'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '排序(数值越大越靠前)',
+            'default'   => '1',
+            'desc'      => '请输入排序',
+            'match'     => 'option',
+            //'update'    => 'text',
+            'search'    => 'order',
+            'list_name' => '排序',
+            'list'      => true,
+            'order'     => 'desc',
+            'edit'      => 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
+    (
+    	'lang' => 'name,value',
+
+        'insert' => false,
+        'edit' => false,
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+        # 列表
+        'list_button' => array
+        (
+            'fast' => array('编辑'),
+        ),
+    ),
+
+    'request' => array
+    (
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'info_id' => 'yes',
+                'ids' => array('yes-id', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => '*',
+        ),
+    )
+);

+ 153 - 0
database/category_attr_value.php

@@ -0,0 +1,153 @@
+<?php
+
+return array
+(
+    # 表名
+    'name' => 'category_attr_value',
+    # 显示给用户看的名称
+    'lang' => '属性值设置',
+    # 是否显示在后台菜单
+    'order' => 9,
+    'menu'  => false,
+
+    # 数据结构
+    'struct' => array
+    (
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'list'      => true,
+        ),
+
+        'category_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分类',
+			'default' 	=> '-1',
+			'desc' 		=> '分类',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'hidden',
+			'value'		=> Dever::input('search_option_category_id'),
+		),
+
+        'attr_id'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '属性id',
+            'default'   => '1',
+            'desc'      => '属性id',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_attr_id'),
+        ),
+
+        'name'      => array
+        (
+            'type'      => 'varchar-1000',
+            'name'      => '属性值名称-如绿色',
+            'default'   => '',
+            'desc'      => '属性值名称',
+            'match'     => 'is_string',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+            'list'      => true,
+            'edit'      => true,
+        ),
+
+        'value'      => array
+        (
+            'type'      => 'varchar-1000',
+            'name'      => '属性具体值-如上述名称为绿色,这里可以是绿色的色值,选填项,可以为空',
+            'default'   => '',
+            'desc'      => '属性具体值',
+            'match'     => 'option',
+            'update'    => 'text',
+            'search'    => 'fulltext',
+        ),
+
+        'icon'      => array
+        (
+            'type'      => 'varchar-150',
+            'name'      => '图标-选填项',
+            'default'   => '',
+            'desc'      => '图标',
+            'match'     => 'option',
+            'update'    => 'image',
+            'key'       => 1,
+        ),
+
+        'reorder'       => array
+        (
+            'type'      => 'int-11',
+            'name'      => '排序(数值越大越靠前)',
+            'default'   => '1',
+            'desc'      => '请输入排序',
+            'match'     => 'option',
+            //'update'    => 'text',
+            'search'    => 'order',
+            'list_name' => '排序',
+            'list'      => true,
+            'order'     => 'desc',
+            'edit'      => 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
+    (
+    	'lang' => 'name',
+
+        'insert' => false,
+        'edit' => false,
+        'button' => array
+        (
+            '新增' => array('fast'),
+        ),
+        # 列表
+        'list_button' => array
+        (
+            'fast' => array('编辑'),
+        ),
+    ),
+
+    'request' => array
+    (
+        'getData' => array
+        (
+            # 匹配的正则或函数 选填项
+            'option' => array
+            (
+                'attr_id' => 'yes',
+                'ids' => array('yes-id', 'in'),
+                'state' => 1,
+            ),
+            'type' => 'all',
+            'order' => array('reorder' => 'desc', 'id' => 'desc'),
+            'col' => 'id,attr_id,name,value,icon,concat(attr_id, "-", id) as price_key|id',
+        ),
+    )
+);

+ 67 - 23
database/info.php

@@ -4,16 +4,27 @@ $audit = Dever::config('base')->audit;
 
 
 $status = Dever::config('base')->status;
 $status = Dever::config('base')->status;
 
 
+$id = Dever::input('where_id');
+
+$unit = function()
+{
+	$array = array();
+	$data = Dever::load('product/unit-state');
+	if($data)
+	{
+		$array += $data;
+	}
+	return $array;
+};
+
 $config = array
 $config = array
 (
 (
 	# 表名
 	# 表名
 	'name' => 'info',
 	'name' => 'info',
 	# 显示给用户看的名称
 	# 显示给用户看的名称
-	'lang' => '商品列表',
+	'lang' => '商品设置',
 	'order' => 200,
 	'order' => 200,
 	'auto' => 10000000,
 	'auto' => 10000000,
-	# 需要设置语言包的字段
-	'lang_col' => array('name', 'content'),
 	'set' => array
 	'set' => array
 	(
 	(
 		'status' => $status,
 		'status' => $status,
@@ -50,33 +61,66 @@ $config = array
 			'default' 	=> '',
 			'default' 	=> '',
 			'desc' 		=> '',
 			'desc' 		=> '',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
-			//'list'		=> true,
+			'list'		=> true,
 		),
 		),
 
 
 		'name'		=> array
 		'name'		=> array
 		(
 		(
 			'type' 		=> 'varchar-800',
 			'type' 		=> 'varchar-800',
-			'name' 		=> '标题',
+			'name' 		=> '商品标题',
 			'default' 	=> '',
 			'default' 	=> '',
-			'desc' 		=> '标题',
+			'desc' 		=> '商品标题',
 			'match' 	=> 'is_string',
 			'match' 	=> 'is_string',
 			'update'	=> 'textarea',
 			'update'	=> 'textarea',
 			'search'	=> 'fulltext',
 			'search'	=> 'fulltext',
-			//'list'		=> true,
+			'list'		=> true,
 			//'edit'		=> true,
 			//'edit'		=> true,
 		),
 		),
 
 
+		'unit'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '商品单位',
+			'default' 	=> '',
+			'desc' 		=> '商品单位',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'select',
+			'lang'		=> '请选择',
+			'update'	=> 'select',
+			'option'	=> $unit,
+			'option_add' => array('[添加新单位]', 'product/unit.add'),
+		),
+
 		'category'		=> array
 		'category'		=> array
 		(
 		(
 			'type' 		=> 'varchar-500',
 			'type' 		=> 'varchar-500',
-			'name' 		=> '分类',
+			'name' 		=> '属性分类',
 			'default' 	=> '',
 			'default' 	=> '',
 			'desc' 		=> '分类',
 			'desc' 		=> '分类',
 			'match' 	=> 'is_string',
 			'match' 	=> 'is_string',
 			'search'	=> 'linkage',
 			'search'	=> 'linkage',
+			//'update'	=> $id ? false : 'linkage',
 			'update'	=> 'linkage',
 			'update'	=> 'linkage',
 			'option'	=> Dever::url('category.get', 'product'),
 			'option'	=> Dever::url('category.get', 'product'),
-			//'list'		=> 'Dever::load("product/category.string", "{category}")',
+			//'update'	=> 'radio',
+			//'option'	=> Dever::db('product/category')->select(),
+			'list'		=> 'Dever::load("product/category.string", "{category}")',
+			'load'		=> 'product-info_attr',
+			'tab'		=> 1,
+		),
+
+		'product-info_attr'=> array
+		(
+			'name' 		=> '属性设置',
+			'default' 	=> '',
+			'desc' 		=> '请先选择属性分类',
+			'match' 	=> 'option',
+			# 同步更新另外一个表的内容,两个表相关联的id,更新另一个表的字段
+			'sync'		=> array('id', 'info_id'),
+			# 根据category字段的值,获取product/attr.search接口的内容
+			'update'	=> 'load',
+			'update_load' => array('product/attr.getManageByCate', 'category'),
+			'tab'		=> 1,
 		),
 		),
 
 
 		# 以下几个分类其实在关联表中已经有了,放到这里是为了查询方便,一般只有三级分类,多了就从关联表查询吧
 		# 以下几个分类其实在关联表中已经有了,放到这里是为了查询方便,一般只有三级分类,多了就从关联表查询吧
@@ -110,7 +154,7 @@ $config = array
 		'pic'		=> array
 		'pic'		=> array
 		(
 		(
 			'type' 		=> 'text-255',
 			'type' 		=> 'text-255',
-			'name' 		=> '商品主图-图片尺寸500*500px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式,用户上传图片之后会自动进行居中裁剪',
+			'name' 		=> '商品主图-图片尺寸500*500px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
 			'default' 	=> '',
 			'default' 	=> '',
 			'desc' 		=> '多张图片',
 			'desc' 		=> '多张图片',
 			'match' 	=> 'option',
 			'match' 	=> 'option',
@@ -128,8 +172,8 @@ $config = array
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 			//'update'	=> 'select',
 			//'update'	=> 'select',
 			'option'	=> $audit,
 			'option'	=> $audit,
-			'search'	=> 'select',
-			'list'		=> true,
+			//'search'	=> 'select',
+			//'list'		=> true,
 			'edit'		=> true,
 			'edit'		=> true,
 		),
 		),
 
 
@@ -137,7 +181,7 @@ $config = array
 		(
 		(
 			'type' 		=> 'tinyint-1',
 			'type' 		=> 'tinyint-1',
 			'name' 		=> '状态',
 			'name' 		=> '状态',
-			'default' 	=> '1',
+			'default' 	=> '2',
 			'desc' 		=> '状态',
 			'desc' 		=> '状态',
 			'match' 	=> 'is_numeric',
 			'match' 	=> 'is_numeric',
 			//'update'	=> 'select',
 			//'update'	=> 'select',
@@ -164,9 +208,9 @@ $config = array
 		'content'		=> array
 		'content'		=> array
 		(
 		(
 			'type' 		=> 'text-800',
 			'type' 		=> 'text-800',
-			'name' 		=> '内容介绍',
+			'name' 		=> '商品介绍',
 			'default' 	=> '',
 			'default' 	=> '',
-			'desc' 		=> '内容介绍',
+			'desc' 		=> '商品介绍',
 			'match' 	=> 'is_string',
 			'match' 	=> 'is_string',
 			'update'	=> 'editor',
 			'update'	=> 'editor',
 			'key'		=> '1',
 			'key'		=> '1',
@@ -217,6 +261,7 @@ $config = array
 	# 管理功能
 	# 管理功能
 	'manage' => array
 	'manage' => array
 	(
 	(
+		'tab' => array('基本设置', '属性设置', '规格设置'),
 		// 载入自定义资源 路径可以配置在config里。这里没有写路径。demo.css
 		// 载入自定义资源 路径可以配置在config里。这里没有写路径。demo.css
 		'res' => array
 		'res' => array
 		(
 		(
@@ -224,7 +269,7 @@ $config = array
 		),
 		),
 		//'insert' => false,
 		//'insert' => false,
 		//'delete' => false,
 		//'delete' => false,
-		'mul' => true,
+		//'mul' => true,
 		# 自定义快捷新增和编辑
 		# 自定义快捷新增和编辑
         'button' => array
         'button' => array
         (
         (
@@ -232,24 +277,23 @@ $config = array
         ),
         ),
 
 
 		# 列表里的按钮
 		# 列表里的按钮
+		/*
 		'list_button' => array
 		'list_button' => array
 		(
 		(
-			'add' => array('属性设置', '"info_attr
+			'add' => array('属性', '"info_attr
 				&project=goods
 				&project=goods
 				&search_option_info_id={id}
 				&search_option_info_id={id}
 				&search_option_category={category}
 				&search_option_category={category}
 				&oper_parent=info&oper_project=goods
 				&oper_parent=info&oper_project=goods
 				&oper_save_jump=info
 				&oper_save_jump=info
-				&where_id={id}"', '{price_type} == 2'),
+				&where_id={id}"'),
 
 
-			'list' => array('sku设置', '"info_sku
+			'list' => array('规格', '"info_sku
 				&project=goods
 				&project=goods
 				&search_option_info_id={id}
 				&search_option_info_id={id}
 				&oper_parent=info&oper_project=goods
 				&oper_parent=info&oper_project=goods
-				&oper_save_jump=info&page_type=1"', '{price_type} == 2'),
-			'br1' => array('<br />'),
-			'delete' => '删除',
-		),
+				&oper_save_jump=info&page_type=1"'),
+		),*/
 	),
 	),
 
 
 	# request 请求接口定义
 	# request 请求接口定义

+ 141 - 0
database/info_attr.php

@@ -0,0 +1,141 @@
+<?php
+$config = array
+(
+	# 表名
+	'name' => 'info_attr',
+	# 显示给用户看的名称
+	'lang' => '属性规格',
+	'order' => 100,
+	'menu' => false,
+
+	# 数据结构 不同的字段放这里
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'update'    => 'hidden',
+		),
+
+		'info_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品',
+            'default'   => '',
+            'desc'      => '商品',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_info_id')
+        ),
+
+        'attr_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '属性id',
+            'default'   => '',
+            'desc'      => '属性id',
+            'match'     => 'is_numeric',
+        ),
+
+        'attr_value'      => array
+        (
+            'type'      => 'varchar-3000',
+            'name'      => '属性值',
+            'default'   => '',
+            'desc'      => '属性值',
+            'match'     => 'is_string',
+        ),
+
+        '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,
+			//'list'		=> 'date("Y-m-d H:i:s", {cdate})',
+		),
+	),
+
+	# 索引
+	'index' => array
+	(
+		1 => array
+		(
+			'search' => 'info_id,attr_id,attr_value',
+		),
+		
+		# 版本号 更改版本号会更新当前表的索引
+		'version' => 1,
+	),
+	
+	# 管理功能
+	'manage' => array
+	(
+
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		# 分页
+		'getPageAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'audit' => array('yes-t_2.audit', 2),
+				'category' => array('yes-t_2.category', 'like'),
+				'top_category_id' => array('yes-t_2.top_category_id'),
+				'second_category_id' => array('yes-t_2.second_category_id'),
+				'category_id' => array('yes-t_2.category_id'),
+				'state' => array('yes-t_2.state', 1),
+			),
+			# 联表
+			'join' => array
+			(
+				array
+				(
+					'table' => 'res/info',
+					'type' => 'left join',
+					'on' => array('info_id','id'),
+					'col' => 'info_id',
+				),
+			),
+			'type' => 'all',
+			'order' => array('t_1.id' => 'desc'),
+			'page' => array(10, 'list'),
+			'col' => '*',
+		),
+
+		'getDataByInfoId' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'info_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'col' => '*|attr_id',
+		),
+	),
+);
+
+return $config;

+ 85 - 0
database/unit.php

@@ -0,0 +1,85 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'unit',
+	# 显示给用户看的名称
+	'lang' => '单位管理',
+	# 是否显示在后台菜单
+	'order' => 10,
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'list'		=> true,
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '单位名称',
+			'default' 	=> '',
+			'desc' 		=> '单位名称',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序(数值越大越靠前)',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			//'update'	=> 'text',
+			'search'	=> 'order',
+			'list_name' => '排序',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> 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
+	(
+		
+	),
+
+	'request' => array
+	(
+		
+	)
+);

+ 18 - 0
lib/Manage.php

@@ -29,4 +29,22 @@ class Manage
             Dever::db('product/category')->update($update);
             Dever::db('product/category')->update($update);
         }
         }
     }
     }
+
+    /**
+     * 更新属性信息
+     *
+     * @return mixed
+     */
+    public function updateAttr($id, $name, $data)
+    {
+        return;
+        $is_sell = Dever::param('is_sell', $data);
+        if ($is_sell > 1) {
+            $update['type'] = 11;
+        }
+        if (isset($update)) {
+            $update['where_id'] = $id;
+            Dever::db('product/category_attr')->update($update);
+        }
+    }
 }
 }

+ 578 - 0
src/Attr.php

@@ -0,0 +1,578 @@
+<?php
+
+namespace Product\Src;
+
+use Dever;
+
+class Attr
+{
+	/**
+	 * 根据分类id,获取属性更新信息,用于后台
+	 *
+	 * @return mixed
+	 */
+	public function getManageByCate()
+	{
+		$id = Dever::input('id');
+		$data = array();
+		if ($id) {
+			$data = Dever::db('product/info_attr')->getDataByInfoId(array('info_id' => $id));
+		}
+
+		$where['category_id'] = Dever::input('category', 2);
+		$attr = Dever::db('product/category_attr')->getCateAll($where);
+		if (!$attr) {
+			return '';
+		}
+		$config = array();
+
+		$this->setDatabaseConfig($attr, $config, $data);
+
+		$data = array();
+
+		$result = Dever::load('manage/database')->update_struct($config, false, $data, -1, 'product-info_attr-', true);
+
+		return implode('', $result);
+	}
+
+	/**
+	 * 根据分类id,获取所有属性
+	 *
+	 * @return mixed
+	 */
+	public function getInfoByCate($cate_id)
+	{
+		$where['category_id'] = $cate_id;
+		$data = Dever::db('product/category_attr')->select($where);
+		if ($data) {
+			$name = array();
+			foreach ($data as $k => $v) {
+				$name[] = $v['name'];
+			}
+			return implode('、', $name);
+		}
+		return '';
+	}
+
+	/**
+	 * 根据json格式获取信息
+	 *
+	 * @return mixed
+	 */
+	public function getInfoByJson($data)
+	{
+		$result = array();
+
+		$string = array();
+
+		foreach ($data as $k => $v) {
+
+			$info = Dever::db('product/category_attr')->find($v['attr_id']);
+			$result[$k]['id'] = $info['id'];
+			$result[$k]['name'] = $info['name'];
+
+			if ($v['id']) {
+				$attr = Dever::db('product/category_attr_value')->find($v['id']);
+				if ($attr) {
+					$result[$k]['value_id'] = $attr['id'];
+					$result[$k]['value_name'] = $attr['name'];
+					$string[] = $result[$k]['value_name'];
+				}
+			}
+		}
+
+		return array('data' => $result, 'string' => implode(',', $string));
+	}
+
+	/**
+	 * 获取属性详细信息,有类别
+	 *
+	 * @return mixed
+	 */
+	public function getInfo($ids, $value)
+	{
+		$result = array();
+		if ($ids) {
+			$where['ids'] = $ids;
+			$cate = Dever::db('product/category')->state();
+			$data = Dever::db('product/category_attr')->getAllByIds($where);
+
+			$ids = explode(',', $ids);
+			$value = explode(',', $value);
+			if ($data) {
+				foreach ($ids as $k => $v) {
+					if (isset($data[$v])) {
+						$cate_id = $data[$v]['category_id'];
+						if (!isset($cate[$cate_id])) {
+							continue;
+						}
+
+						if (!isset($result[$cate_id])) {
+							$result[$cate_id] = array
+							(
+								'name' => $cate[$cate_id]['name'],
+								'id' => $cate_id
+							);
+						}
+
+						$result[$cate_id]['attr'][$v] = array
+						(
+							'name' => $data[$v]['name'],
+							'value' => isset($value[$k]) ? $value[$k] : '',
+							'id' => $v
+						);
+					}
+				}
+			}
+		}
+
+		return $result;
+	}
+
+	public function getInfoAttr($category)
+	{
+	    //$all = Dever::db('category/attr')->all();
+
+	    $table = '';
+	    $attr = array();
+	    $create = Dever::config('database')->create;
+
+	    if ($category) {
+	        if (is_array($category)) {
+	            $category = implode(',', $category);
+	        }
+	        $table = '_' . str_replace(',', '_', $category);
+	        # 自动建表开启并且自动添加字段
+	        $create = false;
+	        $attr = $this->getAttrByCate($category);
+	        $table = str_replace('_-1', '', $table);
+	    }
+
+	    return array($category, $attr, $table, $create);
+	}
+
+	/**
+	 * 设置数据库的结构信息
+	 *
+	 * @return mixed
+	 */
+	public function setDatabaseConfig($attr, &$config, $data = array())
+	{
+		if ($attr) {
+			foreach ($attr as $k => $v) {
+				if ($v['type'] == 9) {
+
+					$k = 'attr_' . $v['id'] . '_s';
+					$config['struct'][$k]['name'] = $v['name'];
+					$config['struct'][$k]['default'] = '';
+					$config['struct'][$k]['desc'] = $v['name'];
+					$config['struct'][$k]['update'] = 'hidden';
+					$config['struct'][$k]['type'] = 'varchar-800';
+					$config['struct'][$k]['match'] = 'is_numeric';
+
+					$k = 'attr_' . $v['id'] . '_e';
+					$config['struct'][$k]['name'] = $v['name'];
+					$config['struct'][$k]['default'] = '';
+					$config['struct'][$k]['desc'] = $v['name'];
+					$config['struct'][$k]['update'] = 'hidden';
+					$config['struct'][$k]['type'] = 'varchar-800';
+					$config['struct'][$k]['match'] = 'is_numeric';
+				}
+
+				$k = 'attr_' . $v['id'];
+				$config['struct'][$k] = array();
+				/*
+				$option = array();
+				if ($v['type_option']) {
+					$v['type_option'] = explode("\n", $v['type_option']);
+					foreach ($v['type_option'] as $k1 => $v1) {
+						$option[$k1+1] = $v1;
+					}
+				}*/
+				$option = Dever::db('product/category_attr_value')->getData(array('attr_id' => $v['id']));
+
+				$config['struct'][$k]['name'] = $v['name'];
+				$config['struct'][$k]['default'] = '';
+				$config['struct'][$k]['desc'] = $v['name'];
+
+				switch ($v['type']) {
+					case 3:
+						$config['struct'][$k]['update'] = 'textarea';
+						$config['struct'][$k]['search'] = 'fulltext';
+						$config['struct'][$k]['type'] = 'varchar-800';
+						$config['struct'][$k]['match'] = 'is_string';
+						break;
+					case 4:
+						$config['struct'][$k]['type'] = 'text-255';
+						$config['struct'][$k]['update'] = 'editor';
+						$config['struct'][$k]['match'] = 'is_string';
+						$config['struct'][$k]['key'] = 1;
+					case 5:
+						$config['struct'][$k]['update'] = 'image';
+						$config['struct'][$k]['type'] = 'varchar-150';
+						$config['struct'][$k]['match'] = 'is_string';
+						$config['struct'][$k]['key'] = 1;
+						break;
+					case 6:
+						$config['struct'][$k]['update'] = 'images';
+						$config['struct'][$k]['type'] = 'text-255';
+						$config['struct'][$k]['match'] = 'is_string';
+						$config['struct'][$k]['key'] = 1;
+						break;
+					case 7:
+						$config['struct'][$k]['type'] = 'varchar-800';
+						$config['struct'][$k]['match'] = 'is_string';
+						$config['struct'][$k]['update'] = 'linkage';
+						$config['struct'][$k]['search'] = 'linkage';
+						$config['struct'][$k]['option'] = Dever::url('area/api.get');
+						//$config['struct'][$k]['list'] = 'Dever::load("area/api.string", "{area}")';
+						break;
+
+					case 10:
+						$config['struct'][$k]['update'] = 'radio';
+						$config['struct'][$k]['type'] = 'varchar-800';
+						$config['struct'][$k]['match'] = 'is_numeric';
+						$config['struct'][$k]['option'] = $option;
+						$config['struct'][$k]['search'] = 'select';
+						$config['struct'][$k]['default'] = '';
+
+						break;
+					case 11:
+						$config['struct'][$k]['update'] = 'checkbox';
+						$config['struct'][$k]['type'] = 'varchar-800';
+						$config['struct'][$k]['match'] = 'is_string';
+						$config['struct'][$k]['option'] = $option;
+						$config['struct'][$k]['search'] = 'select';
+						$config['struct'][$k]['default'] = '';
+						break;
+					case 12:
+						$config['struct'][$k]['update'] = 'select';
+						$config['struct'][$k]['type'] = 'varchar-800';
+						$config['struct'][$k]['match'] = 'is_numeric';
+						$config['struct'][$k]['option'] = $option;
+						$config['struct'][$k]['search'] = 'select';
+						$config['struct'][$k]['default'] = '';
+						break;
+					
+					default:
+						$config['struct'][$k]['update'] = 'text';
+						$config['struct'][$k]['search'] = 'fulltext';
+						if ($v['type'] == 9) {
+							$config['struct'][$k]['name'] .= '-这是一个区间数值,后台填写请用半角逗号,隔开';
+							$config['struct'][$k]['type'] = 'varchar-800';
+							$config['struct'][$k]['match'] = 'is_string';
+						} elseif ($v['data_type'] == 1 || $v['type'] == 1) {
+							$config['struct'][$k]['type'] = 'varchar-800';
+							$config['struct'][$k]['match'] = 'is_numeric';
+						} else {
+							$config['struct'][$k]['type'] = 'varchar-800';
+							$config['struct'][$k]['match'] = 'is_string';
+						}
+				}
+
+				if ($v['is_must'] && $v['is_must'] == 2) {
+					$config['struct'][$k]['match'] = 'option';
+				}
+
+				/*
+				if ($v['value']) {
+					$config['struct'][$k]['default'] = $v['value'];
+				}*/
+				if ($data && isset($data[$v['id']])) {
+					$config['struct'][$k]['default'] = $data[$v['id']]['attr_value'];
+				}
+
+				if ($v['state'] == 2) {
+					unset($config['struct'][$k]['update']);
+				}
+
+				# 还要根据搜索来建立索引,另外,如果数据结构改了怎么办。暂时用varchar
+			}
+		}
+	}
+
+	/**
+	 * 根据属性id,获取属性列表
+	 *
+	 * @return mixed
+	 */
+	public function getList($ids, $value, $order = 'list')
+	{
+		$data = array();
+		if ($ids) {
+			$where['ids'] = $ids;
+			$method = 'getAllByIds';
+			if ($order == 'list') {
+				$method = 'getListByIds';
+			} elseif ($order == 'search') {
+				$method = 'getSearchByIds';
+			} elseif ($order == 'search_reorder') {
+				$method = 'getSearchByIds';
+				$where['search_reorder'] = 1;
+			} elseif ($order == 'view') {
+				$method = 'getViewByIds';
+			}
+			$data = Dever::db('product/category_attr')->$method($where);
+
+			$ids = explode(',', $ids);
+			$value = explode(',', $value);
+			if ($data) {
+				foreach ($ids as $k => $v) {
+					if (isset($data[$v])) {
+						if (isset($value) && isset($value[$k]) && $value[$k]) {
+							$data[$v]['value'] = $value[$k];
+						} else {
+							$data[$v]['value'] = '';
+						}
+					}
+				}
+			}
+		}
+
+		return $data;
+	}
+
+	/**
+	 * 获取属性的值
+	 *
+	 * @return mixed
+	 */
+	public function getValue($info)
+	{
+		# 地区
+		if ($info['type'] == 7) {
+			$info['value'] = Dever::load("area/api.string", $info['value']);
+			/*
+			$info['value'] = explode(',', $info['value']);
+			$temp = end($info['value']);
+			$info['value'] = $temp;
+			*/
+		} elseif ($info['type'] == 9 && $info['value']) {
+			$info['value'] = explode(',', $info['value']);
+			$info['value'] = $info['value'][0] . $info['unit'];
+		} elseif ($info['type'] > 9 && $info['value']) {
+			$value = Dever::db('product/category_attr_value')->getData(array('ids' => $info['value']));
+			if ($value) {
+				$name = array();
+				foreach ($value as $k => $v) {
+					$name[] = $v['name'] . $info['unit'];
+				}
+				$info['value'] = implode(',', $name);
+			}
+		} elseif ($info['unit']) {
+			$info['value'] = $info['value'] . $info['unit'];
+		}
+		return $info['value'];
+	}
+
+	/**
+	 * 获取属性的名称,字符类型
+	 *
+	 * @return mixed
+	 */
+	public function string($ids, $value = '')
+	{
+		$result = $this->getInfo($ids, $value);
+
+		$table = array();
+		foreach ($result as $k => $v) {
+			$table[$v['name']] = '';
+			foreach ($v['attr'] as $k1 => $v1) {
+				$table[$v['name']] .= $v1['name'] . "&nbsp;&nbsp;";
+			}
+		}
+
+		return Dever::table($table);
+	}
+
+
+
+	private function attrSort(&$attr, $reorder = 'list_reorder')
+	{
+		if ($reorder == 'list') {
+			$reorder = 'list_reorder';
+		}
+		$order = Dever::config('base')->attrOrder;
+		if ($order && $order != $reorder) {
+			$reorder = $order;
+		}
+		if ($attr) {
+			foreach ($attr as $k => $v) {
+				$sort[$k] = $v[$reorder];
+				$attr[$k]['option'] = Dever::db('product/category_attr_value')->getData(array('attr_id' => $v['id']));
+				/*
+				if ($v['type_option']) {
+                    $attr[$k]['option'] = explode("\n", $v['type_option']);
+                }
+                */
+			}
+			array_multisort($sort, SORT_DESC, $attr);
+		}
+	}
+
+	public function getAttrByCate($category, $order = 'list_reorder', $total = false)
+	{
+		$data = array();
+		//print_r(Dever::db('category/attr')->all());
+		if ($category && Dever::project('category')) {
+			$array = explode(',', $category);
+			$cate = array();
+			$total = $total ? $total : count($array);
+			$total -= 1;
+			foreach ($array as $k => $v) {
+				$cate[$k] = $v;
+				if ($k < $total) {
+					$cate[] = '-1';
+				}
+				$where['category'] = $cate;
+				$info = Dever::db('category/attr')->one($where);
+				if ($info) {
+					$data += Dever::load('attr/api')->getList($info['attr'], $info['attr_input'], $order);
+				}
+			}
+			$this->attrSort($data, $order);
+		}
+
+		return $data;
+	}
+
+	/**
+	 * 获取某个分类下的搜索列表
+	 *
+	 * @return mixed
+	 */
+	public function getSearch($ids, $cate = true, $city = false, $search_value = false, $total = 3)
+	{
+		$value = array();
+		$search_value = Dever::preInput('attr_', array(), $search_value);
+
+		if ($cate && $ids && Dever::project('category')) {
+			$data = $this->getAttrByCate($ids, 'search_reorder', $total);
+			if (!$data) {
+				return array('search' => array(), 'value' => $value);
+			}
+		} else {
+			$where['ids'] = $ids;
+			$where['search_reorder'] = 1;
+			$data = Dever::db('product/category_attr')->getSearchByIds($where);
+		}
+
+		if ($data) {
+			foreach ($data as $k => $v) {
+				if (isset($ids_input[$v['id']]) && $ids_input[$v['id']]) {
+					$data[$k]['name'] = $ids_input[$v['id']];
+				}
+				$data[$k]['key'] = 'attr_' . $v['id'];
+				if ($v['type'] == 7 && $city > 0) {
+					# 获取地区,获取最后一个级别的地区
+					$data[$k]['option'] = Dever::db('area/county')->state(array('city_id' => $city));
+				} elseif ($v['type'] == 1 || $v['type'] == 9) {
+					$data[$k]['option'] = Dever::db('product/category_attr_search')->getData(array('attr_id' => $v['id']));
+				} else {
+					$data[$k]['option'] = Dever::db('product/category_attr_value')->getData(array('attr_id' => $v['id']));
+				}
+				/*
+				elseif ($v['type_option']) {
+					$temp = explode("\n", $v['type_option']);
+					foreach ($temp as $k1 => $v1) {
+						$v1 = explode(',', $v1);
+						$k1 = $k1+1;
+						$data[$k]['option'][$k1] = array
+						(
+							'id' => $k1,
+							'name' => $v1[0],
+						);
+						if (isset($v1[1])) {
+							$data[$k]['option_match'][$k1] = $v1[1];
+						}
+					}
+				}
+				*/
+
+				if (isset($search_value[$data[$k]['key']])) {
+					$data[$k]['option_value'] = $search_value[$data[$k]['key']];
+					$value[$data[$k]['key']] = $data[$k]['option_value'];
+				}
+			}
+		}
+		
+
+		return array('search' => $data, 'value' => $value);
+	}
+
+	/**
+	 * 获取搜索sql
+	 *
+	 * @return mixed
+	 */
+	public function getSql($attr, $where, $sql = array(), $tname = 't_1')
+	{
+		if (!$attr) {
+			return $sql;
+		}
+		foreach ($attr as $k => $v) {
+            $key = 'attr_' . $v['id'];
+            if (isset($where[$key]) && $where[$key]) {
+                //$where['option'][$key] = array('yes', '=');
+                if ($v['type'] == 7) {
+                    # 地区有点复杂,暂时先这样,后续优化一下
+                    $county = Dever::db('area/county')->one($where[$key]);
+                    if ($county) {
+                        $city = Dever::db('area/city')->one($county['city_id']);
+                        if ($city) {
+                            $province = Dever::db('area/province')->one($city['province_id']);
+                            if ($province) {
+                                $value = $province['id'] . ',' . $city['id'] . ',' . $county['id'];
+                                //$where[$key] = $value;
+                                $sql[] = ' '.$tname.'.'.$key.' = "'.$value.'"';
+                            }
+                        }
+                    }
+                //} elseif ($v['type'] == 1 && $v['type_option']) {
+                } elseif ($v['type'] == 1) {
+
+                	$search = Dever::db('product/category_attr_search')->getData(array('attr_id' => $v['id']));
+                	//print_r($where[$key]);die;
+                	/*
+                    $temp = explode("\n", $v['type_option']);
+                    if (isset($temp[$where[$key]-1])) {
+                        $temp = explode(',', $temp[$where[$key]-1]);
+                        $match = $temp[1];
+
+                        //$where['option'][$key] = array('yes', '<=');
+                        //$where[$key] = 100;
+
+                        $match = str_replace('{v}', $tname . '.' . $key, $match);
+                        $sql[] = $match;
+                    }
+                    */
+                //} elseif ($v['type'] == 9 && $v['type_option']) {
+                } elseif ($v['type'] == 9 && $v['type_option']) {
+
+                	$search = Dever::db('product/category_attr_search')->getData(array('attr_id' => $v['id']));
+                	//print_r($where[$key]);die;
+
+                	/*
+                    $temp = explode("\n", $v['type_option']);
+                    if (isset($temp[$where[$key]-1])) {
+                        $temp = explode(',', $temp[$where[$key]-1]);
+                        $match = $temp[1];
+
+                        //$where['option'][$key] = array('yes', '<=');
+                        //$where[$key] = 100;
+
+                        $match = str_replace('{s}', $tname . '.' . $key . '_s', $match);
+                        $match = str_replace('{e}', $tname . '.' . $key . '_e', $match);
+                        $match = str_replace('{v}', $tname . '.' . $key . '_e', $match);
+                        $sql[] = $match;
+                    }
+                    */
+                } else {
+                    $sql[] = ' '.$tname.'.'.$key.' = "'.$where[$key].'"';
+                }
+            }
+        }
+
+        return $sql;
+	}
+}

+ 20 - 23
src/Category.php

@@ -32,6 +32,9 @@ class Category
      */
      */
     public function get()
     public function get()
     {
     {
+        # 关闭语言包
+        Dever::config('base')->lang = false;
+        
         # 联动总数
         # 联动总数
         $level_total = 100;
         $level_total = 100;
 
 
@@ -61,12 +64,12 @@ class Category
 
 
         # 三级联动
         # 三级联动
         if ($level_num == 1) {
         if ($level_num == 1) {
-            $where['category_id'] = -1;
+            $where['parent_id'] = -1;
         } elseif($level_id > 0) {
         } elseif($level_id > 0) {
-            $where['category_id'] = $level_id;
+            $where['parent_id'] = $level_id;
         }
         }
 
 
-        if (isset($where['category_id'])) {
+        if (isset($where['parent_id'])) {
             $data = Dever::db('product/category')->getAll($where);
             $data = Dever::db('product/category')->getAll($where);
         }
         }
 
 
@@ -109,12 +112,9 @@ class Category
      *
      *
      * @return mixed
      * @return mixed
      */
      */
-    public function getTop($project = false)
+    public function getTop()
     {
     {
         $where = array();
         $where = array();
-        if ($project > 0) {
-            $where['project_id'] = $project;
-        }
         $result = Dever::db('product/category')->getTop($where);
         $result = Dever::db('product/category')->getTop($where);
         return $result;
         return $result;
     }
     }
@@ -124,14 +124,11 @@ class Category
      *
      *
      * @return mixed
      * @return mixed
      */
      */
-    public function getAll($project, $cate = false)
+    public function getAll($parent = false)
     {
     {
         $where = array();
         $where = array();
-        if ($project > 0) {
-            $where['project_id'] = $project;
-        }
-        if ($cate) {
-            $where['category_id'] = $cate;
+        if ($parent) {
+            $where['parent_id'] = $parent;
         }
         }
         $result = Dever::db('product/category')->getList($where);
         $result = Dever::db('product/category')->getList($where);
         return $result;
         return $result;
@@ -172,12 +169,12 @@ class Category
     }
     }
 
 
     # 根据上级分类获取下级分类 按照category_id进行索引
     # 根据上级分类获取下级分类 按照category_id进行索引
-    public function getChild($category_id)
+    public function getChild($parent_id)
     {
     {
-        if (is_numeric($category_id)) {
-            $where['category_id'] = $category_id;
+        if (is_numeric($parent_id)) {
+            $where['parent_id'] = $parent_id;
         } else {
         } else {
-            $where['category_id_in'] = $category_id;
+            $where['parent_id_in'] = $parent_id;
         }
         }
         
         
         $data = Dever::db('product/category')->getChild($where);
         $data = Dever::db('product/category')->getChild($where);
@@ -186,12 +183,12 @@ class Category
     }
     }
 
 
     # 根据上级分类获取下级分类 
     # 根据上级分类获取下级分类 
-    public function getList($category_id)
+    public function getList($parent_id)
     {
     {
-        if (is_numeric($category_id)) {
-            $where['category_id'] = $category_id;
+        if (is_numeric($parent_id)) {
+            $where['parent_id'] = $parent_id;
         } else {
         } else {
-            $where['category_id_in'] = $category_id;
+            $where['parent_id_in'] = $parent_id;
         }
         }
         
         
         $data = Dever::db('product/category')->getList($where);
         $data = Dever::db('product/category')->getList($where);
@@ -200,9 +197,9 @@ class Category
     }
     }
 
 
     # 根据顶级分类获取最低级的分类
     # 根据顶级分类获取最低级的分类
-    public function getChildByTop($top_category_id, $level = -1)
+    public function getChildByTop($top_parent_id, $level = -1)
     {
     {
-        $where['top_category_id'] = $top_category_id;
+        $where['top_parent_id'] = $top_parent_id;
         $where['level'] = $level;
         $where['level'] = $level;
         $data = Dever::db('product/category')->getList($where);
         $data = Dever::db('product/category')->getList($where);
 
 

+ 24 - 0
src/Unit.php

@@ -0,0 +1,24 @@
+<?php
+
+namespace Product\Src;
+
+use Dever;
+
+class Unit
+{
+    # 添加新单位
+    public function add()
+    {
+    	$where['name'] = Dever::input('value');
+    	if (!$where['name']) {
+    		Dever::alert('请输入单位名称');
+    	}
+    	return Dever::db('product/unit')->insert($where);
+    	return 'ok';
+        $info = Dever::db('product/unit')->find($where);
+        if (!$info) {
+        	Dever::db('product/unit')->insert($where);
+        }
+        return 'ok';
+    }
+}