dever 6 years ago
parent
commit
b085a25278

+ 20 - 0
act/database/comment.php

@@ -1,5 +1,6 @@
 <?php
 
+$page = 10;
 $table = Dever::config('base')->type;
 
 return array
@@ -105,4 +106,23 @@ return array
 		'insert' => false,
 		'edit' => false,
 	),
+
+	# request 请求接口定义
+	'request' => array
+	(
+		'getAll' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'data_id' => 'yes',
+				'type' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'page' => array($page, 'list'),
+			'col' => '*',
+		),
+	)
 );

+ 0 - 14
act/database/like.php

@@ -63,20 +63,6 @@ return array
 			'list'		=> 'Dever::load("act/lib/manage.load", "{type}", {data_id})',
 		),
 		
-		'content'		=> array
-		(
-			'type' 		=> 'text-255',
-			'name' 		=> '内容',
-			'update' 	=> 'editor',
-			'key'		=> 1,
-			'default' 	=> '',
-			'desc' 		=> '请输入内容',
-			'match' 	=> 'is_string',
-			'search'	=> 'fulltext',
-			'list'		=> 'table',
-			'modal'		=> '查看详情',
-		),
-		
 		'state'		=> array
 		(
 			'type' 		=> 'tinyint-1',

+ 10 - 0
act/database/share.php

@@ -76,6 +76,16 @@ return array
 			'list'		=> 'table',
 			'modal'		=> '查看详情',
 		),
+
+		'num' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '分享次数',
+			'default' 	=> '',
+			'desc' 		=> '分享次数',
+			'match' 	=> 'option',
+			'list'		=> true,
+		),
 		
 		'state'		=> array
 		(

+ 48 - 0
act/lib/Comment.php

@@ -0,0 +1,48 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+class Comment
+{
+    # 获取评论列表
+    public function get($id, $type)
+    {
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $data = Dever::db('act/comment')->getAll($where);
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $user = Dever::db('passport/api')->info($v['uid']);
+                $data[$k]['username'] = $user['username'];
+                $data[$k]['avatar'] = $user['avatar'];
+            }
+        }
+        return $data;
+    }
+
+    # 发表评论
+    public function submit($uid, $id, $type, $content)
+    {
+        $where['uid'] = $uid;
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $where['content'] = $content;
+        $info = Dever::db('act/comment')->one($where);
+        if (!$info) {
+            Dever::db('act/comment')->insert($where);
+        }
+
+        # 更新评论数
+        $where = array();
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $total = Dever::db('act/comment')->total($where);
+        $table = Dever::config('base')->type_table[$type];
+        Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
+
+        return true;
+    }
+}

+ 53 - 0
act/lib/Like.php

@@ -0,0 +1,53 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+class Like
+{
+    # 获取评论列表
+    public function get($id, $type)
+    {
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        $data = Dever::db('act/comment')->getAll($where);
+
+        if ($data) {
+            foreach ($data as $k => $v) {
+                $user = Dever::db('passport/api')->info($v['uid']);
+                $data[$k]['username'] = $user['username'];
+                $data[$k]['avatar'] = $user['avatar'];
+            }
+        }
+        return $data;
+    }
+
+    # 点赞+喜欢
+    public function submit($uid, $id, $type)
+    {
+        $where['uid'] = $uid;
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $info = Dever::db('act/like')->one($where);
+        if (!$info) {
+            Dever::db('act/live')->insert($where);
+        } else {
+            if ($info['state'] == 1) {
+                Dever::db('act/like')->update(array('where_id' => $info['id'], 'state' => 2));
+            } else {
+                Dever::db('act/like')->update(array('where_id' => $info['id'], 'state' => 1));
+            }
+        }
+
+        # 更新点赞数
+        $where = array();
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $total = Dever::db('act/like')->total($where);
+        $table = Dever::config('base')->type_table[$type];
+        Dever::db($table)->update(array('where_id' => $id, 'num_up' => $total));
+
+        return true;
+    }
+}

+ 52 - 0
act/lib/Share.php

@@ -0,0 +1,52 @@
+<?php
+
+namespace Act\Lib;
+
+use Dever;
+
+class Share
+{
+    # 获取某个用户在某个图文的分享回流数
+    public function getRefluxNum($uid, $id, $type)
+    {
+        $where['source_uid'] = $uid;
+        $where['type'] = $type;
+        $where['data_id'] = $id;
+        return Dever::db('act/share_reflux')->total($where);
+    }
+
+    # 提交分享
+    public function submit($uid, $id, $type)
+    {
+        $where['uid'] = $uid;
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $info = Dever::db('act/share')->one($where);
+        if (!$info) {
+            $where['num'] = 1;
+            Dever::db('act/share')->insert($where);
+        } else {
+            $where['num'] = $info['num'] + 1;
+            $where['where_id'] = $info['id'];
+            Dever::db('act/share')->update($where);
+        }
+
+        return true;
+    }
+
+    # 回流
+    public function submit_reflux($source_uid, $uid, $id, $type)
+    {
+        $where['source_uid'] = $source_uid;
+        $where['uid'] = $uid;
+        $where['data_id'] = $id;
+        $where['type'] = $type;
+        $info = Dever::db('act/share_reflux')->one($where);
+        if (!$info) {
+            Dever::db('act/share_reflux')->insert($where);
+            return true;
+        }
+
+        return false;
+    }
+}

+ 20 - 2
content/database/article.php

@@ -449,6 +449,7 @@ return array
 				'cate_id' => 'yes',
 				'name' => array('yes', 'like'),
 				'id' => 'yes',
+				'state' => 1,
 			),
 			'type' => 'all',
 			'order' => array('reorder' => 'desc', 'id' => 'desc'),
@@ -464,11 +465,28 @@ return array
 				'cate_id' => 'yes',
 				'cate_ids' => array('yes-cate_id', 'in'),
 				'id' => 'yes',
+				'state' => 1,
 			),
 			'type' => 'all',
-			'order' => array('id' => 'desc'),
+			'order' => array('reorder' => 'desc','id' => 'desc'),
 			'page' => array($page, 'list'),
-			'col' => '*',
+			'col' => 'id,name,pic_cover,pdate,num_add_view,num_view,num_up,num_add_up,num_comment,share_yes,share_title,share_pic,share_content,function,content',
+		),
+
+		'getRelation' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'cate_id' => 'yes',
+				'cate_ids' => array('yes-cate_id', 'in'),
+				'noid' => array('yes', '!='),
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('reorder' => 'desc','id' => 'desc'),
+			'limit' => '0,4',
+			'col' => 'id,name,pic_cover,pdate,num_add_view,num_view,num_up,num_add_up,num_comment,share_yes,share_title,share_pic,share_content,function,content',
 		),
 
 		'getOne' => array

+ 14 - 0
content/lib/Article.php

@@ -33,4 +33,18 @@ class Article
         
         return $data;
     }
+
+    # 获取相关推荐
+    public function getRelation($info)
+    {
+        $where['noid'] = $info['id'];
+        $where['cate_id'] = $info['cate_id'];
+        return Dever::db('content/article')->getRelation($where);
+    }
+
+    # 增加浏览量
+    public function addView($id)
+    {
+        Dever::db('content/article')->addView($id);
+    }
 }

+ 118 - 3
doc/apidoc.php

@@ -264,7 +264,7 @@
  * @apiParam {String} signature signature
  * @apiParam {Number} id 图文id
  *
- * @apiSuccess {Object[]} info 更多图文数据
+ * @apiSuccess {Object[]} info 图文数据
  * @apiSuccess {String}   info.id 
  * @apiSuccess {String}   info.name 名称
  * @apiSuccess {String}   info.pic_cover 图片
@@ -280,6 +280,13 @@
  * @apiSuccess {String}   info.function 开启的功能,这是一个字符串,用逗号隔开的,1代表显示浏览量,2代表显示评论,3代表显示喜欢,4代表显示邀请阅读,如值为1,2,3,则显示浏览量、评论、喜欢,不显示邀请阅读
  * @apiSuccess {String}   info.content 内容
  * @apiSuccess {String}   info.content_array 数组内容,请使用该字段循环
+ *
+ * @apiSuccess {Object[]} comment 评论列表
+ * @apiSuccess {String}   comment.id 
+ * @apiSuccess {String}   comment.username 用户名
+ * @apiSuccess {String}   comment.avatar 头像
+ * @apiSuccess {String}   comment.content 内容
+ * @apiSuccess {String}   comment.cdate 时间
  */
 
 /**
@@ -293,7 +300,43 @@
  * @apiParam {String} signature signature
  * @apiParam {Number} id 视频id
  *
- * @apiSuccess {Object[]} info 更多图文等数据
+ * @apiSuccess {Object[]} info 视频数据
+ * @apiSuccess {String}   info.id 
+ * @apiSuccess {String}   info.name 名称
+ * @apiSuccess {String}   info.pic_cover 图片
+ * @apiSuccess {String}   info.type 类型,参考公共参数中的类型设置说明中的type说明,根据它生成path
+ * @apiSuccess {String}   info.pdate 时间
+ * @apiSuccess {String}   info.num_view 浏览量
+ * @apiSuccess {String}   info.num_up 点赞量
+ * @apiSuccess {String}   info.num_comment 评论量
+ * @apiSuccess {String}   info.share_yes 是否显示分享按钮 1显示 2不显示
+ * @apiSuccess {String}   info.share_title 分享标题
+ * @apiSuccess {String}   info.share_pic 分享图片
+ * @apiSuccess {String}   info.share_content 分享内容
+ * @apiSuccess {String}   info.function 开启的功能,这是一个字符串,用逗号隔开的,1代表显示浏览量,2代表显示评论,3代表显示喜欢,4代表显示邀请阅读,如值为1,2,3,则显示浏览量、评论、喜欢,不显示邀请阅读
+ * @apiSuccess {String}   info.content 内容
+ *
+ *
+ * @apiSuccess {Object[]} comment 评论列表
+ * @apiSuccess {String}   comment.id 
+ * @apiSuccess {String}   comment.username 用户名
+ * @apiSuccess {String}   comment.avatar 头像
+ * @apiSuccess {String}   comment.content 内容
+ * @apiSuccess {String}   comment.cdate 时间
+ */
+
+/**
+ * @api {get} wonderful/main/?l=view.live 查看直播内容
+ * @apiVersion 1.0.0
+ * @apiName view.live
+ * @apiGroup Content
+ *
+ * @apiDescription 查看直播内容
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} id 视频id
+ *
+ * @apiSuccess {Object[]} info 直播数据
  * @apiSuccess {String}   info.id 
  * @apiSuccess {String}   info.name 名称
  * @apiSuccess {String}   info.pic_cover 图片
@@ -308,4 +351,76 @@
  * @apiSuccess {String}   info.share_content 分享内容
  * @apiSuccess {String}   info.function 开启的功能,这是一个字符串,用逗号隔开的,1代表显示浏览量,2代表显示评论,3代表显示喜欢,4代表显示邀请阅读,如值为1,2,3,则显示浏览量、评论、喜欢,不显示邀请阅读
  * @apiSuccess {String}   info.content 内容
- */
+ *
+ *
+ * @apiSuccess {Object[]} comment 评论列表
+ * @apiSuccess {String}   comment.id 
+ * @apiSuccess {String}   comment.username 用户名
+ * @apiSuccess {String}   comment.avatar 头像
+ * @apiSuccess {String}   comment.content 内容
+ * @apiSuccess {String}   comment.cdate 时间
+ */
+
+
+/**
+ * @api {get} wonderful/main/?l=user.submit_up 点赞
+ * @apiVersion 1.0.0
+ * @apiName user.submit_up
+ * @apiGroup UserAction
+ *
+ * @apiDescription 点赞
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} type type类型
+ * @apiParam {Number} id 当前的数据id
+ *
+ * @apiSuccess {String}  data ok
+ */
+
+/**
+ * @api {get} wonderful/main/?l=user.submit_share 分享
+ * @apiVersion 1.0.0
+ * @apiName user.submit_share
+ * @apiGroup UserAction
+ *
+ * @apiDescription 分享
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} type type类型
+ * @apiParam {Number} id 当前的数据id
+ *
+ * @apiSuccess {String}  data ok
+ */
+
+/**
+ * @api {get} wonderful/main/?l=user.submit_share_reflux 分享回流
+ * @apiVersion 1.0.0
+ * @apiName user.submit_share_reflux
+ * @apiGroup UserAction
+ *
+ * @apiDescription 分享回流
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} type type类型
+ * @apiParam {Number} id 当前的数据id
+ * @apiParam {String} source_signature 回流的源用户id
+ *
+ * @apiSuccess {String}  data ok
+ */
+
+/**
+ * @api {get} wonderful/main/?l=user.submit_comment 提交评论
+ * @apiVersion 1.0.0
+ * @apiName user.submit_comment
+ * @apiGroup UserAction
+ *
+ * @apiDescription 提交评论
+ *
+ * @apiParam {String} signature signature
+ * @apiParam {Number} type type类型
+ * @apiParam {Number} id 当前的数据id
+ * @apiParam {String} content 评论内容
+ *
+ * @apiSuccess {String}  data ok
+ */
+

+ 45 - 36
main/lib/Core.php

@@ -6,18 +6,23 @@ use Dever;
 
 class Core
 {
+    protected $checkUser = false;
     protected $data;
     public function __construct()
     {
         # 获取用户信息
-        //$this->data['uid'] = Dever::load('passport/applet')->check();
-        $this->data['uid'] = 1;
+        if ($this->checkUser) {
+            $this->data['uid'] = Dever::load('passport/applet')->check();
+        } else {
+            $this->data['uid'] = Dever::load('passport/applet')->check(false);
+            $this->data['uid'] = 1;
+        }
 
         # 获取基本配置
         $this->data['config'] = Dever::db('main/config')->one();
     }
 
-    # 根据类型,解析内容
+    # 列表页里的数据 根据类型,解析内容
     protected function content($data, $content = false)
     {
         $type = $id = false;
@@ -30,39 +35,7 @@ class Core
             $table = Dever::config('base')->type_table[$type];
             $info = Dever::db($table)->getOne($id);
             if ($info) {
-                $info['type'] = $type;
-                $info['data_id'] = $info['id'];
-                if (isset($info['content']) && !$content) {
-                    unset($info['content']);
-                }
-                if (isset($info['pdate']) && $info['pdate'] > 0) {
-                } else {
-                    $info['pdate'] = time();
-                }
-                $info['pdate'] = date('Y-m-d', $info['pdate']);
-
-                if (isset($info['num_add_view']) && isset($info['num_view'])) {
-                    $info['num_view'] = $info['num_add_view'] + $info['num_view'];
-                    unset($info['num_add_view']);
-                }
-                if (isset($info['num_add_up']) && isset($info['num_up'])) {
-                    $info['num_up'] = $info['num_add_up'] + $info['num_up'];
-                    unset($info['num_add_up']);
-                }
-                if (isset($info['num_add_user']) && isset($info['num_user'])) {
-                    $info['num_user'] = $info['num_add_user'] + $info['num_user'];
-                    unset($info['num_add_user']);
-                }
-                if (isset($info['num_add_user']) && isset($info['num_user'])) {
-                    $info['num_user'] = $info['num_add_user'] + $info['num_user'];
-                    unset($info['num_add_user']);
-                }
-                if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
-                    $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
-                    unset($info['num_add_ding']);
-                }
-
-                return $info;
+                return $this->getInfo($type, $info, $content);
             } else {
                 return (object) array();
             }
@@ -71,6 +44,42 @@ class Core
         return (object) array();
     }
 
+    protected function getInfo($type, $info, $content = false)
+    {
+        $info['type'] = $type;
+        $info['data_id'] = $info['id'];
+        if (isset($info['content']) && !$content) {
+            unset($info['content']);
+        }
+        if (isset($info['pdate']) && $info['pdate'] > 0) {
+        } else {
+            $info['pdate'] = time();
+        }
+        $info['pdate'] = date('Y-m-d', $info['pdate']);
+
+        if (isset($info['num_add_view']) && isset($info['num_view'])) {
+            $info['num_view'] = $info['num_add_view'] + $info['num_view'];
+            unset($info['num_add_view']);
+        }
+        if (isset($info['num_add_up']) && isset($info['num_up'])) {
+            $info['num_up'] = $info['num_add_up'] + $info['num_up'];
+            unset($info['num_add_up']);
+        }
+        if (isset($info['num_add_user']) && isset($info['num_user'])) {
+            $info['num_user'] = $info['num_add_user'] + $info['num_user'];
+            unset($info['num_add_user']);
+        }
+        if (isset($info['num_add_user']) && isset($info['num_user'])) {
+            $info['num_user'] = $info['num_add_user'] + $info['num_user'];
+            unset($info['num_add_user']);
+        }
+        if (isset($info['num_add_ding']) && isset($info['num_ding'])) {
+            $info['num_ding'] = $info['num_add_ding'] + $info['num_ding'];
+            unset($info['num_add_ding']);
+        }
+        return $info;
+    }
+
     protected function log()
     {
         $input = Dever::json_encode(Dever::input());

+ 101 - 0
main/src/User.php

@@ -0,0 +1,101 @@
+<?php
+
+namespace Main\Src;
+
+use Dever;
+use Main\Lib\Core;
+
+class User extends Core
+{
+    protected $checkUser = true;
+
+    # 我的页面
+    public function my()
+    {}
+
+    # 分享
+    public function submit_share()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的ID');
+        }
+        $type = Dever::input('type');
+        if (!$type) {
+            Dever::alert('错误的类型');
+        }
+
+        Dever::load('act/lib/share')->submit($this->data['uid'], $id, $type);
+
+        return 'ok';
+    }
+
+    # 回流
+    public function submit_share_reflux()
+    {
+        $source_signature = Dever::input('source_signature');
+
+        if (!$source_signature) {
+            Dever::alert('错误的来源uid');
+        }
+        $user = Dever::loginResult($source_signature);
+        if (!isset($user['uid'])) {
+            Dever::alert('错误的来源uid');
+        }
+
+        $source_uid = $user['uid'];
+
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的ID');
+        }
+        $type = Dever::input('type');
+        if (!$type) {
+            Dever::alert('错误的类型');
+        }
+
+        Dever::load('act/lib/share')->submit($source_uid, $id, $type, $this->data['uid']);
+
+        return 'ok';
+    }
+
+
+    # 点赞
+    public function submit_up()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的ID');
+        }
+        $type = Dever::input('type');
+        if (!$type) {
+            Dever::alert('错误的类型');
+        }
+
+        Dever::load('act/lib/like')->submit($this->data['uid'], $id, $type);
+
+        return 'ok';
+    }
+
+
+    # 发布评论
+    public function submit_comment()
+    {
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的ID');
+        }
+        $type = Dever::input('type');
+        if (!$type) {
+            Dever::alert('错误的类型');
+        }
+        $content = Dever::input('content');
+        if (!$content) {
+            Dever::alert('错误的内容');
+        }
+
+        Dever::load('act/lib/comment')->submit($this->data['uid'], $id, $type, $content);
+
+        return 'ok';
+    }
+}

+ 46 - 38
main/src/View.php

@@ -7,66 +7,74 @@ use Main\Lib\Core;
 
 class View extends Core
 {
-    # 获取图文详情
-    public function article()
+    # 获取评论列表
+    public function comment()
     {
-    	$id = Dever::input('id');
-    	if (!$id) {
-    		Dever::alert('错误的图文ID');
-    	}
-        $this->data['info'] = Dever::load('content/lib/article')->get($id);
-        if (!$this->data['info']) {
-        	Dever::alert('错误的图文ID');
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的ID');
+        }
+        $type = Dever::input('type');
+        if (!$type) {
+            Dever::alert('错误的类型');
         }
 
-        # 获取评论列表
-
-        # 获取相关推荐
-
-        # 获取当前用户分享数
+        $this->data['comment'] = Dever::load('act/lib/comment')->get($id, $type);
 
         return $this->data;
     }
 
-    # 获取视频详情
-    public function vod()
+    private function get($method, $name, $type = 1)
     {
-    	$id = Dever::input('id');
-    	if (!$id) {
-    		Dever::alert('错误的视频ID');
-    	}
-        $this->data['info'] = Dever::load('video/lib/vod')->get($id);
+        $id = Dever::input('id');
+        if (!$id) {
+            Dever::alert('错误的'.$name.'ID');
+        }
+        $this->data['info'] = Dever::load($method)->get($id);
         if (!$this->data['info']) {
-        	Dever::alert('错误的视频ID');
+            Dever::alert('错误的'.$name.'ID');
         }
 
         # 获取评论列表
+        $this->data['comment'] = Dever::load('act/lib/comment')->get($id, $type);
 
         # 获取相关推荐
+        $this->data['relation'] = Dever::load($method)->getRelation($this->data['info']);
+        if ($this->data['relation']) {
+            foreach ($this->data['relation'] as $k => $v) {
+                $this->data['relation'][$k] = $this->getInfo($type, $v);
+            }
+        }
 
         # 获取当前用户分享数
+        if ($this->data['uid'] > 0) {
+            $this->data['share'] = Dever::load('act/lib/share')->getRefluxNum($this->data['uid'], $id, $type);
+        } else {
+            $this->data['share'] = 0;
+        }
+        
+
+        # 浏览量+1
+        Dever::load($method)->addView($id);
 
         return $this->data;
     }
 
-    # 获取直播详情
-    public function live()
+    # 获取图文详情
+    public function article()
     {
-    	$id = Dever::input('id');
-    	if (!$id) {
-    		Dever::alert('错误的直播ID');
-    	}
-        $this->data['info'] = Dever::load('video/lib/live')->get($id);
-        if (!$this->data['info']) {
-        	Dever::alert('错误的直播ID');
-        }
-
-        # 获取评论列表
-
-        # 获取相关推荐
+    	return $this->get('content/lib/article', '图文', 1);
+    }
 
-        # 获取当前用户分享数
+    # 获取视频详情
+    public function vod()
+    {
+        return $this->get('video/lib/vod', '视频', 2);
+    }
 
-        return $this->data;
+    # 获取直播详情
+    public function live()
+    {
+    	return $this->get('video/lib/live', '直播', 3);
     }
 }