123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- <?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;
- }
- }
|