123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137 |
- <?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_remark ur', 'ur.to_user_id = user.id and ur.user_id = '.$this->auth->id, 'LEFT')
- ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender,ur.nickname_remark')
- ->where('black.black_uid',$this->auth->id)->order('black.id desc')->autopage()->select();
- $list = list_domain_image($list,['avatar']);
- $list = list_birthday_age($list);
- foreach ($list as &$val) {
- $val['nickname'] = !empty($val['nickname_remark']) ? $val['nickname_remark'] : $val['nickname'];
- }
- $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_remark ur', 'ur.to_user_id = user.id and ur.user_id = '.$this->auth->id, 'LEFT')
- // ->field('user.id,user.nickname,user.avatar,user.bio,user.birthday,user.gender')
- ->field('black.createtime,user.id,user.nickname,user.avatar,ur.nickname_remark')
- ->where('black.uid',$this->auth->id)->order('black.id desc')->autopage()->select();
- if (!$list) {
- $this->success('success', $list);
- }
- $list = list_domain_image($list,['avatar']);
- // $list = list_birthday_age($list);
- foreach ($list as &$val) {
- $val['createtime'] = date('Y-m-d H:i', $val['createtime']);
- $val['nickname'] = !empty($val['nickname_remark']) ? $val['nickname_remark'] : $val['nickname'];
- }
- $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('已经拉黑了此人');
- }
- //开启事务
- Db::startTrans();
- $map['createtime'] = time();
- $id = Db::name('user_black')->insertGetId($map);
- if (!$id) {
- Db::rollback();
- $this->error('您的网络开小差了~');
- }
- $tenim = new \app\api\controller\Tenim;
- $result = $tenim->black_one($this->auth->id, $black_uid);
- if ($result['ErrorCode'] != 0 || $result['ResultItem'][0]['ResultCode'] != 0) {
- Db::rollback();
- $this->error('您的网络开小差了~');
- }
- //系统消息
- $msg_id = \app\common\model\Message::addMessage($this->auth->id,'拉黑','您已将用户' . $checkuser['nickname'] . '拉入黑名单');
- Db::commit();
- $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,
- ];
- //不检查,全删
- Db::startTrans();
- $rs = Db::name('user_black')->where($map)->delete();
- if ($rs === false) {
- Db::rollback();
- $this->error('您的网络开小差了~');
- }
- if ($rs) {
- $tenim = new \app\api\controller\Tenim;
- $result = $tenim->un_black_one($this->auth->id, $black_uid);
- if ($result['ErrorCode'] != 0 || $result['ResultItem'][0]['ResultCode'] != 0) {
- Db::rollback();
- $this->error('您的网络开小差了~');
- }
- }
- Db::commit();
- $this->success('操作成功');
- }
- }
|