Comment.php 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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. Dever::db($table)->insert($where);
  56. }
  57. # 更新评论数
  58. $where = array();
  59. $where['data_id'] = $id;
  60. $where['type'] = $type;
  61. $where['state'] = 1;
  62. $total = Dever::db($table)->total($where);
  63. $table = Dever::config('base')->type_table[$type];
  64. Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
  65. Dever::score($uid, 'submit_commit', '发表评论');
  66. return true;
  67. }
  68. }