61 lines
1.5 KiB
PHP
61 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use App\Services\IMService;
|
||
|
|
use App\Models\Base;
|
||
|
|
use App\Http\Response\ResponseJson;
|
||
|
|
class CommunityMember extends Base
|
||
|
|
{
|
||
|
|
use ResponseJson;
|
||
|
|
protected $fillable = [];
|
||
|
|
protected $guarded = [];
|
||
|
|
|
||
|
|
public function user()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(User::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function community()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(Community::class);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function profile()
|
||
|
|
{
|
||
|
|
return $this->belongsTo(UserProfile::class, 'user_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function updateCommunityNick($tid, $owner, $accid, $nick)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$im_service = new IMService(env('IM_APP_KEY'), env("IM_APP_SECRET"));
|
||
|
|
$result = $im_service->updateGroupNick($tid,$owner,$accid,$nick);
|
||
|
|
if ($result['code'] != 200) {//失败
|
||
|
|
throw new \Exception("网易修改群昵称失败", 1);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public function leaveCommunity($tid, $accid)
|
||
|
|
{
|
||
|
|
try {
|
||
|
|
$im_service = new IMService(env('IM_APP_KEY'), env("IM_APP_SECRET"));
|
||
|
|
$result = $im_service->leaveGroup($tid,$accid);
|
||
|
|
if ($result['code'] != 200) {//失败
|
||
|
|
throw new \Exception("退出网易群失败", 1);
|
||
|
|
}
|
||
|
|
return true;
|
||
|
|
} catch (\Exception $e) {
|
||
|
|
$this->getError($e);
|
||
|
|
return false;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|