Info.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. <?php
  2. namespace Community\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. private function table($type)
  7. {
  8. $table = Dever::db('community/info')->config['set']['table_name'][$type];
  9. return $table;
  10. }
  11. 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)
  12. {
  13. # 获取分类下的帖子
  14. $where['cate_id'] = $cate_id;
  15. $where['type'] = $type;
  16. $where['type_id'] = $type_id;
  17. if ($id > 0) {
  18. $where['noid'] = $id;
  19. }
  20. if ($day && $day > 0) {
  21. $where['day'] = $day;
  22. } else {
  23. $where['day'] = -1;
  24. }
  25. $data['info'] = Dever::db('community/info')->$method($where);
  26. if ($total) {
  27. if ($method == 'getAll') {
  28. $data['total'] = Dever::total();
  29. } else {
  30. $data['total'] = Dever::db('community/info')->getTotal($where);
  31. }
  32. }
  33. if ($data['info']) {
  34. foreach ($data['info'] as $k => $v) {
  35. $data['info'][$k] = $this->one($uid, $v, $times, $collection_id);
  36. }
  37. }
  38. return $data;
  39. }
  40. public function content($id)
  41. {
  42. $info = Dever::db('community/info')->one($id);
  43. $table = array();
  44. $pic = '';
  45. if ($info['pic']) {
  46. $temp = explode(',', $info['pic']);
  47. foreach ($temp as $k => $v) {
  48. $pic .= '<img src="'.$v.'" width="150" />';
  49. }
  50. }
  51. $table['内容'] = $info['content'];
  52. $table['图片'] = $pic;
  53. return Dever::table($table);
  54. }
  55. # 发表信息
  56. public function submit($uid, $cate_id, $id, $type, $pic, $content, $to_id, $to_uid, $day = false, $score_type = false, $score_type_id = false)
  57. {
  58. $where['uid'] = $uid;
  59. $where['cate_id'] = $cate_id;
  60. $where['type_id'] = $id;
  61. $where['type'] = $type;
  62. $where['content'] = $content;
  63. $table = 'community/info';
  64. //$info = Dever::db($table)->one($where);
  65. $info = false;
  66. if ($pic) {
  67. $where['pic'] = $pic;
  68. }
  69. if ($to_id) {
  70. $where['to_id'] = $to_id;
  71. }
  72. if ($to_uid) {
  73. $where['to_uid'] = $to_uid;
  74. }
  75. if ($day) {
  76. $where['day'] = $day;
  77. }
  78. $data_table = $this->table($type);
  79. if (!$info) {
  80. $data = Dever::db($data_table)->one($id);
  81. if (isset($data['name']) && $data['name']) {
  82. $where['type_name'] = $data['name'];
  83. }
  84. Dever::db($table)->insert($where);
  85. if ($to_uid && $to_uid != $uid) {
  86. Dever::score($uid, 'reply_community', '回复帖子', false, false, false, $score_type, $score_type_id);
  87. Dever::score($to_uid, 'reply_me_community', '被回复帖子', false, false, false, $score_type, $score_type_id);
  88. # 建立聊天相关信息
  89. Dever::load('community/lib/chat')->add($uid, $to_uid, $score_type_id, $content, $pic, $day);
  90. } else {
  91. Dever::score($uid, 'submit_community', '发表帖子', false, false, false, $score_type, $score_type_id);
  92. }
  93. # 更新评论数
  94. /*
  95. $where = array();
  96. $where['type_id'] = $id;
  97. $where['type'] = $type;
  98. $where['state'] = 1;
  99. $total = Dever::db($table)->total($where);
  100. echo $data_table;die;
  101. Dever::db($data_table)->update(array('where_id' => $id, 'num_comment' => $total));
  102. */
  103. }
  104. return true;
  105. }
  106. private function one($uid, $info, $times = false, $collection_id = false)
  107. {
  108. $info['pic'] = explode(',', $info['pic']);
  109. $info['user'] = Dever::load('user/lib/info')->get($info['uid'], $collection_id, true);
  110. $info['cdate_string'] = Dever::load('collection/lib/times')->getDate($info['day'], $info['cdate'], $times);
  111. # 点赞数
  112. $info['num_up'] = $info['num_up'] + 0;
  113. # 反对数
  114. $info['num_oppose'] = $info['num_oppose'] + 0;
  115. $info['is_up'] = $info['is_oppose'] = false;
  116. if ($uid) {
  117. # 是否点赞
  118. $info['is_up'] = Dever::load('community/lib/up')->get($uid, $info['id'], 20);
  119. # 是否反对
  120. $info['is_oppose'] = Dever::load('community/lib/oppose')->get($uid, $info['id'], 20);
  121. }
  122. # 评论数
  123. $info['num_comment'] = $info['num_comment'] + 0;
  124. # 获取引用的数据
  125. $info['to_user'] = array();
  126. if ($info['to_uid']) {
  127. $info['to_user'] = Dever::load('user/lib/info')->get($info['to_uid'], $collection_id, true);
  128. }
  129. # 获取热门的子信息
  130. $info['child'] = array();
  131. if ($info['type'] < 20) {
  132. $child = $this->getData('getHot', $uid, $info['cate_id'], 20, $info['id'], true, false, $times, $info['day'], $collection_id);
  133. if ($child && $child['info']) {
  134. $info['child'] = $child['info'];
  135. $info['child_total'] = $child['total'];
  136. }
  137. }
  138. # 获取最新的服务器时间
  139. $info['server_time'] = time();
  140. return $info;
  141. }
  142. public function getCdate(&$info, $times = false)
  143. {
  144. if ($info['day'] > 0) {
  145. if ($times && $times['year']) {
  146. $year = $times['year'];
  147. } else {
  148. $year = substr($info['day'],0,4);
  149. }
  150. $month = substr($info['day'],4,2);
  151. $day = substr($info['day'],6,2);
  152. $string = $year . '-' . $month . '-' . $day;
  153. } elseif ($times && $times['year']) {
  154. $string = $times['year'] . '-m-d';
  155. } else {
  156. $string = 'Y-m-d';
  157. }
  158. $info['cdate_string'] = date($string . ' H:i', $info['cdate']);
  159. }
  160. }