dever 4 سال پیش
والد
کامیت
4fae3dbd65
4فایلهای تغییر یافته به همراه420 افزوده شده و 0 حذف شده
  1. 95 0
      app/community/database/cate.php
  2. 207 0
      app/community/database/info.php
  3. 9 0
      app/community/index.php
  4. 109 0
      app/community/lib/Info.php

+ 95 - 0
app/community/database/cate.php

@@ -0,0 +1,95 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'cate',
+	# 显示给用户看的名称
+	'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
+	(
+
+	),
+
+	# 默认值
+	'default' => array
+	(
+		'col' => 'name,state,cdate',
+		'value' => array
+		(
+			'"默认类别",1,' . time(),
+		),
+	),
+
+	'request' => array
+	(
+		
+	)
+);

+ 207 - 0
app/community/database/info.php

@@ -0,0 +1,207 @@
+<?php
+
+$page = 10;
+$table = array
+(
+	1 => '合集',
+	2 => '合集章节',
+	3 => '合集内容',
+);
+
+$table_name = array
+(
+	1 => 'collection/info',
+	2 => 'collection/page',
+	3 => 'collection/content',
+);
+
+$cate = function()
+{
+	$array = array();
+	$info = Dever::load('attr/cate-state');
+	if($info)
+	{
+		$array += $info;
+	}
+	return $array;
+};
+
+
+return array
+(
+	# 表名
+	'name' => 'info',
+	# 显示给用户看的名称
+	'lang' => '社区信息管理',
+	# 是否显示在后台菜单
+	'order' => 80,
+	'config' => array
+	(
+		'table' => $table,
+		'table_name' => $table_name,
+	),
+	# 数据结构
+	'struct' => array
+	(
+		'id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> 'ID',
+			'default' 	=> '',
+			'desc' 		=> '',
+			'match' 	=> 'is_numeric',
+			'order'		=> 'desc',
+			//'list'		=> true,
+		),
+		
+
+		'uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '用户名',
+			'default' 	=> '0',
+			'desc' 		=> '请选择用户',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+			//'search'	=> 'select',
+			'search'    => array
+            (
+                'api' => 'passport/user-all',
+                'col' => 'username',
+                'result' => 'id',
+            ),
+			'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
+		),
+
+		'cate_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '所属类别',
+			'default' 	=> '1',
+			'desc' 		=> '所属类别',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'select',
+			'option'	=> $cate,
+			//'list'		=> '{cate_id} > 0 ? Dever::load("attr/cate-one#name", {cate_id}) : "未选择"',
+		),
+
+		'type' 		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '所属数据源',
+			'default' 	=> '',
+			'desc' 		=> '所属数据源',
+			'match' 	=> 'option',
+			'option' 	=> $table,
+			'search'	=> 'select',
+			'update'	=> 'select',
+			'list'		=> true,
+		),
+		
+		'type_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '数据源id',
+			'default' 	=> '',
+			'desc' 		=> '数据源id',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+
+		'type_name' 		=> array
+		(
+			'type' 		=> 'varchar-200',
+			'name' 		=> '数据源标题',
+			'default' 	=> '',
+			'desc' 		=> '数据源标题',
+			'match' 	=> 'option',
+			'search'	=> 'fulltext',
+			'update'	=> 'text',
+			'list'		=> true,
+		),
+
+		'num_up'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '点赞数',
+			'default' 	=> '0',
+			'desc' 		=> '点赞数',
+			'match' 	=> 'option',
+			//'search'	=> 'order',
+			'list'		=> true,
+		),
+		
+		'pic'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '图片-图片尺寸不等,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
+			'default' 	=> '',
+			'desc' 		=> '图片',
+			'match' 	=> 'is_string',
+			'update'	=> 'images',
+			'key' 		=> '1',
+		),
+
+		'content'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '内容',
+			'update' 	=> 'editor',
+			'key'		=> 1,
+			'default' 	=> '',
+			'desc' 		=> '请输入内容',
+			'match' 	=> 'is_string',
+			'search'	=> 'fulltext',
+			//'list'		=> 'table',
+			//'modal'		=> '查看详情',
+			'list'		=> 'Dever::load("community/lib/info.content", "{content}", {id})',
+		),
+		
+		'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,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'type' => array('yes', 'in'),
+				'type_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('cdate' => 'desc'),
+			'page' => array($page, 'list'),
+			'col' => '*',
+		),
+	)
+);

+ 9 - 0
app/community/index.php

@@ -0,0 +1,9 @@
+<?php
+
+define('DEVER_APP_NAME', 'community');
+define('DEVER_APP_LANG', '社区管理');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 100);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-reply-fill
+');
+include(DEVER_APP_PATH . '../boot.php');

+ 109 - 0
app/community/lib/Info.php

@@ -0,0 +1,109 @@
+<?php
+
+namespace Community\Lib;
+
+use Dever;
+
+class Info
+{
+    private function table($type)
+    {
+        $table = Dever::db('community/info')->config['type_name'][$type];
+        return $table;
+    }
+
+    # 获取列表
+    public function get($id, $type, $uid = false)
+    {
+        $where['type'] = $type;
+        $where['type_id'] = $id;
+        $table = $this->table($type);
+        $data = Dever::db($table)->getAll($where);
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $user = Dever::load('passport/api')->info($v['uid']);
+                $data[$k]['time'] = Dever::mdate($v['cdate'], 2);
+                $data[$k]['username'] = $user['username'];
+                $data[$k]['avatar'] = $user['avatar'];
+                $data[$k]['cdate_time'] = date('Y-m-d H:i:s', $v['cdate']);
+
+                # 检查是否点赞
+                if ($uid > 0) {
+                    $data[$k]['up'] = Dever::load('act/lib/like')->get($uid, $v['id'], 11);
+                } else {
+                    $data[$k]['up'] = 0;
+                }
+
+                $data[$k]['content'] = $this->getContent($v['content']);
+            }
+        }
+        return $data;
+    }
+
+    # 获取当前用户的信息列表
+    public function getList($uid)
+    {
+        $where['uid'] = $uid;
+        $where['type'] = '1,2,3';
+        $info = Dever::db('community/comment')->getAll($where);
+
+        if ($info) {
+            foreach ($info as $k => $v) {
+                $info[$k]['content'] = $this->getContent($v['content']);
+            }
+        }
+
+        return $info;
+    }
+
+    public function content($content, $id)
+    {
+        $content = $this->getContent($content);
+
+        return '<span class=dever-emoji>'.$content.'</span>';
+    }
+
+    public function getContent($content)
+    {
+        if (strstr($content, '_b64')) {
+            $content = str_replace('_b64', '', $content);
+            $content = base64_decode($content);
+        }
+
+        return $content;
+    }
+
+    # 发表信息
+    public function submit($uid, $id, $type, $content)
+    {
+        $where['uid'] = $uid;
+        $where['type_id'] = $id;
+        $where['type'] = $type;
+        $where['content'] = base64_encode($content) . '_b64';
+        $table = $this->table($type);
+        $info = Dever::db($table)->one($where);
+        $data_table = $this->table($type);
+        if (!$info) {
+            $data = Dever::db($data_table)->one($id);
+            if (isset($data['name']) && $data['name']) {
+                $where['type_name'] = $data['name'];
+            }
+            
+            Dever::db($table)->insert($where);
+        }
+        Dever::score($uid, 'submit_commit', '发表评论');
+
+        # 更新评论数
+        $where = array();
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $where['state'] = 1;
+        $total = Dever::db($table)->total($where);
+        //Dever::db($data_table)->update(array('where_id' => $id, 'num_comment' => $total));
+
+        
+
+        return true;
+    }
+}