Moment.php 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. <?php
  2. namespace Community\Lib;
  3. use Dever;
  4. class Moment
  5. {
  6. private $table = 'community/moment';
  7. private function table($type)
  8. {
  9. $table = Dever::db($this->table)->config['set']['table_name'][$type];
  10. return $table;
  11. }
  12. public function del($uid, $id, $state = 2)
  13. {
  14. $where['id'] = $id;
  15. $where['uid'] = $uid;
  16. $info = Dever::db($this->table)->one($where);
  17. if ($info) {
  18. $update['where_id'] = $id;
  19. $update['state'] = $state;
  20. Dever::db($this->table)->update($update);
  21. }
  22. return true;
  23. }
  24. public function getData($method = 'getAll', $uid, $type = false, $type_id = false, $total = false, $id = false, $times = false, $day = false, $collection_id = false)
  25. {
  26. $where['type'] = $type;
  27. $where['type_id'] = $type_id;
  28. if ($id > 0) {
  29. $where['noid'] = $id;
  30. }
  31. if ($day && $day > 0) {
  32. $where['day'] = $day;
  33. } else {
  34. $where['day'] = -1;
  35. }
  36. $data['info'] = Dever::db($this->table)->$method($where);
  37. if ($total) {
  38. if ($method == 'getAll') {
  39. $data['total'] = Dever::total();
  40. } else {
  41. $data['total'] = Dever::db($this->table)->getTotal($where);
  42. }
  43. }
  44. if ($data['info']) {
  45. foreach ($data['info'] as $k => $v) {
  46. $data['info'][$k] = $this->one($uid, $v, $times, $collection_id);
  47. }
  48. }
  49. return $data;
  50. }
  51. public function content($id)
  52. {
  53. $info = Dever::db($this->table)->one($id);
  54. $table = array();
  55. $pic = '';
  56. if ($info['pic']) {
  57. $temp = explode(',', $info['pic']);
  58. foreach ($temp as $k => $v) {
  59. $pic .= '<img src="'.$v.'" width="150" />';
  60. }
  61. }
  62. $table['内容'] = $info['content'];
  63. $table['图片'] = $pic;
  64. return Dever::table($table);
  65. }
  66. # 发表信息
  67. public function submit($uid, $id, $type, $pic, $content, $to_id, $to_uid, $day = false, $score_type = false, $score_type_id = false)
  68. {
  69. $where['uid'] = $uid;
  70. $where['type_id'] = $id;
  71. $where['type'] = $type;
  72. if ($day) {
  73. $where['day'] = $day;
  74. }
  75. $where['state'] = 1;
  76. $table = $this->table;
  77. $info = false;
  78. $where['content'] = $content;
  79. if ($pic) {
  80. $where['pic'] = $pic;
  81. }
  82. if ($to_id) {
  83. $where['to_id'] = $to_id;
  84. }
  85. if ($to_uid) {
  86. $where['to_uid'] = $to_uid;
  87. }
  88. if ($info && $type == 3 && !$to_id) {
  89. $info = Dever::db($table)->one($where);
  90. Dever::alert('已发布过动态,仅能发布一次,可删除旧动态后再添加');
  91. }
  92. //$info = false;
  93. $data_table = $this->table($type);
  94. if (!$info) {
  95. $data = Dever::db($data_table)->one($id);
  96. if (isset($data['name']) && $data['name']) {
  97. $where['type_name'] = $data['name'];
  98. }
  99. Dever::db($table)->insert($where);
  100. if ($to_uid && $to_uid != $uid) {
  101. Dever::score($uid, 'reply_moment', '回复朋友圈', false, false, false, $score_type, $score_type_id);
  102. Dever::score($to_uid, 'reply_me_moment', '被回复朋友圈', false, false, false, $score_type, $score_type_id);
  103. } else {
  104. Dever::score($uid, 'submit_moment', '发表朋友圈', false, false, false, $score_type, $score_type_id);
  105. }
  106. }
  107. return true;
  108. }
  109. private function one($uid, $info, $times = false, $collection_id = false)
  110. {
  111. # 验证消息是否是自己的
  112. $info['me'] = 2;
  113. $info['del'] = '';
  114. if ($uid == $info['uid']) {
  115. $info['me'] = 1;
  116. $info['del'] = '删除';
  117. $info['del_state'] = 2;
  118. }
  119. $key = 30;
  120. $info['pic'] = explode(',', $info['pic']);
  121. $info['user'] = Dever::load('user/lib/info')->get($info['uid'], $collection_id, true);
  122. $info['cdate_string'] = Dever::load('collection/lib/times')->getDate($info['day'], $info['cdate'], $times);
  123. # 点赞数
  124. $info['num_up'] = $info['num_up'] + 0;
  125. $info['up_list'] = array();
  126. $info['up_list']['user'] = (object) array();
  127. $info['up_list']['total'] = 0;
  128. $info['up_list_total'] = 0;
  129. if ($info['num_up'] > 0) {
  130. # 批量获取最新的点赞名单
  131. $info['up_list'] = Dever::load('community/lib/up')->getData($info['id'], $key, $collection_id);
  132. $info['up_list_total'] = count($info['up_list']['user']);
  133. }
  134. # 反对数
  135. $info['num_oppose'] = $info['num_oppose'] + 0;
  136. $info['is_up'] = $info['is_oppose'] = false;
  137. if ($uid) {
  138. # 是否点赞
  139. $info['is_up'] = Dever::load('community/lib/up')->get($uid, $info['id'], $key);
  140. # 是否反对
  141. $info['is_oppose'] = Dever::load('community/lib/oppose')->get($uid, $info['id'], $key);
  142. }
  143. # 评论数
  144. $info['num_comment'] = $info['num_comment'] + 0;
  145. # 获取引用的数据
  146. $info['to_user'] = array();
  147. if ($info['to_uid']) {
  148. $info['to_user'] = Dever::load('user/lib/info')->get($info['to_uid'], $collection_id, true);
  149. }
  150. # 获取热门的子信息
  151. $info['child'] = array();
  152. if ($info['type'] < 20) {
  153. $child = $this->getData('getHot', $uid, $key, $info['id'], true, false, $times, $info['day'], $collection_id);
  154. if ($child && $child['info']) {
  155. $info['child'] = $child['info'];
  156. $info['child_total'] = $child['total'];
  157. }
  158. }
  159. # 获取最新的服务器时间
  160. $info['server_time'] = time();
  161. return $info;
  162. }
  163. }