|
@@ -0,0 +1,155 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace Community\Lib;
|
|
|
+
|
|
|
+use Dever;
|
|
|
+
|
|
|
+class Moment
|
|
|
+{
|
|
|
+ private $table = 'community/moment';
|
|
|
+
|
|
|
+ private function table($type)
|
|
|
+ {
|
|
|
+ $table = Dever::db($this->table)->config['set']['table_name'][$type];
|
|
|
+ return $table;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function getData($method = 'getAll', $uid, $type = false, $type_id = false, $total = false, $id = false, $times = false, $day = false, $collection_id = false)
|
|
|
+ {
|
|
|
+ $where['type'] = $type;
|
|
|
+ $where['type_id'] = $type_id;
|
|
|
+ if ($id > 0) {
|
|
|
+ $where['noid'] = $id;
|
|
|
+ }
|
|
|
+ if ($day && $day > 0) {
|
|
|
+ $where['day'] = $day;
|
|
|
+ } else {
|
|
|
+ $where['day'] = -1;
|
|
|
+ }
|
|
|
+ $data['info'] = Dever::db($this->table)->$method($where);
|
|
|
+ if ($total) {
|
|
|
+ if ($method == 'getAll') {
|
|
|
+ $data['total'] = Dever::total();
|
|
|
+ } else {
|
|
|
+ $data['total'] = Dever::db($this->table)->getTotal($where);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if ($data['info']) {
|
|
|
+ foreach ($data['info'] as $k => $v) {
|
|
|
+ $data['info'][$k] = $this->one($uid, $v, $times, $collection_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+
|
|
|
+ public function content($id)
|
|
|
+ {
|
|
|
+ $info = Dever::db($this->table)->one($id);
|
|
|
+ $table = array();
|
|
|
+
|
|
|
+ $pic = '';
|
|
|
+ if ($info['pic']) {
|
|
|
+ $temp = explode(',', $info['pic']);
|
|
|
+ foreach ($temp as $k => $v) {
|
|
|
+ $pic .= '<img src="'.$v.'" width="150" />';
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $table['内容'] = $info['content'];
|
|
|
+ $table['图片'] = $pic;
|
|
|
+
|
|
|
+ return Dever::table($table);
|
|
|
+ }
|
|
|
+
|
|
|
+ # 发表信息
|
|
|
+ public function submit($uid, $id, $type, $pic, $content, $to_id, $to_uid, $day = false, $score_type = false, $score_type_id = false)
|
|
|
+ {
|
|
|
+ $where['uid'] = $uid;
|
|
|
+ $where['type_id'] = $id;
|
|
|
+ $where['type'] = $type;
|
|
|
+ $where['content'] = $content;
|
|
|
+ $table = $this->table;
|
|
|
+ //$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;
|
|
|
+ }
|
|
|
+ if ($day) {
|
|
|
+ $where['day'] = $day;
|
|
|
+ }
|
|
|
+ $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);
|
|
|
+
|
|
|
+ if ($to_uid && $to_uid != $uid) {
|
|
|
+ Dever::score($uid, 'reply_moment', '回复朋友圈', false, false, false, $score_type, $score_type_id);
|
|
|
+
|
|
|
+ Dever::score($to_uid, 'reply_me_moment', '被回复朋友圈', false, false, false, $score_type, $score_type_id);
|
|
|
+ } else {
|
|
|
+ Dever::score($uid, 'submit_moment', '发表朋友圈', false, false, false, $score_type, $score_type_id);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+ private function one($uid, $info, $times = false, $collection_id = false)
|
|
|
+ {
|
|
|
+ $info['pic'] = explode(',', $info['pic']);
|
|
|
+ $info['user'] = Dever::load('user/lib/info')->get($info['uid'], $collection_id, true);
|
|
|
+
|
|
|
+ $info['cdate_string'] = Dever::load('collection/lib/times')->getDate($info['day'], $info['cdate'], $times);
|
|
|
+
|
|
|
+ # 点赞数
|
|
|
+ $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('user/lib/info')->get($info['to_uid'], $collection_id, true);
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取热门的子信息
|
|
|
+ $info['child'] = array();
|
|
|
+ if ($info['type'] < 20) {
|
|
|
+ $child = $this->getData('getHot', $uid, 20, $info['id'], true, 1);
|
|
|
+ if ($child && $child['info']) {
|
|
|
+ $info['child'] = $child['info'];
|
|
|
+ $info['child_total'] = $child['total'];
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ # 获取最新的服务器时间
|
|
|
+ $info['server_time'] = time();
|
|
|
+
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+}
|