Moment.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155
  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 getData($method = 'getAll', $uid, $type = false, $type_id = false, $total = false, $id = false, $times = false, $day = false, $collection_id = false)
  13. {
  14. $where['type'] = $type;
  15. $where['type_id'] = $type_id;
  16. if ($id > 0) {
  17. $where['noid'] = $id;
  18. }
  19. if ($day && $day > 0) {
  20. $where['day'] = $day;
  21. } else {
  22. $where['day'] = -1;
  23. }
  24. $data['info'] = Dever::db($this->table)->$method($where);
  25. if ($total) {
  26. if ($method == 'getAll') {
  27. $data['total'] = Dever::total();
  28. } else {
  29. $data['total'] = Dever::db($this->table)->getTotal($where);
  30. }
  31. }
  32. if ($data['info']) {
  33. foreach ($data['info'] as $k => $v) {
  34. $data['info'][$k] = $this->one($uid, $v, $times, $collection_id);
  35. }
  36. }
  37. return $data;
  38. }
  39. public function content($id)
  40. {
  41. $info = Dever::db($this->table)->one($id);
  42. $table = array();
  43. $pic = '';
  44. if ($info['pic']) {
  45. $temp = explode(',', $info['pic']);
  46. foreach ($temp as $k => $v) {
  47. $pic .= '<img src="'.$v.'" width="150" />';
  48. }
  49. }
  50. $table['内容'] = $info['content'];
  51. $table['图片'] = $pic;
  52. return Dever::table($table);
  53. }
  54. # 发表信息
  55. public function submit($uid, $id, $type, $pic, $content, $to_id, $to_uid, $day = false, $score_type = false, $score_type_id = false)
  56. {
  57. $where['uid'] = $uid;
  58. $where['type_id'] = $id;
  59. $where['type'] = $type;
  60. $where['content'] = $content;
  61. $table = $this->table;
  62. //$info = Dever::db($table)->one($where);
  63. $info = false;
  64. if ($pic) {
  65. $where['pic'] = $pic;
  66. }
  67. if ($to_id) {
  68. $where['to_id'] = $to_id;
  69. }
  70. if ($to_uid) {
  71. $where['to_uid'] = $to_uid;
  72. }
  73. if ($day) {
  74. $where['day'] = $day;
  75. }
  76. $data_table = $this->table($type);
  77. if (!$info) {
  78. $data = Dever::db($data_table)->one($id);
  79. if (isset($data['name']) && $data['name']) {
  80. $where['type_name'] = $data['name'];
  81. }
  82. Dever::db($table)->insert($where);
  83. if ($to_uid && $to_uid != $uid) {
  84. Dever::score($uid, 'reply_moment', '回复朋友圈', false, false, false, $score_type, $score_type_id);
  85. Dever::score($to_uid, 'reply_me_moment', '被回复朋友圈', false, false, false, $score_type, $score_type_id);
  86. } else {
  87. Dever::score($uid, 'submit_moment', '发表朋友圈', false, false, false, $score_type, $score_type_id);
  88. }
  89. }
  90. return true;
  91. }
  92. private function one($uid, $info, $times = false, $collection_id = false)
  93. {
  94. $info['pic'] = explode(',', $info['pic']);
  95. $info['user'] = Dever::load('user/lib/info')->get($info['uid'], $collection_id, true);
  96. $info['cdate_string'] = Dever::load('collection/lib/times')->getDate($info['day'], $info['cdate'], $times);
  97. # 点赞数
  98. $info['num_up'] = $info['num_up'] + 0;
  99. # 反对数
  100. $info['num_oppose'] = $info['num_oppose'] + 0;
  101. $info['is_up'] = $info['is_oppose'] = false;
  102. if ($uid) {
  103. # 是否点赞
  104. $info['is_up'] = Dever::load('community/lib/up')->get($uid, $info['id'], 20);
  105. # 是否反对
  106. $info['is_oppose'] = Dever::load('community/lib/oppose')->get($uid, $info['id'], 20);
  107. }
  108. # 评论数
  109. $info['num_comment'] = $info['num_comment'] + 0;
  110. # 获取引用的数据
  111. $info['to_user'] = array();
  112. if ($info['to_uid']) {
  113. $info['to_user'] = Dever::load('user/lib/info')->get($info['to_uid'], $collection_id, true);
  114. }
  115. # 获取热门的子信息
  116. $info['child'] = array();
  117. if ($info['type'] < 20) {
  118. $child = $this->getData('getHot', $uid, 20, $info['id'], true, 1);
  119. if ($child && $child['info']) {
  120. $info['child'] = $child['info'];
  121. $info['child_total'] = $child['total'];
  122. }
  123. }
  124. # 获取最新的服务器时间
  125. $info['server_time'] = time();
  126. return $info;
  127. }
  128. }