Comment.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. $where['type'] = '1,2,3,6';
  43. $info = Dever::db('act/comment')->getAll($where);
  44. return $info;
  45. }
  46. # 发表评论
  47. public function submit($uid, $id, $type, $content)
  48. {
  49. $where['uid'] = $uid;
  50. $where['data_id'] = $id;
  51. $where['type'] = $type;
  52. $where['content'] = $content;
  53. $table = $this->table($type);
  54. $info = Dever::db($table)->one($where);
  55. if (!$info) {
  56. $data_table = Dever::config('base')->type_table[$type];
  57. $data = Dever::db($data_table)->one($id);
  58. if (isset($data['name']) && $data['name']) {
  59. $where['data_name'] = $data['name'];
  60. }
  61. Dever::db($table)->insert($where);
  62. }
  63. Dever::score($uid, 'submit_commit', '发表评论');
  64. # 更新评论数
  65. if ($type == 5) {
  66. return true;
  67. }
  68. $where = array();
  69. $where['data_id'] = $id;
  70. $where['type'] = $type;
  71. $where['state'] = 1;
  72. $total = Dever::db($table)->total($where);
  73. $table = Dever::config('base')->type_table[$type];
  74. Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
  75. return true;
  76. }
  77. }