123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 关注
- */
- class Userfollow extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //我的关注列表/好友列表
- public function my_follow_list(){
- $type = input('type', 0, 'intval'); //类型:0关注 1好友
- $where = [];
- if ($type == 1) {
- $where['follow.status'] = 1;
- }
- $list = Db::name('user_follow')
- ->alias('follow')
- ->join('user','follow.follow_uid = user.id','LEFT')
- ->field('user.id,user.nickname,user.avatar,user.real_status,user.idcard_status,user.birthday,user.gender,follow.status')
- ->where('follow.uid',$this->auth->id)->where($where)->order('follow.id desc')->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- $list = list_birthday_age($list);
- if ($list) {
- $mt_user_wallet = Db::name('user_wallet'); //钱包
- $mt_wealth_level = Db::name('wealth_level'); //财富等级
- $mt_charm_level = Db::name('charm_level'); //魅力等级
- foreach ($list as &$val) {
- //查询财富等级和魅力等级
- $wallet_info = $mt_user_wallet->where(['user_id' => $val['id']])->find();
- $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
- if ($wealth_level) {
- $val['wealth_level'] = $wealth_level['name'];
- } else {
- $val['wealth_level'] = '';
- }
- $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
- if ($charm_level) {
- $val['charm_level'] = $charm_level['name'];
- } else {
- $val['charm_level'] = '';
- }
- }
- }
- $this->success('success',$list);
- }
- //我的粉丝列表
- public function my_fans_list(){
- $list = Db::name('user_follow')
- ->alias('follow')
- ->join('user','follow.uid = user.id','LEFT')
- ->field('user.id,user.nickname,user.avatar,user.real_status,user.idcard_status,user.birthday,user.gender,follow.status')
- ->where('follow.follow_uid',$this->auth->id)->order('follow.id desc')->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- $list = list_birthday_age($list);
- if ($list) {
- $mt_user_wallet = Db::name('user_wallet'); //钱包
- $mt_wealth_level = Db::name('wealth_level'); //财富等级
- $mt_charm_level = Db::name('charm_level'); //魅力等级
- foreach ($list as &$val) {
- //查询财富等级和魅力等级
- $wallet_info = $mt_user_wallet->where(['user_id' => $val['id']])->find();
- $wealth_level = $mt_wealth_level->where(['value' => ['elt', $wallet_info['pay_money']]])->order('id desc')->find();
- if ($wealth_level) {
- $val['wealth_level'] = $wealth_level['name'];
- } else {
- $val['wealth_level'] = '';
- }
- $charm_level = $mt_charm_level->where(['value' => ['elt', $wallet_info['get_money']]])->order('id desc')->find();
- if ($charm_level) {
- $val['charm_level'] = $charm_level['name'];
- } else {
- $val['charm_level'] = '';
- }
- }
- }
- $this->success('success',$list);
- }
- //关注某人
- public function follow_one(){
- // 接口防并发
- if (!$this->apiLimit(1, 1)) {
- $this->error(__('Operation frequently'));
- }
- $follow_uid = input('follow_uid',0);
- // $gift_id = input('gift_id');// 礼物ID
- // $number = input('number',1,'intval');//数量
- if(!$follow_uid){
- $this->error(__('Invalid parameters'));
- }
- $checkuser = Db::name('user')->find($follow_uid);
- if(empty($checkuser)){
- $this->error('此用户不存在');
- }
- if($follow_uid == $this->auth->id){
- $this->error('不能关注自己');
- }
- $map = [
- 'uid' => $this->auth->id,
- 'follow_uid' => $follow_uid,
- ];
- $check = Db::name('user_follow')->where($map)->find();
- if($check){
- $this->error('已经关注此人');
- }
- /*//查询自己是否是会员, 不是会员需要赠送礼物
- $vip_endtime = Db::name('user_wallet')->where('user_id',$this->auth->id)->value('vip_endtime');
- $time = time();
- if ($vip_endtime < $time) {
- $user_id = $follow_uid;// 赠送对象
- if (!$gift_id) {
- $this->error('请选择要赠送的礼物');
- }
- if ($number < 1) {
- $this->error('请输入正确赠送礼物数量');
- }
- // 获取礼物信息
- $giftinfo = Db::name('gift')->where('id',$gift_id)->find();
- if (!$giftinfo)
- {
- $this->error("请选择礼物");
- }
- $giftvalue = bcmul($giftinfo['value'],$number);
- //被赠送人信息
- $touserinfo = $checkuser;
- // 判断当前用户余额
- $user_gold = model('wallet')->getWallet($this->auth->id,'gold');
- if($user_gold < $giftvalue)
- {
- $this->error("您的金币余额不足");
- }
- }*/
- //查询对方是否关注自己
- $where = [
- 'uid' => $follow_uid,
- 'follow_uid' => $this->auth->id
- ];
- $count = Db::name('user_follow')->where($where)->count('id');
- if ($count) {
- $map['status'] = 1; //状态:0=关注,1=互为关注
- }
- $return_data['money'] = ''; //获得金额
- $return_data['level_remark'] = ''; //亲密度等级提示语
- //开启事务
- Db::startTrans();
- $id = Db::name('user_follow')->insertGetId($map);
- if(!$id){
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- if ($count) {
- //若对方已关注, 则将状态改为 互为关注
- $rs = Db::name('user_follow')->where($where)->where(['status' => 0])->setField('status', 1);
- if (!$rs) {
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- }
- //系统消息
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'喜欢','您已喜欢用户' . $checkuser['nickname']);
- Db::commit();
- $this->success('操作成功', $return_data);
- }
- //取关某人
- public function un_follow_one(){
- $follow_uid = input('follow_uid',0);
- if(!$follow_uid){
- $this->error(__('Invalid parameters'));
- }
- $checkuser = Db::name('user')->find($follow_uid);
- if(empty($checkuser)){
- $this->error('此用户不存在');
- }
- $map = [
- 'uid' => $this->auth->id,
- 'follow_uid' => $follow_uid,
- ];
- $info = Db::name('user_follow')->where($map)->find();
- if (!$info) {
- $this->error('您尚未关注此人~');
- }
- //开启事务
- Db::startTrans();
- $rs = Db::name('user_follow')->where($map)->delete();
- if (!$rs) {
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- $where = [
- 'uid' => $follow_uid,
- 'follow_uid' => $this->auth->id,
- ];
- $count = Db::name('user_follow')->where($where)->count('id');
- if ($count) {
- $rt = Db::name('user_follow')->where($where)->where(['status' => 1])->setField('status', 0);
- if (!$rt) {
- Db::rollback();
- $this->error('您的网络开小差啦~');
- }
- }
- Db::commit();
- $this->success('操作成功');
- }
- }
|