Comment.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace Act\Lib;
  3. use Dever;
  4. class Comment
  5. {
  6. # 获取评论列表
  7. public function get($id, $type)
  8. {
  9. $where['type'] = $type;
  10. $where['data_id'] = $id;
  11. $data = Dever::db('act/comment')->getAll($where);
  12. if ($data) {
  13. foreach ($data as $k => $v) {
  14. $user = Dever::db('passport/api')->info($v['uid']);
  15. $data[$k]['username'] = $user['username'];
  16. $data[$k]['avatar'] = $user['avatar'];
  17. }
  18. }
  19. return $data;
  20. }
  21. # 发表评论
  22. public function submit($uid, $id, $type, $content)
  23. {
  24. $where['uid'] = $uid;
  25. $where['data_id'] = $id;
  26. $where['type'] = $type;
  27. $where['content'] = $content;
  28. $info = Dever::db('act/comment')->one($where);
  29. if (!$info) {
  30. Dever::db('act/comment')->insert($where);
  31. }
  32. # 更新评论数
  33. $where = array();
  34. $where['data_id'] = $id;
  35. $where['type'] = $type;
  36. $total = Dever::db('act/comment')->total($where);
  37. $table = Dever::config('base')->type_table[$type];
  38. Dever::db($table)->update(array('where_id' => $id, 'num_comment' => $total));
  39. return true;
  40. }
  41. }