dever 4 роки тому
коміт
7cd8847dcc
13 змінених файлів з 1955 додано та 0 видалено
  1. 24 0
      assets/manage/html/sku.html
  2. 85 0
      database/brand.php
  3. 386 0
      database/info.php
  4. 132 0
      database/info_attr.php
  5. 65 0
      database/info_category.php
  6. 126 0
      database/info_sku.php
  7. 85 0
      database/shop.php
  8. 8 0
      index.php
  9. 335 0
      lib/Info.php
  10. 222 0
      lib/Manage.php
  11. 363 0
      src/Data.php
  12. 119 0
      src/Pay.php
  13. 5 0
      template/manage/sku.php

+ 24 - 0
assets/manage/html/sku.html

@@ -0,0 +1,24 @@
+<table class="layui-table" id="sku">
+  <thead>
+    <tr>
+      <th>昵称</th>
+      <th>加入时间</th>
+      <th>签名</th>
+    </tr> 
+  </thead>
+  <tbody>
+    <tr>
+      <td>贤心</td>
+      <td>2016-11-29</td>
+      <td>人生就像是一场修行</td>
+    </tr>
+    <tr>
+      <td>许闲心</td>
+      <td>2016-11-28</td>
+      <td>于千万人之中遇见你所遇见的人,于千万年之中,时间的无涯的荒野里…</td>
+    </tr>
+  </tbody>
+</table>
+<script>
+
+</script>

+ 85 - 0
database/brand.php

@@ -0,0 +1,85 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'brand',
+	# 显示给用户看的名称
+	'lang' => '品牌管理',
+	# 是否显示在后台菜单
+	'order' => 1,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'asc',
+			'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
+	(
+		
+	)
+);

+ 386 - 0
database/info.php

@@ -0,0 +1,386 @@
+<?php
+
+$audit = Dever::config('base')->audit;
+
+$status = Dever::config('base')->status;
+
+$brand = function()
+{
+	$array = array();
+	$info = Dever::db('goods/brand')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$shop = function()
+{
+	$array = array();
+	$info = Dever::db('goods/shop')->state();
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+$config = array
+(
+	# 表名
+	'name' => 'info',
+	# 显示给用户看的名称
+	'lang' => '商品列表',
+	'order' => 200,
+	'auto' => 10000000,
+
+	'end' => array
+	(
+		'insert' => 'goods/lib/manage.infoUpdate',
+		'update' => 'goods/lib/manage.infoUpdate',
+	),
+
+	# 同步更新另外一个或多个表的数据,将数据同步到关联表中
+	'sync' => array
+	(
+		'goods/info_category' => array
+		(
+			# 更新另外一个表的字段 => 本表的字段
+			'where' => array('info_id', 'id'),
+			# 要更新的数据
+			'update' => array('category_id' => 'category'),
+			# 同步更新的类型,delete为先删再插入,update为直接更新
+			'type' => 'delete',
+		)
+	),
+
+	# 数据结构 不同的字段放这里
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'list'		=> true,
+		),
+
+		'name'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '标题',
+			'default' 	=> '',
+			'desc' 		=> '标题',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+			'search'	=> 'fulltext',
+			//'list'		=> true,
+			//'edit'		=> true,
+		),
+
+		'brand_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '品牌',
+			'default' 	=> '',
+			'desc' 		=> '品牌',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $brand,
+		),
+
+		'shop_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '店铺',
+			'default' 	=> '',
+			'desc' 		=> '店铺',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $shop,
+		),
+
+		'category'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '分类',
+			'default' 	=> '',
+			'desc' 		=> '分类',
+			'match' 	=> 'is_string',
+			'search'	=> 'linkage',
+			'update'	=> 'linkage',
+			'option'	=> Dever::url('api.get', 'category'),
+			//'list'		=> 'Dever::load("category/api.string", "{category}")',
+		),
+
+		# 以下几个分类其实在关联表中已经有了,放到这里是为了查询方便,一般只有三级分类,多了就从关联表查询吧
+		'top_category_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '顶级分类ID-顶级分类,用于分类查询',
+			'default' 	=> '-1',
+			'desc' 		=> '顶级分类ID',
+			'match' 	=> 'is_numeric',
+		),
+
+		'second_category_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '二级分类ID-二级分类,用于分类查询',
+			'default' 	=> '-1',
+			'desc' 		=> '二级分类ID',
+			'match' 	=> 'is_numeric',
+		),
+
+		'category_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '子分类ID-最后一个级别的分类,用于分类查询',
+			'default' 	=> '-1',
+			'desc' 		=> '子分类ID',
+			'match' 	=> 'is_numeric',
+		),
+
+		'pic_cover'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '封面图-图片尺寸300*300px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式,用户上传图片之后会自动进行居中裁剪',
+			'default' 	=> '',
+			'desc' 		=> '封面图',
+			'match' 	=> 'option',
+			'update'	=> 'image',
+			'key' 		=> '1',
+			'place'		=> '300*300',
+			'list_name'	=> '资源详情',
+			'list'		=> 'Dever::load("goods/lib/manage.info", "{id}")',
+		),
+
+		'pic'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '多张图片-图片尺寸750*422px或等比尺寸,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式,用户上传图片之后会自动进行居中裁剪',
+			'default' 	=> '',
+			'desc' 		=> '多张图片',
+			'match' 	=> 'option',
+			'update'	=> 'images',
+			'key' 		=> '1',
+			'place'		=> '750*422',
+		),
+
+		'audit'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '审核',
+			'default' 	=> '2',
+			'desc' 		=> '审核',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'select',
+			'option'	=> $audit,
+			'search'	=> 'select',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'status'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '状态',
+			'default' 	=> '1',
+			'desc' 		=> '状态',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'select',
+			'option'	=> $status,
+			'search'	=> 'select',
+			'list'		=> true,
+			'edit'		=> true,
+		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序-数值越大越靠前,相当于置顶',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			//'update'	=> 'text',
+			'search'	=> 'order',
+			'list'		=> true,
+			'order'		=> 'desc',
+			'edit'		=> true,
+		),
+
+		'udate'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '更新时间',
+			'match' 	=> array('is_numeric', time()),
+			'desc' 		=> '',
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'text-800',
+			'name' 		=> '内容介绍',
+			'default' 	=> '',
+			'desc' 		=> '内容介绍',
+			'match' 	=> 'is_string',
+			'update'	=> 'editor',
+			'key'		=> '1',
+		),
+
+		'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})',
+		),
+	),
+
+# 索引
+	'index' => array
+	(
+		1 => array
+		(
+			'search' => 'shop_id,brand_id,category,top_category_id,second_category_id,category_id',
+		),
+		
+		# 版本号 更改版本号会更新当前表的索引
+		'version' => 1,
+	),
+	
+	# 管理功能
+	'manage' => array
+	(
+		// 载入自定义资源 路径可以配置在config里。这里没有写路径。demo.css
+		'res' => array
+		(
+			//'css' => 'demo',
+		),
+		//'insert' => false,
+		//'delete' => false,
+		'mul' => true,
+		# 自定义快捷新增和编辑
+        'button' => array
+        (
+        	//'类别管理' => array('list', 'cate&project=demand&search_option_key=cate&search_option_tablename=类别&oper_parent=info&oper_project=demand'),
+        ),
+
+		# 列表里的按钮
+		'list_button' => array
+		(
+			'add' => array('属性设置', '"info_attr
+				&project=goods
+				&search_option_info_id={id}
+				&search_option_category={category}
+				&oper_parent=info&oper_project=goods
+				&oper_save_jump=info
+				&where_id={id}"'),
+
+			'list' => array('sku设置', '"info_sku
+				&project=goods
+				&search_option_info_id={id}
+				&oper_parent=info&oper_project=goods
+				&oper_save_jump=info&page_type=1"'),
+			'br1' => array('<br />'),
+			'delete' => '删除',
+		),
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		# 后台搜索用到
+		'search' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'ids' => array('yes-id', 'in'),
+				'name' => array('yes', 'like'),
+				'id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'desc'),
+			'limit' => '0,1000',
+			'col' => 'name as name, id, id as value, "" as selected, "" as disabled|id',
+		),
+
+		# 列表
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'audit' => 2,
+				'category' => array('yes', 'like'),
+				'top_category_id' => 'yes',
+				'second_category_id' => 'yes',
+				'category_id' => 'yes',
+				//'status' => 1,
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'desc'),
+			'limit' => '0,10',
+			//'page' => array(10, 'list'),
+			'col' => '*',
+		),
+
+		# 分页
+		'getPageAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'shop_id' => 'yes',
+				'brand_id' => 'yes',
+				'name' => array('yes', 'like'),
+				'audit' => 2,
+				'category' => array('yes', 'like'),
+				'top_category_id' => 'yes',
+				'second_category_id' => 'yes',
+				'category_id' => 'yes',
+				//'status' => 1,
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc', 'id' => 'desc'),
+			'page' => array(10, 'list'),
+			'col' => '*',
+		),
+		
+		# 更新浏览量
+		'addView' => array
+		(
+			'type' => 'update',
+			'where' => array
+			(
+				'id' => 'yes',
+			),
+			'set' => array
+			(
+				'num_view' => array('1', '+='),
+			),
+		),
+	),
+);
+
+return $config;

+ 132 - 0
database/info_attr.php

@@ -0,0 +1,132 @@
+<?php
+list($category, $attr, $table, $create) = getInfoAttr();
+
+//print_r($attr);die;
+$config = array
+(
+	# 表名
+	'name' => 'info_attr' . $table,
+	# 显示给用户看的名称
+	'lang' => '属性规格',
+	'order' => 100,
+	'menu' => false,
+	'create' => $create,
+	'attr' => $attr,
+	'auto' => 10000000,
+
+	'end' => array
+	(
+		'insert' => 'attr/lib/manage.update',
+		'update' => 'attr/lib/manage.update',
+	),
+
+	# 数据结构 不同的字段放这里
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'update'    => 'hidden',
+            'value'     => Dever::input('where_id')
+            //'list'        => true,
+		),
+
+		'info_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '商品',
+            'default'   => '',
+            'desc'      => '商品',
+            'match'     => 'is_numeric',
+            'update'    => 'hidden',
+            'value'     => Dever::input('search_option_info_id')
+        ),
+
+        'category'		=> array
+		(
+			'type' 		=> 'varchar-500',
+			'name' 		=> '分类-直接继承主表的分类',
+			'default' 	=> '',
+			'desc' 		=> '分类',
+			'match' 	=> 'is_string',
+			'update'    => 'hidden',
+            'value'     => $category
+		),
+
+		'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',
+		),
+		
+		# 版本号 更改版本号会更新当前表的索引
+		'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'),
+				//'status' => 1,
+				//'poster_pay_type' => array('yes-t_2.poster_pay_type', 2),
+				'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('reorder' => 'desc', 't_1.id' => 'desc'),
+			'page' => array(10, 'list'),
+			'col' => '*',
+		),
+	),
+);
+
+
+# 属性完全自定义吧。这种情况用dever就是方便了。其他框架都需要自己实现
+Dever::load('attr/api')->setDatabaseConfig($attr, $config);
+
+return $config;

+ 65 - 0
database/info_category.php

@@ -0,0 +1,65 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'info_category',
+	# 显示给用户看的名称
+	'lang' => '商品分类关联表',
+	'menu' => false,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'search'	=> 'order',
+			//'list'		=> true,
+		),
+		
+		'info_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '商品ID',
+			'default' 	=> '',
+			'desc' 		=> '商品ID',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'category_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})',
+		),
+	),
+
+	'manage' => array
+	(
+		'delete' => false,
+		'edit' => false,
+		'insert' => false,
+	),
+);

+ 126 - 0
database/info_sku.php

@@ -0,0 +1,126 @@
+<?php
+
+$config = array
+(
+	# 表名
+	'name' => 'info_sku',
+	# 显示给用户看的名称
+	'lang' => '商品价格设置',
+	'order' => 200,
+	'menu' => false,
+
+	# 数据结构 不同的字段放这里
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			//'list'		=> true,
+		),
+
+		'info_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '商品ID',
+			'default' 	=> '',
+			'desc' 		=> '商品ID',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'attr'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '属性组合规则',
+			'default' 	=> '',
+			'desc' 		=> '属性组合规则',
+			'match' 	=> 'is_string',
+			'update'	=> 'textarea',
+			'list'		=> true,
+		),
+
+		'price'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '售价',
+			'default' 	=> '',
+			'desc' 		=> '售价',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		's_price'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '售价',
+			'default' 	=> '',
+			'desc' 		=> '售价',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'num'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '库存',
+			'default' 	=> '',
+			'desc' 		=> '库存',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'reorder'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '排序-数值越大越靠前,相当于置顶',
+			'default' 	=> '1',
+			'desc' 		=> '请输入排序',
+			'match' 	=> 'option',
+			//'update'	=> 'text',
+			'search'	=> 'order',
+			'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
+    (
+        'insert' => false,
+        'edit' => false,
+        'delete' => false,
+        'num' => false,
+        'page_list_table' => 'sku',
+    ),
+);
+
+return $config;

+ 85 - 0
database/shop.php

@@ -0,0 +1,85 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'shop',
+	# 显示给用户看的名称
+	'lang' => '店铺管理',
+	# 是否显示在后台菜单
+	'order' => 1,
+
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'asc',
+			'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
+	(
+		
+	)
+);

+ 8 - 0
index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'goods');
+define('DEVER_APP_LANG', '商品管理');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 98);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-component');
+include(DEVER_APP_PATH . '../boot.php');

+ 335 - 0
lib/Info.php

@@ -0,0 +1,335 @@
+<?php
+
+# 核心类,数据获取类
+
+namespace Goods\Lib;
+
+use Dever;
+
+class Info
+{
+	private $table_info = 'goods/info';
+	private $table_attr = 'goods/info_attr';
+    /**
+     * instance
+     *
+     * @var string
+     */
+    protected static $instance;
+
+    /**
+     * init
+     *
+     * @return mixed
+     */
+    public static function init($top_category = false)
+    {
+        if (empty(self::$instance[$top_category])) {
+            self::$instance[$top_category] = new self($top_category);
+        }
+
+        return self::$instance[$top_category];
+    }
+
+	public function __construct($top_category = false)
+	{
+		$this->top_category = $top_category;
+
+        # 必有有分类才能进入到需求中
+        if (!$this->top_category) {
+            Dever::alert('错误的分类信息');
+        }
+	}
+
+    private function setAttr($cate, $order = 'list_reorder')
+    {
+        if ($order != 'list_reorder') {
+            Dever::config('base')->attrOrder = $order;
+        }
+        
+        Dever::setInput('search_option_category', $cate);
+        $attr = Dever::db($this->table_attr, array(), $cate);
+        return $attr;
+    }
+
+    public function getAttr($cate)
+    {
+        return Dever::load('attr/api')->getAttrByCate($cate, 'list');
+    }
+
+    # 根据分类获取需求列表数据
+    public function getData($cate = false, $limit = '0,10', $page = false, $attr = true)
+    {
+        if (!$limit) {
+            $limit = '0,10';
+        }
+        $where = $data = array();
+        if (!$cate) {
+            if ($this->top_category > 0) {
+                $where['top_category_id'] = $this->top_category;
+            }
+        } elseif (strstr($cate, ',')) {
+            $where['category'] = $this->top_category . ',' . $cate;
+        } else {
+            $where['second_category_id'] = $cate;
+        }
+        
+        if ($page) {
+            $method = 'getPageAll';
+        } else {
+            $where['limit'] = $limit;
+            $method = 'getAll';
+        }
+        $name = Dever::input('name');
+        if ($name) {
+            $where['name'] = $name;
+        }
+        $data = Dever::db($this->table_info)->$method($where);
+        if ($data && $attr) {
+            foreach ($data as $k => $v) {
+                $data[$k] = $this->info($v, 'list_reorder');
+            }
+        }
+
+        return $data;
+    }
+
+    # 根据属性获取需求列表数据 这里带有检索属性的功能 此处还需优化
+    public function getDataByAttr($cate = false, $where = array())
+    {
+        if (!$cate) {
+            Dever::alert('错误的分类信息');
+        }
+        $where_sql = array();
+        $name = Dever::input('name');
+        if ($name) {
+            //$where['name'] = $name;
+            $where_sql[] = ' t_2.name = "'.$name.'"';
+        }
+
+        $attr = $this->setAttr($this->top_category . ',' . $cate);
+        //print_r($attr->config['attr']);
+
+        $where_sql = Dever::load('attr/api')->getSql($attr->config['attr'], $where, $where_sql);
+        if (!$where_sql) {
+            return array();
+        }
+        # 这里用pdo的数据绑定,字符串字段的区间查询就是有问题。。。只能用sql了
+        //$data = $attr->getPageAll($where);
+
+        $page['template'] = 'list';
+        $page['num'] = 10;
+        $where_sql = implode(' and ', $where_sql);
+
+        $sql = 'SELECT t_2.* FROM `info_goods_'.$attr->config['name'].'` as t_1 Left Join `info_goods_info` AS t_2 ON t_1.`info_id`=t_2.`id` WHERE '.$where_sql.' order by t_2.`reorder` desc,t_2.`id` desc';
+
+        $data = $attr->fetchAll($sql, array(), $page);
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $data[$k] = $this->info($v, 'list_reorder');
+            }
+        }
+
+        return $data;
+    }
+
+	# 获取列表页的搜索条件
+    public function getSearch($cate = false)
+    {
+    	# 获取搜索条件
+        if (!$cate) {
+            $search_cate = $cate = $this->top_category;
+        } else {
+            $search_cate = $cate;
+        }
+        # 1是当前用户所在的城市,暂时写死
+        # 获取搜索条件
+        $search = Dever::load('attr/api')->getSearch($search_cate, true, 1, false, 2);
+        # 下级分类
+        $search['cate'] = Dever::load('category/api')->getList($cate);
+
+        # 上级分类
+        $search['parent_cate'] = Dever::load('category/api')->getList($this->top_category);
+        return $search;
+    }
+
+    public function getPayState($uid, $id, $category)
+    {
+        $pay_where['category'] = $category;
+        $pay = Dever::db('goods/pay')->one($pay_where);
+        $pay_state = 0;
+        if ($pay && $pay['num'] > 0) {
+            $pay_state = $pay['num'];
+        } elseif (strstr($category, ',')) {
+            $category = explode(',', $category);
+            $category = array_pop($category);
+            $pay_state = $this->getPayState($uid, $id, $category);
+        }
+
+        //$update['where_id'] = $id;
+        //$update['poster_pay_type'] = $pay_state;
+        //Dever::db($this->table_info)->update($update);
+
+        return $pay_state;
+    }
+
+    # 更新需求
+    public function update($top, $cate, $data, $id, $uid)
+    {
+        if ($cate) {
+            $category = $top . ',' . $cate;
+        } else {
+            $category = $top;
+        }
+        $attr = $this->setAttr($category);
+
+        $attr_update = Dever::preInput('attr_');
+        if ($attr_update) {
+            foreach ($attr_update as $k => $v) {
+                if (strstr($k, '_s')) {
+                    $k = str_replace('_s', '', $k);
+                    $attr_update[$k] = $v;
+                }
+                if (strstr($k, '_e')) {
+                    $k = str_replace('_e', '', $k);
+                    $attr_update[$k] .= ',' . $v;
+                }
+            }
+        }
+
+        $update = array();
+        $update['name'] = $data['name'];
+        $update['category'] = $category;
+        $update['pic'] = $data['pic'];
+        //$update['pic_cover'] = $data['pic'];
+        $update['poster_uid'] = $uid;
+        if (isset($data['view_price']) && $data['view_price']) {
+            $update['view_price'] = $data['view_price'];
+        }
+        if ($uid && $id) {
+            # 此处要判断是用户自己的
+            $info = Dever::db($this->table_info)->one($id);
+
+            /*
+            if ($uid == $info['poster_uid']) {
+                Dever::alert('错误的用户参数');
+            }
+            */
+            $update['where_id'] = $attr_update['where_id'] = $id;
+            Dever::db($this->table_info)->update($update);
+            Dever::db($this->table_attr)->update($attr_update);
+            $pay = 0;
+        } else {
+            $id = Dever::db($this->table_info)->insert($update);
+            $attr_update['category'] = $update['category'];
+            $attr_update['info_id'] = $id;
+            $attr_update['id'] = $id;
+            Dever::db($this->table_attr)->insert($attr_update);
+
+            # 验证是否需要支付,根据category判断
+            $pay = false;
+            //$pay = $this->getPayState($uid, $id, $category);
+
+            $info = Dever::db($this->table_info)->one($id);
+            $info = $this->getInfoLink($info);
+        }
+        return array('id' => $id, 'pay' => $pay, 'cate' => $category, 'top' => $top, 'info' => $info);
+    }
+
+    # 获取需求基本信息
+    public function getInfo($id, $attr = true, $order = 'view_reorder')
+    {
+        $info = Dever::db($this->table_info)->one($id);
+
+        if ($info && $attr) {
+            $info = $this->info($info, $order);
+        }
+
+        if ($info['poster_uid'] < 0) {
+            $info['poster_uid'] = 1;
+        }
+
+        if ($info['poster_uid'] > 0) {
+            $info['user'] = Dever::db('passport/user')->one($info['poster_uid']);
+            $sex = Dever::db('passport/user')->config['sex'];
+            if ($info['user']['area']) {
+                $info['user']['area'] = str_replace(',', '-', $info['user']['area']);
+                $info['user']['area'] .= '-';
+            }
+            $info['user']['text'] = $info['user']['area'] . $sex[$info['user']['sex']];
+
+            if (!$info['user']['avatar']) {
+                $config = Dever::db('main/config')->one();
+                $info['user']['avatar'] = $config['avatar'];
+            }
+        }
+
+        $info['num_view_text'] = $info['num_view'] + $info['num_add_view'];
+
+        $info['num_view_text'] .= '人浏览';
+
+        if ($info['pic']) {
+            $info['pic'] = explode(',', $info['pic']);
+        }
+        
+
+        return $info;
+    }
+
+    # 获取需求基本信息
+    public function info($info, $key = 'list_reorder')
+    {
+        $attr = $this->setAttr($info['category'], $key);
+        $attr_data = $attr->one($info['id']);
+        $info['category_array'] = Dever::load('category/api')->string($info['category']);
+
+        $info['attr'] = array();
+
+        if ($attr->config['attr']) {
+            foreach ($attr->config['attr'] as $k => $v) {
+                if (isset($v[$key]) && $v[$key] > 0) {
+                    if (isset($attr_data['attr_' . $v['id']])) {
+                        $v['value'] = $attr_data['attr_' . $v['id']];
+                    } else {
+                        continue;
+                        $v['value'] = '';
+                    }
+
+                    $v['value_string'] = Dever::load('attr/api')->getValue($v);
+                    
+                    if ($v['ename'] == 'price') {
+                        $info['price'] = $v['value_string'];
+                    } else {
+                        $v['bg'] = 'background-image: url('.$v['icon'].')';
+                        $v['pic'] = '<img src="'.$v['icon'].'" width="18" />';
+                        $info['attr'][] = $v;
+                    }
+                }
+            }
+        }
+       
+        if (isset($info['cdate']) && $info['cdate']) {
+            $info['cdate_string'] = Dever::mdate($info['cdate'], 2);
+        }
+
+        $info = $this->getInfoLink($info);
+        
+    	return $info;
+    }
+
+    public function getInfoLink($info)
+    {
+        if (isset($this->view_path)) {
+            $info['view_path'] = $this->view_path . '?top=' . $info['top_category_id'] . '&id=' . $info['id'];
+            $info['view_link'] = Dever::url($info['view_path']);
+        }
+
+        return $info;
+    }
+
+    public function setViewPath($path)
+    {
+        $this->view_path = $path;
+    }
+}

+ 222 - 0
lib/Manage.php

@@ -0,0 +1,222 @@
+<?php
+
+namespace Goods\Lib;
+
+use Dever;
+
+class Manage
+{
+    /**
+     * 更新信息
+     *
+     * @return mixed
+     */
+    public function infoUpdate($id, $name, $data)
+    {
+        # 更新分类id
+        $category = Dever::param('category', $data);
+        if ($category) {
+            if (is_array($category)) {
+                $category_id = end($category);
+                $top_category_id = $category[0];
+                if (isset($category[1])) {
+                    $second_category_id = $category[1];
+                } else {
+                    $second_category_id = $category[0];
+                }
+                
+            } else {
+                $category_id = $category;
+                $top_category_id = $category;
+                $second_category_id = $category;
+            }
+            
+
+            $update['top_category_id'] = $top_category_id;
+            $update['second_category_id'] = $second_category_id;
+            $update['category_id'] = $category_id;
+            
+        }
+
+        $pic = Dever::param('pic', $data);
+        $pic_cover = Dever::param('pic_cover', $data);
+        if ($pic && !$pic_cover) {
+            if (is_string($pic)) {
+                $pic = explode(',', $pic);
+            }
+            $update['pic_cover'] = $pic[0];
+        }
+
+        if (isset($update)) {
+            $update['where_id'] = $id;
+            Dever::db('goods/info')->update($update);
+        }
+    }
+
+    /**
+     * 更新需求属性信息
+     *
+     * @return mixed
+     */
+    public function attrUpdate($id, $name, $data)
+    {
+        print_r($data);die;
+        foreach ($data as $k => $v) {
+
+        }
+    }
+
+    /**
+     * 显示信息
+     *
+     * @return mixed
+     */
+    public function info($id)
+    {
+        $info = Dever::db('goods/info')->one($id);
+        if ($info) {
+            $table['编号'] = $info['id'];
+            $table['标题'] = $info['name'];
+            $table['分类'] = Dever::load("category/api.string", $info['category']);
+
+            if ($info['pic_cover']) {
+                $table['封面图'] = '<img src="'.$info['pic_cover'].'" width="150" />';
+            }
+
+            if ($info['shop_id'] > 0) {
+                $shop = Dever::load('goods/shop-one', $info['shop_id']);
+                $table['所属店铺'] = $shop['name'];
+            }
+
+            if ($info['brand_id'] > 0) {
+                $brand = Dever::load('goods/brand-one', $info['brand_id']);
+                $table['所属品牌'] = $brand['name'];
+            }
+
+            //$table['属性'] = $this->attrInfo($info);
+
+            if ($info['cdate']) {
+                $table['发布时间'] = date("Y-m-d H:i:s", $info['cdate']);
+            }
+        }
+
+        return Dever::table($table);
+    }
+
+    private function attrInfo($info)
+    {
+        $table = array();
+
+        $info = Info::init($info['top_category_id']);
+
+        if ($info) {
+            $info = $info->info($info, 'id');
+            if ($info && isset($info['attr'])) {
+                foreach ($info['attr'] as $k => $v) {
+                    $table[$v['name']] = $v['value_string'];
+                }
+            }
+        }
+        
+        return Dever::table($table);
+    }
+
+    public function area($id, $name, $data)
+    {
+        # 不再执行syncone等后续操作
+        Dever::config('base')->after = 1;
+
+        $type = Dever::input('type');
+
+        $area = Dever::param('area', $data);
+
+        if ($area) {
+
+            if (isset($area[2])) {
+                $update['district_id'] = $area[2];
+            }
+
+            if (isset($area[1])) {
+                $update['city_id'] = $area[1];
+            }
+
+            if (isset($area[0])) {
+                $update['province_id'] = $area[0];
+            }
+
+            if (isset($update)) {
+                $update['where_id'] = $id;
+
+                Dever::db($type . '/info')->update($update);
+            }
+        }
+    }
+
+    public function skuInput()
+    {
+        $id = Dever::input('search_option_info_id');
+
+        $info = Dever::db('goods/info')->one($id);
+
+        $info = Info::init(-1)->info($info, 'list_reorder');
+
+        if ($info['attr']) {
+            $head = '<thead><tr>';
+            $body = '<tbody>';
+            foreach ($info['attr'] as $k => $v) {
+                $head .= '<th>'.$v['name'].'</th>';
+            }
+
+            $head .= '<th>原价</th>';
+            $head .= '<th>现价</th>';
+            $head .= '<th>库存</th>';
+            $head .= '</tr></thead>';
+        }
+
+        $data = array(
+         array('白色','银色','玫瑰金'),
+         array('64G','128G'),
+         array('移动','电信','联通'),
+         array('国行','港版')
+        );
+
+        //打印结果
+        $result = $this->Cartesian($info['attr']);
+        print_r($result);die;
+
+       // print_r($option);die;
+
+        $html = $head . $body;
+
+        return $html;
+    }
+
+    function Cartesian($data){
+        $len = count($data);
+
+        // 取第一个集合数组值
+        $result = $data[0]['option'];
+        for ($i = 0; $i< $len-1; $i++) {
+            $arr1 = $result;
+            $result = [];
+            // 数组第一个值和第二个值组合
+            foreach ($arr1 as $res) {
+                //数组第二个值...$i+1
+                foreach($data[$i+1] as $k => $v){ 
+                    if(!is_array($res)) {
+                        $res = array($res);
+                    }
+                    if(!is_array($v)){
+                        $sec = array($v['option']);
+                    }
+                    $result[] = array_merge_recursive($res,$sec);
+                }
+            }
+
+        }
+
+        return $result;
+    }
+
+
+}

+ 363 - 0
src/Data.php

@@ -0,0 +1,363 @@
+<?php
+
+# 接口类
+
+namespace Goods\Src;
+
+use Dever;
+use Goods\lib\Info;
+use Main\Lib\Core;
+use Dever\Routing\Uri;
+
+class Data extends Core
+{
+    protected $checkUser = true;
+    # 列表页path
+    private $list_path = 'main/list';//'info/data.getList';//main/list
+    # 详情页path
+    private $view_path = 'main/view';//'info/data.getInfo';//main/view
+
+    private $info = false;
+    public function __construct()
+    {
+        # 当没有top时,就是首页
+        $this->top = Dever::input('top', -1);
+        if ($this->top) {
+            $this->info = Info::init($this->top);
+        }
+
+        # 当没有cate,但有top时就是顶级分类列表页,如果有cate,就是二级分类列表页
+        $this->cate = Dever::input('cate');
+
+        # 当有id时,就是详情页
+        $this->id = Dever::input('id');
+    }
+
+    # 获取顶级分类列表,首页用到
+    public function top()
+    {
+        $top = Dever::load('category/api')->getTop(Dever::config('base')->category);
+
+        $result = array();
+        if ($top) {
+            $cates = array_keys($top);
+
+            $child = Dever::load('category/api')->getChild($cates);
+            $i = 0;
+            $path = $this->list_path;
+            if (Uri::$value == 'submit') {
+                $path = 'submit_next';
+            }
+            foreach ($top as $k => $v) {
+                $result[$i] = $v;
+                $result[$i]['path'] = $path . '?top=' . $v['id'];
+                if (isset($child[$v['id']]) && $child[$v['id']][0]['level'] != -1) {
+                    $result[$i]['child'] = $child[$v['id']];
+                    if (Uri::$value == 'submit') {
+                        $result[$i]['path'] = 'submit_cate?top=' . $v['id'];
+                    } else {
+                        $result[$i]['path'] .= '&cate=' . $child[$v['id']][0]['id'];
+                    }
+                }
+
+                if ($v['status'] == 1) {
+                    $result[$i]['link'] = Dever::url($result[$i]['path']);
+                } else {
+                    $result[$i]['link'] = 'javascript:hui.toast(\'暂未开放\');';
+                }
+                
+                $i++;
+            }
+        }
+
+        return $result;
+    }
+
+    # 获取首页的分类和需求数据
+    # 接口:http://192.168.33.10/info/info/?l=data.getIndex
+    public function getIndex()
+    {
+        $top = Dever::load('goods/data.top');
+
+        if ($top) {
+            $this->cate = false;
+            foreach ($top as $k => $v) {
+                $this->info = Info::init($v['id']);
+                # 首页显示多少条需求数据,暂定10条
+                $top[$k]['data'] = $this->getList('0,10', $v);
+            }
+        }
+
+        return $top;
+    }
+
+    # 获取最新需求数据
+    # 接口:http://192.168.33.10/info/demand/?l=data.getNew
+    public function getNew()
+    {
+        $info = Info::init(-1);
+
+        $data = $info->getData($this->cate, '0,10', false, false);
+        return $data;
+
+        # 这里需要有用户信息
+        if ($data) {
+            $info->setViewPath($this->view_path);
+            foreach ($data as $k => $v) {
+                if ($v['poster_uid'] < 0) {
+                    $v['poster_uid'] = 1;
+                }
+
+                $data[$k] = $info->getInfoLink($v);
+                $link = $data[$k]['view_link'];
+                $data[$k]['user'] = Dever::db('passport/user')->one($v['poster_uid']);
+                $data[$k]['text'] = '<span class="cuIcon-notifcation"></span><a href="'.$link.'"><span class="text-blue">'.$data[$k]['user']['username'].'刚刚发布:</span>' . Dever::cut($v['name'], 10) . '</a>';
+            }
+        }
+
+        return $data;
+    }
+
+    # 获取搜索条件列表 分类列表页用到
+    # 接口:http://192.168.33.10/info/demand/?l=data.getSearch&top=1&cate=3,7&json=1
+    public function getSearch()
+    {
+        $this->checkInfo();
+        return $this->info->getSearch($this->cate);
+    }
+
+    # 获取搜索条件列表 分类列表页用到 只用到了搜索条件
+    # 接口:http://192.168.33.10/info/demand/?l=data.getSearchList&top=1&cate=3,7&json=1
+    public function getSearchList()
+    {
+        $data = $this->getSearch();
+
+        $result = array();
+        if ($data && $data['cate']) {
+            $result[0]['id'] = -1;
+            $result[0]['name'] = '分类';
+            $result[0]['option'] = $data['cate'];
+
+            $result = array_merge($result, $data['search']);
+        }
+
+        return $result;
+    }
+
+    public function getCateInfo()
+    {
+        $cate = $this->cate ? $this->cate : $this->top;
+        $data = Dever::db('category/info')->one($cate);
+
+        $name = Dever::input('name');
+
+        if ($name) {
+            $data['name'] = urldecode($name);
+        }
+
+        return $data;
+    }
+
+    # 获取分类子信息
+    public function getCateChild()
+    {
+        $data = Dever::load('category/api')->getChild($this->top);
+
+        if ($data) {
+            $data = $data[$this->top];
+            foreach ($data as $k => $v) {
+                $data[$k]['name'] = '我要' . $v['name'];
+                $path = 'submit_next?top=' . $this->top . '&cate=' . $v['id'] . '&name=' . urlencode($data[$k]['name']);
+                $data[$k]['link'] = Dever::url('main/' . $path);
+            }
+        }
+
+        return $data;
+    }
+
+    # 根据顶级分类或者二级分类,获取需求列表 分类列表页用到
+    # 接口:http://192.168.33.10/info/demand/?l=data.getList&top=1&cate=3,7&json=1&&attr_5=1&attr_2=9&attr_4=1
+    public function getList($limit, $cate = array())
+    {
+        $this->checkInfo();
+
+        $page = false;
+
+        if (!$limit) {
+            $page = true;
+        }
+
+        $where = Dever::preInput('attr_');
+
+        $this->info->setViewPath($this->view_path);
+
+        if ($where) {
+            $data = $this->info->getDataByAttr($this->cate, $where);
+        } else {
+            $data = $this->info->getData($this->cate, $limit, $page);
+        }
+
+        if (Dever::input('test') == 1) {
+            return $data;
+        }
+
+        if (!$cate) {
+            $cate = Dever::db('category/info')->one($this->top);
+        }
+
+        $data = array('data' => $data, 'cate' => $cate, 'top' => $this->top);
+        $data['show'] = false;
+        if ($cate && $this->top < 0) {
+            $data['show'] = true;
+        }
+        return Dever::render('render/list', $data, 'main');
+    }
+
+    # 获取当前用户的需求列表
+    # 接口:http://192.168.33.10/info/demand/?l=data.getUserList&top=-1
+    public function getUserList($limit)
+    {
+        $this->checkInfo();
+
+        $data = $this->info->getDataByUid($this->data['uid']);
+
+        return $data;
+    }
+
+    # 获取需求详情
+    # 接口:http://192.168.33.10/info/demand/?l=data.getInfo&top=1&json=1&id=10000000
+    public function getInfo()
+    {
+        if (!$this->id) {
+            Dever::alert('错误的参数,请重试');
+        }
+        $this->checkInfo();
+
+        $data = $this->info->getInfo($this->id);
+
+        $data['like'] = 2;
+        $data['tip'] = 2;
+        # 检查当前用户是否已收藏、已举报
+        if ($this->data['uid'] && $this->data['uid'] > 0) {
+            $data['like'] = Dever::load('service/lib/like')->get($this->data['uid'], $this->id, 1);
+        }
+        
+
+        return $data;
+    }
+
+    # 获取需求详情
+    # 接口:http://192.168.33.10/info/demand/?l=data.getInfo&top=1&json=1&id=10000000
+    public function getInfoPic()
+    {
+        $data = Dever::load('goods/data.getInfo');
+
+        if ($data['pic']) {
+            return $data['pic'];
+        }
+        return false;
+    }
+
+    # 获取需求详情
+    # 接口:http://192.168.33.10/info/demand/?l=data.getInfo&top=1&json=1&id=10000000
+    public function getInfoAttr()
+    {
+        $data = Dever::load('goods/data.getInfo');
+
+        if ($data['attr']) {
+            return $data['attr'];
+        }
+        return array();
+    }
+
+    # 获取更新需求时的字段
+    public function getUpdate()
+    {
+        $this->checkInfo();
+
+        if ($this->cate) {
+            $cate = $this->cate;
+            $category = $this->top . ',' . $cate;
+        } else {
+            $cate = $this->top;
+            $category = $this->top;
+        }
+        $cate = $this->cate ? $this->cate : $this->top;
+
+        $data = Dever::load('category/api')->getChild($cate);
+
+        if ($data) {
+            $data = $data[$cate];
+        }
+        $data = array('cate' => $data, 'category' => $category);
+
+        # 获取当前分类的属性
+        $attr = $this->info->getAttr($category);
+        $data['attr'] = '';
+        $data['attr_id'] = array();
+        if ($attr) {
+            foreach ($attr as $k => $v) {
+                $data['attr_id'][] = $v['id'];
+            }
+            $data['attr_id'] = implode(',', $data['attr_id']);
+            $data['attr'] = Dever::render('render/submit_attr', array('attr' => $attr), 'main');
+        }
+
+        return Dever::render('render/submit', $data, 'main');
+    }
+
+    # 获取分类下的属性
+    public function getAttr()
+    {
+        $category = Dever::input('category');
+        $attr_id = Dever::input('attr_id');
+
+        $attr = $this->info->getAttr($category);
+
+        if ($attr) {
+            $attr_id = explode(',', $attr_id);
+            foreach ($attr as $k => $v) {
+                if (in_array($v['id'], $attr_id)) {
+                    unset($attr[$k]);
+                }
+            }
+            if ($attr) {
+                return Dever::render('render/submit_attr', array('attr' => $attr), 'main');
+            }
+        }
+
+        echo '';die;
+    }
+
+    # 更新或者新增需求
+    # 接口:http://192.168.33.10/info/demand/?l=data.update&top=1&json=1&id=10000000&name=test&cate=1,3,9&attr_2=1
+    public function update()
+    {
+        $this->checkInfo();
+
+        if ($this->cate) {
+            $cate = $this->top . ',' . $this->cate;
+        } else {
+            $cate = $this->top;
+        }
+        $data['name'] = Dever::input('name');
+        if (!$data['name']) {
+            Dever::alert('请输入标题');
+        }
+        $data['pic'] = Dever::input('pic');
+        $data['view_price'] = Dever::input('view_price');
+        $this->info->setViewPath($this->view_path);
+        $data = $this->info->update($this->top, $this->cate, $data, $this->id, $this->data['uid']);
+
+        # 提交信息之后,验证是否需要支付
+        $url = $data['info']['view_link'];
+        return $url;
+    }
+
+    private function checkInfo()
+    {
+        if (!$this->info) {
+            Dever::alert('错误的参数,请重试');
+        }
+    }
+}

+ 119 - 0
src/Pay.php

@@ -0,0 +1,119 @@
+<?php
+
+# 支付类
+
+namespace Goods\Lib;
+
+use Dever;
+
+class Pay extends Data
+{
+	# 发需求需要支付
+    public function post_info()
+    {
+    	$this->action(1);
+    }
+
+    # 查看需求也需要支付
+    public function view_info()
+    {
+        $this->action(2);
+    }
+
+    private function action($type = 1)
+    {
+    	$this->checkDemand();
+        if (!$this->data['uid']) {
+            Dever::alert('错误的用户信息');
+        }
+
+        $product = $this->demand->getInfo($id, false);
+
+        $user = Dever::db('passport/user')->one($this->data['uid']);
+        $wechat = Dever::db('passport/wechat')->one(array('uid' => $this->data['uid'], 'type' => 1, 'system_id' => 1));
+
+        if ($this->source_type == 'ios') {
+            $method = 'apple';
+            $account_id = 3;
+            # 使用苹果内购支付
+            $receipt = Dever::input('receipt');
+            if (!$receipt) {
+                Dever::alert('苹果内购支付失败,没有receipt参数');
+            }
+        } elseif ($this->source_type == 'android') {
+            $method = 'app';
+            $account_id = 3;
+        } elseif ($this->source_type == 'applet') {
+            $method = 'applet';
+            $account_id = 1;
+        } else {
+        	# 默认是网页支付
+        	$method = 'page';
+        	$account_id = 2;
+        }
+
+        //$order_id = $this->createOrder('JP');
+        $order_data['category'] = $product['category'];
+        //$order_data['order_id'] = $order_id;
+        $order_data['product_id'] = $product['id'];
+        $order_data['uid'] = $this->data['uid']; 
+        $order_data['type'] = $type;
+
+        # 验证是否已经支付过
+        $one = Dever::db('demand/order')->one($order_data);
+
+        if (!$one) {
+            Dever::alert('您已经支付过了');
+        }
+
+        $order_data['status'] = 1;
+
+        $order_data['name'] = $product['name'];
+
+        if ($type == 1) {
+        	$cash = $this->demand->getPayState($this->data['uid'], $product['id'], $product['category']);
+
+        	$order_data['cash'] = $cash;
+        } else {
+        	$cash = $product['view_price'];
+        }
+
+        $id = Dever::db('demand/order')->insert($order_data);
+
+        if (!$id) {
+            Dever::alert('支付失败');
+        }
+
+        $order_id = $this->createOrderId($order_data, $id);
+
+        //$param参数
+        $param = array
+        (
+            'account_id' => $account_id,
+            'project_id' => 1,
+            'uid' => $this->data['uid'],
+            'username' => $user['username'],
+            'name' => $order_data['name'],
+            'cash' => $order_data['cash'],
+            'cash' => '0.01',
+            'openid' => $wechat['openid'],
+            'product_id' => $product['id'],
+            'order_id' => $order_id,
+        );
+
+        if ($method == 'apple') {
+            $param['other'] = $receipt;
+        }
+
+        $this->data['pay'] = Dever::load('pay/api.' . $method, $param);
+
+        $this->data['order_id'] = $order_id;
+
+        return $this->data;
+    }
+
+    private function createOrderId($data, $id)
+    {
+        
+    }
+}

+ 5 - 0
template/manage/sku.php

@@ -0,0 +1,5 @@
+<?php
+
+$view
+->fetch('#sku', 'goods/lib/manage.skuInput')
+->display();