|
@@ -13,308 +13,6 @@ class Topicdongtai extends Api
|
|
|
protected $noNeedLogin = ['info','floor_info','topic_list'];
|
|
|
protected $noNeedRight = ['*'];
|
|
|
|
|
|
-
|
|
|
-
|
|
|
- //是否点赞
|
|
|
- private function is_good($dt_id,$uid){
|
|
|
- $where = [
|
|
|
- 'dt_id' => $dt_id,
|
|
|
- 'user_id' => $uid,
|
|
|
- ];
|
|
|
- $check = Db::name('topic_dongtai_good')->where($where)->find();
|
|
|
- if($check){
|
|
|
- return 1;
|
|
|
- }else{
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //评论
|
|
|
- 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();
|
|
|
- }
|
|
|
-
|
|
|
- //关键字替换
|
|
|
- $content = Keyworld::sensitive($content);
|
|
|
-
|
|
|
- //判断
|
|
|
- if($level == 2 && $floor == 0){
|
|
|
- $this->error('楼层错误');
|
|
|
- }
|
|
|
-
|
|
|
- //黑名单判断
|
|
|
- //是否被动态发布者拉黑
|
|
|
- $dongtai_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
|
|
|
- $black_check = $this->is_black($dongtai_user_id,$this->auth->id);
|
|
|
- if($black_check){
|
|
|
- $this->error('您已被对方拉黑,禁止评论此动态');
|
|
|
- }
|
|
|
- //是否被层主拉黑
|
|
|
- if($level == 2){
|
|
|
- $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
|
|
|
- $black_check = $this->is_black($answer_info['user_id'],$this->auth->id);
|
|
|
- if($black_check){
|
|
|
- $this->error('您已被对方拉黑,禁止点评此评论');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //回复楼主,最新楼层
|
|
|
- if($level == 1 || $floor == 0){
|
|
|
- $to_user_id = 0;
|
|
|
- $floor = 1; //默认一楼
|
|
|
-
|
|
|
- $last_floor = Db::name('topic_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(),
|
|
|
- ];
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
|
|
|
-
|
|
|
- if($level == 1){
|
|
|
- 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 = $this->auth->nickname.'评论了你的动态';
|
|
|
- $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 = $this->auth->nickname.'点评了你的动态评论';
|
|
|
- $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();
|
|
|
- $this->success('评价成功');
|
|
|
- }
|
|
|
-
|
|
|
- //用户是否拉黑
|
|
|
- private function is_black($uid,$black_uid){
|
|
|
- $where = [
|
|
|
- 'uid' => $uid,
|
|
|
- 'black_uid' => $black_uid,
|
|
|
- ];
|
|
|
- $check = Db::name('user_black')->where($where)->find();
|
|
|
- if($check){
|
|
|
- return 1;
|
|
|
- }else{
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //某动态的评论列表
|
|
|
- public function answer_list(){
|
|
|
- $dt_id = input('id',0);
|
|
|
- //楼
|
|
|
- $floor_list = Db::name('topic_dongtai_answer')
|
|
|
- ->alias('a')
|
|
|
- ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
- ->join('user','a.user_id = user.id','LEFT')
|
|
|
- ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('a.id desc')->autopage()->select();
|
|
|
- $floor_list = list_domain_image($floor_list,['avatar']);
|
|
|
-
|
|
|
- //追加子评论
|
|
|
- if(!empty($floor_list)){
|
|
|
- foreach($floor_list as $key => &$val){
|
|
|
- //下面几条子回复,字符串
|
|
|
- $val['childremark'] = '';
|
|
|
-
|
|
|
- $map = [
|
|
|
- 'a.dt_id' => $dt_id,
|
|
|
- 'a.floor' => $val['floor'],
|
|
|
- 'a.level' => 2,
|
|
|
- ];
|
|
|
- $number = Db::name('topic_dongtai_answer')->alias('a')->where($map)->count();
|
|
|
- if($number > 0){
|
|
|
- $answer_info = Db::name('topic_dongtai_answer')
|
|
|
- ->alias('a')
|
|
|
- ->field('user.nickname')
|
|
|
- ->join('user','a.user_id = user.id','LEFT')
|
|
|
- ->where($map)->order('a.id desc')->find();
|
|
|
-
|
|
|
- $val['childremark'] = $answer_info['nickname'].'...等人,共'.$number.'条回复';
|
|
|
- }
|
|
|
-
|
|
|
- //时间处理
|
|
|
- $val['createtime'] = get_last_time($val['createtime']);
|
|
|
-
|
|
|
- //回复是否已赞
|
|
|
- $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
|
|
|
-
|
|
|
- //用户年龄
|
|
|
- $val['birthday'] = birthtime_to_age($val['birthday']);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- $this->success(1,$floor_list);
|
|
|
- }
|
|
|
-
|
|
|
- //单独某一层的详细
|
|
|
- public function answer_info(){
|
|
|
- $answer_id = input('answer_id');
|
|
|
-
|
|
|
- //楼
|
|
|
- $floor_info = Db::name('topic_dongtai_answer')
|
|
|
- ->alias('a')
|
|
|
- ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
- ->join('user','a.user_id = user.id','LEFT')
|
|
|
- ->where(['a.id'=>$answer_id])->find();
|
|
|
- if(empty($floor_info)){
|
|
|
- $this->success(1,[]);
|
|
|
- }
|
|
|
- $floor_info = info_domain_image($floor_info,['avatar']);
|
|
|
- $floor_info['createtime'] = get_last_time($floor_info['createtime']);
|
|
|
- //用户年龄
|
|
|
- $floor_info['birthday'] = birthtime_to_age($floor_info['birthday']);
|
|
|
- //回复是否已赞
|
|
|
- $floor_info['is_good'] = $this->answer_is_good($answer_id,$this->auth->id);
|
|
|
- $floor_info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$floor_info['dt_id'],'floor'=>$floor_info['floor'],'level'=>2])->count();
|
|
|
-
|
|
|
- //层
|
|
|
- $floors = $floor_info['floor'];
|
|
|
- $child_lists = Db::name('topic_dongtai_answer')->alias('a')
|
|
|
- ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
- ->join('user','a.user_id = user.id','LEFT')
|
|
|
- ->where(['a.dt_id'=>$floor_info['dt_id'],'a.floor'=>$floors,'a.level'=>2])->order('a.id desc')->autopage()->select();
|
|
|
- $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
|
|
|
- if(!empty($child_lists)){
|
|
|
- foreach($child_lists as $key => &$answer){
|
|
|
- //用户年龄
|
|
|
- $answer['birthday'] = birthtime_to_age($answer['birthday']);
|
|
|
-
|
|
|
- $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
|
|
|
- $answer['createtime'] = get_last_time($answer['createtime']);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //合并
|
|
|
- $floor_info['child'] = $child_lists;
|
|
|
-
|
|
|
- $this->success('success',$floor_info);
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- //对评论点赞
|
|
|
- public function answer_good(){
|
|
|
- $dt_id = input('dt_id',0);
|
|
|
- $answer_id = input('answer_id',0);
|
|
|
-
|
|
|
- $where = [
|
|
|
- 'dt_id' => $dt_id,
|
|
|
- 'answer_id' => $answer_id,
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
- ];
|
|
|
- $check = Db::name('topic_answer_good')->where($where)->find();
|
|
|
-
|
|
|
- if($check){
|
|
|
- Db::name('topic_answer_good')->where($where)->delete();
|
|
|
- Db::name('topic_dongtai_answer')->where('id',$answer_id)->setDec('goodnum');
|
|
|
- $this->success('已取消点赞');
|
|
|
- }else{
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- $where['createtime'] = time();
|
|
|
- $rs = Db::name('topic_answer_good')->insertGetId($where);
|
|
|
- $up = Db::name('topic_dongtai_answer')->where('id',$answer_id)->setInc('goodnum');
|
|
|
-
|
|
|
- if($rs && $up !== false){
|
|
|
- Db::commit();
|
|
|
- $this->success('点赞成功');
|
|
|
- }
|
|
|
- Db::rollback();
|
|
|
- $this->error('点赞失败');
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //回复是否点赞
|
|
|
- private function answer_is_good($answer_id,$uid){
|
|
|
- $where = [
|
|
|
- 'answer_id' => $answer_id,
|
|
|
- 'user_id' => $uid,
|
|
|
- ];
|
|
|
- $check = Db::name('topic_answer_good')->where($where)->find();
|
|
|
- if($check){
|
|
|
- return 1;
|
|
|
- }else{
|
|
|
- return 0;
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- //删除我的某个评论
|
|
|
- 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 adddongtai(){
|
|
|
$content = input('content','', 'trim');
|
|
@@ -326,9 +24,9 @@ class Topicdongtai extends Api
|
|
|
if(!$content && !$images){
|
|
|
$this->error(__('Invalid parameters'));
|
|
|
}
|
|
|
- /* if (!in_array($show_real, [0, 1])) {
|
|
|
- $this->error(__('Invalid parameters'));
|
|
|
- }*/
|
|
|
+ /* if (!in_array($show_real, [0, 1])) {
|
|
|
+ $this->error(__('Invalid parameters'));
|
|
|
+ }*/
|
|
|
/*if ($show_real == 1 && $this->auth->real_status != 1) { //验证是否已经通过真人认证
|
|
|
$this->error('您尚未通过真人认证,暂不能标记真人');
|
|
|
}*/
|
|
@@ -436,9 +134,79 @@ class Topicdongtai extends Api
|
|
|
->join('user','dt.user_id = user.id','LEFT')
|
|
|
->join('user_wallet uw','user.id = uw.user_id','LEFT')
|
|
|
->join('topic_hub th','dt.topic_id = th.id','LEFT')
|
|
|
- ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,user.is_hideaddress,th.name,user.real_status,uw.vip_endtime')
|
|
|
+ ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.idcard_status,user.is_hideaddress,th.name,user.real_status,uw.vip_endtime')
|
|
|
+ ->where($where)
|
|
|
+ ->where($where_follow)
|
|
|
+ ->order($orderby)->autopage()->select();
|
|
|
+ $list = list_domain_image($list,['images','avatar']);
|
|
|
+
|
|
|
+ //追加是否点赞
|
|
|
+ if(!empty($list)){
|
|
|
+ $ids = array_column($list,'id');
|
|
|
+ $map = [
|
|
|
+ 'dt_id' => ['IN',$ids],
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $good_list = Db::name('topic_dongtai_good')->where($map)->select();
|
|
|
+ $mt_user_greet = Db::name('user_greet'); //是否打过招呼
|
|
|
+ $mt_gift_user_dongtai = Db::name('gift_user_dongtai');
|
|
|
+
|
|
|
+ foreach ($list as &$val) {
|
|
|
+ $val['name'] = $val['name'] ? : '';
|
|
|
+ $val['birthday'] = birthtime_to_age($val['birthday']);
|
|
|
+ $val['createtime'] = get_last_time($val['createtime']);
|
|
|
+ $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'] ;
|
|
|
+ //用户vip
|
|
|
+ $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
|
|
|
+ unset($val['vip_endtime']);
|
|
|
+
|
|
|
+ //是否点过赞:0否 1是
|
|
|
+ $val['isgood'] = 0;
|
|
|
+ foreach($good_list as $k => $v){
|
|
|
+ if($val['id'] == $v['dt_id']){
|
|
|
+ $val['isgood'] = 1;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ //礼物数量
|
|
|
+ $val['gift_count'] = $mt_gift_user_dongtai->where(['dt_id' => $val['id']])->count('id');
|
|
|
+ //查询是否打过招呼
|
|
|
+ $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $val['user_id']])->count('id');
|
|
|
+ if ($count) {
|
|
|
+ $val['is_chat'] = 1; //是否打过招呼: 1是 0否
|
|
|
+ } else {
|
|
|
+ $val['is_chat'] = 0; //是否打过招呼: 1是 0否
|
|
|
+ }
|
|
|
+
|
|
|
+ //创建视频缩略图
|
|
|
+ $val['images_thumb'] = '';
|
|
|
+ if ($val['type'] == 2) {
|
|
|
+ $images_url = explode('.', $val['images']);
|
|
|
+ unset($images_url[count($images_url) - 1]);
|
|
|
+ $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success('success',$list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户动态列表
|
|
|
+ public function mydongtailist() {
|
|
|
+ $user_id = input('user_id', $this->auth->id);
|
|
|
+ if (!$user_id) {
|
|
|
+ $this->error('您的网络开小差啦~');
|
|
|
+ }
|
|
|
+ $where['dt.user_id'] = $user_id;
|
|
|
+ $where['dt.status'] = 0;
|
|
|
+ $where['dt.auit_status'] = 1;
|
|
|
+ $orderby = 'dt.id desc';
|
|
|
+
|
|
|
+ $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_hub th','dt.topic_id = th.id','LEFT')
|
|
|
+ ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.is_hideaddress,th.name,user.real_status,user.idcard_status,uw.vip_endtime')
|
|
|
->where($where)
|
|
|
- ->where($where_follow)
|
|
|
->order($orderby)->autopage()->select();
|
|
|
$list = list_domain_image($list,['images','avatar']);
|
|
|
|
|
@@ -453,11 +221,12 @@ class Topicdongtai extends Api
|
|
|
$mt_user_greet = Db::name('user_greet'); //是否打过招呼
|
|
|
$mt_gift_user_dongtai = Db::name('gift_user_dongtai');
|
|
|
|
|
|
+
|
|
|
foreach ($list as &$val) {
|
|
|
- $val['name'] = $val['name'] ? : '';
|
|
|
$val['birthday'] = birthtime_to_age($val['birthday']);
|
|
|
$val['createtime'] = get_last_time($val['createtime']);
|
|
|
- $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'] ;
|
|
|
+ $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'];
|
|
|
+
|
|
|
//用户vip
|
|
|
$val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
|
|
|
unset($val['vip_endtime']);
|
|
@@ -532,105 +301,363 @@ class Topicdongtai extends Api
|
|
|
$info['is_chat'] = 0; //是否打过招呼: 1是 0否
|
|
|
}
|
|
|
|
|
|
- //创建视频缩略图
|
|
|
- $info['images_thumb'] = '';
|
|
|
- if ($info['type'] == 2) {
|
|
|
- $images_url = explode('.', $info['images']);
|
|
|
- unset($images_url[count($images_url) - 1]);
|
|
|
- $info['images_thumb'] = join('.', $images_url) . '_0.jpg';
|
|
|
+ //创建视频缩略图
|
|
|
+ $info['images_thumb'] = '';
|
|
|
+ if ($info['type'] == 2) {
|
|
|
+ $images_url = explode('.', $info['images']);
|
|
|
+ unset($images_url[count($images_url) - 1]);
|
|
|
+ $info['images_thumb'] = join('.', $images_url) . '_0.jpg';
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ $this->success('success',$info);
|
|
|
+ }
|
|
|
+
|
|
|
+ //点赞
|
|
|
+ public function good(){
|
|
|
+ $id = input('id', 0, 'intval');
|
|
|
+ if (!$id) {
|
|
|
+ $this->error('您的网络开小差啦~');
|
|
|
+ }
|
|
|
+ $info = Db::name('topic_dongtai')->find($id);
|
|
|
+ if (!$info) {
|
|
|
+ $this->error('您的网络开小差啦~');
|
|
|
+ }
|
|
|
+ if ($info['status'] != 0) {
|
|
|
+ $this->error('您的网络开小差啦~');
|
|
|
+ }
|
|
|
+
|
|
|
+ $where = [
|
|
|
+ 'dt_id' => $id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('topic_dongtai_good')->where($where)->find();
|
|
|
+ $dt_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
|
|
|
+
|
|
|
+ if($check){
|
|
|
+ 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);
|
|
|
+ if(!$rs){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点赞失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
|
|
|
+ if($up === false){
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点赞失败');
|
|
|
+ }
|
|
|
+
|
|
|
+ //系统消息
|
|
|
+ /*if($dt_user_id != $this->auth->id){
|
|
|
+ $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞',$this->auth->nickname.'赞了你的动态','dongtai_good',$id);
|
|
|
+ }*/
|
|
|
+
|
|
|
+ Db::commit();
|
|
|
+ $this->success('点赞成功');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //是否点赞
|
|
|
+ private function is_good($dt_id,$uid){
|
|
|
+ $where = [
|
|
|
+ 'dt_id' => $dt_id,
|
|
|
+ 'user_id' => $uid,
|
|
|
+ ];
|
|
|
+ $check = Db::name('topic_dongtai_good')->where($where)->find();
|
|
|
+ if($check){
|
|
|
+ return 1;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //评论
|
|
|
+ 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();
|
|
|
+ }
|
|
|
+
|
|
|
+ //关键字替换
|
|
|
+ $content = Keyworld::sensitive($content);
|
|
|
+
|
|
|
+ //判断
|
|
|
+ if($level == 2 && $floor == 0){
|
|
|
+ $this->error('楼层错误');
|
|
|
+ }
|
|
|
+
|
|
|
+ //黑名单判断
|
|
|
+ //是否被动态发布者拉黑
|
|
|
+ $dongtai_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
|
|
|
+ $black_check = $this->is_black($dongtai_user_id,$this->auth->id);
|
|
|
+ if($black_check){
|
|
|
+ $this->error('您已被对方拉黑,禁止评论此动态');
|
|
|
+ }
|
|
|
+ //是否被层主拉黑
|
|
|
+ if($level == 2){
|
|
|
+ $answer_info = Db::name('topic_dongtai_answer')->where(['dt_id'=>$id,'level'=>1,'floor'=>$floor])->find();
|
|
|
+ $black_check = $this->is_black($answer_info['user_id'],$this->auth->id);
|
|
|
+ if($black_check){
|
|
|
+ $this->error('您已被对方拉黑,禁止点评此评论');
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //回复楼主,最新楼层
|
|
|
+ if($level == 1 || $floor == 0){
|
|
|
+ $to_user_id = 0;
|
|
|
+ $floor = 1; //默认一楼
|
|
|
+
|
|
|
+ $last_floor = Db::name('topic_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(),
|
|
|
+ ];
|
|
|
+
|
|
|
+ Db::startTrans();
|
|
|
+ $rs = Db::name('topic_dongtai_answer')->insertGetId($data);
|
|
|
+
|
|
|
+ if($level == 1){
|
|
|
+ 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 = $this->auth->nickname.'评论了你的动态';
|
|
|
+ $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 = $this->auth->nickname.'点评了你的动态评论';
|
|
|
+ $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();
|
|
|
+ $this->success('评价成功');
|
|
|
+ }
|
|
|
+
|
|
|
+ //用户是否拉黑
|
|
|
+ private function is_black($uid,$black_uid){
|
|
|
+ $where = [
|
|
|
+ 'uid' => $uid,
|
|
|
+ 'black_uid' => $black_uid,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_black')->where($where)->find();
|
|
|
+ if($check){
|
|
|
+ return 1;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //某动态的评论列表
|
|
|
+ public function answer_list(){
|
|
|
+ $dt_id = input('id',0);
|
|
|
+ //楼
|
|
|
+ $floor_list = Db::name('topic_dongtai_answer')
|
|
|
+ ->alias('a')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
+ ->join('user','a.user_id = user.id','LEFT')
|
|
|
+ ->where(['a.dt_id'=>$dt_id,'a.level'=>1])->order('a.id desc')->autopage()->select();
|
|
|
+ $floor_list = list_domain_image($floor_list,['avatar']);
|
|
|
+
|
|
|
+ //追加子评论
|
|
|
+ if(!empty($floor_list)){
|
|
|
+ foreach($floor_list as $key => &$val){
|
|
|
+ //下面几条子回复,字符串
|
|
|
+ $val['childremark'] = '';
|
|
|
+
|
|
|
+ $map = [
|
|
|
+ 'a.dt_id' => $dt_id,
|
|
|
+ 'a.floor' => $val['floor'],
|
|
|
+ 'a.level' => 2,
|
|
|
+ ];
|
|
|
+ $number = Db::name('topic_dongtai_answer')->alias('a')->where($map)->count();
|
|
|
+ if($number > 0){
|
|
|
+ $answer_info = Db::name('topic_dongtai_answer')
|
|
|
+ ->alias('a')
|
|
|
+ ->field('user.nickname')
|
|
|
+ ->join('user','a.user_id = user.id','LEFT')
|
|
|
+ ->where($map)->order('a.id desc')->find();
|
|
|
+
|
|
|
+ $val['childremark'] = $answer_info['nickname'].'...等人,共'.$number.'条回复';
|
|
|
+ }
|
|
|
+
|
|
|
+ //时间处理
|
|
|
+ $val['createtime'] = get_last_time($val['createtime']);
|
|
|
+
|
|
|
+ //回复是否已赞
|
|
|
+ $val['is_good'] = $this->answer_is_good($val['id'],$this->auth->id);
|
|
|
+
|
|
|
+ //用户年龄
|
|
|
+ $val['birthday'] = birthtime_to_age($val['birthday']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ $this->success(1,$floor_list);
|
|
|
+ }
|
|
|
+
|
|
|
+ //单独某一层的详细
|
|
|
+ public function answer_info(){
|
|
|
+ $answer_id = input('answer_id');
|
|
|
+
|
|
|
+ //楼
|
|
|
+ $floor_info = Db::name('topic_dongtai_answer')
|
|
|
+ ->alias('a')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
+ ->join('user','a.user_id = user.id','LEFT')
|
|
|
+ ->where(['a.id'=>$answer_id])->find();
|
|
|
+ if(empty($floor_info)){
|
|
|
+ $this->success(1,[]);
|
|
|
+ }
|
|
|
+ $floor_info = info_domain_image($floor_info,['avatar']);
|
|
|
+ $floor_info['createtime'] = get_last_time($floor_info['createtime']);
|
|
|
+ //用户年龄
|
|
|
+ $floor_info['birthday'] = birthtime_to_age($floor_info['birthday']);
|
|
|
+ //回复是否已赞
|
|
|
+ $floor_info['is_good'] = $this->answer_is_good($answer_id,$this->auth->id);
|
|
|
+ $floor_info['answernumber'] = Db::name('topic_dongtai_answer')->where(['dt_id'=>$floor_info['dt_id'],'floor'=>$floor_info['floor'],'level'=>2])->count();
|
|
|
+
|
|
|
+ //层
|
|
|
+ $floors = $floor_info['floor'];
|
|
|
+ $child_lists = Db::name('topic_dongtai_answer')->alias('a')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
+ ->join('user','a.user_id = user.id','LEFT')
|
|
|
+ ->where(['a.dt_id'=>$floor_info['dt_id'],'a.floor'=>$floors,'a.level'=>2])->order('a.id desc')->autopage()->select();
|
|
|
+ $child_lists = list_domain_image($child_lists,['avatar','to_avatar']);
|
|
|
+ if(!empty($child_lists)){
|
|
|
+ foreach($child_lists as $key => &$answer){
|
|
|
+ //用户年龄
|
|
|
+ $answer['birthday'] = birthtime_to_age($answer['birthday']);
|
|
|
+
|
|
|
+ $answer['is_good'] = $this->answer_is_good($answer['id'],$this->auth->id);
|
|
|
+ $answer['createtime'] = get_last_time($answer['createtime']);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
+ //合并
|
|
|
+ $floor_info['child'] = $child_lists;
|
|
|
+
|
|
|
+ $this->success('success',$floor_info);
|
|
|
|
|
|
- $this->success('success',$info);
|
|
|
}
|
|
|
|
|
|
- //点赞
|
|
|
- public function good(){
|
|
|
- $id = input('id', 0, 'intval');
|
|
|
- if (!$id) {
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }
|
|
|
- $info = Db::name('topic_dongtai')->find($id);
|
|
|
- if (!$info) {
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }
|
|
|
- if ($info['status'] != 0) {
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }
|
|
|
+ //对评论点赞
|
|
|
+ public function answer_good(){
|
|
|
+ $dt_id = input('dt_id',0);
|
|
|
+ $answer_id = input('answer_id',0);
|
|
|
|
|
|
$where = [
|
|
|
- 'dt_id' => $id,
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
+ 'dt_id' => $dt_id,
|
|
|
+ 'answer_id' => $answer_id,
|
|
|
+ 'user_id' => $this->auth->id,
|
|
|
];
|
|
|
- $check = Db::name('topic_dongtai_good')->where($where)->find();
|
|
|
- $dt_user_id = Db::name('topic_dongtai')->where('id',$id)->value('user_id');
|
|
|
+ $check = Db::name('topic_answer_good')->where($where)->find();
|
|
|
|
|
|
if($check){
|
|
|
- Db::name('topic_dongtai_good')->where($where)->delete();
|
|
|
- $down = Db::name('topic_dongtai')->where('id',$id)->setDec('goodnum');
|
|
|
+ Db::name('topic_answer_good')->where($where)->delete();
|
|
|
+ Db::name('topic_dongtai_answer')->where('id',$answer_id)->setDec('goodnum');
|
|
|
$this->success('已取消点赞');
|
|
|
}else{
|
|
|
|
|
|
Db::startTrans();
|
|
|
$where['createtime'] = time();
|
|
|
- $rs = Db::name('topic_dongtai_good')->insertGetId($where);
|
|
|
- if(!$rs){
|
|
|
- Db::rollback();
|
|
|
- $this->error('点赞失败');
|
|
|
- }
|
|
|
+ $rs = Db::name('topic_answer_good')->insertGetId($where);
|
|
|
+ $up = Db::name('topic_dongtai_answer')->where('id',$answer_id)->setInc('goodnum');
|
|
|
|
|
|
- $up = Db::name('topic_dongtai')->where('id',$id)->setInc('goodnum');
|
|
|
- if($up === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error('点赞失败');
|
|
|
+ if($rs && $up !== false){
|
|
|
+ Db::commit();
|
|
|
+ $this->success('点赞成功');
|
|
|
}
|
|
|
-
|
|
|
- //系统消息
|
|
|
- /*if($dt_user_id != $this->auth->id){
|
|
|
- $msg_id = \app\common\model\Message::addMessage($dt_user_id,'动态点赞',$this->auth->nickname.'赞了你的动态','dongtai_good',$id);
|
|
|
- }*/
|
|
|
-
|
|
|
- Db::commit();
|
|
|
- $this->success('点赞成功');
|
|
|
+ Db::rollback();
|
|
|
+ $this->error('点赞失败');
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //点赞列表
|
|
|
- public function dongtaigoodlist() {
|
|
|
- $id = input('id', 0, 'intval');
|
|
|
- if (!$id) {
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
+ //回复是否点赞
|
|
|
+ private function answer_is_good($answer_id,$uid){
|
|
|
+ $where = [
|
|
|
+ 'answer_id' => $answer_id,
|
|
|
+ 'user_id' => $uid,
|
|
|
+ ];
|
|
|
+ $check = Db::name('topic_answer_good')->where($where)->find();
|
|
|
+ if($check){
|
|
|
+ return 1;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
}
|
|
|
- //点赞只能查看异性
|
|
|
- $dongtaiWhere['td.id'] = $id;
|
|
|
- $dongtai = Db::name('topic_dongtai')->alias('td')->field('td.id,td.user_id,u.gender')
|
|
|
- ->join('user u','u.id = td.user_id','LEFT')
|
|
|
- ->where($dongtaiWhere)->find();
|
|
|
- $where['a.dt_id'] = $id;
|
|
|
- $gender = isset($dongtai['gender']) ? $dongtai['gender'] : 0;
|
|
|
- if ($gender == 1) {
|
|
|
- $where['user.gender'] = 0;
|
|
|
- } elseif ($gender == 0) {
|
|
|
- $where['user.gender'] = 1;
|
|
|
+ }
|
|
|
+
|
|
|
+ //删除我的某个评论
|
|
|
+ public function delete_answer(){
|
|
|
+ $id = input('id',0);
|
|
|
+ if(!$id){
|
|
|
+ $this->error();
|
|
|
}
|
|
|
- $list = Db::name('topic_dongtai_good')->alias('a')
|
|
|
- ->join('user', 'a.user_id = user.id', 'left')
|
|
|
- ->field('a.*, user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
- ->where($where)
|
|
|
- ->order('a.id desc')
|
|
|
- ->autopage()->select();
|
|
|
|
|
|
- if (!$list) {
|
|
|
- $this->success('success', $list);
|
|
|
+ Db::startTrans();
|
|
|
+ $info = Db::name('topic_dongtai_answer')->where('id',$id)->where('user_id',$this->auth->id)->find();
|
|
|
+ if(!$info){
|
|
|
+ $this->error('不存在的动态评论');
|
|
|
}
|
|
|
- $list = list_domain_image($list,['avatar']);
|
|
|
|
|
|
- foreach ($list as &$v) {
|
|
|
- $v['birthday'] = birthtime_to_age($v['birthday']);
|
|
|
- $v['createtime'] = get_last_time($v['createtime']);
|
|
|
+ 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();//评论点赞删掉
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
- $this->success('success', $list);
|
|
|
+ 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();
|
|
|
}
|
|
|
|
|
|
//动态赠送礼物
|
|
@@ -825,77 +852,47 @@ class Topicdongtai extends Api
|
|
|
$this->success('success', $list);
|
|
|
}
|
|
|
|
|
|
- //用户动态列表
|
|
|
- public function mydongtailist() {
|
|
|
- $user_id = input('user_id', $this->auth->id);
|
|
|
- if (!$user_id) {
|
|
|
+/////////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
+
|
|
|
+ //点赞列表
|
|
|
+ public function dongtaigoodlist() {
|
|
|
+ $id = input('id', 0, 'intval');
|
|
|
+ if (!$id) {
|
|
|
$this->error('您的网络开小差啦~');
|
|
|
}
|
|
|
- $where['dt.user_id'] = $user_id;
|
|
|
- $where['dt.status'] = 0;
|
|
|
- $where['dt.auit_status'] = 1;
|
|
|
- $orderby = 'dt.id desc';
|
|
|
-
|
|
|
- $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_hub th','dt.topic_id = th.id','LEFT')
|
|
|
- ->field('dt.*,user.nickname,user.avatar,user.gender,user.birthday,user.is_hideaddress,th.name,user.real_status,user.idcard_status,uw.vip_endtime')
|
|
|
+ //点赞只能查看异性
|
|
|
+ $dongtaiWhere['td.id'] = $id;
|
|
|
+ $dongtai = Db::name('topic_dongtai')->alias('td')->field('td.id,td.user_id,u.gender')
|
|
|
+ ->join('user u','u.id = td.user_id','LEFT')
|
|
|
+ ->where($dongtaiWhere)->find();
|
|
|
+ $where['a.dt_id'] = $id;
|
|
|
+ $gender = isset($dongtai['gender']) ? $dongtai['gender'] : 0;
|
|
|
+ if ($gender == 1) {
|
|
|
+ $where['user.gender'] = 0;
|
|
|
+ } elseif ($gender == 0) {
|
|
|
+ $where['user.gender'] = 1;
|
|
|
+ }
|
|
|
+ $list = Db::name('topic_dongtai_good')->alias('a')
|
|
|
+ ->join('user', 'a.user_id = user.id', 'left')
|
|
|
+ ->field('a.*, user.nickname,user.avatar,user.gender,user.birthday')
|
|
|
->where($where)
|
|
|
- ->order($orderby)->autopage()->select();
|
|
|
- $list = list_domain_image($list,['images','avatar']);
|
|
|
-
|
|
|
- //追加是否点赞
|
|
|
- if(!empty($list)){
|
|
|
- $ids = array_column($list,'id');
|
|
|
- $map = [
|
|
|
- 'dt_id' => ['IN',$ids],
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
- ];
|
|
|
- $good_list = Db::name('topic_dongtai_good')->where($map)->select();
|
|
|
- $mt_user_greet = Db::name('user_greet'); //是否打过招呼
|
|
|
- $mt_gift_user_dongtai = Db::name('gift_user_dongtai');
|
|
|
-
|
|
|
-
|
|
|
- foreach ($list as &$val) {
|
|
|
- $val['birthday'] = birthtime_to_age($val['birthday']);
|
|
|
- $val['createtime'] = get_last_time($val['createtime']);
|
|
|
- $val['cityname'] = $val['is_hideaddress'] ? '' : $val['address'];
|
|
|
-
|
|
|
- //用户vip
|
|
|
- $val['is_vip'] = $val['vip_endtime'] > time() ? 1 : 0;
|
|
|
- unset($val['vip_endtime']);
|
|
|
+ ->order('a.id desc')
|
|
|
+ ->autopage()->select();
|
|
|
|
|
|
- //是否点过赞:0否 1是
|
|
|
- $val['isgood'] = 0;
|
|
|
- foreach($good_list as $k => $v){
|
|
|
- if($val['id'] == $v['dt_id']){
|
|
|
- $val['isgood'] = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- //礼物数量
|
|
|
- $val['gift_count'] = $mt_gift_user_dongtai->where(['dt_id' => $val['id']])->count('id');
|
|
|
- //查询是否打过招呼
|
|
|
- $count = $mt_user_greet->where(['user_id' => $this->auth->id, 'user_to_id' => $val['user_id']])->count('id');
|
|
|
- if ($count) {
|
|
|
- $val['is_chat'] = 1; //是否打过招呼: 1是 0否
|
|
|
- } else {
|
|
|
- $val['is_chat'] = 0; //是否打过招呼: 1是 0否
|
|
|
- }
|
|
|
+ if (!$list) {
|
|
|
+ $this->success('success', $list);
|
|
|
+ }
|
|
|
+ $list = list_domain_image($list,['avatar']);
|
|
|
|
|
|
- //创建视频缩略图
|
|
|
- $val['images_thumb'] = '';
|
|
|
- if ($val['type'] == 2) {
|
|
|
- $images_url = explode('.', $val['images']);
|
|
|
- unset($images_url[count($images_url) - 1]);
|
|
|
- $val['images_thumb'] = join('.', $images_url) . '_0.jpg';
|
|
|
- }
|
|
|
- }
|
|
|
+ foreach ($list as &$v) {
|
|
|
+ $v['birthday'] = birthtime_to_age($v['birthday']);
|
|
|
+ $v['createtime'] = get_last_time($v['createtime']);
|
|
|
}
|
|
|
|
|
|
- $this->success('success',$list);
|
|
|
+ $this->success('success', $list);
|
|
|
}
|
|
|
-/////////////////////////////////////////////////////////////////////////////////
|
|
|
+
|
|
|
//删除动态
|
|
|
public function deldongtai() {
|
|
|
$id = input('id', 0, 'intval');
|