dever 4 年之前
父節點
當前提交
6025b08cd1

+ 43 - 24
app/community/database/info.php

@@ -1,23 +1,7 @@
 <?php
 
-$page = 10;
-$table = array
-(
-	1 => '合集',
-	2 => '合集章节',
-	3 => '合集内容',
-	20 => '主信息',
-	21 => '子信息',
-);
-
-$table_name = array
-(
-	1 => 'collection/info',
-	2 => 'collection/page',
-	3 => 'collection/content',
-	20 => 'community/info',
-	21 => 'community/info',
-);
+$table = Dever::config('base')->table;
+$table_name = Dever::config('base')->table_name;
 
 $cate = function()
 {
@@ -39,7 +23,7 @@ return array
 	'lang' => '社区信息管理',
 	# 是否显示在后台菜单
 	'order' => 80,
-	'config' => array
+	'set' => array
 	(
 		'table' => $table,
 		'table_name' => $table_name,
@@ -77,6 +61,26 @@ return array
 			'list'		=> '{uid} > 0 ? Dever::load("passport/user-one#username", {uid}) : "匿名用户"',
 		),
 
+		'to_id'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '引用的信息id',
+			'default' 	=> '0',
+			'desc' 		=> '引用的信息id',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
+		'to_uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '引用的信息所属uid',
+			'default' 	=> '0',
+			'desc' 		=> '引用的信息所属uid',
+			'match' 	=> 'is_numeric',
+			'update'	=> 'text',
+		),
+
 		'cate_id'		=> array
 		(
 			'type' 		=> 'int-11',
@@ -221,13 +225,14 @@ return array
 			(
 				'uid' => 'yes',
 				'cate_id' => 'yes',
-				'type' => array('yes', 'in'),
+				'type' => 'yes',
 				'type_id' => 'yes',
+				'noid' => array('yes-id', '!='),
 				'state' => 1,
 			),
 			'type' => 'all',
-			'order' => array('id' => 'desc'),
-			'page' => array($page, 'list'),
+			'order' => array('num_up`-`num_oppose' => 'desc', 'id' => 'desc'),
+			'page' => array(5, 'list'),
 			'col' => '*',
 		),
 
@@ -238,14 +243,28 @@ return array
 			(
 				'uid' => 'yes',
 				'cate_id' => 'yes',
-				'type' => array('yes', 'in'),
+				'type' => 'yes',
 				'type_id' => 'yes',
 				'state' => 1,
 			),
 			'type' => 'all',
-			'order' => array('num_comment' => 'desc', 'id' => 'desc'),
+			'order' => array('num_up`-`num_oppose' => 'desc', 'id' => 'desc'),
 			'limit' => '0,1',
 			'col' => '*',
 		),
+
+		'getTotal' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'cate_id' => 'yes',
+				'type' => 'yes',
+				'type_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'count',
+		),
 	)
 );

+ 119 - 0
app/community/database/oppose.php

@@ -0,0 +1,119 @@
+<?php
+
+$table = Dever::config('base')->table;
+$table_name = Dever::config('base')->table_name;
+
+return array
+(
+	# 表名
+	'name' => 'oppose',
+	# 显示给用户看的名称
+	'lang' => '反对日志',
+	# 是否显示在后台菜单
+	'order' => 79,
+	'menu' => false,
+	# 数据结构
+	'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}) : "匿名用户"',
+		),
+
+		'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',
+		),
+		
+		'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,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'type_id' => 'yes',
+				'type' => array('yes', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'page' => array(15, 'list'),
+			'col' => 'uid,type,type_id,cdate',
+		),
+	)
+);

+ 119 - 0
app/community/database/up.php

@@ -0,0 +1,119 @@
+<?php
+
+$table = Dever::config('base')->table;
+$table_name = Dever::config('base')->table_name;
+
+return array
+(
+	# 表名
+	'name' => 'up',
+	# 显示给用户看的名称
+	'lang' => '点赞日志',
+	# 是否显示在后台菜单
+	'order' => 79,
+	'menu' => false,
+	# 数据结构
+	'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}) : "匿名用户"',
+		),
+
+		'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',
+		),
+		
+		'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,
+	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'uid' => 'yes',
+				'type_id' => 'yes',
+				'type' => array('yes', 'in'),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'page' => array(15, 'list'),
+			'col' => 'uid,type,type_id,cdate',
+		),
+	)
+);

+ 73 - 0
app/community/lib/Core.php

@@ -0,0 +1,73 @@
+<?php
+
+namespace Community\Lib;
+
+use Dever;
+
+class Core
+{
+    # 获取当前用户是否点赞
+    public function get($uid, $id, $type)
+    {
+        $where['uid'] = $uid;
+        $where['type'] = $type;
+        $where['type_id'] = $id;
+        $where['state'] = 1;
+        $info = Dever::db($this->table)->one($where);
+
+        if ($info) {
+            return true;
+        } else {
+            return false;
+        }
+    }
+
+    # 获取当前用户的数据列表
+    public function getList($uid)
+    {
+        $where['uid'] = $uid;
+        $info = Dever::db($this->table)->getAll($where);
+
+        return $info;
+    }
+
+    # 更新提交数据
+    public function submit($uid, $id, $type, $data = array())
+    {
+        if ($this->otable) {
+            $oinfo = Dever::load($this->otable)->get($uid, $id, $type);
+            if ($oinfo) {
+                Dever::alert('已经做过其他操作');
+            }
+        }
+        $where['uid'] = $uid;
+        $where['type_id'] = $id;
+        $where['type'] = $type;
+        $info = Dever::db($this->table)->one($where);
+        if ($data) {
+            $where += $data;
+        }
+        if (!$info) {
+            Dever::db($this->table)->insert($where);
+        } else {
+            if ($info['state'] == 1) {
+                Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 2));
+            } else {
+                Dever::db($this->table)->update(array('where_id' => $info['id'], 'state' => 1));
+            }
+        }
+
+        # 更新点赞数
+        $where = array();
+        $where['type_id'] = $id;
+        $where['type'] = $type;
+        $where['state'] = 1;
+        $total = Dever::db($this->table)->total($where);
+        $table = Dever::config('base')->table_name[$type];
+        $state = Dever::db($table)->update(array('where_id' => $id, 'num_' . $this->name => $total));
+
+        Dever::score($uid, 'submit_' . $this->name, $this->lang);
+
+        return true;
+    }
+}

+ 89 - 51
app/community/lib/Info.php

@@ -8,53 +8,34 @@ class Info
 {
     private function table($type)
     {
-        $table = Dever::db('community/info')->config['type_name'][$type];
+        $table = Dever::db('community/info')->config['set']['table_name'][$type];
         return $table;
     }
 
-    # 获取列表
-    public function get($id, $type, $uid = false)
+    public function getData($method = 'getAll', $uid, $cate_id = false, $type = false, $type_id = false, $total = false, $id = false)
     {
+        # 获取分类下的帖子
+        $where['cate_id'] = $cate_id;
         $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']);
+        $where['type_id'] = $type_id;
+        if ($id > 0) {
+            $where['noid'] = $id;
+        }
+        $data['info'] = Dever::db('community/info')->$method($where);
+        if ($total) {
+            if ($method == 'getAll') {
+                $data['total'] = Dever::total();
+            } else {
+                $data['total'] = Dever::db('community/info')->getTotal($where);
             }
         }
-        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']);
+        if ($data['info']) {
+            foreach ($data['info'] as $k => $v) {
+                $data['info'][$k] = $this->one($uid, $v);
             }
         }
 
-        return $info;
+        return $data;
     }
 
     public function content($content, $id)
@@ -75,14 +56,25 @@ class Info
     }
 
     # 发表信息
-    public function submit($uid, $id, $type, $content)
+    public function submit($uid, $cate_id, $id, $type, $pic, $content, $to_id, $to_uid)
     {
         $where['uid'] = $uid;
+        $where['cate_id'] = $cate_id;
         $where['type_id'] = $id;
         $where['type'] = $type;
-        $where['content'] = base64_encode($content) . '_b64';
-        $table = $this->table($type);
-        $info = Dever::db($table)->one($where);
+        $where['content'] = $content;
+        $table = 'community/info';
+        //$info = Dever::db($table)->one($where);
+        $info = false;
+        if ($pic) {
+            $where['pic'] = $pic;
+        }
+        if ($to_id) {
+            $where['to_id'] = $to_id;
+        }
+        if ($to_uid) {
+            $where['to_uid'] = $to_uid;
+        }
         $data_table = $this->table($type);
         if (!$info) {
             $data = Dever::db($data_table)->one($id);
@@ -91,19 +83,65 @@ class Info
             }
             
             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));
+            Dever::score($uid, 'submit_community', '发表帖子');
 
-        
+            # 更新评论数
+            $where = array();
+            $where['type_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;
     }
+
+    private function one($uid, $info)
+    {
+        $info['pic'] = explode(',', $info['pic']);
+        $info['user'] = Dever::load('passport/api')->info($info['uid']);
+        $info['cdate_string'] = Dever::mdate($info['cdate'], 2);
+
+        # 点赞数
+        $info['num_up'] = $info['num_up'] + 0;
+
+        # 反对数
+        $info['num_oppose'] = $info['num_oppose'] + 0;
+
+        $info['is_up'] = $info['is_oppose'] = false;
+
+        if ($uid) {
+            # 是否点赞
+            $info['is_up'] = Dever::load('community/lib/up')->get($uid, $info['id'], 20);
+
+            # 是否反对
+            $info['is_oppose'] = Dever::load('community/lib/oppose')->get($uid, $info['id'], 20);
+        }
+
+        # 评论数
+        $info['num_comment'] = $info['num_comment'] + 0;
+
+        # 获取引用的数据
+        $info['to_user'] = array();
+        if ($info['to_uid']) {
+            $info['to_user'] = Dever::load('passport/api')->info($info['to_uid']);
+        }
+
+        # 获取热门的子信息
+        $info['child'] = array();
+        if ($info['type'] < 20) {
+            $child = $this->getData('getHot', $uid, $info['cate_id'], 20, $info['id'], true, 1);
+            if ($child && $child['info']) {
+                $info['child'] = $child['info'];
+                $info['child_total'] = $child['total'];
+            }
+        }
+
+        # 获取最新的服务器时间
+        $info['server_time'] = time();
+
+        return $info;
+    }
 }

+ 14 - 0
app/community/lib/Oppose.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace Community\Lib;
+
+use Dever;
+
+class Oppose extends Core
+{
+    protected $lang = '反对';
+    protected $name = 'oppose';
+    protected $table = 'community/oppose';
+    # 互斥的table
+    protected $otable = 'community/lib/up';
+}

+ 14 - 0
app/community/lib/Up.php

@@ -0,0 +1,14 @@
+<?php
+
+namespace Community\Lib;
+
+use Dever;
+
+class Up extends Core
+{
+    protected $lang = '点赞';
+    protected $name = 'up';
+    protected $table = 'community/up';
+    # 互斥的table
+    protected $otable = 'community/lib/oppose';
+}

+ 63 - 64
app/community/src/Api.php

@@ -6,6 +6,14 @@ use Dever;
 
 class Api
 {
+	public function __construct()
+	{
+        $this->uid = 1;
+		$this->cate_id = Dever::input('cate_id');
+        $this->type = Dever::input('type', 3);
+        $this->type_id = Dever::input('type_id', 1);
+	}
+
     # 获取社区下的分类
     public function category()
     {
@@ -21,79 +29,70 @@ class Api
     # 获取社区下的帖子
     public function info()
     {
-    	# 获取分类下的帖子
-    	$where['cate_id'] = Dever::input('cate_id');
-        $where['type'] = Dever::input('type', 3);
-        $where['type_id'] = Dever::input('type_id', 1);
-        $data['info'] = Dever::db('community/info')->getAll($where);
-    	if ($data['info']) {
-    		foreach ($data['info'] as $k => $v) {
-    			$data['info'][$k] = $this->one($v);
-    		}
-    	}
-
-        return $data;
-    }
-
-    # 获取社区下的热门帖子
-    public function hot()
-    {
-    	# 获取分类下的帖子
-    	$where['cate_id'] = Dever::input('cate_id');
-        $where['type'] = Dever::input('type', 3);
-        $where['type_id'] = Dever::input('type_id', 1);
-        $data['info'] = Dever::db('community/info')->getHot($where);
-    	if ($data['info']) {
-    		foreach ($data['info'] as $k => $v) {
-    			$data['info'][$k] = $this->one($v);
-    		}
-    	}
-
+    	$id = Dever::input('id');
+    	$data = Dever::load('community/lib/info')->getData('getAll', $this->uid, $this->cate_id, $this->type, $this->type_id, false, $id);
         return $data;
     }
 
     # 发布信息
     public function add()
     {
-    	$data['uid'] = 1;
-    	$data['content'] = Dever::input('content');
-    	if (!$data['content']) {
-    		Dever::alert('请填写内容');
-    	}
-    	$data['pic'] = Dever::input('pic');
-    	$data['cate_id'] = Dever::input('cate_id');
-    	$data['type'] = Dever::input('type');
-    	$data['type_id'] = Dever::input('type_id');
-    	if (!$data['cate_id'] || !$data['type'] || !$data['type_id']) {
-    		Dever::alert('错误的信息');
-    	}
-
-    	Dever::db('community/info')->insert($data);
-
-    	return 'yes';
+        $pic = Dever::input('pic');
+        $content = Dever::input('content');
+        if (!$content) {
+            Dever::alert('请填写内容');
+        }
+
+        $cate_id = Dever::input('cate_id');
+        if (!$cate_id) {
+            Dever::alert('错误的信息');
+        }
+    	$type_id = Dever::input('type_id');
+        if (!$type_id) {
+            Dever::alert('错误的信息');
+        }
+        $type = Dever::input('type');
+        if (!$type) {
+            Dever::alert('错误的信息');
+        }
+
+        $to_id = Dever::input('to_id');
+        $to_uid = Dever::input('to_uid');
+        
+        Dever::load('community/lib/info')->submit($this->uid, $cate_id, $type_id, $type, $pic, $content, $to_id, $to_uid);
+
+        return 'yes';
     }
 
-    private function one($info)
+    # 点赞
+    public function up()
     {
-    	$info['pic'] = explode(',', $info['pic']);
-    	$info['user'] = Dever::load('passport/api')->info($info['uid']);
-    	$info['cdate_string'] = Dever::mdate($info['cdate'], 2);
-
-    	# 点赞数
-    	$info['num_up'] = $info['num_up'] + 0;
-
-    	# 反对数
-    	$info['num_oppose'] = $info['num_oppose'] + 0;
-
-    	# 是否点赞
-    	$info['is_up'] = false;
-
-    	# 是否反对
-    	$info['is_oppose'] = false;
-
-    	# 评论数
-    	$info['num_comment'] = $info['num_comment'] + 0;
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的信息');
+        }
+        $type = Dever::input('type', 20);
+        if (!$type) {
+            Dever::alert('错误的信息');
+        }
+        Dever::load('community/lib/up')->submit($this->uid, $id, $type);
+
+        return 'yes';
+    }
 
-    	return $info;
+    # 反对
+    public function oppose()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的信息');
+        }
+        $type = Dever::input('type', 20);
+        if (!$type) {
+            Dever::alert('错误的信息');
+        }
+        Dever::load('community/lib/oppose')->submit($this->uid, $id, $type);
+
+        return 'yes';
     }
 }

+ 10 - 4
config/base.php

@@ -11,15 +11,21 @@ $config['base'] = array
     'top' => 'passport/system_id',
 
     # 设置类型
-    'type' => array
+    'table' => array
     (
-        1 => '需求',
+        1 => '合集',
+        2 => '合集章节',
+        3 => '合集内容',
+        20 => '信息',
     ),
 
     # 功能类型
-    'type_table' => array
+    'table_name' => array
     (
-        1 => 'demand/info',
+        1 => 'collection/info',
+        2 => 'collection/page',
+        3 => 'collection/content',
+        20 => 'community/info',
     ),
 
     'audit' => array