operator_id ?? 0; } if(!in_array($operatorId, $enableUserIdList)){ $errno = 5254; return $errno; } DB::beginTransaction(); # 更新数据到dj_operation_group $groupId = OperationGroup::setConfig($groupId, $groupName, $operatorId, $sysGroupId, $adminId, $errno); if($groupId === false) { DB::rollBack(); return $errno; } # 保存配置详情到dj_operation_group_detail $corpUserList = json_decode($corpUserList, true); if(empty($corpUserList)) { DB::rollBack(); return 5251; } # 删除未保留的成员配置信息 OperationGroupDetail::where('enable', 1)->where('group_id', $groupId) ->update(['enable' => 0]); foreach ($corpUserList as $corpUser) { $corpid = $corpUser['corpid']; $userId = $corpUser['user_id']; # 数据入库 OperationGroupDetail::updateOrCreate(['group_id' => $groupId, 'corpid' => $corpid, 'user_id' => $userId], ['enable' => 1]); } DB::commit(); } catch (\Exception $e) { DB::rollBack(); Log::logError('设置运营组过程发生异常', [ 'line' => $e->getLine(), 'msg' => $e->getMessage(), 'data' => [ 'group_name' => $groupName, 'operator_id' => $operatorId, 'corp_u_list' => $corpUserList, 'sys_group_id' => $sysGroupId, 'admin_id' => $adminId, 'id' => $groupId ] ], 'OperationGroup'); } return 0; } /** * 获取运营组列表 * */ public static function groupList($sysGroupId, $adminId, $operatorId, $page, $pageSize) { list($list, $count) = OperationGroup::groupList($sysGroupId, $adminId, $operatorId, $page, $pageSize); if(!$count) return [[], 0]; # 获取运营组对应的成员信息 $groupIdLIst = $list->pluck('group_id'); $configData = OperationGroupDetail::select('group_id', 'corpid', 'user_id')->whereIn('group_id', $groupIdLIst)->where('enable', 1)->get(); # 获取所需的企微信息和成员信息 $corpidList = array_unique($configData->pluck('corpid')->toArray()); $useridList = array_unique($configData->pluck('user_id')->toArray()); $corpData = AuthorizeCorp::select('corpid', 'corp_name')->whereIn('corpid', $corpidList)->get(); $corpUserList = DjUser::select('corpid', 'user_id', 'name')->whereIn('corpid', $corpidList) ->whereIn('user_id', $useridList)->where('status', 1)->get(); # 获取运营组对应的运营信息 $operatorIds = $list->pluck('operator_id'); $operatorList = Users::select('id', 'name')->whereIn('id', $operatorIds)->get(); foreach ($list as $item) { # 获取运营名称 $operatorInfo = $operatorList->where('id', $item->operator_id)->first(); $item->operator_name = $operatorInfo->name ?? null; # 获取运营组内的成员信息 $configList = $configData->where('group_id', $item->group_id)->all(); foreach ($configList as $k => $config) { # 获取对应的企微名称和成员名称 $corpInfo = $corpData->where('corpid', $config->corpid)->first(); $corpName = $corpInfo->corp_name ?? null; $userInfo = $corpUserList->where('corpid', $config->corpid)->where('user_id', $config->user_id)->first(); $userName = $userInfo->name ?? null; if(empty($userName)) { unset($configList[$k]); continue; } $config->user_info = $corpName . '-' . $userName; } $item->corp_user_list = array_values($configList); } return [$list, $count]; } /** * 获取运营组详情信息 * */ public static function groupDetail($groupId, $sysGroupId, &$errno) { $groupBasicInfo = OperationGroup::where('id', $groupId)->first(); if($sysGroupId != -1) $groupBasicInfo->where('sys_group_id', $sysGroupId); if(empty($groupBasicInfo)) { $errno = 5250; return []; } # 获取运营组对应的企微成员信息 $groupDetail = OperationGroupDetail::select('corpid', 'user_id')->where('enable', 1)->where('group_id', $groupId) ->get(); $corpidList = array_unique($groupDetail->pluck('corpid')->toArray()); # 数据处理 $userList = []; foreach ($corpidList as $corpid) { # 获取企微对应的成员user_id $userIds = $groupDetail->where('corpid', $corpid)->pluck('user_id')->toArray(); $midData = [ 'app_id' => $corpid, 'user_list' => $userIds ]; array_push($userList, $midData); } $groupBasicInfo->corp_user_list = $userList; return $groupBasicInfo; } /** * 更新运营组状态 * */ public static function changeStatus($sysGroupId, $groupId, $status) { # 判断运营组是否存在 $groupInfo = OperationGroup::where('sys_group_id', $sysGroupId) ->where('id', $groupId)->first(); if(empty($groupInfo)) return 5250; if($groupInfo->enable == $status) return 5252; $groupInfo->enable = $status; $result = $groupInfo->save(); return $result ? 0 : 5253; } }