123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739 |
- <?php
- namespace App\Services\Data;
- use App\Models\JxCostDailyData;
- use App\Models\JxQtaskLiveOrderList;
- use App\Models\JxQtaskVideoFlowOrderList;
- use App\Models\JxQtaskVideoOrderList;
- use App\Models\JxStarLiveFlowOrderList;
- use App\Models\JxStarLiveOrderList;
- use App\Models\JxStarVideoFlowOrderList;
- use App\Models\JxStarVideoOrderList;
- class CustomerService
- {
- public static function summaryTrend($advertiserIds, $stDate, $enDate)
- {
- if (empty($advertiserIds)) return [];
- $formatData = [
- 'cost' => 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);
- }
- }
- }
|