56 lines
2.0 KiB
PHP
56 lines
2.0 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Models;
|
||
|
|
|
||
|
|
use App\Models\Live\Viewer;
|
||
|
|
use Illuminate\Database\Eloquent\Model;
|
||
|
|
use App\Models\PaasCommunityGroup;
|
||
|
|
class CommunityGroup extends Model
|
||
|
|
{
|
||
|
|
|
||
|
|
|
||
|
|
public function communityGrouplinks()
|
||
|
|
{
|
||
|
|
return $this->hasMany(CommunityGroupLink::class, 'group_id', 'id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function communities()
|
||
|
|
{
|
||
|
|
return $this->belongsToMany(Community::class, 'community_group_links', 'group_id', 'community_id');
|
||
|
|
}
|
||
|
|
|
||
|
|
public function groupCommunities()
|
||
|
|
{
|
||
|
|
$community_ids = $this->communityGroupLinks()->pluck('community_id');
|
||
|
|
$communities = Community::withCount('moment')->with('user')->whereIn('id', $community_ids)->orderBy('click_num', 'desc')->orderBy('member_num', 'desc')->orderBy('id', 'desc')->where('is_hided', 0)->paginate(56);
|
||
|
|
return $communities;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function joinCommunitiesLog(){
|
||
|
|
$community_ids = $this->communityGroupLinks()->pluck('community_id')->toArray();
|
||
|
|
$communites = Community::whereIn('id', $community_ids)->where('is_hided', 0)->orderBy('created_at', 'asc')->get();
|
||
|
|
foreach ($communites as $community){
|
||
|
|
$community->class = CommunityMember::with('user:id,name,photo,circle_avatar')->where('community_id', $community->id)->orderBy('created_at', 'desc')->limit(3)->get();
|
||
|
|
foreach ($community->class as $val){
|
||
|
|
if(empty($val->user->name)){
|
||
|
|
$val->user->name = $val->user->nickname;
|
||
|
|
}
|
||
|
|
if(empty($val->user->photo)){
|
||
|
|
$val->user->photo = $val->user->circle_avatar;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
return $communites;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function paasGroupIds($paas_id)
|
||
|
|
{
|
||
|
|
$paas_group_ids = PaasCommunityGroup::where('paas_id', $paas_id)->distinct('group_id')->pluck('group_id')->toArray();
|
||
|
|
return $paas_group_ids;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function admin(){
|
||
|
|
return $this->belongsToMany(User::class,'community_group_admin', 'group_id', 'user_id');
|
||
|
|
}
|
||
|
|
}
|