|
@@ -19,7 +19,7 @@ class Topicdongtai extends Api
|
|
public function addone(){
|
|
public function addone(){
|
|
$content = input('content','');
|
|
$content = input('content','');
|
|
$images = input('images','');
|
|
$images = input('images','');
|
|
- $topic_id = input('topic_id','');
|
|
|
|
|
|
+ $topic_id = input('topic_id',1);
|
|
if(!$content && !$images){
|
|
if(!$content && !$images){
|
|
$this->error(__('Invalid parameters'));
|
|
$this->error(__('Invalid parameters'));
|
|
}
|
|
}
|
|
@@ -82,7 +82,7 @@ class Topicdongtai extends Api
|
|
$val['createtime_text'] = get_last_time($val['createtime']);
|
|
$val['createtime_text'] = get_last_time($val['createtime']);
|
|
|
|
|
|
//关注
|
|
//关注
|
|
- $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
|
|
|
|
|
|
+ $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
|
|
|
|
|
|
//评论
|
|
//评论
|
|
$val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
|
|
$val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
|
|
@@ -94,29 +94,38 @@ class Topicdongtai extends Api
|
|
|
|
|
|
//动态删除
|
|
//动态删除
|
|
public function delete(){
|
|
public function delete(){
|
|
- try {
|
|
|
|
- $id = input('id',0);
|
|
|
|
- $where['id'] = $id;
|
|
|
|
- $where['user_id'] = $this->auth->id;
|
|
|
|
- $dongtai = Db::name('topic_dongtai')->field('id,topic_id')->where($where)->find();
|
|
|
|
- if (empty($dongtai)) {
|
|
|
|
- throw new Exception('未找到动态信息');
|
|
|
|
- }
|
|
|
|
- $delRes = Db::name('topic_dongtai')->where('id',$id)->where('user_id',$this->auth->id)->delete();
|
|
|
|
- if (!$delRes) {
|
|
|
|
- throw new Exception('动态删除失败');
|
|
|
|
- }
|
|
|
|
- //圈子新增一个贴
|
|
|
|
- if (!empty($dongtai['topic_id'])) {
|
|
|
|
- $res = Db::name('topic_hub')->where('id',$dongtai['topic_id'])->setDec('t_number');
|
|
|
|
- if (!$res) {
|
|
|
|
- throw new Exception('更新话题数量失败');
|
|
|
|
- }
|
|
|
|
|
|
+
|
|
|
|
+ $id = input('id',0);
|
|
|
|
+ $where['id'] = $id;
|
|
|
|
+ $where['user_id'] = $this->auth->id;
|
|
|
|
+ $dongtai = Db::name('topic_dongtai')->field('id,topic_id')->where($where)->find();
|
|
|
|
+ if (empty($dongtai)) {
|
|
|
|
+ $this->error('未找到动态信息');
|
|
|
|
+ }
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ $delRes = Db::name('topic_dongtai')->where('id',$id)->where('user_id',$this->auth->id)->delete();
|
|
|
|
+ if (!$delRes) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('动态删除失败');
|
|
|
|
+ }
|
|
|
|
+ //圈子新增一个贴
|
|
|
|
+ if (!empty($dongtai['topic_id'])) {
|
|
|
|
+ $res = Db::name('topic_hub')->where('id',$dongtai['topic_id'])->setDec('t_number');
|
|
|
|
+ if (!$res) {
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('更新话题数量失败');
|
|
}
|
|
}
|
|
- $this->success('删除成功');
|
|
|
|
- } catch (Exception $e) {
|
|
|
|
- $this->error($e->getMessage());
|
|
|
|
}
|
|
}
|
|
|
|
+ //删除对应的评论,
|
|
|
|
+ Db::name('topic_dongtai_answer')->where('dt_id',$id)->delete();
|
|
|
|
+ //点赞,
|
|
|
|
+ Db::name('topic_dongtai_good')->where('dt_id',$id)->delete();
|
|
|
|
+ //评论点赞
|
|
|
|
+ Db::name('topic_answer_good')->where('dt_id',$id)->delete();
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+ $this->success('删除成功');
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
//是否点赞
|
|
//是否点赞
|
|
@@ -146,13 +155,13 @@ class Topicdongtai extends Api
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- //是否关注
|
|
|
|
- private function is_follow($user_id,$fans_id){
|
|
|
|
|
|
+ //用户是否拉黑
|
|
|
|
+ private function is_black($uid,$black_uid){
|
|
$where = [
|
|
$where = [
|
|
- 'user_id' => $user_id,
|
|
|
|
- 'fans_id' => $fans_id,
|
|
|
|
|
|
+ 'user_id' => $uid,
|
|
|
|
+ 'black_user_id' => $black_uid,
|
|
];
|
|
];
|
|
- $check = Db::name('user_fans_follow')->where($where)->find();
|
|
|
|
|
|
+ $check = Db::name('user_blacklist')->where($where)->find();
|
|
if($check){
|
|
if($check){
|
|
return 1;
|
|
return 1;
|
|
}else{
|
|
}else{
|
|
@@ -160,6 +169,8 @@ class Topicdongtai extends Api
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+
|
|
|
|
+
|
|
//详情
|
|
//详情
|
|
public function info(){
|
|
public function info(){
|
|
$id = input('id');
|
|
$id = input('id');
|
|
@@ -188,7 +199,7 @@ class Topicdongtai extends Api
|
|
$info['createtime_text'] = get_last_time($info['createtime']);
|
|
$info['createtime_text'] = get_last_time($info['createtime']);
|
|
|
|
|
|
//关注
|
|
//关注
|
|
- $info['is_follow'] = $this->is_follow($info['user_id'],$this->auth->id);
|
|
|
|
|
|
+ $info['is_follow'] = $this->is_follow($this->auth->id,$info['user_id']);
|
|
|
|
|
|
//评论
|
|
//评论
|
|
$info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->count();
|
|
$info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1])->count();
|
|
@@ -207,23 +218,33 @@ class Topicdongtai extends Api
|
|
'user_id' => $this->auth->id,
|
|
'user_id' => $this->auth->id,
|
|
];
|
|
];
|
|
$check = Db::name('topic_dongtai_good')->where($where)->find();
|
|
$check = Db::name('topic_dongtai_good')->where($where)->find();
|
|
|
|
+ $dt_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
|
|
|
|
|
|
if($check){
|
|
if($check){
|
|
- $this->error('已经赞过了');
|
|
|
|
- }
|
|
|
|
|
|
+ Db::name('topic_dongtai_good')->where($where)->delete();
|
|
|
|
+ $down = Db::name('topic_dongtai')->where('id',$id)->setDec('goodnum');
|
|
|
|
+ $this->success('已取消点赞');
|
|
|
|
+ }else{
|
|
|
|
|
|
- Db::startTrans();
|
|
|
|
- $where['createtime'] = time();
|
|
|
|
- $rs = Db::name('topic_dongtai_good')->insertGetId($where);
|
|
|
|
- $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
|
|
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ $where['createtime'] = time();
|
|
|
|
+ $rs = Db::name('topic_dongtai_good')->insertGetId($where);
|
|
|
|
+ if(!$rs){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('点赞失败');
|
|
|
|
+ }
|
|
|
|
+ $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
|
|
|
|
+ if($up === false){
|
|
|
|
+ Db::rollback();
|
|
|
|
+ $this->error('点赞失败');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //系统消息
|
|
|
|
+ $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞','有人赞了你的动态','dongtai_good',$id);
|
|
|
|
|
|
- if($rs && $up !== false){
|
|
|
|
- \app\common\model\TaskLog::tofinish($this->auth->id,"VpXtablCsZ",1);
|
|
|
|
Db::commit();
|
|
Db::commit();
|
|
$this->success('点赞成功');
|
|
$this->success('点赞成功');
|
|
}
|
|
}
|
|
- Db::rollback();
|
|
|
|
- $this->error('点赞失败');
|
|
|
|
}
|
|
}
|
|
|
|
|
|
//评论
|
|
//评论
|
|
@@ -282,6 +303,23 @@ class Topicdongtai extends Api
|
|
|
|
|
|
Db::name('topic_dongtai')->where('id',$id)->setInc('answernum');
|
|
Db::name('topic_dongtai')->where('id',$id)->setInc('answernum');
|
|
|
|
|
|
|
|
+ //系统消息
|
|
|
|
+ if($level == 1){
|
|
|
|
+ //发给动态用户
|
|
|
|
+ $msg_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
|
|
|
|
+ $msg_title = '动态评论';
|
|
|
|
+ $msg_content = '有人评论了你的动态';
|
|
|
|
+ $infotype_id = $rs;
|
|
|
|
+ }else{
|
|
|
|
+ //发给层主
|
|
|
|
+ $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
|
|
|
|
+ $msg_user_id = $answer_info['user_id'];
|
|
|
|
+ $msg_title = '动态评论点评';
|
|
|
|
+ $msg_content = '有人点评了你的动态评论';
|
|
|
|
+ $infotype_id = $answer_info['id'];
|
|
|
|
+ }
|
|
|
|
+ $msg_id = \app\common\model\Message::addMessage($msg_user_id,$msg_title,$msg_content,'dongtai_answer',$infotype_id);
|
|
|
|
+
|
|
Db::commit();
|
|
Db::commit();
|
|
$this->success('评价成功');
|
|
$this->success('评价成功');
|
|
}
|
|
}
|
|
@@ -299,7 +337,9 @@ class Topicdongtai extends Api
|
|
$check = Db::name('topic_answer_good')->where($where)->find();
|
|
$check = Db::name('topic_answer_good')->where($where)->find();
|
|
|
|
|
|
if($check){
|
|
if($check){
|
|
- $this->error('已经赞过了');
|
|
|
|
|
|
+ Db::name('topic_answer_good')->where($where)->delete();
|
|
|
|
+ Db::name('topic_dongtai_answer')->where('id',$answer_id)->setDec('goodnum');
|
|
|
|
+ $this->success('已取消点赞');
|
|
}
|
|
}
|
|
|
|
|
|
Db::startTrans();
|
|
Db::startTrans();
|
|
@@ -328,7 +368,7 @@ class Topicdongtai extends Api
|
|
}
|
|
}
|
|
|
|
|
|
//举报
|
|
//举报
|
|
- /*public function report(){
|
|
|
|
|
|
+ public function report(){
|
|
$field = ['dt_id','type','content','images'];
|
|
$field = ['dt_id','type','content','images'];
|
|
$data = request_post_hub($field);
|
|
$data = request_post_hub($field);
|
|
|
|
|
|
@@ -340,7 +380,7 @@ class Topicdongtai extends Api
|
|
|
|
|
|
Db::name('topic_dongtai_report')->insertGetId($data);
|
|
Db::name('topic_dongtai_report')->insertGetId($data);
|
|
$this->success('举报成功');
|
|
$this->success('举报成功');
|
|
- }*/
|
|
|
|
|
|
+ }
|
|
|
|
|
|
//不感兴趣,屏蔽某条
|
|
//不感兴趣,屏蔽某条
|
|
public function screen(){
|
|
public function screen(){
|
|
@@ -500,7 +540,7 @@ class Topicdongtai extends Api
|
|
$val['createtime_text'] = get_last_time($val['createtime']);
|
|
$val['createtime_text'] = get_last_time($val['createtime']);
|
|
|
|
|
|
//关注
|
|
//关注
|
|
- $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
|
|
|
|
|
|
+ $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
|
|
|
|
|
|
//评论
|
|
//评论
|
|
$val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
|
|
$val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
|
|
@@ -560,5 +600,135 @@ class Topicdongtai extends Api
|
|
$this->success(1,$list);
|
|
$this->success(1,$list);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+////////////////////
|
|
|
|
+ //我的评论
|
|
|
|
+ public function my_answer(){
|
|
|
|
+ $map = [
|
|
|
|
+ 'a.user_id' => $this->auth->id,
|
|
|
|
+ 'a.level' => 1,
|
|
|
|
+ ];
|
|
|
|
+ $list = Db::name('topic_dongtai_answer')->alias('a')
|
|
|
|
+ ->field('a.id,a.createtime,a.content,a.dt_id,
|
|
|
|
+ dt.images,dt.content as dt_content,dt.type as dt_type,dtuser.nickname as dtuser_nickname,dtuser.username as dtuser_username,user.username,
|
|
|
|
+ user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
|
|
|
|
+ ->join('topic_dongtai dt','a.dt_id = dt.id','LEFT')
|
|
|
|
+ ->join('user dtuser','dt.user_id = dtuser.id','LEFT')
|
|
|
|
+ ->join('user user','a.user_id = user.id','LEFT')
|
|
|
|
+ ->join('user_wallet uw','user.id = uw.user_id','LEFT')
|
|
|
|
+ ->where($map)->order('a.id desc')->autopage()->select();
|
|
|
|
+ $list = list_domain_image($list,['avatar']);
|
|
|
|
+ if(!empty($list)){
|
|
|
|
+ foreach($list as $key => &$val){
|
|
|
|
+
|
|
|
|
+ //用户年龄
|
|
|
|
+ $val['age'] = birthtime_to_age($val['birthday']);
|
|
|
|
+ unset($val['birthday']);
|
|
|
|
+
|
|
|
|
+ //用户vip
|
|
|
|
+ $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
|
|
|
|
+ unset($val['vip_endtime']);
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->success(1,$list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ //删除我的某个评论
|
|
|
|
+ public function delete_answer(){
|
|
|
|
+ $id = input('id',0);
|
|
|
|
+ if(!$id){
|
|
|
|
+ $this->error();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::startTrans();
|
|
|
|
+ $info = Db::name('topic_dongtai_answer')->where('id',$id)->where('user_id',$this->auth->id)->find();
|
|
|
|
+ if(!$info){
|
|
|
|
+ $this->error('不存在的动态评论');
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ if($info['level'] == 1){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //楼层内都删
|
|
|
|
+ $louceng_id = Db::name('topic_dongtai_answer')->where('dt_id',$info['dt_id'])->where('level',2)->where('floor',$info['floor'])->column('id');
|
|
|
|
+ if(!empty($louceng_id)){
|
|
|
|
+ Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum',count($louceng_id));//回复数减1
|
|
|
|
+ Db::name('topic_dongtai_answer')->where('id','IN',$louceng_id)->delete();//评论删掉
|
|
|
|
+ Db::name('topic_answer_good')->where('answer_id','IN',$louceng_id)->delete();//评论点赞删掉
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Db::name('topic_dongtai')->where('id',$info['dt_id'])->setDec('answernum');//回复数减1
|
|
|
|
+ Db::name('topic_dongtai_answer')->where('id',$id)->delete(); //评论删掉
|
|
|
|
+ Db::name('topic_answer_good')->where('answer_id',$id)->delete();//评论点赞删掉
|
|
|
|
+
|
|
|
|
+ Db::commit();
|
|
|
|
+
|
|
|
|
+ $this->success();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ //我点赞的动态
|
|
|
|
+ public function my_good(){
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $where = ['good.user_id'=>$this->auth->id];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ $list = Db::name('topic_dongtai')->alias('dt')
|
|
|
|
+ ->join('user','dt.user_id = user.id','LEFT')
|
|
|
|
+ ->join('user_wallet uw','user.id = uw.user_id','LEFT')
|
|
|
|
+ ->join('topic_dongtai_good good','dt.id = good.dt_id','LEFT')
|
|
|
|
+ ->field('dt.*,dt.id as dt_id,user.username,user.nickname,user.avatar,user.gender,user.birthday,user.attribute,uw.vip_endtime')
|
|
|
|
+ ->where($where)
|
|
|
|
+ ->order('dt.id desc')->autopage()->select();
|
|
|
|
+ $list = list_domain_image($list,['images','audio_file','avatar']);
|
|
|
|
+
|
|
|
|
+ if(!empty($list)){
|
|
|
|
+ foreach($list as $key => &$val){
|
|
|
|
+ $val['aite'] = json_decode($val['aite'],true);
|
|
|
|
+
|
|
|
|
+ //用户年龄
|
|
|
|
+ $val['age'] = birthtime_to_age($val['birthday']);
|
|
|
|
+ unset($val['birthday']);
|
|
|
|
+
|
|
|
|
+ //用户vip
|
|
|
|
+ $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
|
|
|
|
+ unset($val['vip_endtime']);
|
|
|
|
+
|
|
|
|
+ //追加点赞
|
|
|
|
+ $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
|
|
|
|
+
|
|
|
|
+ //时间
|
|
|
|
+ $val['createtime_text'] = get_last_time($val['createtime']);
|
|
|
|
+
|
|
|
|
+ //关注
|
|
|
|
+ $val['is_follow'] = $this->is_follow($this->auth->id,$val['user_id']);
|
|
|
|
+
|
|
|
|
+ //收藏
|
|
|
|
+ $val['is_collect'] = $this->is_collect($val['id'],$this->auth->id);
|
|
|
|
+
|
|
|
|
+ //拉黑
|
|
|
|
+ $val['is_black'] = $this->is_black($this->auth->id,$val['user_id']);
|
|
|
|
+
|
|
|
|
+ //层主评论数量
|
|
|
|
+ $val['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$val['id'],'level'=>1])->count();
|
|
|
|
+
|
|
|
|
+ //话题
|
|
|
|
+ $ids_str = $val['topic_ids'];
|
|
|
|
+ if($ids_str){
|
|
|
|
+ $val['topic_text'] = Db::name('topic_hub')->where('id','IN',$val['topic_ids'])->orderRaw('field(id,'.$ids_str.')')->column('name');
|
|
|
|
+ }else{
|
|
|
|
+ $val['topic_text'] = [];
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ $this->success('success',$list);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+
|
|
|
|
|
|
}
|
|
}
|