|  | @@ -6,6 +6,7 @@ use addons\epay\library\Service;
 | 
	
		
			
				|  |  |  use app\api\controller\Common;
 | 
	
		
			
				|  |  |  use app\api\validate\user\Report;
 | 
	
		
			
				|  |  |  use app\common\model\UserPower;
 | 
	
		
			
				|  |  | +use app\common\service\TenimService;
 | 
	
		
			
				|  |  |  use outh\outh;
 | 
	
		
			
				|  |  |  use think\Db;
 | 
	
		
			
				|  |  |  use app\common\controller\RedisLeaderboard;
 | 
	
	
		
			
				|  | @@ -769,21 +770,37 @@ class UserCenter extends Common
 | 
	
		
			
				|  |  |       * 加入黑名单
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public function addBlacklist() {
 | 
	
		
			
				|  |  | -        $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
 | 
	
		
			
				|  |  | -        if (!$black_user_id) {
 | 
	
		
			
				|  |  | -            $this->error(__('Invalid parameters'));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        $userblacklistModel = new \app\common\model\UserBlacklist();
 | 
	
		
			
				|  |  | -        $data = [];
 | 
	
		
			
				|  |  | -        $data["user_id"] = $this->auth->id;
 | 
	
		
			
				|  |  | -        $data["black_user_id"] = $black_user_id;
 | 
	
		
			
				|  |  | -        if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
 | 
	
		
			
				|  |  | -        $data["createtime"] = time();
 | 
	
		
			
				|  |  | -        $res = $userblacklistModel->insertGetId($data);
 | 
	
		
			
				|  |  | -        if($res) {
 | 
	
		
			
				|  |  | +        Db::startTrans();
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            $black_user_id = $this->request->request('black_user_id'); // 黑名单用户ID
 | 
	
		
			
				|  |  | +            if (!$black_user_id) {
 | 
	
		
			
				|  |  | +                throw new Exception(__('Invalid parameters'));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $userblacklistModel = new \app\common\model\UserBlacklist();
 | 
	
		
			
				|  |  | +            $data = [];
 | 
	
		
			
				|  |  | +            $data["user_id"] = $this->auth->id;
 | 
	
		
			
				|  |  | +            $data["black_user_id"] = $black_user_id;
 | 
	
		
			
				|  |  | +            if($userblacklistModel->where($data)->find()) $this->error(__('已在黑名单!'));
 | 
	
		
			
				|  |  | +            $data["createtime"] = time();
 | 
	
		
			
				|  |  | +            $res = $userblacklistModel->insertGetId($data);
 | 
	
		
			
				|  |  | +            if(!$res) {
 | 
	
		
			
				|  |  | +                throw new Exception("网络错误,请稍后重试");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //im加入黑名单
 | 
	
		
			
				|  |  | +            $tenimService = new TenimService();
 | 
	
		
			
				|  |  | +            $params = [
 | 
	
		
			
				|  |  | +                'user_id' => $this->auth->id,
 | 
	
		
			
				|  |  | +                'black_user_ids' => [(string)$black_user_id],
 | 
	
		
			
				|  |  | +            ];
 | 
	
		
			
				|  |  | +            $imResult = $tenimService->addBlack($params);
 | 
	
		
			
				|  |  | +            if (!$imResult['status']) {
 | 
	
		
			
				|  |  | +                throw new Exception($imResult['msg']);
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Db::commit();
 | 
	
		
			
				|  |  |              $this->success("加入成功!");
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            $this->error("网络错误,请稍后重试");
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            Db::rollback();
 | 
	
		
			
				|  |  | +            $this->error($e->getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 | 
	
	
		
			
				|  | @@ -815,27 +832,50 @@ class UserCenter extends Common
 | 
	
		
			
				|  |  |       * 移除用户黑名单
 | 
	
		
			
				|  |  |       */
 | 
	
		
			
				|  |  |      public function removeUserBlack() {
 | 
	
		
			
				|  |  | -        $id = $this->request->request('id'); // 黑名单ID
 | 
	
		
			
				|  |  | -        $userId = $this->request->request('user_id'); // 用户ID
 | 
	
		
			
				|  |  | -        if (!$id && !$userId) {
 | 
	
		
			
				|  |  | -            $this->error(__('Invalid parameters'));
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | +        Db::startTrans();
 | 
	
		
			
				|  |  | +        try {
 | 
	
		
			
				|  |  | +            $id = $this->request->request('id'); // 黑名单ID
 | 
	
		
			
				|  |  | +            $userId = $this->request->request('user_id'); // 用户ID
 | 
	
		
			
				|  |  | +            if (!$id && !$userId) {
 | 
	
		
			
				|  |  | +                throw new Exception(__('Invalid parameters'));
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  |  
 | 
	
		
			
				|  |  | -        $userblacklistModel = new \app\common\model\UserBlacklist();
 | 
	
		
			
				|  |  | -        $where = [];
 | 
	
		
			
				|  |  | -        $id && $where["id"] = $id;
 | 
	
		
			
				|  |  | -        if ($userId) {
 | 
	
		
			
				|  |  | -            $where['user_id'] = $this->auth->id;
 | 
	
		
			
				|  |  | -            $where['black_user_id'] = $userId;
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        $res = false;
 | 
	
		
			
				|  |  | -        if (!empty($where)) {
 | 
	
		
			
				|  |  | -            $res = $userblacklistModel->where($where)->delete();
 | 
	
		
			
				|  |  | -        }
 | 
	
		
			
				|  |  | -        if($res) {
 | 
	
		
			
				|  |  | +            $userblacklistModel = new \app\common\model\UserBlacklist();
 | 
	
		
			
				|  |  | +            $where = [];
 | 
	
		
			
				|  |  | +            $id && $where["id"] = $id;
 | 
	
		
			
				|  |  | +            if ($userId) {
 | 
	
		
			
				|  |  | +                $where['user_id'] = $this->auth->id;
 | 
	
		
			
				|  |  | +                $where['black_user_id'] = $userId;
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $userBlack = $userblacklistModel->where($where)->find();
 | 
	
		
			
				|  |  | +            if (empty($userBlack)) {
 | 
	
		
			
				|  |  | +                throw new Exception('未找到黑名单信息');
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            $blackUserId = isset($userBlack['black_user_id']) ? $userBlack['black_user_id'] : 0;
 | 
	
		
			
				|  |  | +            $res = false;
 | 
	
		
			
				|  |  | +            if (!empty($userBlack)) {
 | 
	
		
			
				|  |  | +                $res = $userblacklistModel->where($where)->delete();
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            if(!$res) {
 | 
	
		
			
				|  |  | +                $this->error("网络错误,请稍后重试!");
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            //im加入黑名单
 | 
	
		
			
				|  |  | +            if (!empty($blackUserId)) {
 | 
	
		
			
				|  |  | +                $tenimService = new TenimService();
 | 
	
		
			
				|  |  | +                $params = [
 | 
	
		
			
				|  |  | +                    'user_id' => $this->auth->id,
 | 
	
		
			
				|  |  | +                    'black_user_ids' => [(string)$blackUserId],
 | 
	
		
			
				|  |  | +                ];
 | 
	
		
			
				|  |  | +                $imResult = $tenimService->delBlack($params);
 | 
	
		
			
				|  |  | +                if (!$imResult['status']) {
 | 
	
		
			
				|  |  | +                    throw new Exception($imResult['msg']);
 | 
	
		
			
				|  |  | +                }
 | 
	
		
			
				|  |  | +            }
 | 
	
		
			
				|  |  | +            Db::commit();
 | 
	
		
			
				|  |  |              $this->success("移除成功!",$res);
 | 
	
		
			
				|  |  | -        } else {
 | 
	
		
			
				|  |  | -            $this->error("网络错误,请稍后重试!");
 | 
	
		
			
				|  |  | +        } catch (Exception $e) {
 | 
	
		
			
				|  |  | +            Db::rollback();
 | 
	
		
			
				|  |  | +            $this->error($e->getMessage());
 | 
	
		
			
				|  |  |          }
 | 
	
		
			
				|  |  |      }
 | 
	
		
			
				|  |  |  
 |