Comment.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Comment
  5. {
  6. private function table($type) {
  7. if ($type == 3) {
  8. $table = 'act/live_comment';
  9. } else {
  10. $table = 'act/comment';
  11. }
  12. return $table;
  13. }
  14. # 获取评论列表
  15. public function get($id, $type, $uid = false)
  16. {
  17. $where['type'] = $type;
  18. $where['data_id'] = $id;
  19. $table = $this->table($type);
  20. $data = Dever::db($table)->getAll($where);
  21. if ($data) {
  22. foreach ($data as $k => $v) {
  23. $user = Dever::load('passport/api')->info($v['uid']);
  24. $data[$k]['time'] = Dever::mdate($v['cdate'], 2);
  25. $data[$k]['username'] = $user['username'];
  26. $data[$k]['avatar'] = $user['avatar'];
  27. $data[$k]['cdate_time'] = date('Y-m-d H:i:s', $v['cdate']);
  28. # 检查是否点赞
  29. if ($uid > 0) {
  30. $data[$k]['up'] = Dever::load('act/lib/like')->get($uid, $v['id'], 11);
  31. } else {
  32. $data[$k]['up'] = 2;
  33. }
  34. }
  35. }
  36. return $data;
  37. }
  38. # 获取当前用户的评论列表
  39. public function getList($uid)
  40. {
  41. $where['uid'] = $uid;
  42. $info = Dever::db('act/comment')->getAll($where);
  43. return $info;
  44. }
  45. # 发表评论
  46. public function submit($uid, $id, $type, $content)
  47. {
  48. $where['uid'] = $uid;
  49. $where['data_id'] = $id;
  50. $where['type'] = $type;
  51. $where['content'] = $content;
  52. $table = $this->table($type);
  53. $info = Dever::db($table)->one($where);
  54. if (!$info) {
  55. if (isset($info['name']) && $info['name']) {
  56. $where['data_name'] = $info['name'];
  57. }
  58. Dever::db($table)->insert($where);
  59. }
  60. Dever::score($uid, 'submit_commit', '发表评论');
  61. # 更新评论数
  62. if ($type == 5) {
  63. return true;
  64. }
  65. $where = array();
  66. $where['data_id'] = $id;
  67. $where['type'] = $type;
  68. $where['state'] = 1;
  69. $total = Dever::db($table)->total($where);
  70. $table = Dever::config('base')->type_table[$type];
  71. Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
  72. return true;
  73. }
  74. }