Info.php 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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)
  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 ($times && $times > 0) {
  34. $times = Dever::db('collection/times')->one($times);
  35. }
  36. if ($data['info']) {
  37. foreach ($data['info'] as $k => $v) {
  38. $data['info'][$k] = $this->one($uid, $v, $times);
  39. }
  40. }
  41. return $data;
  42. }
  43. public function content($id)
  44. {
  45. $info = Dever::db('community/info')->one($id);
  46. $table = array();
  47. $pic = '';
  48. if ($info['pic']) {
  49. $temp = explode(',', $info['pic']);
  50. foreach ($temp as $k => $v) {
  51. $pic .= '<img src="'.$v.'" width="150" />';
  52. }
  53. }
  54. $table['内容'] = $info['content'];
  55. $table['图片'] = $pic;
  56. return Dever::table($table);
  57. }
  58. # 发表信息
  59. public function submit($uid, $cate_id, $id, $type, $pic, $content, $to_id, $to_uid, $day = false)
  60. {
  61. $where['uid'] = $uid;
  62. $where['cate_id'] = $cate_id;
  63. $where['type_id'] = $id;
  64. $where['type'] = $type;
  65. $where['content'] = $content;
  66. $table = 'community/info';
  67. //$info = Dever::db($table)->one($where);
  68. $info = false;
  69. if ($pic) {
  70. $where['pic'] = $pic;
  71. }
  72. if ($to_id) {
  73. $where['to_id'] = $to_id;
  74. }
  75. if ($to_uid) {
  76. $where['to_uid'] = $to_uid;
  77. }
  78. if ($day) {
  79. $where['day'] = $day;
  80. }
  81. $data_table = $this->table($type);
  82. if (!$info) {
  83. $data = Dever::db($data_table)->one($id);
  84. if (isset($data['name']) && $data['name']) {
  85. $where['type_name'] = $data['name'];
  86. }
  87. Dever::db($table)->insert($where);
  88. Dever::score($uid, 'submit_community', '发表帖子');
  89. # 更新评论数
  90. /*
  91. $where = array();
  92. $where['type_id'] = $id;
  93. $where['type'] = $type;
  94. $where['state'] = 1;
  95. $total = Dever::db($table)->total($where);
  96. echo $data_table;die;
  97. Dever::db($data_table)->update(array('where_id' => $id, 'num_comment' => $total));
  98. */
  99. }
  100. return true;
  101. }
  102. private function one($uid, $info, $times = false)
  103. {
  104. $info['pic'] = explode(',', $info['pic']);
  105. $info['user'] = Dever::load('passport/api')->info($info['uid']);
  106. if ($info['day'] > 0) {
  107. if ($times && $times['year']) {
  108. $year = $times['year'];
  109. } else {
  110. $year = substr($info['day'],0,4);
  111. }
  112. $month = substr($info['day'],4,2);
  113. $day = substr($info['day'],6,2);
  114. $string = $year . '-' . $month . '-' . $day;
  115. } elseif ($times && $times['year']) {
  116. $string = $times['year'] . '-m-d';
  117. } else {
  118. $string = 'Y-m-d';
  119. }
  120. $info['cdate_string'] = date($string . ' H:i', $info['cdate']);
  121. # 点赞数
  122. $info['num_up'] = $info['num_up'] + 0;
  123. # 反对数
  124. $info['num_oppose'] = $info['num_oppose'] + 0;
  125. $info['is_up'] = $info['is_oppose'] = false;
  126. if ($uid) {
  127. # 是否点赞
  128. $info['is_up'] = Dever::load('community/lib/up')->get($uid, $info['id'], 20);
  129. # 是否反对
  130. $info['is_oppose'] = Dever::load('community/lib/oppose')->get($uid, $info['id'], 20);
  131. }
  132. # 评论数
  133. $info['num_comment'] = $info['num_comment'] + 0;
  134. # 获取引用的数据
  135. $info['to_user'] = array();
  136. if ($info['to_uid']) {
  137. $info['to_user'] = Dever::load('passport/api')->info($info['to_uid']);
  138. }
  139. # 获取热门的子信息
  140. $info['child'] = array();
  141. if ($info['type'] < 20) {
  142. $child = $this->getData('getHot', $uid, $info['cate_id'], 20, $info['id'], true, 1);
  143. if ($child && $child['info']) {
  144. $info['child'] = $child['info'];
  145. $info['child_total'] = $child['total'];
  146. }
  147. }
  148. # 获取最新的服务器时间
  149. $info['server_time'] = time();
  150. return $info;
  151. }
  152. }