From b1e03297b8882d5d99022bbb48edc07615306316 Mon Sep 17 00:00:00 2001 From: dengbw Date: Fri, 11 Nov 2022 20:34:32 +0800 Subject: [PATCH] market_order_1111_4 --- market/controllers/api/sylive/Statistics.php | 464 ++++++++++++++----- 1 file changed, 351 insertions(+), 113 deletions(-) diff --git a/market/controllers/api/sylive/Statistics.php b/market/controllers/api/sylive/Statistics.php index 9587ae66..ead1d28f 100644 --- a/market/controllers/api/sylive/Statistics.php +++ b/market/controllers/api/sylive/Statistics.php @@ -585,156 +585,367 @@ class Statistics extends BaseController $this->return_json('参数错误'); } $title = ''; - $activityData1 = $activityData2 = $teamData = $consultantData = $funnel = $allTeamIds = []; - $browse = $subscribe = $watch = $order = 0; + $activityData1 = $activityData2 = $areaAry = $funnel = $allTeamIds = []; + $days[] = ['name' => '全部日期', 'value' => '']; $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); if ($re) { + if ($re['timeEnd'] != '0000-00-00 00:00:00') { + $timeEnd = date("Y-m-d", strtotime($re['timeEnd'])); + for ($i = 6; $i >= 0; $i--) { + $day = date("Y-m-d", strtotime("$timeEnd -{$i} day")); + $days[] = ['name' => $day, 'value' => $day]; + } + } $title = $re['title']; $channelId = $re['channelId']; - $res_biz = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'browse desc'); + $res_biz = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status>=' => 0], 'browse desc'); foreach ($res_biz as $k => $v) { $areaId = intval($v['teamId1']); $bizId = intval($v['teamId2']); - $re_team = $this->mdSyliveTeam->get(['teamId' => $bizId]); - if ($re_team) { - $consultant = $this->mdSyliveActivityKpidata->count(['bizId' => $bizId, 'type' => 1, 'activityId' => $activityId], 'distinct(cfUserId)'); - $livePV = $watchDuration = 0; - if ($channelId) { - $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') - ->from('lc_market_sylive_activity_kpidata as a') - ->join('lc_market_sylive_user as b', "b.userId=a.userId", 'left') - ->where(['a.bizId' => $bizId, 'a.type' => 1, 'a.activityId' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) - ->limit(10000, 0) - ->get()->result_array(); - if ($res_watch) { - $str_unionids = implode("','", array_column($res_watch, 'unionid')); - $where_pv = ['channelId' => $channelId, 'param3' => 'live']; - $where_pv["param1 in ('" . $str_unionids . "')"] = null; - $livePV = $this->mdPolyvViewlog->count($where_pv); - $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); - if ($re_sum['playDuration']) { - $playDuration = ceil($re_sum['playDuration'] / 60); - $watchDuration = round($playDuration / $livePV); - } - } + if ($areaId) { + if (!in_array($areaId, $areaAry)) { + $areaAry[] = $areaId; } - //统计顾问 - $allConsultant = 0; - if ($areaId) { - if (!in_array($areaId, $allTeamIds)) { - $allTeamIds[] = $areaId; - } + if (!in_array($areaId, $allTeamIds)) { + $allTeamIds[] = $areaId; } - if ($bizId) { - $allTeamIds[] = $bizId; - $consultants = []; - $consultants[] = $bizId; - $res_org = $this->mdSyliveTeam->select(['parentId' => $bizId, 'status>=' => 0], 'teamId desc', 0, 0, 'teamId'); - foreach ($res_org as $k2 => $v2) { - $allTeamIds[] = $v2['teamId']; - $consultants[] = $v2['teamId']; - } - $str_teamId = implode(',', array_unique($consultants)); - $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_teamId})" => null, 'status>=' => 0, 'teamId>' => 0]); - } - $consultant > $allConsultant && $allConsultant = $consultant; - $teamData[] = ['areaId' => $areaId, 'bizId' => $bizId, - 'teamName' => $re_team['teamName'], 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'] - , 'watch' => $v['watch'], 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } - } - $res_user = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', ['activityId' => $activityId, 'type' => 1], 'id desc', 0, 0, 'cfUserId,bizId'); - foreach ($res_user as $k => $v) { - $cfUserId = intval($v['cfUserId']); - $re_user = $this->mdSyliveUser->get(['userId' => $cfUserId]); - if ($re_user) { - $consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; - $re_team = $this->mdSyliveTeam->get(['teamId' => $v['bizId']]); - $re_team && $consultantName .= "({$re_team['teamName']})"; - $browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'cfUserId' => $cfUserId, 'kpi' => 'browse']); - $subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'cfUserId' => $cfUserId, 'kpi' => 'subscribe']); - $watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'cfUserId' => $cfUserId, 'kpi' => 'watch']); - $order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'cfUserId' => $cfUserId, 'kpi' => 'order']); - $livePV = $watchDuration = 0; - if ($channelId) { - $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') - ->from('lc_market_sylive_activity_kpidata as a') - ->join('lc_market_sylive_user as b', "b.userId=a.userId", 'left') - ->where(['a.cfUserId' => $cfUserId, 'a.activityId' => $activityId, 'a.type' => 1, 'a.kpi' => 'watch', "unionid!=''" => null]) - ->limit(10000, 0) - ->get()->result_array(); - if ($res_watch) { - $str_unionids = implode("','", array_column($res_watch, 'unionid')); - $where_pv = ['channelId' => $channelId, 'param3' => 'live']; - $where_pv["param1 in ('" . $str_unionids . "')"] = null; - $livePV = $this->mdPolyvViewlog->count($where_pv); - $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); - if ($re_sum['playDuration']) { - $playDuration = ceil($re_sum['playDuration'] / 60); - $watchDuration = round($playDuration / $livePV); - } - } + if ($bizId) { + $allOrganizationIds[] = $bizId; + $res_org = $this->mdSyliveTeam->select(['parentId' => $bizId, 'status>=' => 0], 'teamId desc', 0, 0, 'teamId'); + foreach ($res_org as $k2 => $v2) { + $allTeamIds[] = $v2['teamId']; } - $consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch - , 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } $browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'browse']); $subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'subscribe']); $watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'watch']); - $order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'order']); - $duration = $livePV = $watchDuration = $watchDuration = $pvDuration = 0; + $order = $this->mdSyliveOrder->count(['activityId' => $activityId, 'cfrom' => 1, 'status' => 1]); + $duration_min = $livePV = $liveUV = $watchDuration = $watchDuration = $pvDuration = 0; if ($channelId) { $re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]); if ($re_duration['duration']) { - $re_liveUV = $this->mdPolyvSession->sum('liveUV', ['channelId' => $channelId]); $re_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]); - $duration = ceil($re_duration['duration'] / 60); + $re_liveUV = $this->mdPolyvSession->sum('liveUV', ['channelId' => $channelId]); $livePV = $re_livePV['livePV']; - $watchDuration = round($duration / $livePV); - $pvDuration = round($livePV / $re_liveUV['liveUV'], 1); + $liveUV = $re_liveUV['liveUV']; + $re_totalPlayDuration = $this->mdPolyvSession->sum('totalPlayDuration', ['channelId' => $channelId]); + $duration_min = round($re_duration['duration'] / 60); + $totalPlayDuration_min = round($re_totalPlayDuration['totalPlayDuration'] / 60); + $watchDuration = round($totalPlayDuration_min / $liveUV); + $pvDuration = round($livePV / $liveUV, 1); } } $allConsultant = 0; - $consultant = count($res_user); + $consultant = $this->mdSyliveActivityUser->count(['activityId' => $activityId, 'teamId>' => 0, 'userId>' => 0]); if ($allTeamIds) { - $str_allTeamIds = implode(',', array_unique($allTeamIds)); - $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_allTeamIds})" => null, 'status>=' => 0, 'teamId>' => 0]); + $str_teamIds = implode(',', array_unique($allTeamIds)); + $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_teamIds})" => null, 'status>=' => 0, 'teamId>' => 0]); } $consultant > $allConsultant && $allConsultant = $consultant; - $url = "/sylive/activity/statistics/piechart?activityId={$activityId}&type=1&"; - $activityData1 = [['name' => '参与团队数', 'value' => count($teamData)] + $activityData1 = [['name' => '参与团队数', 'value' => count($areaAry)] , ['name' => '参与/全部团员数', 'value' => $consultant . '/' . $allConsultant]]; + $url = "/sylive/activity/statistics/piechart?activityId={$activityId}&type=1&"; + $watch_un = 0; + if ($liveUV) { + $watch_un = $watch - $liveUV; + $watch_un < 0 && $watch_un = 0; + } $activityData2 = [['name' => '浏览数(人)', 'value' => $browse, 'url' => ''], ['name' => '预约数(人)', 'value' => $subscribe, 'url' => ''] - , ['name' => '观看数(人)', 'value' => $watch, 'url' => ''], ['name' => '订单数(单)', 'value' => $order, 'url' => ''] - , ['name' => '直播时长(分)', 'value' => $duration, 'url' => ''], ['name' => '观看数(人次)', 'value' => $livePV, 'url' => ''] + , ['name' => '订单数(单)', 'value' => $order, 'url' => ''], ['name' => '有效观看(人)', 'value' => $liveUV, 'url' => ''], ['name' => '无效观看(人)', 'value' => $watch_un, 'url' => ''] + , ['name' => '直播时长(分)', 'value' => $duration_min, 'url' => ''], ['name' => '观看数(人次)', 'value' => $livePV, 'url' => ''] , ['name' => '人均观看(分)', 'value' => $watchDuration, 'url' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, 'url' => '']]; // $activityData2 = [['name' => '浏览数(人)', 'value' => $browse, 'url' => "{$url}kpi=browse"], ['name' => '预约数(人)', 'value' => $subscribe, 'url' => "{$url}kpi=subscribe"] // , ['name' => '观看数(人)', 'value' => $watch, 'url' => "{$url}kpi=watch"], ['name' => '订单数(单)', 'value' => $order, 'url' => "{$url}kpi=order"] // , ['name' => '直播时长(分)', 'value' => $duration, 'url' => ''], ['name' => '观看数(人次)', 'value' => $livePV, 'url' => ''] // , ['name' => '人均观看(分)', 'value' => $watchDuration, 'url' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, 'url' => '']]; } - $watch_per = number_format_com($watch / $browse * 100, 1, ''); - $order_per = number_format_com($order / $watch_per * 100, 1, ''); - $browse_expected_data = [['name' => "浏览人数(100%)", 'value' => 100], ['name' => "观看人数({$watch_per}%)", 'value' => 66.7], ['name' => "订单数({$order_per}%)", 'value' => 33.3]]; - $browse_actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '观看人数', 'value' => $watch], ['name' => '订单数', 'value' => $order]]; - $funnel_browse = ['title' => '浏览转化漏斗', 'expected_data' => $browse_expected_data, 'actual_data' => $browse_actual_data]; - $id_in = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND type=1 AND kpi = 'subscribe')"; - $watch_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'watch', $id_in => null]); - $order_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'order', $id_in => null]); - $subscribe_per = number_format_com($subscribe / $browse * 100, 1, ''); - $watch_subscribe_per = number_format_com($watch_subscribe / $subscribe * 100, 1, ''); - $order_subscribe_per = number_format_com($order_subscribe / $watch_subscribe * 100, 1, ''); - $subscribe_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "预约人数({$subscribe_per}%)", 'value' => 75] - , ['name' => "观看人数({$watch_subscribe_per}%)", 'value' => 50], ['name' => "订单数({$order_subscribe_per}%)", 'value' => 25]]; - $subscribe_actual_data = [['name' => '浏览人数', 'value' => $browse], ['name' => '预约人数', 'value' => $subscribe] - , ['name' => '观看人数', 'value' => $watch_subscribe], ['name' => '订单数', 'value' => $order_subscribe]]; - $funnel_subscribe = ['title' => '预约转化漏斗', 'expected_data' => $subscribe_expected_data, 'actual_data' => $subscribe_actual_data]; - $data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => $activityData1, 'activityData2' => $activityData2, - 'teamData' => $teamData, 'consultantData' => $consultantData, 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe]; + $timeStart = strtotime($re['timeStart']);//直播开始时间 + $left_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND type = 1 AND kpi = 'browse' AND createTime < {$timeStart})"; + $left_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'browse', 'createTime<' => $timeStart]); + $left_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'subscribe']); + $left_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'watch', $left_browse_where => null]); + $left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'order', $left_browse_where => null]); + $left_subscribe_per = number_format_com($left_subscribe / $left_browse * 100, 1, ''); + $left_watch_per = number_format_com($left_watch / $left_subscribe * 100, 1, ''); + $left_order_per = number_format_com($left_order / $left_watch * 100, 1, ''); + $left_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "预约人数({$left_subscribe_per}%)", 'value' => 75] + , ['name' => "观看人数({$left_watch_per}%)", 'value' => 50], ['name' => "订单数({$left_order_per}%)", 'value' => 25]]; + $left_actual_data = [['name' => '浏览人数', 'value' => $left_browse], ['name' => '预约人数', 'value' => $left_subscribe] + , ['name' => '观看人数', 'value' => $left_watch], ['name' => '订单数', 'value' => $left_order]]; + $funnel_browse = ['title' => '浏览转化漏斗((预热阶段)', 'expected_data' => $left_expected_data, 'actual_data' => $left_actual_data]; + + $right_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND type = 1 AND kpi = 'browse' AND createTime >= {$timeStart})"; + $right_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'browse', 'createTime>=' => $timeStart]); + $right_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'watch', $right_browse_where => null]); + $right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'order', $right_browse_where => null]); + $right_watch_per = number_format_com($right_watch / $right_browse * 100, 1, ''); + $right_order_per = number_format_com($right_order / $right_watch * 100, 1, ''); + $right_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "观看人数({$right_watch_per}%)", 'value' => 66.7], ['name' => "订单数({$right_order_per}%)", 'value' => 33.3]]; + $right_actual_data = [['name' => '浏览人数_' . $right_browse, 'value' => $right_browse], ['name' => '观看人数', 'value' => $right_watch], ['name' => '订单数', 'value' => $right_order]]; + $funnel_subscribe = ['title' => '浏览转化漏斗(直播阶段)', 'expected_data' => $right_expected_data, 'actual_data' => $right_actual_data]; + + $data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => ['list' => $activityData1, 'style' => 'width: 50%'], 'activityData2' => ['list' => $activityData2, 'style' => 'width: 11.1%'] + , 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe, 'days' => $days]; $this->return_response($data); } + /** + * Notes:团队统计列表 + * Created on: 2022/10/27 14:48 + * Created by: dengbw + */ + public function page_team_biz_get() + { + $activityId = intval($this->input_param('activityId')); + $page = $this->input_param('page'); + $limit = $this->input_param('limit'); + $sort = $this->input_param('sort'); + $order = $this->input_param('order'); + $day = $this->input_param('day'); + !$page && $page = 1; + !$limit && $limit = 10; + $list = []; + $count = 0; + $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); + if ($re) { + $channelId = intval($re['channelId']); + !$sort && $sort = 'browse'; + !$order && $order = 'desc'; + if ($sort == 'order' && !$day) { + $sort_order = 'orderTotal ' . $order; + } else { + $sort_order = $sort . ' ' . $order; + } + if ($day) {//按天搜索 + $where = ['activityId' => $activityId, 'day' => $day, 'type' => 1, 'bizId>' => 0, 'kpi' => $sort]; + $count = $this->mdSyliveActivityKpidata->count($where, 'bizId'); + if ($count) { + $res = $this->mdSyliveActivityKpidata->select_groupby('bizId', $where, "total {$order},id desc", $page, $limit, "bizId,count(id) as total"); + foreach ($res as $v) { + $bizId = intval($v['bizId']); + $re_biz = $this->mdSyliveTeam->get(['teamId' => $bizId, 'status>=' => 0]); + $bizName = $re_biz ? $re_biz['teamName'] : '-'; + $where['bizId'] = $bizId; + if ($sort == 'browse') { + $browse = $v['total']; + } else { + $where['kpi'] = 'browse'; + $browse = $this->mdSyliveActivityKpidata->count($where); + } + if ($sort == 'subscribe') { + $subscribe = $v['total']; + } else { + $where['kpi'] = 'subscribe'; + $subscribe = $this->mdSyliveActivityKpidata->count($where); + } + if ($sort == 'watch') { + $watch = $v['total']; + } else { + $where['kpi'] = 'watch'; + $watch = $this->mdSyliveActivityKpidata->count($where); + } + if ($sort == 'order') { + $order = $v['total']; + } else { + $where['kpi'] = 'order'; + $order = $this->mdSyliveActivityKpidata->count($where); + } + $consultant = $this->mdSyliveActivityUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'teamId>' => 0, 'userId>' => 0]); + $consultants = []; + $consultants[] = $bizId; + $res_org = $this->mdSyliveTeam->select(['parentId' => $bizId, 'status>=' => 0], 'teamId desc', 0, 0, 'teamId'); + foreach ($res_org as $k2 => $v2) { + $consultants[] = $v2['teamId']; + } + $str_organizationIds = implode(',', array_unique($consultants)); + $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_organizationIds})" => null, 'status>=' => 0, 'teamId>' => 0]); + $livePV = $watchDuration = 0; + if ($channelId) { + $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') + ->from('lc_market_sylive_activity_kpidata as a') + ->join('lc_market_sylive_user as b', "b.userId=a.userId", 'left') + ->where(['a.bizId' => $bizId, 'a.type' => 1, 'a.day' => $day, 'a.activityId' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) + ->limit(10000, 0) + ->get()->result_array(); + if ($res_watch) { + $str_unionids = implode("','", array_column($res_watch, 'unionid')); + $where_pv = ['channelId' => $channelId, 'param3' => 'live']; + $where_pv["param1 in ('" . $str_unionids . "')"] = null; + $livePV = $this->mdPolyvViewlog->count($where_pv); + $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); + } + } + } + $list[] = [ + 'bizName' => $bizName, 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe + , 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + } + } + } else { + $where = ['activityId' => $activityId, 'status>=' => 0, 'teamId2>' => 0]; + $count = $this->mdSyliveActivityTeam->count($where); + if ($count) { + $res = $this->mdSyliveActivityTeam->select($where, "{$sort_order},id desc", $page, $limit); + foreach ($res as $v) { + $bizId = intval($v['teamId2']); + $re_biz = $this->mdSyliveTeam->get(['teamId' => $bizId, 'status>=' => 0]); + $bizName = $re_biz ? $re_biz['teamName'] : '-'; + $consultant = $this->mdSyliveActivityUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'teamId>' => 0, 'userId>' => 0]); + //统计顾问数 + $consultants = []; + $consultants[] = $bizId; + $res_org = $this->mdSyliveTeam->select(['parentId' => $bizId, 'status>=' => 0], 'teamId desc', 0, 0, 'teamId'); + foreach ($res_org as $k2 => $v2) { + $consultants[] = $v2['teamId']; + } + $str_organizationIds = implode(',', array_unique($consultants)); + $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_organizationIds})" => null, 'status>=' => 0, 'teamId>' => 0]); + $consultant > $allConsultant && $allConsultant = $consultant; + $livePV = $watchDuration = 0; + if ($channelId) { + $livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId, 'type' => 1]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId, 'type' => 1]); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); + } + } + $list[] = [ + 'bizName' => $bizName, 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'] + , 'watch' => $v['watch'], 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + } + } + } + } + $date = ['list' => $list, 'count' => $count]; + $this->return_response_list($date); + } + + /** + * Notes:团员统计列表 + * Created on: 2022/11/11 14:48 + * Created by: dengbw + */ + public function page_team_consultant_get() + { + $activityId = intval($this->input_param('activityId')); + $page = $this->input_param('page'); + $limit = $this->input_param('limit'); + $sort = $this->input_param('sort'); + $order = $this->input_param('order'); + $day = $this->input_param('day'); + !$page && $page = 1; + !$limit && $limit = 10; + $list = []; + $count = 0; + $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); + if ($re) { + $channelId = intval($re['channelId']); + !$sort && $sort = 'browse'; + !$order && $order = 'desc'; + if ($sort == 'order' && !$day) { + $sort_order = 'orderTotal ' . $order; + } else { + $sort_order = $sort . ' ' . $order; + } + if ($day) { + $where = ['activityId' => $activityId, 'day' => $day, 'type' => 1, 'cfUserId>' => 0, 'kpi' => $sort]; + $count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId'); + if ($count) { + $res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "total {$order},id desc", $page, $limit, "bizId,cfUserId,count(id) as total"); + foreach ($res as $v) { + $cfUserId = intval($v['cfUserId']); + $re_org = $this->mdSyliveTeam->get(['teamId' => $v['bizId'], 'status>=' => 0]); + $teamName = $re_org['teamName'] ? $re_org['teamName'] : '-'; + $re_user = $this->mdSyliveUser->get(['userId' => $cfUserId, 'status>=' => 0]); + $uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; + $consultantName = $teamName . ' ' . $uname; + $where['cfUserId'] = $cfUserId; + if ($sort == 'browse') { + $browse = $v['total']; + } else { + $where['kpi'] = 'browse'; + $browse = $this->mdSyliveActivityKpidata->count($where); + } + if ($sort == 'subscribe') { + $subscribe = $v['total']; + } else { + $where['kpi'] = 'subscribe'; + $subscribe = $this->mdSyliveActivityKpidata->count($where); + } + if ($sort == 'watch') { + $watch = $v['total']; + } else { + $where['kpi'] = 'watch'; + $watch = $this->mdSyliveActivityKpidata->count($where); + } + if ($sort == 'order') { + $order = $v['total']; + } else { + $where['kpi'] = 'order'; + $order = $this->mdSyliveActivityKpidata->count($where); + } + $livePV = $watchDuration = 0; + if ($channelId) { + $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') + ->from('lc_market_sylive_activity_kpidata as a') + ->join('lc_market_sylive_user as b', "b.userId=a.userId", 'left') + ->where(['a.cfUserId' => $cfUserId, 'a.type' => 1, 'a.day' => $day, 'a.activityId' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) + ->limit(10000, 0) + ->get()->result_array(); + if ($res_watch) { + $str_unionids = implode("','", array_column($res_watch, 'unionid')); + $where_pv = ['channelId' => $channelId, 'param3' => 'live']; + $where_pv["param1 in ('" . $str_unionids . "')"] = null; + $livePV = $this->mdPolyvViewlog->count($where_pv); + $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); + } + } + } + $list[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe + , 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + } + } + } else { + $where = ['activityId' => $activityId, 'teamId>' => 0]; + $count = $this->mdSyliveActivityUser->count($where, 'userId'); + if ($count) { + $filed = 'userId,bizId,browse,subscribe,orderTotal,watch'; + $res = $this->mdSyliveActivityUser->select_groupby('userId', $where, "{$sort_order},id desc", $page, $limit, $filed); + foreach ($res as $v) { + $userId = intval($v['userId']); + $re_org = $this->mdSyliveTeam->get(['teamId' => $v['bizId'], 'status>=' => 0]); + $teamName = $re_org['teamName'] ? $re_org['teamName'] : '-'; + $re_user = $this->mdSyliveUser->get(['userId' => $userId, 'status>=' => 0]); + $uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; + $consultantName = $teamName . ' ' . $uname; + $livePV = $watchDuration = 0; + if ($channelId) { + $livePV = $this->mdSyliveViewlog->count(['cfUserId' => $userId, 'activityId' => $activityId, 'type' => 1]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $userId, 'activityId' => $activityId, 'type' => 1]); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); + } + } + $list[] = ['consultantName' => $consultantName, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'], 'watch' => $v['watch'] + , 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + } + } + } + } + $date = ['list' => $list, 'count' => $count]; + $this->return_response_list($date); + } + /** * Notes:获取区域饼状数据 * Created on: 2022/10/9 17:21 @@ -876,7 +1087,34 @@ class Statistics extends BaseController $area = $biz = $consultant = []; $kpi == 'order' && $kpi = 'orderTotal'; if ($type == 1) { - + //团队排名 + $res = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status>=' => 0] + , "{$kpi} desc,id desc", 1, 10, "{$kpi},teamId2"); + if ($res) { + $bizMax = $res[0][$kpi]; + foreach ($res as $k => $v) { + $bizId = intval($v['teamId2']); + $re = $this->mdSyliveTeam->get(['teamId' => $bizId]); + $name = $re['teamName'] ? $re['teamName'] : '-'; + $percent = ceil(($v[$kpi] / $bizMax) * 100); + $biz[] = ['name' => $name, 'value' => $v[$kpi], 'percent' => $percent]; + } + } + //顾问排名 + $res = $this->mdSyliveActivityUser->select_groupby('userId', ['activityId' => $activityId, 'teamId>' => 0] + , "{$kpi} desc,id desc", 1, 10, "{$kpi},bizId,userId"); + if ($res) { + $consultantMax = $res[0][$kpi]; + foreach ($res as $k => $v) { + $userId = intval($v['userId']); + $re_user = $this->mdSyliveUser->get(['userId' => $userId, 'status>=' => 0]); + $name = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; + $re_org = $this->mdSyliveTeam->get(['teamId' => $v['bizId']]); + $re_org && $name .= "({$re_org['teamName']})"; + $percent = ceil(($v[$kpi] / $consultantMax) * 100); + $consultant[] = ['name' => $name, 'value' => $v[$kpi], 'percent' => $percent]; + } + } } else { //大区排名 $res = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0, 'bizId>=' => 0], "id desc", 0, 0, 'distinct(areaId)');