Info.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace Community\Lib;
  3. use Dever;
  4. class Info
  5. {
  6. private function table($type)
  7. {
  8. $table = Dever::db('community/info')->config['type_name'][$type];
  9. return $table;
  10. }
  11. # 获取列表
  12. public function get($id, $type, $uid = false)
  13. {
  14. $where['type'] = $type;
  15. $where['type_id'] = $id;
  16. $table = $this->table($type);
  17. $data = Dever::db($table)->getAll($where);
  18. if ($data) {
  19. foreach ($data as $k => $v) {
  20. $user = Dever::load('passport/api')->info($v['uid']);
  21. $data[$k]['time'] = Dever::mdate($v['cdate'], 2);
  22. $data[$k]['username'] = $user['username'];
  23. $data[$k]['avatar'] = $user['avatar'];
  24. $data[$k]['cdate_time'] = date('Y-m-d H:i:s', $v['cdate']);
  25. # 检查是否点赞
  26. if ($uid > 0) {
  27. $data[$k]['up'] = Dever::load('act/lib/like')->get($uid, $v['id'], 11);
  28. } else {
  29. $data[$k]['up'] = 0;
  30. }
  31. $data[$k]['content'] = $this->getContent($v['content']);
  32. }
  33. }
  34. return $data;
  35. }
  36. # 获取当前用户的信息列表
  37. public function getList($uid)
  38. {
  39. $where['uid'] = $uid;
  40. $where['type'] = '1,2,3';
  41. $info = Dever::db('community/comment')->getAll($where);
  42. if ($info) {
  43. foreach ($info as $k => $v) {
  44. $info[$k]['content'] = $this->getContent($v['content']);
  45. }
  46. }
  47. return $info;
  48. }
  49. public function content($content, $id)
  50. {
  51. $content = $this->getContent($content);
  52. return '<span class=dever-emoji>'.$content.'</span>';
  53. }
  54. public function getContent($content)
  55. {
  56. if (strstr($content, '_b64')) {
  57. $content = str_replace('_b64', '', $content);
  58. $content = base64_decode($content);
  59. }
  60. return $content;
  61. }
  62. # 发表信息
  63. public function submit($uid, $id, $type, $content)
  64. {
  65. $where['uid'] = $uid;
  66. $where['type_id'] = $id;
  67. $where['type'] = $type;
  68. $where['content'] = base64_encode($content) . '_b64';
  69. $table = $this->table($type);
  70. $info = Dever::db($table)->one($where);
  71. $data_table = $this->table($type);
  72. if (!$info) {
  73. $data = Dever::db($data_table)->one($id);
  74. if (isset($data['name']) && $data['name']) {
  75. $where['type_name'] = $data['name'];
  76. }
  77. Dever::db($table)->insert($where);
  78. }
  79. Dever::score($uid, 'submit_commit', '发表评论');
  80. # 更新评论数
  81. $where = array();
  82. $where['data_id'] = $id;
  83. $where['type'] = $type;
  84. $where['state'] = 1;
  85. $total = Dever::db($table)->total($where);
  86. //Dever::db($data_table)->update(array('where_id' => $id, 'num_comment' => $total));
  87. return true;
  88. }
  89. }