| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768 | <?phpnamespace app\api\controller;use app\common\controller\Api;use think\Db;/** * 话题中心 */class Topichub extends Api{    protected $noNeedLogin = [];    protected $noNeedRight = ['*'];    //话题列表    public function lists(){        $list = Db::name('topic_hub')->where('status',1)->order('weight desc,id desc')->autopage()->select();        $list = list_domain_image($list,['image']);        $this->success('success',$list);    }    //某个话题详情    public function info(){        $id   = input('id',0);        $info = Db::name('topic_hub')->where(['status'=>1,'id'=>$id])->find();        $info = info_domain_image($info,['image']);        //是否关注        $is_follow = Db::name('user_follow_topic')->where(['uid'=>$this->auth->id,'topic_id'=>$id])->find();        $info['is_follow'] = !empty($is_follow) ? 1 : 0;        $this->success('success',$info);    }    //关注某人    public function follow_one(){        $topic_id = input('topic_id',0);        if(!$topic_id){            $this->error(__('Invalid parameters'));        }        $topic_hub = Db::name('topic_hub')->find($topic_id);        if(empty($topic_hub)){            $this->error('此话题不存在');        }        $map = [            'uid' => $this->auth->id,            'topic_id' => $topic_id,        ];        $check = Db::name('user_follow_topic')->where($map)->find();        if($check){            //取关            $rs = Db::name('user_follow_topic')->where($map)->delete();            $this->success('操作成功');        }        $id = Db::name('user_follow_topic')->insertGetId($map);        $this->success('操作成功',$id);    }}
 |