Comment.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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]['username'] = $user['username'];
  25. $data[$k]['avatar'] = $user['avatar'];
  26. $data[$k]['cdate_time'] = date('Y-m-d H:i:s', $v['cdate']);
  27. # 检查是否点赞
  28. if ($uid > 0) {
  29. $data[$k]['up'] = Dever::load('act/lib/like')->get($uid, $v['id'], 11);
  30. } else {
  31. $data[$k]['up'] = 2;
  32. }
  33. }
  34. }
  35. return $data;
  36. }
  37. # 获取当前用户的评论列表
  38. public function getList($uid)
  39. {
  40. $where['uid'] = $uid;
  41. $info = Dever::db('act/comment')->getAll($where);
  42. return $info;
  43. }
  44. # 发表评论
  45. public function submit($uid, $id, $type, $content)
  46. {
  47. $where['uid'] = $uid;
  48. $where['data_id'] = $id;
  49. $where['type'] = $type;
  50. $where['content'] = $content;
  51. $table = $this->table($type);
  52. $info = Dever::db($table)->one($where);
  53. if (!$info) {
  54. Dever::db($table)->insert($where);
  55. }
  56. # 更新评论数
  57. $where = array();
  58. $where['data_id'] = $id;
  59. $where['type'] = $type;
  60. $where['state'] = 1;
  61. $total = Dever::db($table)->total($where);
  62. $table = Dever::config('base')->type_table[$type];
  63. Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
  64. Dever::score($uid, 'submit_commit', '发表评论');
  65. return true;
  66. }
  67. }