Topicdongtai.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. <?php
  2. namespace app\api\controller;
  3. use app\common\controller\Api;
  4. use think\Db;
  5. use app\common\library\Keyworld;
  6. /**
  7. * 圈子动态
  8. */
  9. class Topicdongtai extends Api
  10. {
  11. protected $noNeedLogin = ['info','floor_info','topic_list','answer_list'];
  12. protected $noNeedRight = ['*'];
  13. //某个话题里的动态列表
  14. public function topic_list(){
  15. $topic_id = input('topic_id',0);
  16. $orderby = 'dt.id desc';
  17. $list = Db::name('topic_dongtai')->alias('dt')
  18. ->join('user','dt.user_id = user.id','LEFT')
  19. ->field('dt.*,user.nickname,user.avatar');
  20. //非必传
  21. if($topic_id){
  22. $list = $list->where('find_in_set(:topic_ids,topic_ids)', ['topic_ids' => $topic_id]);
  23. }
  24. $list = $list->order($orderby)->autopage()->select();
  25. $list = list_domain_image($list,['images','avatar']);
  26. $this->success('success',$list);
  27. }
  28. //详情
  29. public function info(){
  30. $id = input('id');
  31. //展示数量自增1
  32. $up = Db::name('topic_dongtai')->where('id',$id)->setInc('looknum');
  33. $info = Db::name('topic_dongtai')->alias('dt')
  34. ->join('user','dt.user_id = user.id','LEFT')
  35. ->field('dt.*,user.nickname,user.avatar')
  36. ->where('dt.id',$id)->find();
  37. $info = info_domain_image($info,['images','avatar']);
  38. $topic_text = Db::name('topic_hub')->where('id','IN',$info['topic_ids'])->column('name');
  39. $info['topic_text'] = implode(',',$topic_text);
  40. //评论
  41. if($info){
  42. $info['answernumber'] = Db::name('topic_dongtai_answer')->where('dt_id',$id)->where('level',1)->count('id');
  43. }
  44. //是否赞过
  45. $info['is_good'] = 0;
  46. if($this->auth->isLogin()){
  47. $is_good = Db::name('topic_dongtai_good')->where(['user_id'=>$this->auth->id,'dongtai_id'=>$id])->find();
  48. if($is_good){
  49. $info['is_good'] = 1;
  50. }
  51. }
  52. $this->success('success',$info);
  53. }
  54. //评论列表
  55. public function answer_list(){
  56. $dt_id = input('id');
  57. //楼
  58. $floor_list = Db::name('topic_dongtai_answer')
  59. ->alias('a')
  60. ->field('a.*,user.nickname,user.avatar')
  61. ->join('user','a.user_id = user.id','LEFT')
  62. ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('id asc')->autopage()->select();
  63. $floor_list = list_domain_image($floor_list,['avatar']);
  64. $this->success('success',$floor_list);
  65. }
  66. //发布动态
  67. public function addone(){
  68. $title = input('title','');
  69. $content = input('content','');
  70. $images = input('images','');
  71. $topic_ids = input('topic_ids','');
  72. $topic_ids = implode(',',explode(',',$topic_ids));
  73. if(empty($title) || empty($content) || empty($images)){
  74. $this->error(__('Invalid parameters'));
  75. }
  76. //关键字替换
  77. //$content = Keyworld::sensitive($content);
  78. $data = [
  79. 'topic_ids' => $topic_ids,
  80. 'user_id' => $this->auth->id,
  81. 'title' => $title,
  82. 'content' => $content,
  83. 'images' => $images,
  84. 'createtime' => time(),
  85. 'updatetime' => time(),
  86. ];
  87. $id = Db::name('topic_dongtai')->insertGetId($data);
  88. //圈子新增一个贴
  89. $rs = Db::name('topic_hub')->where('id','IN',$topic_ids)->setInc('t_number');
  90. $this->success('发布成功',$id);
  91. }
  92. //点赞
  93. public function good(){
  94. $id = input('id');
  95. $where = ['user_id'=>$this->auth->id,'dongtai_id'=>$id];
  96. $check = Db::name('topic_dongtai_good')->where($where)->find();
  97. if($check){
  98. Db::name('topic_dongtai_good')->where($where)->delete();
  99. Db::name('topic_dongtai')->where('id',$id)->setDec('goodnum');
  100. }else{
  101. Db::name('topic_dongtai_good')->insertGetId($where);
  102. $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
  103. }
  104. $goodnum = Db::name('topic_dongtai')->where('id',$id)->value('goodnum');
  105. $this->success(1,$goodnum);
  106. }
  107. //评论
  108. public function answer(){
  109. $id = input('id',0);
  110. $content = input('content','');
  111. if(empty($content) || empty($id)){
  112. $this->error();
  113. }
  114. //关键字替换
  115. //$content = Keyworld::sensitive($content);
  116. //data
  117. $data = [
  118. 'dt_id' => $id,
  119. 'floor' => 1,
  120. 'user_id' => $this->auth->id,
  121. 'content' => $content,
  122. 'to_user_id' => 0,
  123. 'level' => 1,
  124. 'createtime' => time(),
  125. 'updatetime' => time(),
  126. ];
  127. $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
  128. $this->success('评价成功');
  129. }
  130. }