1. 程式人生 > >獲取組織分類後群資料

獲取組織分類後群資料

/**
     * 獲取組織分類後群資料
     * @param UrlManager $urlManager
     * @param Request $request
     * @return \Illuminate\Http\JsonResponse
     */
    public function getOfficialGroupMy(UrlManager $urlManager,Request $request){
//使用者id
$user_id = $request->user()->id;
$in_group = ImCluster::where('affiliations','like',"%\":\"{$user_id
}\"}%") ->select(['cluster_id','id as im_group_id','name','description','affiliations_count', 'owner','member','deleted_at','group_level','privacy'] )->get()->toArray(); $push_config=ImGroupMessageConfig::where('user_id',$user_id)->get()->toArray();
$in_group_ids=[]; foreach ($in_group as $key =>$val){ $in_group_ids[]=$val['im_group_id']; $in_group[$key]['em_ignore_notification'] = false; foreach ($push_config as $key_push => $push){ if ($push['im_group_id'] == $val['im_group_id']){
$in_group[$key]['em_ignore_notification'] = (bool)$push['em_ignore_notification']; break; } } } //查出組織關聯的群 $organize = ImOrganize::where('status',1)->select('id','name','sorts')->orderBy('sorts','desc')->get()->toArray(); $withs=ImGroupOrganize::whereIn('im_group_id',$in_group_ids)->get()->toArray(); $withs_ids=[]; foreach ($withs as $key =>$val){ $withs_ids[]=$val['organize_id']; } $withs_ids=array_unique($withs_ids); $group_with_org_ids = []; foreach ($organize as $key =>$org_group){ if(in_array($org_group['id'],$withs_ids)){ //如果$with_ids中包含有該遍歷的 org_id $organize[$key]['group'] = []; foreach ($withs as $key_org =>$org){ //拿到相對應的群組id foreach ($in_group as $key_group =>$group){ if($org['organize_id'] == $org_group['id'] && $org['im_group_id'] == $group['im_group_id']){ array_push($organize[$key]['group'],$group); //記錄已關聯組織的群組id array_push($group_with_org_ids,$group['im_group_id']); } } } }else{ $organize[$key]['group'] = null; } } //拿到未與組織繫結的群組 $group_without_org_ids = array_diff($in_group_ids,$group_with_org_ids); //如果有未與組織繫結的群組,手動新增未選組織 if($group_without_org_ids){ $ssss['id']=null; $ssss['name']='未選組織'; $ssss['group'] = []; foreach ($group_without_org_ids as $key_group =>$group_id){ foreach ($in_group as $key_group =>$group){ if($group['im_group_id'] == $group_id){ array_push($ssss['group'],$group); break; } } } array_push($organize,$ssss); } return response()->json($organize)->setStatusCode(200); }