dever %!s(int64=4) %!d(string=hai) anos
pai
achega
d025edca10

+ 1 - 1
app/collection/database/function.php

@@ -10,7 +10,7 @@ $type = array
     //'befall' 	=> '降临',
     //'music' 	=> '音乐',
     //'ranking' 	=> '排行',
-    //'my'    => '我的',
+    'my'    => '个人',
     'share'     => '分享',
 );
 

+ 155 - 0
app/collection/database/user.php

@@ -0,0 +1,155 @@
+<?php
+
+$sex = array
+(
+	1 => '男',
+	2 => '女',
+	3 => '未知',
+);
+
+return array
+(
+    # 表名
+    'name' => 'user',
+    # 显示给用户看的名称
+    'lang' => '用户扩展信息表',
+    'menu' => false,
+    # 数据结构
+    'struct' => array
+    (
+    
+        'id'        => array
+        (
+            'type'      => 'int-11',
+            'name'      => 'ID',
+            'default'   => '',
+            'desc'      => '',
+            'match'     => 'is_numeric',
+            'search'    => 'order',
+            'update'    => 'hidden',
+            //'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}) : "匿名用户"',
+		),
+
+        'info_id'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '合集',
+            'default'   => '',
+            'desc'      => '合集',
+            'match'     => 'is_numeric',
+            'update'    => 'text',
+        ),
+
+        'username'		=> array
+		(
+			'type' 		=> 'varchar-50',
+			'name' 		=> '用户名',
+			'default' 	=> '',
+			'desc' 		=> '请输入用户名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'avatar'		=> array
+		(
+			'type' 		=> 'varchar-150',
+			'name' 		=> '头像',
+			'default' 	=> '',
+			'desc' 		=> '请选择头像',
+			'match' 	=> 'option',
+			'update'	=> 'image',
+			'key' 		=> '1',
+			'place'		=> '150',
+			'list_name'	=> '详细信息',
+			//'list'		=> '"{avatar}" ? "<img src=\'{avatar}\' width=\'150\'>": ""',
+			'list'		=> 'Dever::load("passport/lib/manage.show", {id})',
+		),
+
+		'sex'		=> array
+		(
+			'type' 		=> 'tinyint-1',
+			'name' 		=> '用户性别',
+			'default' 	=> '3',
+			'desc' 		=> '用户性别',
+			'match' 	=> 'is_numeric',
+			'option' 	=> $sex,
+			'update'	=> 'radio',
+			//'list'		=> true,
+		),
+
+		'title'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '头衔',
+			'default' 	=> '',
+			'desc' 		=> '请输入头衔',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> true,
+		),
+
+		'info'		=> array
+		(
+			'type' 		=> 'varchar-800',
+			'name' 		=> '签名-描述',
+			'default' 	=> '',
+			'desc' 		=> '签名',
+			'match' 	=> 'is_string',
+			'update'	=> 'text',
+			'search'	=> 'fulltext',
+			'list'		=> 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
+    (
+        
+    ),
+);

+ 26 - 0
app/collection/lib/Core.php

@@ -26,6 +26,11 @@ class Core
         $this->user = Dever::load('passport/api')->info($this->uid);
     }
 
+    protected function checkInfo()
+    {
+        return Dever::db('collection/info')->one($this->id);
+    }
+
     protected function checkCode()
     {
         $this->code = Dever::input('code');
@@ -132,4 +137,25 @@ class Core
 
         return $where;
     }
+
+    # 获取按钮的样式
+    protected function button($info)
+    {
+        $button = array(
+            'bgcolor' => 'background: linear-gradient(to right, #000000,#000000) !important;color:#fff;',
+            'color' => 'color:#fff',
+            'name' => array('入口', '排行榜')
+        );
+
+        $button['name'] = explode(',', $info['button']);
+        if ($info['button_bgcolor'] && $info['button_bgjcolor']) {
+            $button['bgcolor'] = 'background: linear-gradient(to right, '.$info['button_bgcolor'].','.$info['button_bgjcolor'].') !important;';
+        }
+        if ($info['button_ftcolor']) {
+            $button['color'] = 'color:' . $info['button_ftcolor'];
+            $button['bgcolor'] .= $button['color'];
+        }
+
+        return $button;
+    }
 }

+ 38 - 0
app/collection/lib/Times.php

@@ -6,6 +6,7 @@ use Dever;
 
 class Times
 {
+    private $times = false;
     /**
      * 获取所有数据
      *
@@ -35,4 +36,41 @@ class Times
 
     	return $parent['name'] . '·' . $info['name'];
     }
+
+    # 获取当前时间
+    public function getDate($day, $cdate, $times = false, $array = false)
+    {
+        if (!$this->times && $times && $times > 0) {
+            $this->times = Dever::db('collection/times')->one($times);
+        }
+
+        if ($day > 0) {
+            if ($this->times && $this->times['year']) {
+                $year = $this->times['year'];
+            } else {
+                $year = substr($day,0,4);
+            }
+            
+            $month = substr($day,4,2);
+            $day = substr($day,6,2);
+            $string = $year . '-' . $month . '-' . $day;
+        } elseif ($this->times && $this->times['year']) {
+            $string = $this->times['year'] . '-m-d';
+        } else {
+            $string = 'Y-m-d';
+        }
+
+        $cdate = date($string . ' H:i', $cdate);
+
+        if ($array) {
+            $temp = explode(' ', $cdate);
+            $cdate = array
+            (
+                $temp[0],
+                $temp[1]
+            );
+        }
+
+        return $cdate;
+    }
 }

+ 36 - 0
app/collection/lib/User.php

@@ -0,0 +1,36 @@
+<?php
+
+namespace Collection\Lib;
+
+use Dever;
+
+class User
+{
+	# 获取用户信息
+	public function get($user, $id)
+	{
+		if (is_numeric($user)) {
+			$user = Dever::load('passport/api')->info($user);
+		}
+		$result = array();
+		if ($user) {
+			# 获取合集扩展信息
+	        $result = Dever::db('collection/user')->one(array('uid' => $user['id'], 'info_id' => $id));
+	        if (!$result) {
+	        	$result['uid'] = $user['id'];
+	            $result['username'] = $user['username'];
+	            $result['avatar'] = $user['avatar'];
+	            $result['info'] = $user['info'];
+	            $result['sex'] = $user['sex'];
+	            $result['title'] = '';
+	        } else {
+	        	!$result['username'] && $result['username'] = $user['username'];
+	        	!$result['avatar'] && $result['avatar'] = $user['avatar'];
+	        	!$result['info'] && $result['info'] = $user['info'];
+	        	!$result['sex'] && $result['sex'] = $user['sex'];
+	        }
+		}
+		
+		return $result;
+	}
+}

+ 1 - 41
app/collection/src/Api.php

@@ -32,22 +32,7 @@ class Api extends Core
         return 1;
     }
 
-    # 获取用户信息
-    public function getUser()
-    {
-        $data['user'] = $this->user;
-
-        $data['num'] = array
-        (
-            array('¥199', '', '钱包'),
-            array('200', '', '金币'),
-            array('10', '', '好友'),
-            array('30', '', '动态'),
-        );
-
-        return $data;
-    }
-
+    # 获取二维码
     public function qrcode($url, $content_id)
     {
         $file = 'shareDv_' . $this->uid . '_' . $this->id . '_' . $content_id;
@@ -56,11 +41,6 @@ class Api extends Core
         return $file['url'];
     }
 
-    private function checkInfo()
-    {
-        return Dever::db('collection/info')->one($this->id);
-    }
-
     public function getUrl($url)
     {
         # 转成短域名
@@ -219,26 +199,6 @@ class Api extends Core
         return $data;
     }
 
-    private function button($info)
-    {
-        $button = array(
-            'bgcolor' => 'background: linear-gradient(to right, #000000,#000000) !important;color:#fff;',
-            'color' => 'color:#fff',
-            'name' => array('入口', '排行榜')
-        );
-
-        $button['name'] = explode(',', $info['button']);
-        if ($info['button_bgcolor'] && $info['button_bgjcolor']) {
-            $button['bgcolor'] = 'background: linear-gradient(to right, '.$info['button_bgcolor'].','.$info['button_bgjcolor'].') !important;';
-        }
-        if ($info['button_ftcolor']) {
-            $button['color'] = 'color:' . $info['button_ftcolor'];
-            $button['bgcolor'] .= $button['color'];
-        }
-
-        return $button;
-    }
-
     # 获取合集下的内容
     public function getContent()
     {

+ 3 - 16
app/collection/src/Pay.php

@@ -14,17 +14,6 @@ class Pay extends Core
             Dever::alert('用户信息错误');
         }
 
-        # 直接支付成功 测试用
-        $send['pay_order_id'] = '13Q9EAPMVRCNFH3TKP5Q2IFE0I';
-        $send['pay_status'] = 2;
-        $send['pay_msg'] = 'yes';
-        $send['dever_token'] = 'goods_dever_2020';
-        $data = Dever::load('goods/lib/pay.success', $send);
-
-        print_r($data);die;
-
-        return;
-
         $uid = $this->user['id'];
 
         $content_id = Dever::input('content_id');
@@ -37,12 +26,10 @@ class Pay extends Core
             Dever::alert('请传入正确的产品ID');
         }
 
-        $info = Dever::db('collection/info')->one($this->id);
-        if ($info['score_type']) {
-            
-        }
-
         $pay = Dever::load('goods/lib/pay')->action($this->share_uid, $uid, $goods_id, $sku, $num, $source, 'collection/info', $this->id);
+
+        //return $pay;
+
         # 直接支付成功 测试用
         $send['pay_order_id'] = $pay['order_id'];
         $send['pay_status'] = 2;

+ 91 - 0
app/collection/src/User.php

@@ -0,0 +1,91 @@
+<?php
+
+namespace Collection\Src;
+
+use Dever;
+use Collection\Lib\Core;
+
+class User extends Core
+{
+    public function __construct()
+    {
+        parent::__construct();
+    }
+
+    # 获取用户信息
+    public function get()
+    {
+        $info = $this->checkInfo();
+
+        # 获取合集扩展信息
+        $data['user'] = Dever::load('collection/lib/user')->get($this->uid, $this->id);
+
+        $score = Dever::load('score/lib/core')->getUserScore($this->uid);
+        if ($score) {
+            $data['num'][0] = array('¥' . $score['score'], '', $score['name']);
+        }
+        $score = Dever::load('score/lib/core')->getUserScore($this->uid, $info['score_id'], 'collection/info', $info['id']);
+        if ($score) {
+            $data['num'][1] = array($score['score'], '', $score['name']);
+        }
+
+        //$data['num'][2] = array('10', '', '好友');
+        //$data['num'][3] = array('30', '', '动态');
+
+        return $data;
+    }
+
+    # 保存用户信息
+    public function up()
+    {
+    	$update['username'] = Dever::input('name');
+    	if (!$update['username']) {
+    		Dever::alert('昵称不能为空');
+    	}
+    	$update['title'] = Dever::input('title');
+    	$update['info'] = Dever::input('info');
+    	$update['info_id'] = $this->id;
+    	$user = Dever::db('collection/user')->one(array('uid' => $this->uid));
+        if (!$user) {
+        	$update['uid'] = $this->uid;
+            Dever::db('collection/user')->insert($update);
+        } else {
+        	$update['where_id'] = $user['id'];
+        	Dever::db('collection/user')->update($update);
+        }
+        return 'ok';
+    }
+
+    # 保存头像
+    public function upAvatar()
+    {
+    	$update['avatar'] = Dever::input('avatar');
+    	if (!$update['avatar']) {
+    		Dever::alert('头像不能为空');
+    	}
+    	$update['info_id'] = $this->id;
+    	$user = Dever::db('collection/user')->one(array('uid' => $this->uid));
+        if (!$user) {
+        	$update['uid'] = $this->uid;
+            Dever::db('collection/user')->insert($update);
+        } else {
+        	$update['where_id'] = $user['id'];
+        	Dever::db('collection/user')->update($update);
+        }
+        return 'ok';
+    }
+
+    # 查看我的订单
+    public function order()
+    {
+        $data['order'] = Dever::load('goods/lib/order')->getList($this->uid, 'collection/info', $this->id);
+        return $data;
+    }
+
+    # 查看关于我的社区帖子
+    public function community()
+    {
+    	$data['chat'] = Dever::load('community/lib/chat')->getUser($this->uid, $this->id);
+        return $data;
+    }
+}

+ 180 - 0
app/community/database/chat_info.php

@@ -0,0 +1,180 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'chat_info',
+	# 显示给用户看的名称
+	'lang' => '聊天信息',
+	# 是否显示在后台菜单
+	'order' => 20,
+	'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}) : "匿名用户"',
+		),
+
+		'to_uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '聊天对象uid',
+			'default' 	=> '0',
+			'desc' 		=> '聊天对象uid',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'text',
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '聊天key',
+			'default' 	=> '',
+			'desc' 		=> '聊天key',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'text',
+		),
+		
+		'info_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '数据源id',
+			'default' 	=> '',
+			'desc' 		=> '数据源id',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+
+		'collection_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '合集id',
+			'default' 	=> '',
+			'desc' 		=> '合集id',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+
+		'text'		=> array
+		(
+			'type' 		=> 'text-255',
+			'name' 		=> '文本内容',
+			'update' 	=> 'editor',
+			'default' 	=> '',
+			'desc' 		=> '请输入文本内容',
+			'match' 	=> 'is_string',
+		),
+
+		'pic'		=> array
+		(
+			'type' 		=> 'varchar-2000',
+			'name' 		=> '图片-图片尺寸不等,上传大小不能超过2M,支持JPG、PNG、GIF格式,建议上传JPG格式',
+			'default' 	=> '',
+			'desc' 		=> '图片',
+			'match' 	=> 'is_string',
+			'update'	=> 'images',
+			'key' 		=> '1',
+		),
+
+		'day'      => array
+        (
+            'type'      => 'int-11',
+            'name'      => '日期',
+            'default'   => '-1',
+            'desc'      => '日期',
+            'match'     => 'is_numeric',
+            //'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
+			(
+				'key' => 'yes',
+				'uid' => 'yes',
+				'to_uid' => 'yes',
+				'collection_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'page' => array(15, 'list'),
+			'col' => '*',
+		),
+
+		'getNew' => array
+		(
+			# 匹配的正则或函数 选填项
+			'option' => array
+			(
+				'key' => 'yes',
+				'uid' => 'yes',
+				'to_uid' => 'yes',
+				'collection_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'one',
+			'order' => array('id' => 'desc'),
+			'col' => '*',
+		),
+	)
+);

+ 123 - 0
app/community/database/chat_user.php

@@ -0,0 +1,123 @@
+<?php
+
+return array
+(
+	# 表名
+	'name' => 'chat_user',
+	# 显示给用户看的名称
+	'lang' => '聊天好友关系',
+	# 是否显示在后台菜单
+	'order' => 20,
+	'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}) : "匿名用户"',
+		),
+
+		'to_uid'		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '聊天对象uid',
+			'default' 	=> '0',
+			'desc' 		=> '聊天对象uid',
+			'match' 	=> 'is_numeric',
+			//'update'	=> 'text',
+		),
+
+		'collection_id' 		=> array
+		(
+			'type' 		=> 'int-11',
+			'name' 		=> '合集id',
+			'default' 	=> '',
+			'desc' 		=> '合集id',
+			'match' 	=> 'option',
+			'update'	=> 'text',
+		),
+
+		'key'		=> array
+		(
+			'type' 		=> 'varchar-100',
+			'name' 		=> '好友关系key',
+			'default' 	=> '',
+			'desc' 		=> '好友关系key',
+			'match' 	=> 'is_numeric',
+			//'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
+			(
+				'key' => 'yes',
+				'uid' => 'yes',
+				'to_uid' => 'yes',
+				'collection_id' => 'yes',
+				'state' => 1,
+			),
+			'type' => 'all',
+			'order' => array('id' => 'desc'),
+			'page' => array(15, 'list'),
+			'col' => '*',
+		),
+	)
+);

+ 99 - 0
app/community/lib/Chat.php

@@ -0,0 +1,99 @@
+<?php
+
+namespace Community\Lib;
+
+use Dever;
+
+class Chat
+{
+	# 生成key
+	private function getKey($uid, $to_uid)
+	{
+		if ($uid > $to_uid) {
+			return $uid . '_' . $to_uid;
+		} else {
+			return $to_uid . '_' . $uid;
+		}
+	}
+
+	# 加入聊天信息
+	public function add($uid, $to_uid, $collection_id, $text, $pic, $day = false)
+	{
+		$data['uid'] = $uid;
+		$data['to_uid'] = $to_uid;
+		$data['collection_id'] = $collection_id;
+		$user = Dever::db('community/chat_user')->one($data);
+		$data['key'] = $this->getKey($uid, $to_uid);
+		if (!$user) {
+			Dever::db('community/chat_user')->insert($data);
+		}
+
+		$data['text'] = $text;
+		$data['pic'] = $pic;
+		if ($day) {
+			$data['day'] = $day;
+		}
+		return Dever::db('community/chat_info')->insert($data);
+	}
+
+	# 获取聊天对象
+	public function getUser($uid, $collection_id, $times = false)
+	{
+		$data['to_uid'] = $uid;
+		$data['collection_id'] = $collection_id;
+		$user = Dever::db('community/chat_user')->getAll($data);
+
+		# 获取最新的一条聊天记录
+		if ($user) {
+			$time = time();
+			foreach ($user as $k => $v) {
+				$where['uid'] = $v['uid'];
+				$where['collection_id'] = $collection_id;
+				$chat = Dever::db('community/chat_info')->getNew($where);
+				$user[$k]['user'] = Dever::load('collection/lib/user')->get($v['uid'], $collection_id);
+
+				if ($chat) {
+					if ($chat['pic'] && !$chat['text']) {
+						$chat['text'] = '[图片]';
+					} else {
+						$chat['text'] = strip_tags($chat['text']);
+					}
+
+					$date = Dever::load('collection/lib/times')->getDate($chat['day'], $chat['cdate'], $times, true);
+
+					$chat['day'] = $date[0];
+					$chat['date'] = $date[1];
+				}
+
+				$user[$k]['chat'] = $chat;
+			}
+		}
+
+		return $user;
+	}
+
+	# 获取聊天记录
+	public function getInfo($uid, $to_uid, $collection_id, $times = false)
+	{
+		$where['key'] = $this->getKey($uid, $to_uid);
+		$where['collection_id'] = $collection_id;
+		$data['chat'] = Dever::db('community/chat_info')->getAll($where);
+
+		if ($data['chat']) {
+			$data['user'][$uid] = Dever::load('collection/lib/user')->get($uid, $collection_id);
+			$data['user'][$to_uid] = Dever::load('collection/lib/user')->get($to_uid, $collection_id);
+			$data['title'] = $data['user'][$to_uid]['username'];
+			foreach ($data['chat'] as $k => $v) {
+				$data['chat'][$k]['date'] = Dever::load('collection/lib/times')->getDate($v['day'], $v['cdate'], $times);
+				$data['chat'][$k]['self'] = false;
+				if ($uid == $v['uid']) {
+					$data['chat'][$k]['self'] = true;
+				}
+			}
+
+			$data['chat'] = array_reverse($data['chat']);
+		}
+
+		return $data;
+	}
+}

+ 4 - 4
app/community/lib/Comment.php

@@ -6,7 +6,7 @@ use Dever;
 
 class Comment
 {
-    public function getData($method = 'getAll', $uid, $type = false, $type_id = false, $user = false)
+    public function getData($method = 'getAll', $uid, $type = false, $type_id = false, $user = false, $collection_id = false)
     {
         $where['type'] = $type;
         $where['type_id'] = $type_id;
@@ -21,7 +21,7 @@ class Comment
                     $data['info'][$k]['pic'] = explode(',', $v['pic']);
                 }
                 if ($user) {
-                    $data['info'][$k]['user'] = Dever::load('passport/api')->info($v['uid']);
+                    $data['info'][$k]['user'] = Dever::load('collection/lib/user')->get($v['uid'], $collection_id);
                     $data['info'][$k]['cdate_string'] = Dever::mdate($v['cdate'], 2);
                 }
             }
@@ -31,7 +31,7 @@ class Comment
     }
 
     # 发表信息
-    public function submit($uid, $id, $type, $pic, $content)
+    public function submit($uid, $id, $type, $pic, $content, $score_type = false, $score_type_id = false)
     {
         # 如果是商品,要先验证是否购买
         if ($type == 'content/product') {
@@ -48,7 +48,7 @@ class Comment
         $info = false;
         if (!$info) {
             Dever::db($table)->insert($where);
-            Dever::score($uid, 'submit_comment', '发布弹幕');
+            Dever::score($uid, 'submit_comment', '发布弹幕/评论', false, false, false, $score_type, $score_type_id);
         }
 
         return true;

+ 41 - 27
app/community/lib/Info.php

@@ -12,7 +12,7 @@ class Info
         return $table;
     }
 
-    public function getData($method = 'getAll', $uid, $cate_id = false, $type = false, $type_id = false, $total = false, $id = false, $times = false, $day = false)
+    public function getData($method = 'getAll', $uid, $cate_id = false, $type = false, $type_id = false, $total = false, $id = false, $times = false, $day = false, $collection_id = false)
     {
         # 获取分类下的帖子
         $where['cate_id'] = $cate_id;
@@ -34,12 +34,9 @@ class Info
                 $data['total'] = Dever::db('community/info')->getTotal($where);
             }
         }
-        if ($times && $times > 0) {
-            $times = Dever::db('collection/times')->one($times);
-        }
         if ($data['info']) {
             foreach ($data['info'] as $k => $v) {
-                $data['info'][$k] = $this->one($uid, $v, $times);
+                $data['info'][$k] = $this->one($uid, $v, $times, $collection_id);
             }
         }
 
@@ -66,7 +63,7 @@ class Info
     }
 
     # 发表信息
-    public function submit($uid, $cate_id, $id, $type, $pic, $content, $to_id, $to_uid, $day = false)
+    public function submit($uid, $cate_id, $id, $type, $pic, $content, $to_id, $to_uid, $day = false, $score_type = false, $score_type_id = false)
     {
         $where['uid'] = $uid;
         $where['cate_id'] = $cate_id;
@@ -97,7 +94,18 @@ class Info
             
             Dever::db($table)->insert($where);
 
-            Dever::score($uid, 'submit_community', '发表帖子');
+            if ($to_uid && $to_uid != $uid) {
+                Dever::score($uid, 'reply_community', '回复帖子', false, false, false, $score_type, $score_type_id);
+
+                Dever::score($to_uid, 'reply_me_community', '被回复帖子', false, false, false, $score_type, $score_type_id);
+
+                # 建立聊天相关信息
+                Dever::load('community/lib/chat')->add($uid, $to_uid, $score_type_id, $content, $pic, $day);
+
+            } else {
+                Dever::score($uid, 'submit_community', '发表帖子', false, false, false, $score_type, $score_type_id);
+            }
+
 
             # 更新评论数
             /*
@@ -114,27 +122,12 @@ class Info
         return true;
     }
 
-    private function one($uid, $info, $times = false)
+    private function one($uid, $info, $times = false, $collection_id = false)
     {
         $info['pic'] = explode(',', $info['pic']);
-        $info['user'] = Dever::load('passport/api')->info($info['uid']);
-        if ($info['day'] > 0) {
-            if ($times && $times['year']) {
-                $year = $times['year'];
-            } else {
-                $year = substr($info['day'],0,4);
-            }
-            
-            $month = substr($info['day'],4,2);
-            $day = substr($info['day'],6,2);
-            $string = $year . '-' . $month . '-' . $day;
-        } elseif ($times && $times['year']) {
-            $string = $times['year'] . '-m-d';
-        } else {
-            $string = 'Y-m-d';
-        }
-
-        $info['cdate_string'] = date($string . ' H:i', $info['cdate']);
+        $info['user'] = Dever::load('collection/lib/user')->get($info['uid'], $collection_id);
+        
+        $info['cdate_string'] = Dever::load('collection/lib/times')->getDate($info['day'], $info['cdate'], $times);
 
         # 点赞数
         $info['num_up'] = $info['num_up'] + 0;
@@ -158,7 +151,7 @@ class Info
         # 获取引用的数据
         $info['to_user'] = array();
         if ($info['to_uid']) {
-            $info['to_user'] = Dever::load('passport/api')->info($info['to_uid']);
+            $info['to_user'] = Dever::load('collection/lib/user')->get($info['to_uid'], $collection_id);
         }
 
         # 获取热门的子信息
@@ -176,4 +169,25 @@ class Info
 
         return $info;
     }
+
+    public function getCdate(&$info, $times = false)
+    {
+        if ($info['day'] > 0) {
+            if ($times && $times['year']) {
+                $year = $times['year'];
+            } else {
+                $year = substr($info['day'],0,4);
+            }
+            
+            $month = substr($info['day'],4,2);
+            $day = substr($info['day'],6,2);
+            $string = $year . '-' . $month . '-' . $day;
+        } elseif ($times && $times['year']) {
+            $string = $times['year'] . '-m-d';
+        } else {
+            $string = 'Y-m-d';
+        }
+
+        $info['cdate_string'] = date($string . ' H:i', $info['cdate']);
+    }
 }

+ 5 - 6
app/community/src/Api.php

@@ -30,17 +30,16 @@ class Api extends Core
     # 获取社区下的帖子
     public function info()
     {
-    	$id = Dever::input('id');
-    	$data = Dever::load('community/lib/info')->getData('getAll', $this->uid, $this->cate_id, $this->type, $this->type_id, false, $id, $this->times, $this->day);
+    	$id = Dever::input('info_id');
+    	$data = Dever::load('community/lib/info')->getData('getAll', $this->uid, $this->cate_id, $this->type, $this->type_id, false, $id, $this->times, $this->day, $this->id);
         return $data;
     }
 
     # 获取弹幕、评论
     public function comment()
     {
-        $id = Dever::input('id');
         $user = Dever::input('user', false);
-        $data = Dever::load('community/lib/comment')->getData('getAll', $this->uid, $this->type, $this->type_id, $user);
+        $data = Dever::load('community/lib/comment')->getData('getAll', $this->uid, $this->type, $this->type_id, $user, $this->id);
         return $data;
     }
 
@@ -62,7 +61,7 @@ class Api extends Core
             Dever::alert('错误的信息');
         }
         
-        Dever::load('community/lib/comment')->submit($this->uid, $type_id, $type, $pic, $content);
+        Dever::load('community/lib/comment')->submit($this->uid, $type_id, $type, $pic, $content, 'collection/info', $this->id);
 
         return 'yes';
     }
@@ -92,7 +91,7 @@ class Api extends Core
         $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, $this->day);
+        Dever::load('community/lib/info')->submit($this->uid, $cate_id, $type_id, $type, $pic, $content, $to_id, $to_uid, $this->day, 'collection/info', $this->id);
 
         return 'yes';
     }

+ 109 - 0
app/community/src/Chat.php

@@ -0,0 +1,109 @@
+<?php
+# 聊天服务
+namespace Community\Src;
+
+use Dever;
+use Collection\Lib\Core;
+use Im_gateway_client\Lib\Gateway;
+
+class Chat extends Core
+{
+	public function __construct()
+	{
+		parent::__construct();
+
+		# 测试用
+		$uid = Dever::input('uid');
+		if ($uid == 1) {
+			$this->uid = 2;
+		}
+	}
+
+	private function connect()
+	{
+		Gateway::$registerAddress = '192.168.33.10:1238';
+	}
+
+	# 初始化,绑定client_id
+	public function init()
+	{
+		$this->connect();
+		$client_id = Dever::input('client_id');
+		if ($client_id) {
+			Gateway::bindUid($client_id, $this->uid);
+		}
+
+		return 'ok';
+	}
+
+	# 发送消息
+	public function send()
+	{
+		$uid = Dever::input('uid');
+		$msg = Dever::input('msg');
+		$pic = Dever::input('pic');
+
+		if (!$uid || $uid == $this->uid) {
+			Dever::alert('你要发给谁?');
+		}
+
+		if (!$msg && !$pic) {
+			Dever::alert('没有任何消息');
+		}
+
+		Dever::load('community/lib/chat')->add($this->uid, $uid, $this->id, $msg, $pic, $this->day);
+
+		$this->connect();
+		# 谁发给谁,发的什么
+		$this->push($this->uid, $uid, $msg, $pic);
+		$data['msg'] = $this->msg($this->uid, $this->uid, $msg, $pic);
+
+		return $data;
+	}
+
+	# 获取聊天记录
+	public function getList()
+	{
+		$uid = Dever::input('uid');
+		if (!$uid || $uid == $this->uid) {
+			Dever::alert('你要发给谁?');
+		}
+		$data = Dever::load('community/lib/chat')->getInfo($this->uid, $uid, $this->id, $this->times);
+
+		$info = $this->checkInfo();
+		if ($info) {
+			$button = $this->button($info);
+			$data['bgcolor'] = $button['bgcolor'];
+		}
+
+		return $data;
+	}
+
+	# 发送消息给用户
+	public function push($from_uid, $uid, $msg, $pic)
+	{
+		if (Gateway::isUidOnline($uid)) {
+			$send = $this->msg($from_uid, $uid, $msg, $pic);
+			$send = Dever::json_encode($send);
+			Gateway::sendToUid($uid, $send);
+		}
+		return $this;
+	}
+
+	# 获取消息体
+	public function msg($from_uid, $uid, $msg, $pic)
+	{
+		$self = false;
+		if ($from_uid == $uid) {
+			$self = true;
+		}
+		$send = array();
+		$send['uid'] = $from_uid;
+		$send['self'] = $self;
+		$send['type'] = 'msg';
+		$send['text'] = $msg;
+		$send['pic'] = $pic;
+		$send['date'] = Dever::load('collection/lib/times')->getDate($this->day, time(), $this->times);
+		return $send;
+	}
+}

+ 8 - 0
app/im/index.php

@@ -0,0 +1,8 @@
+<?php
+
+define('DEVER_APP_NAME', 'im');
+define('DEVER_APP_LANG', '聊天组件');
+define('DEVER_APP_PATH', dirname(__FILE__) . DIRECTORY_SEPARATOR);
+define('DEVER_MANAGE_ORDER', 10);
+define('DEVER_MANAGE_ICON', 'glyphicon glyphicon-tower layui-icon-reply-fill');
+include(DEVER_APP_PATH . '../boot.php');

+ 61 - 0
app/im/src/Test.php

@@ -0,0 +1,61 @@
+<?php namespace Im\Src;
+
+use Dever;
+
+class Test
+{
+	private $host = 'http://39.100.131.66:18080/';
+	private $key = 'hlhuala1999';
+	private $uid = 1;
+
+	# 注册
+	public function reg()
+	{
+		$param['userId'] = $this->uid;
+		$param['name'] = 'suwibin';
+		$param['displayName'] = 'rabin';
+
+		$result = $this->result('admin/user/create', $param);
+		
+		return $result;
+	}
+
+	# 获取token
+	public function token()
+	{
+		$param['userId'] = $this->uid;
+		$param['clientId'] = $this->uid;
+		$param['platform'] = 5;
+
+		$result = $this->result('admin/user/get_token', $param);
+		
+		return $result;
+	}
+
+	private function result($uri, $param)
+	{
+		$url = $this->host . $uri;
+		$result = Dever::curl($url, $param, 'post', true, $this->sign());
+		return $result;
+	}
+
+	private function sign()
+	{
+		$option['nonce'] = $this->nonce();
+		$option['timestamp'] = $this->timestamp();
+		$option['sign'] = sha1($option['nonce'] . '|' . $this->key . '|' . $option['timestamp']);
+		return $option;
+	}
+
+	private function nonce()
+    {
+        return substr(sha1(microtime()), rand(10, 15));
+    }
+
+    private function timestamp()
+    {
+        list($msec, $sec) = explode(' ', microtime());
+        $msectime = (float)sprintf('%.0f', (floatval($msec) + floatval($sec)) * 1000);
+        return $msectime;
+    }
+}

+ 1 - 1
config/base.php

@@ -1,7 +1,7 @@
 <?php
 $config['base'] = array
 (
-	'name' => '境',
+	'name' => '境',
 	'version' => '1.0.0 Beta',
 
     # 设置分类组件中的栏目下的分类为系统使用的主分类

+ 1 - 1
main/database/config.php

@@ -81,7 +81,7 @@ return array
 		'col' => 'name,info,cdate',
 		'value' => array
 		(
-			'"云境","云境",' . time(),
+			'"幻境","幻境",' . time(),
 		),
 	),