123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- <?php
- namespace app\api\controller;
- use app\common\controller\Api;
- use think\Db;
- /**
- * 黑名单
- */
- class Userblack extends Api
- {
- protected $noNeedLogin = [];
- protected $noNeedRight = ['*'];
- //拉黑我的人列表
- public function black_me_list(){
- $list = Db::name('user_black')
- ->alias('black')
- ->join('user','black.uid = user.id','LEFT')
- ->join('user_wallet uw','user.id = uw.user_id','LEFT')
- ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
- ->where('black.black_uid',$this->auth->id)->order('black.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('success',$list);
- }
- //我拉黑的人列表
- public function my_black_list(){
- $list = Db::name('user_black')
- ->alias('black')
- ->join('user','black.black_uid = user.id','LEFT')
- ->join('user_wallet uw','user.id = uw.user_id','LEFT')
- ->field('user.id,user.username,user.nickname,user.avatar,user.bio,user.birthday,user.gender,user.attribute,uw.vip_endtime')
- ->where('black.uid',$this->auth->id)->order('black.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('success',$list);
- }
- //拉黑某人
- public function black_one(){
- $black_uid = input('black_uid',0);
- if(!$black_uid){
- $this->error(__('Invalid parameters'));
- }
- $checkuser = Db::name('user')->find($black_uid);
- if(empty($checkuser)){
- $this->error('此用户不存在');
- }
- if($black_uid == $this->auth->id){
- $this->error('不能拉黑自己');
- }
- $map = [
- 'uid' => $this->auth->id,
- 'black_uid' => $black_uid,
- ];
- $check = Db::name('user_black')->where($map)->find();
- if($check){
- $this->error('已经拉黑了此人');
- }
- $id = Db::name('user_black')->insertGetId($map);
- $this->success('操作成功',$id);
- }
- //取消拉黑某人
- public function un_black_one(){
- $black_uid = input('black_uid',0);
- if(!$black_uid){
- $this->error(__('Invalid parameters'));
- }
- $map = [
- 'uid' => $this->auth->id,
- 'black_uid' => $black_uid,
- ];
- //不检查,全删
- $rs = Db::name('user_black')->where($map)->delete();
- $this->success('操作成功');
- }
- }
|