123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- use app\common\library\Keyworld;
- /**
- * 圈子动态
- */
- class Topicdongtai extends Api
- {
- protected $noNeedLogin = ['info','floor_info','topic_list','answer_list'];
- protected $noNeedRight = ['*'];
- //某个话题里的动态列表
- public function topic_list(){
- $topic_id = input('topic_id',0);
- $orderby = 'dt.id desc';
- $list = Db::name('topic_dongtai')->alias('dt')
- ->join('user','dt.user_id = user.id','LEFT')
- ->field('dt.*,user.nickname,user.avatar');
- //非必传
- if($topic_id){
- $list = $list->where('find_in_set(:topic_ids,topic_ids)', ['topic_ids' => $topic_id]);
- }
- $list = $list->order($orderby)->autopage()->select();
- $list = list_domain_image($list,['images','avatar']);
- $this->success('success',$list);
- }
- //详情
- public function info(){
- $id = input('id');
- //展示数量自增1
- $up = Db::name('topic_dongtai')->where('id',$id)->setInc('looknum');
- $info = Db::name('topic_dongtai')->alias('dt')
- ->join('user','dt.user_id = user.id','LEFT')
- ->field('dt.*,user.nickname,user.avatar')
- ->where('dt.id',$id)->find();
- $info = info_domain_image($info,['images','avatar']);
- $topic_text = Db::name('topic_hub')->where('id','IN',$info['topic_ids'])->column('name');
- $info['topic_text'] = implode(',',$topic_text);
- //评论
- if($info){
- $info['answernumber'] = Db::name('topic_dongtai_answer')->where('dt_id',$id)->where('level',1)->count('id');
- }
- //是否赞过
- $info['is_good'] = 0;
- if($this->auth->isLogin()){
- $is_good = Db::name('topic_dongtai_good')->where(['user_id'=>$this->auth->id,'dongtai_id'=>$id])->find();
- if($is_good){
- $info['is_good'] = 1;
- }
- }
- $this->success('success',$info);
- }
- //评论列表
- public function answer_list(){
- $dt_id = input('id');
- //楼
- $floor_list = Db::name('topic_dongtai_answer')
- ->alias('a')
- ->field('a.*,user.nickname,user.avatar')
- ->join('user','a.user_id = user.id','LEFT')
- ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('id asc')->autopage()->select();
- $floor_list = list_domain_image($floor_list,['avatar']);
- $this->success('success',$floor_list);
- }
- //发布动态
- public function addone(){
- $title = input('title','');
- $content = input('content','');
- $images = input('images','');
- $topic_ids = input('topic_ids','');
- $topic_ids = implode(',',explode(',',$topic_ids));
- if(empty($title) || empty($content) || empty($images)){
- $this->error(__('Invalid parameters'));
- }
- //关键字替换
- //$content = Keyworld::sensitive($content);
- $data = [
- 'topic_ids' => $topic_ids,
- 'user_id' => $this->auth->id,
- 'title' => $title,
- 'content' => $content,
- 'images' => $images,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- $id = Db::name('topic_dongtai')->insertGetId($data);
- //圈子新增一个贴
- $rs = Db::name('topic_hub')->where('id','IN',$topic_ids)->setInc('t_number');
- $this->success('发布成功',$id);
- }
- //点赞
- public function good(){
- $id = input('id');
- $where = ['user_id'=>$this->auth->id,'dongtai_id'=>$id];
- $check = Db::name('topic_dongtai_good')->where($where)->find();
- if($check){
- Db::name('topic_dongtai_good')->where($where)->delete();
- Db::name('topic_dongtai')->where('id',$id)->setDec('goodnum');
- }else{
- Db::name('topic_dongtai_good')->insertGetId($where);
- $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
- }
- $goodnum = Db::name('topic_dongtai')->where('id',$id)->value('goodnum');
- $this->success(1,$goodnum);
- }
- //评论
- public function answer(){
- $id = input('id',0);
- $content = input('content','');
- if(empty($content) || empty($id)){
- $this->error();
- }
- //关键字替换
- //$content = Keyworld::sensitive($content);
- //data
- $data = [
- 'dt_id' => $id,
- 'floor' => 1,
- 'user_id' => $this->auth->id,
- 'content' => $content,
- 'to_user_id' => 0,
- 'level' => 1,
- 'createtime' => time(),
- 'updatetime' => time(),
- ];
- $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
- $this->success('评价成功');
- }
- }
|