0, 'starVideoCost' => 0, 'starLiveCost' => 0, 'quickTaskCost' => 0, 'flowAssistCost' => 0 ]; $trend = getDayArr($stDate, $enDate, $formatData); $summary = [ 'talCost' => 0, 'talStarVideoCost' => 0, 'talStarLiveCost' => 0, 'talQuickTaskCost' => 0, 'talFlowAssistCost' => 0 ]; $costDailyList = JxCostDailyData::query() ->selectRaw("day") ->selectRaw("SUM(star_video_cost) AS star_video_cost") ->selectRaw("SUM(star_live_cost) AS star_live_cost") ->selectRaw("SUM(qtask_video_cost) AS qtask_video_cost") ->selectRaw("SUM(qtask_live_cost) AS qtask_live_cost") ->selectRaw("SUM(flow_star_video_cost) AS flow_star_video_cost") ->selectRaw("SUM(flow_star_live_cost) AS flow_star_live_cost") ->selectRaw("SUM(flow_qtask_video_cost) AS flow_qtask_video_cost") ->whereIn('advertiser_id', $advertiserIds) ->where('enable', 1) ->groupBy('day') ->get(); if ($costDailyList->isNotEmpty()) { $costDailyListMap = $costDailyList->keyBy('day'); foreach ($trend as &$item) { $costDailyData = $costDailyListMap->get($item['day']) ?? []; if (empty($costDailyData)) continue; $item['starVideoCost'] += $costDailyData->star_video_cost; $item['starLiveCost'] += $costDailyData->star_live_cost; $item['quickTaskCost'] += ($costDailyData->qtask_video_cost + $costDailyData->qtask_live_cost); $item['flowAssistCost'] += ($costDailyData->flow_star_video_cost + $costDailyData->flow_star_live_cost + $costDailyData->flow_qtask_video_cost); $item['cost'] += ($item['starVideoCost'] + $item['starLiveCost'] + $item['quickTaskCost'] + $item['flowAssistCost']); $summary['talStarVideoCost'] += $item['starVideoCost']; $summary['talStarLiveCost'] += $item['starLiveCost']; $summary['talQuickTaskCost'] += $item['quickTaskCost']; $summary['talFlowAssistCost'] += $item['flowAssistCost']; $summary['talCost'] += $item['cost']; self::formatData($item); } self::formatData($summary); } return [ 'trend' => $trend, 'summary' => $summary ]; } public static function dataList($prType, $advertiserIds, $stDate, $enDate) { if (empty($advertiserIds)) return []; $fun = 'getCus'.ucwords($prType).'Data'; $res = self::$fun($advertiserIds, $stDate, $enDate); return $res; } protected static function getCusStarVideoData($advertiserIds, $stDate, $enDate) { $summary = [ 'tal_real_amount' => 0, 'tal_view' => 0, 'tal_play' => 0, 'tal_action' => 0, 'tal_admire' => 0, 'tal_comment' => 0, 'tal_click' => 0, 'tal_play_5s' => 0, 'tal_play_end' => 0, 'tal_item_impression_cnt' => 0, 'tal_item_click_cnt' => 0, 'tal_user_cnt' => 0, 'tal_ctr' => 0, 'tal_cpm' => 0, 'tal_cpc' => 0, 'tal_item_click_rate' => 0, 'tal_cpa' => 0, 'tal_play_5s_rate' => 0, 'tal_play_end_rate' => 0 ]; $orderList = JxStarVideoOrderList::query() ->selectRaw("DATE_FORMAT(star_release_time, '%Y-%m-%d') AS day") ->selectRaw("SUM(real_amount) AS real_amount") ->selectRaw("SUM(view) AS view") ->selectRaw("SUM(play) AS play") ->selectRaw("SUM(action) AS action") ->selectRaw("SUM(admire) AS admire") ->selectRaw("SUM(comment) AS comment") ->selectRaw("SUM(click) AS click") ->selectRaw("SUM(play_5s) AS play_5s") ->selectRaw("SUM(play_end) AS play_end") ->selectRaw("SUM(item_impression_cnt) AS item_impression_cnt") ->selectRaw("SUM(item_click_cnt) AS item_click_cnt") ->selectRaw("SUM(user_cnt) AS user_cnt") ->whereIn('advertiser_id', $advertiserIds) ->whereBetween('star_release_time', [$stDate.' 00:00:00', $enDate.' 23:59:59']) ->groupBy('day') ->orderByDesc('day') ->get(); if ($orderList->isNotEmpty()) { foreach ($orderList as $item) { # 处理汇总 $summary['tal_real_amount'] += $item->real_amount; $summary['tal_view'] += $item->view; $summary['tal_play'] += $item->play; $summary['tal_action'] += $item->action; $summary['tal_admire'] += $item->admire; $summary['tal_comment'] += $item->comment; $summary['tal_click'] += $item->click; $summary['tal_item_impression_cnt'] += $item->item_impression_cnt; $summary['tal_item_click_cnt'] += $item->item_click_cnt; $summary['tal_play_5s'] += $item->play_5s; $summary['tal_play_end'] += $item->play_end; # 处理列表 $item->ctr = $item->view > 0 ? round($item->click / $item->view * 100, 4) : 0; $item->cpm = $item->play > 0 ? round($item->real_amount / $item->play, 4) : 0; $item->cpc = $item->click > 0 ? round(($item->real_amount / $item->click) / 1000, 4) : 0; $item->item_click_rate = $item->item_impression_cnt > 0 ? round($item->item_click_cnt / $item->item_impression_cnt * 100, 4) : 0; $item->cpa = $item->item_click_cnt > 0 ? round(($item->real_amount / $item->item_click_cnt) / 1000, 4) : 0; $item->play_5s_rate = $item->view > 0 ? round($item->play_5s / $item->view * 100, 4) : 0; $item->play_end_rate = $item->view > 0 ? round($item->play_end / $item->view * 100, 4) : 0; $item->real_amount = round($item->real_amount / 1000, 4); } $summary['tal_ctr'] = $summary['tal_view'] > 0 ? round($summary['tal_click'] / $summary['tal_view'] * 100, 4) : 0; $summary['tal_cpm'] = $summary['tal_play'] > 0 ? round($summary['tal_real_amount'] / $summary['tal_play'], 4) : 0; $summary['tal_cpc'] = $summary['tal_click'] > 0 ? round(($summary['tal_real_amount'] / $summary['tal_click']) / 1000, 4) : 0; $summary['tal_item_click_rate'] = $summary['tal_item_impression_cnt'] > 0 ? round($summary['tal_item_click_cnt'] / $summary['tal_item_impression_cnt'] * 100, 4) : 0; $summary['tal_cpa'] = $summary['tal_item_click_cnt'] > 0 ? round(($summary['tal_real_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0; $summary['tal_play_5s_rate'] = $summary['tal_view'] > 0 ? round($summary['tal_play_5s'] / $summary['tal_view'] * 100, 4) : 0; $summary['tal_play_end_rate'] = $summary['tal_view'] > 0 ? round($summary['tal_play_end'] / $summary['tal_view'] * 100, 4) : 0; $summary['tal_real_amount'] = round($summary['tal_real_amount'] / 1000, 4); } return [ 'summary' => $summary, 'list' => $orderList ]; } protected static function getCusStarLiveData($advertiserIds, $stDate, $enDate) { $summary = [ 'tal_real_amount' => 0, 'tal_play_cnt' => 0, 'tal_play_uv' => 0, 'tal_like_cnt' => 0, 'tal_comment_cnt' => 0, 'tal_share_cnt' => 0, 'tal_live_duration' => 0, 'tal_item_show_cnt' => 0, 'tal_item_click_cnt' => 0, 'tal_sale_product_cnt' => 0, 'tal_sale_amount' => 0, 'tal_cpm' => 0, 'tal_item_click_rate' => 0, 'tal_cpa' => 0 ]; $orderList = JxStarLiveOrderList::query() ->selectRaw("DATE_FORMAT(live_start_time, '%Y-%m-%d') AS day") ->selectRaw("SUM(real_amount) AS real_amount") ->selectRaw("SUM(play_cnt) AS play_cnt") ->selectRaw("SUM(play_uv) AS play_uv") ->selectRaw("SUM(like_cnt) AS like_cnt") ->selectRaw("SUM(comment_cnt) AS comment_cnt") ->selectRaw("SUM(share_cnt) AS share_cnt") ->selectRaw("SUM(live_duration) AS live_duration") ->selectRaw("SUM(item_show_cnt) AS item_show_cnt") ->selectRaw("SUM(item_click_cnt) AS item_click_cnt") ->selectRaw("SUM(sale_product_cnt) AS sale_product_cnt") ->selectRaw("SUM(sale_amount) AS sale_amount") ->whereIn('advertiser_id', $advertiserIds) ->whereBetween('live_start_time', [$stDate.' 00:00:00', $enDate.' 23:59:59']) ->groupBy('day') ->orderByDesc('day') ->get(); if ($orderList->isNotEmpty()) { foreach ($orderList as $item) { # 处理汇总 $summary['tal_real_amount'] += $item->real_amount; $summary['tal_play_cnt'] += $item->play_cnt; $summary['tal_play_uv'] += $item->play_uv; $summary['tal_like_cnt'] += $item->like_cnt; $summary['tal_comment_cnt'] += $item->comment_cnt; $summary['tal_share_cnt'] += $item->share_cnt; $summary['tal_live_duration'] += $item->live_duration; $summary['tal_item_show_cnt'] += $item->item_show_cnt; $summary['tal_item_click_cnt'] += $item->item_click_cnt; $summary['tal_sale_product_cnt'] += $item->sale_product_cnt; $summary['tal_sale_amount'] += $item->sale_amount; $item->cpm = $item->play_cnt > 0 ? round($item->real_amount / $item->play_cnt, 4) : 0; $item->item_click_rate = $item->item_show_cnt > 0 ? round($item->item_click_cnt / $item->item_show_cnt * 100, 4) : 0; $item->cpa = $item->item_click_cnt > 0 ? round(($item->real_amount / $item->item_click_cnt) / 1000, 4) : 0; $item->real_amount = round($item->real_amount / 1000, 4); } $summary['tal_cpm'] = $summary['tal_play_cnt'] > 0 ? round($summary['tal_real_amount'] / $summary['tal_play_cnt'], 4) : 0; $summary['tal_item_click_rate'] = $summary['tal_item_show_cnt'] > 0 ? round($summary['tal_item_click_cnt'] / $summary['tal_item_show_cnt'] * 100, 4) : 0; $summary['tal_cpa'] = $summary['tal_play_cnt'] > 0 ? round(($summary['tal_real_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0; $summary['tal_real_amount'] = round($summary['tal_real_amount'] / 1000, 4); } return [ 'summary' => $summary, 'list' => $orderList ]; } protected static function getCusQtaskVideoData($advertiserIds, $stDate, $enDate) { $summary = [ 'tal_amount' => 0, 'tal_view' => 0, 'tal_play' => 0, 'tal_action' => 0, 'tal_admire' => 0, 'tal_comment' => 0, 'tal_click' => 0, 'tal_play_3s' => 0, 'tal_play_5s' => 0, 'tal_play_end' => 0, 'tal_item_impression_cnt' => 0, 'tal_item_click_cnt' => 0, 'tal_ctr' => 0, 'tal_cpm' => 0, 'tal_cpc' => 0, 'tal_item_click_rate' => 0, 'tal_cpa' => 0, 'tal_play_3s_rate' => 0, 'tal_play_5s_rate' => 0, 'tal_play_end_rate' => 0, ]; $orderList = JxQtaskVideoOrderList::query() ->selectRaw("DATE_FORMAT(star_release_time, '%Y-%m-%d') AS day") ->selectRaw("SUM(amount) AS amount") ->selectRaw("SUM(view) AS view") ->selectRaw("SUM(play) AS play") ->selectRaw("SUM(action) AS action") ->selectRaw("SUM(admire) AS admire") ->selectRaw("SUM(comment) AS comment") ->selectRaw("SUM(click) AS click") ->selectRaw("SUM(play_3s) AS play_3s") ->selectRaw("SUM(play_5s) AS play_5s") ->selectRaw("SUM(play_end) AS play_end") ->selectRaw("SUM(item_impression_cnt) AS item_impression_cnt") ->selectRaw("SUM(item_click_cnt) AS item_click_cnt") ->whereIn('advertiser_id', $advertiserIds) ->whereBetween('star_release_time', [$stDate.' 00:00:00', $enDate.' 23:59:59']) ->groupBy('day') ->orderByDesc('day') ->get(); if ($orderList->isNotEmpty()) { foreach ($orderList as $item) { # 处理汇总 $summary['tal_amount'] += $item->amount; $summary['tal_view'] += $item->view; $summary['tal_play'] += $item->play; $summary['tal_action'] += $item->action; $summary['tal_admire'] += $item->admire; $summary['tal_comment'] += $item->comment; $summary['tal_click'] += $item->click; $summary['tal_play_3s'] += $item->play_3s; $summary['tal_play_5s'] += $item->play_5s; $summary['tal_play_end'] += $item->play_end; $summary['tal_item_impression_cnt'] += $item->item_impression_cnt; $summary['tal_item_click_cnt'] += $item->item_click_cnt; # 处理列表 $item->ctr = $item->view > 0 ? round($item->click / $item->view * 100, 4) : 0; $item->cpm = $item->play > 0 ? round($item->amount / $item->play, 4) : 0; $item->cpc = $item->click > 0 ? round(($item->amount / $item->click) / 1000, 4) : 0; $item->item_click_rate = $item->item_impression_cnt > 0 ? round($item->item_click_cnt / $item->item_impression_cnt * 100, 4) : 0; $item->cpa = $item->item_click_cnt > 0 ? round(($item->amount / $item->item_click_cnt) / 1000, 4) : 0; $item->play_3s_rate = $item->play > 0 ? round($item->play_3s / $item->play * 100, 4) : 0; $item->play_5s_rate = $item->play > 0 ? round($item->play_5s / $item->play * 100, 4) : 0; $item->play_end_rate = $item->play > 0 ? round($item->play_end / $item->play * 100, 4) : 0; $item->amount = round($item->amount / 1000, 4); } $summary['tal_ctr'] = $summary['tal_view'] > 0 ? round($summary['tal_click'] / $summary['tal_view'] * 100, 4) : 0; $summary['tal_cpm'] = $summary['tal_play'] > 0 ? round($summary['tal_amount'] / $summary['tal_play'], 4) : 0; $summary['tal_cpc'] = $summary['tal_click'] > 0 ? round(($summary['tal_amount'] / $summary['tal_click']) / 1000, 4) : 0; $summary['tal_item_click_rate'] = $summary['tal_item_impression_cnt'] > 0 ? round($summary['tal_item_click_cnt'] / $summary['tal_item_impression_cnt'] * 100, 4) : 0; $summary['tal_cpa'] = $summary['tal_item_click_cnt'] > 0 ? round(($summary['tal_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0; $summary['tal_play_3s_rate'] = $summary['tal_play'] > 0 ? round($summary['tal_play_3s'] / $summary['tal_play'] * 100, 4) : 0; $summary['tal_play_5s_rate'] = $summary['tal_play'] > 0 ? round($summary['tal_play_5s'] / $summary['tal_play'] * 100, 4) : 0; $summary['tal_play_end_rate'] = $summary['tal_play'] > 0 ? round($summary['tal_play_end'] / $summary['tal_play'] * 100, 4) : 0; $summary['tal_amount'] = round($summary['tal_amount'] / 1000, 4); } return [ 'summary' => $summary, 'list' => $orderList ]; } protected static function getCusQtaskLiveData($advertiserIds, $stDate, $enDate) { $summary = [ 'tal_amount' => 0, 'tal_play_cnt' => 0, 'tal_play_uv' => 0, 'tal_like_cnt' => 0, 'tal_comment_cnt' => 0, 'tal_share_cnt' => 0, 'tal_live_duration' => 0, 'tal_item_show_cnt' => 0, 'tal_item_click_cnt' => 0, 'tal_cpm' => 0, 'tal_item_click_rate' => 0, 'tal_cpa' => 0 ]; $orderList = JxQtaskLiveOrderList::query() ->selectRaw("DATE_FORMAT(star_release_time, '%Y-%m-%d') AS day") ->selectRaw("SUM(amount) AS amount") ->selectRaw("SUM(play_cnt) AS play_cnt") ->selectRaw("SUM(play_uv) AS play_uv") ->selectRaw("SUM(like_cnt) AS like_cnt") ->selectRaw("SUM(comment_cnt) AS comment_cnt") ->selectRaw("SUM(share_cnt) AS share_cnt") ->selectRaw("SUM(live_duration) AS live_duration") ->selectRaw("SUM(item_show_cnt) AS item_show_cnt") ->selectRaw("SUM(item_click_cnt) AS item_click_cnt") ->whereIn('advertiser_id', $advertiserIds) ->whereBetween('star_release_time', [$stDate.' 00:00:00', $enDate.' 23:59:59']) ->groupBy('day') ->orderByDesc('day') ->get(); if ($orderList->isNotEmpty()) { foreach ($orderList as $item) { # 处理汇总 $summary['tal_amount'] += $item->amount; $summary['tal_play_cnt'] += $item->play_cnt; $summary['tal_play_uv'] += $item->play_uv; $summary['tal_like_cnt'] += $item->like_cnt; $summary['tal_comment_cnt'] += $item->comment_cnt; $summary['tal_share_cnt'] += $item->share_cnt; $summary['tal_live_duration'] += $item->live_duration; $summary['tal_item_show_cnt'] += $item->item_show_cnt; $summary['tal_item_click_cnt'] += $item->item_click_cnt; # 处理列表 $item->cpm = $item->play_cnt > 0 ? round($item->amount / $item->play_cnt, 4) : 0; $item->item_click_rate = $item->item_show_cnt > 0 ? round($item->item_click_cnt / $item->item_show_cnt * 100, 4) : 0; $item->cpa = $item->item_click_cnt > 0 ? round(($item->amount / $item->item_click_cnt) / 1000, 4) : 0; $item->amount = round($item->amount / 1000, 4); } $summary['tal_cpm'] = $summary['tal_play_cnt'] > 0 ? round($summary['tal_amount'] / $summary['tal_play_cnt'], 4) : 0; $summary['tal_item_click_rate'] = $summary['tal_item_show_cnt'] > 0 ? round($summary['tal_item_click_cnt'] / $summary['tal_item_show_cnt'] * 100, 4) : 0; $summary['tal_cpa'] = $summary['tal_item_click_cnt'] > 0 ? round(($summary['tal_amount'] / $summary['tal_item_click_cnt']) / 1000, 4) : 0; $summary['tal_amount'] = round($summary['tal_amount'] / 1000, 4); } return [ 'summary' => $summary, 'list' => $orderList ]; } protected static function getCusFlowStarVideoData($advertiserIds, $stDate, $enDate) { $summary = [ 'tal_consume_amount' => 0, 'tal_view' => 0, 'tal_play' => 0, 'tal_action' => 0, 'tal_conversion' => 0, 'tal_admire' => 0, 'tal_comment' => 0, 'tal_played3s_cnt' => 0, 'tal_cash_amount' => 0, 'tal_client_amount' => 0, 'tal_agency_amount' => 0, 'tal_credit_consume_amount' => 0, 'tal_cpm' => 0, 'tal_action_rate' => 0, 'tal_cpa' => 0, 'tal_play_3s_rate' => 0 ]; $orderList = JxStarVideoFlowOrderList::query() ->selectRaw("DATE_FORMAT(promotion_begin_time, '%Y-%m-%d') AS day") ->selectRaw("SUM(consume_amount) AS consume_amount") ->selectRaw("SUM(view) AS view") ->selectRaw("SUM(play) AS play") ->selectRaw("SUM(action) AS action") ->selectRaw("SUM(conversion) AS conversion") ->selectRaw("SUM(admire) AS admire") ->selectRaw("SUM(comment) AS comment") ->selectRaw("SUM(played3s_cnt) AS played3s_cnt") ->selectRaw("SUM(cash_amount) AS cash_amount") ->selectRaw("SUM(client_amount) AS client_amount") ->selectRaw("SUM(agency_amount) AS agency_amount") ->selectRaw("SUM(credit_consume_amount) AS credit_consume_amount") ->whereIn('advertiser_id', $advertiserIds) ->whereBetween('promotion_begin_time', [$stDate.' 00:00:00', $enDate.' 23:59:59']) ->groupBy('day') ->orderByDesc('day') ->get(); if ($orderList->isNotEmpty()) { foreach ($orderList as $item) { # 处理汇总 $summary['tal_consume_amount'] += $item->consume_amount; $summary['tal_view'] += $item->view; $summary['tal_play'] += $item->play; $summary['tal_action'] += $item->action; $summary['tal_conversion'] += $item->conversion; $summary['tal_admire'] += $item->admire; $summary['tal_comment'] += $item->comment; $summary['tal_played3s_cnt'] += $item->played3s_cnt; $summary['tal_cash_amount'] += $item->cash_amount; $summary['tal_client_amount'] += $item->client_amount; $summary['tal_agency_amount'] += $item->agency_amount; $summary['tal_credit_consume_amount'] += $item->credit_consume_amount; # 处理列表 $item->cpm = $item->play > 0 ? round($item->consume_amount / $item->play, 4) : 0; $item->action_rate = $item->play > 0 ? round($item->action / $item->play * 100, 4) : 0; $item->cpa = $item->conversion > 0 ? round(($item->consume_amount / $item->conversion) / 1000, 4) : 0; $item->cash_amount = round($item->cash_amount / 1000, 4); $item->client_amount = round($item->client_amount / 1000, 4); $item->agency_amount = round($item->agency_amount / 1000, 4); $item->credit_consume_amount = round($item->credit_consume_amount / 1000, 4); $item->play_3s_rate = $item->play > 0 ? round($item->played3s_cnt / $item->play * 100, 4) : 0; $item->consume_amount = round($item->consume_amount / 1000, 4); } $summary['tal_cpm'] = $summary['tal_play'] > 0 ? round($summary['tal_consume_amount'] / $summary['tal_play'], 4) : 0; $summary['tal_action_rate'] = $summary['tal_play'] > 0 ? round($summary['tal_action'] / $summary['tal_play'] * 100, 4) : 0; $summary['tal_cpa'] = $summary['tal_conversion'] > 0 ? round(($summary['tal_consume_amount'] / $summary['tal_conversion']) / 1000, 4) : 0; $summary['tal_consume_amount'] = round($summary['tal_consume_amount'] / 1000, 4); $summary['tal_cash_amount'] = round($summary['tal_cash_amount'] / 1000, 4); $summary['tal_client_amount'] = round($summary['tal_client_amount'] / 1000, 4); $summary['tal_agency_amount'] = round($summary['tal_agency_amount'] / 1000, 4); $summary['tal_credit_consume_amount'] = round($summary['tal_credit_consume_amount'] / 1000, 4); $summary['tal_play_3s_rate'] = $summary['tal_play'] > 0 ? round($summary['tal_played3s_cnt'] / $summary['tal_play'] * 100, 4) : 0; } return [ 'summary' => $summary, 'list' => $orderList ]; } protected static function getCusFlowStarLiveData($advertiserIds, $stDate, $enDate) { $summary = [ 'tal_consume_amount' => 0, 'tal_audience_num' => 0, 'tal_played3s_num' => 0, 'tal_fans_increase_num' => 0, 'tal_item_impression_num' => 0, 'tal_interactive_num' => 0, 'tal_conversion_impression_num' => 0, 'tal_conversion_action_num' => 0, 'tal_cash_amount' => 0, 'tal_client_amount' => 0, 'tal_agency_amount' => 0, 'tal_credit_consume_amount' => 0, 'tal_conversion_action_rate' => 0, 'tal_cpa' => 0, 'tal_conversion_action_cost' => 0 ]; $orderList = JxStarLiveFlowOrderList::query() ->selectRaw("DATE_FORMAT(promotion_begin_time, '%Y-%m-%d') AS day") ->selectRaw("SUM(consume_amount) AS consume_amount") ->selectRaw("SUM(audience_num) AS audience_num") ->selectRaw("SUM(played3s_num) AS played3s_num") ->selectRaw("SUM(fans_increase_num) AS fans_increase_num") ->selectRaw("SUM(item_impression_num) AS item_impression_num") ->selectRaw("SUM(interactive_num) AS interactive_num") ->selectRaw("SUM(conversion_impression_num) AS conversion_impression_num") ->selectRaw("SUM(conversion_action_num) AS conversion_action_num") ->selectRaw("SUM(cash_amount) AS cash_amount") ->selectRaw("SUM(client_amount) AS client_amount") ->selectRaw("SUM(agency_amount) AS agency_amount") ->selectRaw("SUM(credit_consume_amount) AS credit_consume_amount") ->whereIn('advertiser_id', $advertiserIds) ->whereBetween('promotion_begin_time', [$stDate.' 00:00:00', $enDate.' 23:59:59']) ->groupBy('day') ->orderByDesc('day') ->get(); if ($orderList->isNotEmpty()) { foreach ($orderList as $item) { # 处理汇总 $summary['tal_consume_amount'] += $item->consume_amount; $summary['tal_audience_num'] += $item->audience_num; $summary['tal_played3s_num'] += $item->played3s_num; $summary['tal_fans_increase_num'] += $item->fans_increase_num; $summary['tal_item_impression_num'] += $item->item_impression_num; $summary['tal_interactive_num'] += $item->interactive_num; $summary['tal_conversion_impression_num'] += $item->conversion_impression_num; $summary['tal_conversion_action_num'] += $item->conversion_action_num; $summary['tal_cash_amount'] += $item->cash_amount; $summary['tal_client_amount'] += $item->client_amount; $summary['tal_agency_amount'] += $item->agency_amount; $summary['tal_credit_consume_amount'] += $item->credit_consume_amount; # 处理列表 $item->conversion_action_rate = $item->conversion_impression_num > 0 ? round($item->conversion_action_num / $item->conversion_impression_num * 100, 4) : 0; $item->cpa = $item->consume_amount > 0 ? round(($item->consume_amount / $item->conversion_action_num) / 1000, 4) : 0; $item->consume_amount = round($item->consume_amount / 1000, 4); $item->cash_amount = round($item->cash_amount / 1000, 4); $item->client_amount = round($item->client_amount / 1000, 4); $item->agency_amount = round($item->agency_amount / 1000, 4); $item->credit_consume_amount = round($item->credit_consume_amount / 1000, 4); $item->conversion_action_cost = $item->conversion_action_num > 0 ? round(($item->consume_amount / $item->conversion_action_num) / 1000, 4) : 0; } $summary['tal_conversion_action_rate'] = $summary['tal_conversion_impression_num'] > 0 ? round($summary['tal_conversion_action_num'] / $summary['tal_conversion_impression_num'] * 100, 4) : 0; $summary['tal_cpa'] = $summary['tal_conversion_action_num'] > 0 ? round(($summary['tal_consume_amount'] / $summary['tal_conversion_action_num']) / 1000, 4) : 0; $summary['tal_consume_amount'] = round($summary['tal_consume_amount'] / 1000, 4); $summary['tal_cash_amount'] = round($summary['tal_cash_amount'] / 1000, 4); $summary['tal_client_amount'] = round($summary['tal_client_amount'] / 1000, 4); $summary['tal_agency_amount'] = round($summary['tal_agency_amount'] / 1000, 4); $summary['tal_credit_consume_amount'] = round($summary['tal_credit_consume_amount'] / 1000, 4); $summary['tal_conversion_action_cost'] = $summary['tal_conversion_action_num'] > 0 ? round(($summary['tal_consume_amount'] / $summary['tal_conversion_action_num']) / 1000, 4) : 0; } return [ 'summary' => $summary, 'list' => $orderList ]; } protected static function getCusFlowQtaskVideoData($advertiserIds, $stDate, $enDate) { $summary = [ 'tal_consume_amount' => 0, 'tal_view' => 0, 'tal_play' => 0, 'tal_action' => 0, 'tal_conversion' => 0, 'tal_admire' => 0, 'tal_comment' => 0, 'tal_played3s_cnt' => 0, 'tal_cash_amount' => 0, 'tal_client_amount' => 0, 'tal_agency_amount' => 0, 'tal_credit_consume_amount' => 0, 'tal_cpm' => 0, 'tal_action_rate' => 0, 'tal_cpa' => 0, 'tal_play_3s_rate' => 0 ]; $orderList = JxQtaskVideoFlowOrderList::query() ->selectRaw("DATE_FORMAT(promotion_begin_time, '%Y-%m-%d') AS day") ->selectRaw("SUM(consume_amount) AS consume_amount") ->selectRaw("SUM(view) AS view") ->selectRaw("SUM(play) AS play") ->selectRaw("SUM(action) AS action") ->selectRaw("SUM(conversion) AS conversion") ->selectRaw("SUM(admire) AS admire") ->selectRaw("SUM(comment) AS comment") ->selectRaw("SUM(played3s_cnt) AS played3s_cnt") ->selectRaw("SUM(cash_amount) AS cash_amount") ->selectRaw("SUM(client_amount) AS client_amount") ->selectRaw("SUM(agency_amount) AS agency_amount") ->selectRaw("SUM(credit_consume_amount) AS credit_consume_amount") ->whereIn('advertiser_id', $advertiserIds) ->whereBetween('promotion_begin_time', [$stDate.' 00:00:00', $enDate.' 23:59:59']) ->groupBy('day') ->orderByDesc('day') ->get(); if ($orderList->isNotEmpty()) { foreach ($orderList as &$item) { # 处理汇总 $summary['tal_consume_amount'] += $item->consume_amount; $summary['tal_view'] += $item->view; $summary['tal_play'] += $item->play; $summary['tal_action'] += $item->action; $summary['tal_conversion'] += $item->conversion; $summary['tal_admire'] += $item->admire; $summary['tal_comment'] += $item->comment; $summary['tal_played3s_cnt'] += $item->played3s_cnt; $summary['tal_cash_amount'] += $item->cash_amount; $summary['tal_client_amount'] += $item->client_amount; $summary['tal_agency_amount'] += $item->agency_amount; $summary['tal_credit_consume_amount'] += $item->credit_consume_amount; # 处理列表 $item->cpm = $item->play > 0 ? round($item->consume_amount / $item->play, 4) : 0; $item->action_rate = $item->play > 0 ? round($item->action / $item->play * 100, 4) : 0; $item->cpa = $item->conversion > 0 ? round(($item->consume_amount / $item->conversion) / 1000, 4) : 0; $item->consume_amount = round($item->consume_amount / 1000, 4); $item->cash_amount = round($item->cash_amount / 1000, 4); $item->client_amount = round($item->client_amount / 1000, 4); $item->agency_amount = round($item->agency_amount / 1000, 4); $item->credit_consume_amount = round($item->credit_consume_amount / 1000, 4); $item->play_3s_rate = $item->play > 0 ? round($item->played3s_cnt / $item->play * 100, 4) : 0; } $summary['tal_cpm'] = $summary['tal_play'] > 0 ? round($summary['tal_consume_amount'] / $summary['tal_play'], 4) : 0; $summary['tal_action_rate'] = $summary['tal_play'] > 0 ? round($summary['tal_action'] / $summary['tal_play'] * 100, 4) : 0; $summary['tal_cpa'] = $summary['tal_conversion'] > 0 ? round(($summary['tal_consume_amount'] / $summary['tal_conversion']) / 1000, 4) : 0; $summary['tal_consume_amount'] = round($summary['tal_consume_amount'] / 1000, 4); $summary['tal_cash_amount'] = round($summary['tal_cash_amount'] / 1000, 4); $summary['tal_client_amount'] = round($summary['tal_client_amount'] / 1000, 4); $summary['tal_agency_amount'] = round($summary['tal_agency_amount'] / 1000, 4); $summary['tal_credit_consume_amount'] = round($summary['tal_credit_consume_amount'] / 1000, 4); $summary['tal_play_3s_rate'] = $summary['tal_play'] > 0 ? round($summary['tal_played3s_cnt'] / $summary['tal_play'] * 100, 4) : 0; } return [ 'summary' => $summary, 'list' => $orderList ]; } protected static function formatData(&$result) { # 格式化 foreach ($result as &$item) { if (!is_numeric($item)) continue; $item = round($item / 1000, 4); } } }