'DAY'.($i+1), 'column' => 'day'.($i+1) ]; $daysHeader[] = $title; } $header = array_merge($commonHeader, $daysHeader); # 数据权限 $params['is_super_user'] = AdminService::isSuperUser($params['is_system_admin'], $params['sys_group_id'], $params['admin_id']); if($params['is_super_user']) { $params['user_list'] = Users::getCorpUserList($params['sys_group_id']); if(empty($params['user_list'])) return [0, [], $header]; } # 查询数据 list($list, $count) = OperateDataTrend::publicAccountDataList($params, $sortField, $sortType, $page, $pageSize); if(empty($list)) return [0, [], $header]; # 公众号信息 $appIdList = array_unique(array_column($list, 'app_id')); $officialAccountList = OfficialAccount::getAppInfoList($appIdList); # 查询所有配置关系 // $dramaList = DramaUserRela::query()->where('enable', 1)->get(); # 投手 运营人员信息 $userList = Users::query()->select(['id', 'name'])->get(); foreach ($list as &$item) { # 公众号信息处理 $item['app_name'] = $officialAccountList[$item['app_id']] ?? '-'; # 绑定运营人员处理 $operateUser = $userList->whereIn('id', $item['operate_uid_list'])->all(); $item['operator_list'] = array_column($operateUser, 'name'); # 绑定投手信息 $item['pitcher_id_list'] = explode(' ', $item['pitchers']); $pitcherUser = $userList->whereIn('id', $item['pitcher_id_list'])->all(); $item['pitcher_list'] = array_column($pitcherUser, 'name'); // $operatorCount = count($item['operator_list']); $operatorCount = 1; # 消耗金额单位处理 $item['paid'] = ($item['paid'] / 100) / $operatorCount; # 首日roi $item['first_roi'] = round($item['first_roi'] * 100, 2) . '%'; # 用户累计充值金额 $item['pay_money_total'] = ($item['pay_money_total'] / 100) / $operatorCount; # 首日下单成本 $item['first_charge_user_cost'] = round($item['first_charge_user_cost'] / 100, 2); # 首日新增用户充值金额 $item['pay_money'] = ($item['pay_money'] / 100) / $operatorCount; # 总回本率 $item['cost_cover_rate'] = round($item['cost_cover_rate'] * 100, 2) . '%'; # 首日付费人数 $item['pay_user'] = $item['pay_user'] / $operatorCount; # 累计付费人数 $item['pay_user_total'] = $item['pay_user_total'] / $operatorCount; # 首日付费次数 $item['pay_count'] = $item['pay_count'] / $operatorCount; # 累计付费次数 $item['pay_count_total'] = $item['pay_count_total'] / $operatorCount; # 查询150天数据 $dayInfo = []; $dayData = OperateDataTrend::getDataAfterExpense($params, $item['expense_date'], $item['app_id']); $paidDataMid = []; $payMoneyTotal = 0; if(!empty($dayData)){ foreach($dayData as $val){ $nd = (strtotime($val['ref_date']) - strtotime($val['expense_date'])) / 86400; $payMoneyTotal += $val['pay_money']; if(isset($paidDataMid[$nd])) { $paidDataMid[$nd]['active_fans'] += $val['active_fans']; $paidDataMid[$nd]['pay_user'] += $val['pay_user']; $paidDataMid[$nd]['pay_money'] += $val['pay_money']; $paidDataMid[$nd]['pay_money_total'] += $payMoneyTotal; } else { $paidDataMid[$nd]['active_fans'] = $val['active_fans']; $paidDataMid[$nd]['pay_user'] = $val['pay_user']; $paidDataMid[$nd]['pay_money'] = $val['pay_money']; $paidDataMid[$nd]['pay_money_total'] = $payMoneyTotal; } } foreach ($paidDataMid as $i=>$v) { $new_roi = $item['paid'] ? round($v['pay_money'] / 100 / $item['paid'], 4) * 100 . '%' : '0%'; $total_roi = $item['paid'] ? round($v['pay_money_total'] / 100 / $item['paid'], 4) * 100 . '%' : '0%'; $income_times = $item['pay_money'] ? round($v['pay_money_total'] / 100 / $item['pay_money'], 2) : 0; $dayInfo[$i] = [ 'days' => 'day' . ($i+1), 'pay_money' => round($v['pay_money']/100, 2) / $operatorCount, 'new_roi' => $new_roi, 'total_roi' => $total_roi, 'income_times' => $income_times, 'charge_user' => $v['pay_user'] / $operatorCount ]; } } $item['day_info'] = $dayInfo; } return [$count, $list, $header]; } public static function publicAccountDataSummary($params) { # 表头处理 $header = config('publicAccountData.summary'); # 数据权限 $params['is_super_user'] = AdminService::isSuperUser($params['is_system_admin'], $params['sys_group_id'], $params['admin_id']); if($params['is_super_user']) { $params['user_list'] = Users::getCorpUserList($params['sys_group_id']); if(empty($params['user_list'])) return [[], $header]; } $data = OperateDataTrend::publicAccountDataSummary($params); # 消耗金额单位处理 $data['paid'] = $data['paid'] / 100; # 首日roi $data['first_roi'] = round($data['first_roi'] * 100, 2) . '%'; # 总回本率 $data['cost_cover_rate'] = round($data['cost_cover_rate'] * 100, 2) . '%'; # 首日新增用户充值金额 $data['pay_money'] = $data['pay_money'] / 100; # 用户累计充值金额 $data['pay_money_total'] = $data['pay_money_total'] / 100; # 首日下单成本 $data['first_charge_user_cost'] = round($data['first_charge_user_cost'] / 100, 2); # 公众号 $data['app_name'] = '汇总'; # 运营 $data['operator_list'] = '汇总'; # 投手 $data['pitcher_list'] = '汇总'; # 日期 $data['expense_date'] = '汇总'; return [$data, $header]; } }