pluck('admin_id'); $adminData = Users::query()->select(['id','name'])->whereIn('id', $adminIds)->get(); # 统计发送信息 $ruleIds = $list->pluck('rule_id'); $sendStatData = MassMsgRecord::query()->selectRaw("rule_id, sum(send_success) as send_success, " ."sum(send_fail) as send_fail, sum(send_total) as send_total, count(CASE WHEN status =-1 AND errcode != 41048" ." AND errcode!= 84061 THEN 1 END) as send_fail_user") ->where('type', 1)->whereIn('rule_id', $ruleIds)->groupBy(['rule_id'])->get(); # 列表数据格式化 foreach($list as $info) { # 创建人信息 $adminInfo = $adminData->where('id', $info->admin_id)->first(); $info->creator = isset($adminInfo->name) ? $adminInfo->name : ''; # 统计发送情况 $sendStatInfo = $sendStatData->where('rule_id', $info->rule_id)->first(); $info->send_success = isset($sendStatInfo->send_success) ? $sendStatInfo->send_success : 0; $info->send_fail = isset($sendStatInfo->send_fail) ? $sendStatInfo->send_fail : 0; $info->send_total = isset($sendStatInfo->send_total) ? $sendStatInfo->send_total : 0; $info->send_fail_user = isset($sendStatInfo->send_fail_user) ? $sendStatInfo->send_fail_user : 0; } return [['total' => $totalData, 'list' => $list], $count]; } # 客户群群发消息送达数据 public static function chatGroupMassMsgServiceData($creatorId, $sendTimeStart, $sendTimeEnd, $title, $sysGroupId , $page, $pageSize) { $corpids = StatisticsService::getAuthCorpids($sysGroupId); if(empty($corpids)) { return []; } # 查询总计数据 $totalData = ChatGroupMassMsg::getServiceDataTotal($corpids, $creatorId, $sendTimeStart, $sendTimeEnd, $title); # 查询列表数据 list($list, $count) = ChatGroupMassMsg::getServiceDataList($corpids, $creatorId, $sendTimeStart, $sendTimeEnd , $title, $page, $pageSize); # 获取创建人信息 $adminIds = $list->pluck('admin_id'); $adminData = Users::query()->select(['id','name'])->whereIn('id', $adminIds)->get(); # 统计发送信息 $ruleIds = $list->pluck('rule_id'); $sendStatData = ChatGroupMassMsgRecord::query()->selectRaw("rule_id, count(CASE WHEN status=2 THEN 1 END) AS " ."send_user_success, count(CASE WHEN status !=2 THEN 1 END) AS send_user_fail") ->whereIn('rule_id', $ruleIds)->groupBy(['rule_id'])->get(); // $sendChatData = ChatGroupMassMsgLog::query()->selectRaw("rule_id, count(CASE WHEN status=1 THEN 1 END) AS " // ."send_chat_success, count(CASE WHEN status !=1 THEN 1 END) AS send_chat_fail, sum(member_count) as member_count") // ->whereIn('rule_id', $ruleIds)->groupBy(['rule_id'])->get(); $sendChatData = ChatGroupMassMsgLogEs::getChatGroupData($ruleIds); # 列表数据格式化 foreach($list as $info) { # 创建人信息 $adminInfo = $adminData->where('id', $info->admin_id)->first(); $info->creator = isset($adminInfo->name) ? $adminInfo->name : ''; # 统计发送情况 $sendStatInfo = $sendStatData->where('rule_id', $info->rule_id)->first(); $info->send_user_success = isset($sendStatInfo->send_user_success) ? $sendStatInfo->send_user_success : 0; $info->send_user_fail = isset($sendStatInfo->send_user_fail) ? $sendStatInfo->send_user_fail : 0; // $sendChatInfo = $sendChatData->where('rule_id', $info->rule_id)->first(); $sendChatInfo = $sendChatData[$info->rule_id] ?? []; $info->member_count = isset($sendChatInfo['member_count']) ? $sendChatInfo['member_count'] : 0; $info->send_chat_success = isset($sendChatInfo['send_chat_success']) ? $sendChatInfo['send_chat_success'] : 0; $info->send_chat_fail = isset($sendChatInfo['send_chat_fail']) ? $sendChatInfo['send_chat_fail'] : 0; } return [['total' => $totalData, 'list' => $list], $count]; } # 智能群发消息送达数据 public static function periodMassMsgServiceData($creatorId, $sendTimeStart, $sendTimeEnd, $keyword, $sysGroupId , $page, $pageSize) { $corpids = StatisticsService::getAuthCorpids($sysGroupId); if(empty($corpids)) { return []; } $ruleIdList = []; if(!empty($keyword) || !empty($creatorId)) { $ruleIdList = PeriodMassMsg::getServiceDataList($corpids, $creatorId, $keyword); if(empty($ruleIdList)) { return [['total' => ['send_success' => 0, 'send_fail' => 0], 'list' => []], 0]; } } # 查询总计数据 $totalData = PeriodMassMsgRecord::getServiceDataTotal($corpids, $sendTimeStart, $sendTimeEnd, $ruleIdList); # 查询列表数据 list($list, $count) = PeriodMassMsgRecord::getServiceDataList($corpids, $sendTimeStart, $sendTimeEnd , $ruleIdList, $page, $pageSize); # 获取创建人信息 $adminData = Users::query()->select(['id','name'])->get(); # 获取分组信息 $ruleIds = $list->pluck('rule_id'); $ruleData = PeriodMassMsg::getInfoById($ruleIds); $groupIds = array_column($ruleData->toArray(), 'group_id'); $groupData = PeriodMassMsgGroup::getInfoById($groupIds); # 列表数据格式化 foreach($list as $info) { # 获取群发规则信息以及创建人信息 $ruleInfo = $ruleData->where('id', $info->rule_id)->first(); $adminId = isset($ruleInfo->admin_id) ? $ruleInfo->admin_id : null; if($adminId) { $adminInfo = $adminData->where('id', $adminId)->first(); } $info->creator = isset($adminInfo->name) ? $adminInfo->name : ''; $info->name = isset($ruleInfo->name) ? $ruleInfo->name : ''; # 获取群发分组信息 $groupId = isset($ruleInfo->group_id) ? $ruleInfo->group_id : 0; $ruleGroupInfo = $groupData->where('id', $groupId)->first(); $info->group_name = isset($ruleGroupInfo->title) ? $ruleGroupInfo->title : ''; } return [['total' => $totalData, 'list' => $list], $count]; } }