|
@@ -0,0 +1,235 @@
|
|
|
+<?php
|
|
|
+
|
|
|
+namespace app\api\controller;
|
|
|
+
|
|
|
+use app\common\controller\Api;
|
|
|
+use think\Db;
|
|
|
+/**
|
|
|
+ * 圈子动态
|
|
|
+ */
|
|
|
+class Topicdongtai extends Api
|
|
|
+{
|
|
|
+ protected $noNeedLogin = ['info','floor_info'];
|
|
|
+ protected $noNeedRight = ['*'];
|
|
|
+
|
|
|
+ //发布动态
|
|
|
+ public function addone(){
|
|
|
+ $content = input('content','');
|
|
|
+ $images = input('images','');
|
|
|
+ if(!$content && !$images){
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }
|
|
|
+
|
|
|
+ $data = [
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'content' => $content,
|
|
|
+ 'images' => $images,
|
|
|
+ 'longitude' => input('longitude',''),
|
|
|
+ 'latitude' => input('latitude',''),
|
|
|
+ 'createtime' => time(),
|
|
|
+ 'updatetime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+
|
|
|
+ $id = Db::name('user_dongtai')->insertGetId($data);
|
|
|
+
|
|
|
+ $this->success('success',$id);
|
|
|
+ }
|
|
|
+
|
|
|
+ //自己看列表
|
|
|
+ public function my_lists(){
|
|
|
+
|
|
|
+ $list = Db::name('user_dongtai')->alias('dt')
|
|
|
+ ->join('user','dt.user_id = user.id','LEFT')
|
|
|
+ ->field('dt.*,user.nickname,user.avatar')
|
|
|
+ ->where('dt.user_id',$this->auth->id)
|
|
|
+ ->order('dt.id desc')->autopage()->select();
|
|
|
+ $list = list_domain_image($list,['images','avatar']);
|
|
|
+
|
|
|
+ $this->success('success',$list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //详情
|
|
|
+ public function info(){
|
|
|
+ $id = input('id');
|
|
|
+
|
|
|
+ $info = Db::name('user_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']);
|
|
|
+
|
|
|
+ //是否点赞过
|
|
|
+ if($info){
|
|
|
+ $where = [
|
|
|
+ 'dt_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_dongtai_good')->where($where)->find();
|
|
|
+
|
|
|
+ if($check){
|
|
|
+ $info['isgood'] = 1;
|
|
|
+ }else{
|
|
|
+ $info['isgood'] = 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //评论
|
|
|
+ $info['answer'] = $this->answer_list($id);
|
|
|
+
|
|
|
+ $this->success('success',$info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //点赞
|
|
|
+ public function good(){
|
|
|
+ $id = input('id');
|
|
|
+
|
|
|
+ $where = [
|
|
|
+ 'dt_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_dongtai_good')->where($where)->find();
|
|
|
+
|
|
|
+ if($check){
|
|
|
+ $this->error('已经赞过了');
|
|
|
+ }
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ $rs = Db::name('user_dongtai_good')->insertGetId($where);
|
|
|
+ $up = Db::name('user_dongtai')->where('id',$id)->setInc('goodnum');
|
|
|
+
|
|
|
+ if($rs && $up !== false){
|
|
|
+ Db::commit();
|
|
|
+ $this->success('点赞成功');
|
|
|
+ }
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点赞失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //评论
|
|
|
+ public function answer(){
|
|
|
+ $id = input('id',0);
|
|
|
+ $content = input('content','');
|
|
|
+ $to_user_id = input('to_user_id',0);
|
|
|
+ $level = input('level',1); //回复类型:1=层主回复楼主,2=层中回复
|
|
|
+ $floor = input('floor',0);
|
|
|
+
|
|
|
+ if(empty($content) || empty($id)){
|
|
|
+ $this->error();
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断
|
|
|
+ if($level == 2 && $floor == 0){
|
|
|
+ $this->error('楼层错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ //回复楼主,最新楼层
|
|
|
+ if($level == 1 || $floor == 0){
|
|
|
+ $to_user_id = 0;
|
|
|
+ $floor = 1; //默认一楼
|
|
|
+
|
|
|
+ $last_floor = Db::name('user_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->order('floor desc')->value('floor');
|
|
|
+ if($last_floor){
|
|
|
+ $floor = $last_floor + 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //判断user_id
|
|
|
+ if($to_user_id){
|
|
|
+ $to_user = Db::name('user')->where('id',$to_user_id)->value('id');
|
|
|
+ if(empty($to_user)){
|
|
|
+ $this->error('被回复的用户不存在');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //data
|
|
|
+ $data = [
|
|
|
+ 'dt_id' => $id,
|
|
|
+ 'floor' => $floor,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ 'content' => $content,
|
|
|
+ 'to_user_id' => $to_user_id,
|
|
|
+ 'level' => $level,
|
|
|
+ 'createtime' => time(),
|
|
|
+ 'updatetime' => time(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ $rs = Db::name('user_dongtai_answer')->insertGetId($data);
|
|
|
+ $this->success('评价成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //评论列表
|
|
|
+ private function answer_list($dt_id){
|
|
|
+ //楼
|
|
|
+ $floor_list = Db::name('user_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']);
|
|
|
+ if(empty($floor_list)){
|
|
|
+ return [];
|
|
|
+ }
|
|
|
+
|
|
|
+ //层
|
|
|
+ $floors = array_column($floor_list,'floor');
|
|
|
+ $child_lists = Db::name('user_dongtai_answer')->alias('a')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,tuser.nickname as to_nickname,tuser.avatar as to_avatar')
|
|
|
+ ->join('user','a.user_id = user.id','LEFT')
|
|
|
+ ->join('user tuser','a.to_user_id = tuser.id','LEFT')
|
|
|
+ ->where(['a.floor'=>['IN',$floors],'a.level'=>2])->order('id asc')->select();
|
|
|
+ $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
|
|
|
+ /*if(empty($child_lists)){
|
|
|
+ return $floor_list;
|
|
|
+ }*/
|
|
|
+
|
|
|
+ //合并
|
|
|
+ foreach($floor_list as $key => $val){
|
|
|
+ $child = [];
|
|
|
+ foreach($child_lists as $k => $v){
|
|
|
+ if($val['floor'] == $v['floor']){
|
|
|
+ $child[] = $v;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //追加到外循环
|
|
|
+ $floor_list[$key]['childcount'] = 0;
|
|
|
+ if(count($child) > 4){
|
|
|
+ $floor_list[$key]['childcount'] = count($child) - 4;
|
|
|
+ }
|
|
|
+ $floor_list[$key]['child'] = array_slice($child,0,4);
|
|
|
+ }
|
|
|
+
|
|
|
+ return $floor_list;
|
|
|
+ }
|
|
|
+
|
|
|
+ //单独某一层的详细
|
|
|
+ public function floor_info(){
|
|
|
+ $floor_id = input('floor_id');
|
|
|
+
|
|
|
+ //楼
|
|
|
+ $floor_info = Db::name('user_dongtai_answer')
|
|
|
+ ->alias('a')
|
|
|
+ ->field('a.*,user.nickname,user.avatar')
|
|
|
+ ->join('user','a.user_id = user.id','LEFT')
|
|
|
+ ->where(['a.id'=>$floor_id])->find();
|
|
|
+ $floor_info = info_domain_image($floor_info,['avatar']);
|
|
|
+
|
|
|
+ //层
|
|
|
+ $floors = $floor_info['floor'];
|
|
|
+ $child_lists = Db::name('user_dongtai_answer')->alias('a')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,tuser.nickname as to_nickname,tuser.avatar as to_avatar')
|
|
|
+ ->join('user','a.user_id = user.id','LEFT')
|
|
|
+ ->join('user tuser','a.to_user_id = tuser.id','LEFT')
|
|
|
+ ->where(['a.floor'=>$floors,'a.level'=>2])->order('id asc')->autopage()->select();
|
|
|
+ $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
|
|
|
+
|
|
|
+ //合并
|
|
|
+ $floor_info['child'] = $child_lists;
|
|
|
+
|
|
|
+ $this->success('success',$floor_info);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+}
|