|
@@ -53,7 +53,8 @@ class Topicdongtai extends Api
|
|
|
$uid = input('uid',$this->auth->id);
|
|
|
$list = Db::name('topic_dongtai')->alias('dt')
|
|
|
->join('user','dt.user_id = user.id','LEFT')
|
|
|
- ->field('dt.*,user.nickname,user.avatar')
|
|
|
+ ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')
|
|
|
+ ->field('dt.*,user.nickname,user.avatar,user.gender,topic.name as topic_name')
|
|
|
->where('dt.user_id',$uid)
|
|
|
->order('dt.id desc')->autopage()->select();
|
|
|
$list = list_domain_image($list,['images','avatar']);
|
|
@@ -69,11 +70,11 @@ class Topicdongtai extends Api
|
|
|
unset($images_url[count($images_url) - 1]);
|
|
|
$val['images_thumb'] = join('.', $images_url) . '_0.jpg';
|
|
|
}
|
|
|
+
|
|
|
+ $val['createtime_text'] = $this->get_last_time($val['createtime']);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
-
|
|
|
-
|
|
|
$this->success('success',$list);
|
|
|
}
|
|
|
|
|
@@ -91,13 +92,28 @@ class Topicdongtai extends Api
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ //是否关注
|
|
|
+ private function is_follow($user_id,$fans_id){
|
|
|
+ $where = [
|
|
|
+ 'user_id' => $user_id,
|
|
|
+ 'fans_id' => $fans_id,
|
|
|
+ ];
|
|
|
+ $check = Db::name('user_fans_follow')->where($where)->find();
|
|
|
+ if($check){
|
|
|
+ return 1;
|
|
|
+ }else{
|
|
|
+ return 0;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
//详情
|
|
|
public function info(){
|
|
|
$id = input('id');
|
|
|
|
|
|
$info = Db::name('topic_dongtai')->alias('dt')
|
|
|
->join('user','dt.user_id = user.id','LEFT')
|
|
|
- ->field('dt.*,user.nickname,user.avatar')
|
|
|
+ ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')
|
|
|
+ ->field('dt.*,user.nickname,user.avatar,user.gender,topic.name as topic_name')
|
|
|
->where('dt.id',$id)->find();
|
|
|
$info = info_domain_image($info,['images','avatar']);
|
|
|
|
|
@@ -111,7 +127,7 @@ class Topicdongtai extends Api
|
|
|
unset($images_url[count($images_url) - 1]);
|
|
|
$info['images_thumb'] = join('.', $images_url) . '_0.jpg';
|
|
|
}
|
|
|
-
|
|
|
+ $info['createtime_text'] = $this->get_last_time($info['createtime']);
|
|
|
}
|
|
|
|
|
|
//评论
|
|
@@ -202,6 +218,8 @@ class Topicdongtai extends Api
|
|
|
Db::startTrans();
|
|
|
$rs = Db::name('topic_dongtai_answer')->insertGetId($data);
|
|
|
|
|
|
+ Db::name('topic_dongtai')->setInc('answernum');
|
|
|
+
|
|
|
Db::commit();
|
|
|
$this->success('评价成功');
|
|
|
}
|
|
@@ -211,41 +229,32 @@ class Topicdongtai extends Api
|
|
|
//楼
|
|
|
$floor_list = Db::name('topic_dongtai_answer')
|
|
|
->alias('a')
|
|
|
- ->field('a.*,user.nickname,user.avatar')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,user.gender')
|
|
|
->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('topic_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.dt_id'=>$dt_id,'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){
|
|
|
+ $val['childremark'] = '';
|
|
|
|
|
|
- //合并
|
|
|
- foreach($floor_list as $key => $val){
|
|
|
- $child = [];
|
|
|
- foreach($child_lists as $k => $v){
|
|
|
- if($val['floor'] == $v['floor']){
|
|
|
- $child[] = $v;
|
|
|
- }
|
|
|
+ $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.'条回复';
|
|
|
}
|
|
|
- //追加到外循环
|
|
|
- $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;
|
|
@@ -258,7 +267,7 @@ class Topicdongtai extends Api
|
|
|
//楼
|
|
|
$floor_info = Db::name('topic_dongtai_answer')
|
|
|
->alias('a')
|
|
|
- ->field('a.*,user.nickname,user.avatar')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,user.gender')
|
|
|
->join('user','a.user_id = user.id','LEFT')
|
|
|
->where(['a.id'=>$floor_id])->find();
|
|
|
$floor_info = info_domain_image($floor_info,['avatar']);
|
|
@@ -266,7 +275,7 @@ class Topicdongtai extends Api
|
|
|
//层
|
|
|
$floors = $floor_info['floor'];
|
|
|
$child_lists = Db::name('topic_dongtai_answer')->alias('a')
|
|
|
- ->field('a.*,user.nickname,user.avatar,tuser.nickname as to_nickname,tuser.avatar as to_avatar')
|
|
|
+ ->field('a.*,user.nickname,user.avatar,user.gender,tuser.nickname as to_nickname,tuser.avatar as to_avatar,tuser.gender as to_gender')
|
|
|
->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();
|
|
@@ -279,7 +288,7 @@ class Topicdongtai extends Api
|
|
|
|
|
|
}
|
|
|
|
|
|
- //某个圈子里的动态列表,全部,最新,最热
|
|
|
+ //某个圈子里的动态列表,最新,推荐
|
|
|
public function topic_list(){
|
|
|
$topic_id = input('topic_id',0);
|
|
|
$order = input('orderby','new');
|
|
@@ -289,221 +298,83 @@ class Topicdongtai extends Api
|
|
|
$orderby = 'dt.goodnum desc';
|
|
|
}
|
|
|
|
|
|
+ $where = [];
|
|
|
+ if($topic_id){
|
|
|
+ $where['dt.topic_id'] = $topic_id;
|
|
|
+ }
|
|
|
+
|
|
|
+ if($order == 'follow'){
|
|
|
+ $follow_user_ids = Db::name('user_fans_follow')->where(['fans_id'=>$this->auth->id])->column('user_id');
|
|
|
+ $where['dt.user_id'] = ['IN',$follow_user_ids];
|
|
|
+ }
|
|
|
+
|
|
|
$list = Db::name('topic_dongtai')->alias('dt')
|
|
|
->join('user','dt.user_id = user.id','LEFT')
|
|
|
- ->field('dt.*,user.nickname,user.avatar')
|
|
|
- ->where('dt.topic_id',$topic_id)
|
|
|
+ ->join('topic_hub topic','dt.topic_id = topic.id','LEFT')
|
|
|
+ ->field('dt.*,user.nickname,user.avatar,user.gender,topic.name as topic_name')
|
|
|
+ ->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('dt_id','IN',$ids)->select();
|
|
|
-
|
|
|
- foreach($list as $key => $val){
|
|
|
- $list[$key]['isgood'] = 0;
|
|
|
-
|
|
|
- foreach($good_list as $k => $v){
|
|
|
- if($val['id'] == $v['dt_id']){
|
|
|
- $list[$key]['isgood'] = 1;
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- $this->success('success',$list);
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- //动态赠送礼物
|
|
|
- public function givegiftdongtai() {
|
|
|
- // 接口防并发
|
|
|
- if (!$this->apiLimit(1, 1000)) {
|
|
|
- $this->error(__('Operation frequently'));
|
|
|
- }
|
|
|
-
|
|
|
-// $user_id = input('user_id');// 赠送对象
|
|
|
- $dt_id = input('dt_id', 0, 'intval'); //动态id
|
|
|
- $gift_id = input('gift_id');// 礼物ID
|
|
|
- $number = input('number',1,'intval');//数量
|
|
|
-
|
|
|
- if (!$dt_id || !$gift_id || $number < 1) {
|
|
|
- $this->error();
|
|
|
- }
|
|
|
- //查询动态
|
|
|
- $dongtai_info = Db::name('topic_dongtai')->find($dt_id);
|
|
|
- if (!$dongtai_info) {
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }
|
|
|
- if ($dongtai_info['status'] != 0) {
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }
|
|
|
- $user_id = $dongtai_info['user_id'];
|
|
|
-
|
|
|
- // 不可以赠送给自己
|
|
|
- if($this->auth->id == $user_id) {
|
|
|
- $this->error("不可以赠送给自己");
|
|
|
- }
|
|
|
-
|
|
|
- // 获取礼物信息
|
|
|
- $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
|
|
|
- if (!$giftinfo)
|
|
|
- {
|
|
|
- $this->error("请选择礼物");
|
|
|
- }
|
|
|
- $giftvalue = bcmul($giftinfo['value'],$number);
|
|
|
-
|
|
|
- //被赠送人信息
|
|
|
- $touserinfo = Db::name('user')->where('id',$user_id)->find();
|
|
|
- if (!$touserinfo) {
|
|
|
- $this->error("不存在的用户");
|
|
|
- }
|
|
|
- // 判断当前用户余额
|
|
|
- $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
|
|
|
- if($user_gold < $giftvalue) {
|
|
|
- $this->error("您的金币余额不足");
|
|
|
- }
|
|
|
-
|
|
|
- Db::startTrans();
|
|
|
- // 添加礼物赠送记录表
|
|
|
- $data = [
|
|
|
- 'user_id' => $this->auth->id,
|
|
|
- 'user_to_id' => $user_id,
|
|
|
- 'dt_id' => $dt_id,
|
|
|
- 'gift_id' => $giftinfo['id'],
|
|
|
- 'gift_name' => $giftinfo['name'],
|
|
|
- 'number' => $number,
|
|
|
- 'price' => $giftvalue,
|
|
|
- 'createtime' => time(),
|
|
|
- ];
|
|
|
- $log_id = Db::name('gift_user_dongtai')->insertGetId($data);
|
|
|
- if(!$log_id){
|
|
|
- Db::rollback();
|
|
|
- $this->error('赠送失败');
|
|
|
- }
|
|
|
-
|
|
|
- if($giftvalue > 0){
|
|
|
- // 扣除当前用户余额
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($this->auth->id,$user_id,'gold',-$giftvalue,59,'赠送礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
- }
|
|
|
-
|
|
|
- // 添加赠送用户余额
|
|
|
- $money_to_gold = config('site.money_to_gold');
|
|
|
- $gift_plat_scale = config('site.gift_plat_scale');
|
|
|
-
|
|
|
- $giftmoney = bcdiv($giftvalue,$money_to_gold,2);
|
|
|
+ foreach($list as $key => &$val){
|
|
|
|
|
|
- $money = bcdiv(bcmul($giftmoney,100 - $gift_plat_scale,2),100,2);
|
|
|
- $wallet_rs = model('wallet')->lockChangeAccountRemain($user_id,$this->auth->id,'money',$money,60,'获得礼物:'.$giftinfo["name"] . '*' . $number,'gift_user_dongtai',$log_id,2);
|
|
|
- if($wallet_rs['status'] === false){
|
|
|
- Db::rollback();
|
|
|
- $this->error($wallet_rs['msg']);
|
|
|
- }
|
|
|
+ //追加点赞
|
|
|
+ $val['isgood'] = $this->is_good($val['id'],$this->auth->id);
|
|
|
|
|
|
- /*//增加赠送用户上级金币
|
|
|
- if ($touserinfo['intro_uid']) {
|
|
|
- //获取返利比率
|
|
|
- $intro_gift_rebate_rate = (int)config('site.intro_gift_rebate_rate'); //邀请人收礼物返利比率
|
|
|
- if ($intro_gift_rebate_rate > 0 && $intro_gift_rebate_rate <= 100) {
|
|
|
- //上级获得金币数量
|
|
|
- $intro_uid_gold = floor($giftvalue * $intro_gift_rebate_rate / 100);
|
|
|
- if ($intro_uid_gold > 0) {
|
|
|
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'gold',$intro_uid_gold,66, '动态礼物获赠奖励','gift_user_dongtai',$log_id);
|
|
|
- if($intro_result['status']===false)
|
|
|
- {
|
|
|
- Db::rollback();
|
|
|
- $this->error($intro_result['msg']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }*/
|
|
|
- //增加赠送用户上级余额
|
|
|
- if ($touserinfo['intro_uid']) {
|
|
|
- //获取返利比率
|
|
|
- $is_agent = Db::name('user')->where(['id' => $touserinfo['intro_uid']])->value('is_agent');
|
|
|
- $intro_income_rebate_rate = $is_agent ? (int)config('site.h_intro_income_rebate_rate') : (int)config('site.intro_income_rebate_rate'); //邀请人收礼物返利比率
|
|
|
- if ($intro_income_rebate_rate > 0 && $intro_income_rebate_rate <= 100) {
|
|
|
- //上级获得金额
|
|
|
- $intro_uid_money = number_format($money * $intro_income_rebate_rate / 100, 2, '.', '');
|
|
|
- if ($intro_uid_money > 0) {
|
|
|
- $intro_result = model('Wallet')->lockChangeAccountRemain($touserinfo['intro_uid'],$user_id,'money',$intro_uid_money,68, '邀请人动态礼物获赠奖励','gift_user_dongtai',$log_id);
|
|
|
- if($intro_result['status']===false)
|
|
|
- {
|
|
|
- Db::rollback();
|
|
|
- $this->error($intro_result['msg']);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ //时间
|
|
|
+ $val['createtime_text'] = $this->get_last_time($val['createtime']);
|
|
|
|
|
|
- if ($this->auth->gender == 1 && $touserinfo['gender'] == 0) {
|
|
|
- //增加亲密度
|
|
|
- $user_intimacy_rs = addintimacy($this->auth->id, $user_id, $giftvalue);
|
|
|
- if (!$user_intimacy_rs['status']) {
|
|
|
- Db::rollback();
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }
|
|
|
+ //关注
|
|
|
+ $val['is_follow'] = $this->is_follow($val['user_id'],$this->auth->id);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- //tag任务赠送金币
|
|
|
- //搭讪奖励
|
|
|
-// $task_rs = \app\common\model\TaskLog::tofinish($this->auth->id,15);
|
|
|
-// if($task_rs === false){
|
|
|
-// Db::rollback();
|
|
|
-// $this->error('完成任务赠送奖励失败');
|
|
|
-// }
|
|
|
|
|
|
- Db::commit();
|
|
|
-
|
|
|
- //发送消息
|
|
|
- if (isset($user_intimacy_rs) && $user_intimacy_rs['level_remark']) {
|
|
|
- $tenim = new \app\api\controller\Tenim;
|
|
|
- $tenim->sendMessageToUser($this->auth->id, $user_id, $user_intimacy_rs['level_remark'], 1);
|
|
|
- }
|
|
|
|
|
|
- $return_data['money'] = $money; //获得金额
|
|
|
- $return_data['level_remark'] = isset($user_intimacy_rs) ? $user_intimacy_rs['level_remark'] : ''; //亲密度等级提示语
|
|
|
- $this->success('赠送成功', $return_data);
|
|
|
+ $this->success('success',$list);
|
|
|
}
|
|
|
|
|
|
- //动态收到礼物列表
|
|
|
- public function dongtaigiftlist() {
|
|
|
- $id = input('id', 0, 'intval');
|
|
|
- if (!$id) {
|
|
|
- $this->error('您的网络开小差啦~');
|
|
|
- }
|
|
|
|
|
|
- $list = Db::name('gift_user_dongtai')->field('user_id, count(id) count')->where(['dt_id' => $id])->group('user_id')->order('id desc')->autopage()->select();
|
|
|
- if (!$list) {
|
|
|
- $this->success('success', $list);
|
|
|
+ /**
|
|
|
+ * 评论时间转换
|
|
|
+ * @param null $time
|
|
|
+ * @return false|string
|
|
|
+ */
|
|
|
+ private function get_last_time($time = NULL) {
|
|
|
+ $text = '';
|
|
|
+ $time = $time === NULL || $time > time() ? time() : intval($time);
|
|
|
+ $t = time() - $time; //时间差 (秒)
|
|
|
+ $y = date('Y', $time)-date('Y', time());//是否跨年
|
|
|
+ switch($t){
|
|
|
+ case $t == 0:
|
|
|
+ $text = '刚刚';
|
|
|
+ break;
|
|
|
+ case $t < 60:
|
|
|
+ $text = $t . '秒前'; // 一分钟内
|
|
|
+ break;
|
|
|
+ case $t < 60 * 60:
|
|
|
+ $text = floor($t / 60) . '分钟前'; //一小时内
|
|
|
+ break;
|
|
|
+ case $t < 60 * 60 * 24:
|
|
|
+ $text = floor($t / (60 * 60)) . '小时前'; // 一天内
|
|
|
+ break;
|
|
|
+ case $t < 60 * 60 * 24 * 3:
|
|
|
+ $text = floor($time/(60*60*24)) ==1 ?'昨天 ' . date('H:i', $time) : '前天 ' . date('H:i', $time) ; //昨天和前天
|
|
|
+ break;
|
|
|
+ case $t < 60 * 60 * 24 * 30:
|
|
|
+ $text = date('m月d日 H:i', $time); //一个月内
|
|
|
+ break;
|
|
|
+ case $t < 60 * 60 * 24 * 365&&$y==0:
|
|
|
+ $text = date('m月d日', $time); //一年内
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $text = date('Y年m月d日', $time); //一年以前
|
|
|
+ break;
|
|
|
}
|
|
|
|
|
|
- $mt_user = Db::name('user');
|
|
|
- foreach ($list as &$v) {
|
|
|
- $user_info = $mt_user->field('nickname, avatar, gender, birthday')->where(['id' => $v['user_id']])->find();
|
|
|
- $v['nickname'] = $user_info['nickname'];
|
|
|
- $v['avatar'] = one_domain_image($user_info['avatar']);
|
|
|
- $v['birthday'] = birthtime_to_age($user_info['birthday']);
|
|
|
- }
|
|
|
-
|
|
|
- $this->success('success', $list);
|
|
|
+ return $text;
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
}
|