Comment.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. if (isset($info['name']) && $info['name']) {
  57. $where['data_name'] = $info['name'];
  58. }
  59. Dever::db($table)->insert($where);
  60. }
  61. Dever::score($uid, 'submit_commit', '发表评论');
  62. # 更新评论数
  63. if ($type == 5) {
  64. return true;
  65. }
  66. $where = array();
  67. $where['data_id'] = $id;
  68. $where['type'] = $type;
  69. $where['state'] = 1;
  70. $total = Dever::db($table)->total($where);
  71. $table = Dever::config('base')->type_table[$type];
  72. Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
  73. return true;
  74. }
  75. }