market_statistics_1027
This commit is contained in:
@@ -517,385 +517,6 @@ class Activity extends BaseController
|
||||
$this->return_response();
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:活动统计
|
||||
* Created on: 2022/9/27 10:02
|
||||
* Created by: dengbw
|
||||
* @param null $activityId
|
||||
*/
|
||||
public function statistics_get($activityId = null)
|
||||
{
|
||||
$activityId = intval($activityId);
|
||||
if (!$activityId) {
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
||||
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
||||
$this->load->model('live/Live_polyv_session_model', 'mdPolyvSession');
|
||||
$this->load->model('live/Live_polyv_viewlog_model', 'mdPolyvViewlog');
|
||||
$title = '';
|
||||
$activityData1 = $activityData2 = $areaData = $bizData = $consultantData = $areaAry = $funnel = $allOrganizationIds = [];
|
||||
$browse = $subscribe = $watch = $order = 0;
|
||||
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
||||
if ($re) {
|
||||
$title = $re['title'];
|
||||
$channelId = $re['channelId'];
|
||||
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status' => 0], 'browse desc');
|
||||
foreach ($res_biz as $k => $v) {
|
||||
$areaId = intval($v['areaId']);
|
||||
$bizId = intval($v['bizId']);
|
||||
$re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId]);
|
||||
if ($re_biz) {
|
||||
$consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)');
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId, '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.uid", 'left')
|
||||
->where(['a.biz_id' => $bizId, 'a.type' => 0, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
//统计顾问
|
||||
$allConsultant = 0;
|
||||
if ($areaId) {
|
||||
if (!in_array($areaId, $allOrganizationIds)) {
|
||||
$allOrganizationIds[] = $areaId;
|
||||
}
|
||||
}
|
||||
if ($bizId) {
|
||||
$allOrganizationIds[] = $bizId;
|
||||
$areaAry[$areaId]['biz'][] = $bizId;
|
||||
$consultants = [];
|
||||
$consultants[] = $bizId;
|
||||
$res_org = $this->mdSyliveOrganization->select(['parentId' => $bizId, 'status>=' => 0], 'organizationId desc', 0, 0, 'organizationId');
|
||||
foreach ($res_org as $k2 => $v2) {
|
||||
$allOrganizationIds[] = $v2['organizationId'];
|
||||
$areaAry[$areaId]['sales'][] = $v2['organizationId'];
|
||||
$consultants[] = $v2['organizationId'];
|
||||
}
|
||||
$str_organizationIds = implode(',', array_unique($consultants));
|
||||
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$bizData[] = ['areaId' => $areaId, 'bizId' => $bizId,
|
||||
'bizName' => $re_biz['organizationName'], 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
|
||||
, 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
foreach ($areaAry as $k => $v) {
|
||||
$areaId = intval($k);
|
||||
$re_area = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
|
||||
if ($re_area) {
|
||||
$consultant = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)');
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId, '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.uid", 'left')
|
||||
->where(['a.area_id' => $areaId, 'a.type' => 0, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$allConsultant = 0;
|
||||
if ($v['biz']) {
|
||||
$organizationIds = $v['sales'] ? array_merge($v['biz'], $v['sales']) : $v['biz'];
|
||||
$str_organizationIds = implode(',', array_unique($organizationIds));
|
||||
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$areaData[] = ['areaName' => $re_area['organizationName'], 'biz' => count($v['biz']), 'consultant' => $consultant . '/' . $allConsultant
|
||||
, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch, 'order' => $order
|
||||
, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
$res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id');
|
||||
foreach ($res_user as $k => $v) {
|
||||
$userId = intval($v['userId']);
|
||||
$re_user = $this->mdSyliveUser->get(['userId' => $userId]);
|
||||
if ($re_user) {
|
||||
$consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
||||
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $v['biz_id']]);
|
||||
$re_org && $consultantName .= "({$re_org['organizationName']})";
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, '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.uid", 'left')
|
||||
->where(['a.cf_uid' => $userId, 'a.a_id' => $activityId, 'a.type' => 0, '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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch
|
||||
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'order']);
|
||||
$duration = $livePV = $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);
|
||||
$livePV = $re_livePV['livePV'];
|
||||
$watchDuration = round($duration / $livePV);
|
||||
$pvDuration = round($livePV / $re_liveUV['liveUV'], 1);
|
||||
}
|
||||
}
|
||||
$allConsultant = 0;
|
||||
$consultant = count($res_user);
|
||||
if ($allOrganizationIds) {
|
||||
$str_organizationIds = implode(',', array_unique($allOrganizationIds));
|
||||
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$activityData1 = [['name' => '参与区域数', 'value' => count($areaData)], ['name' => '参与门店数', 'value' => count($bizData)]
|
||||
, ['name' => '参与/全部顾问数', 'value' => $consultant . '/' . $allConsultant]];
|
||||
$url = "/sylive/activity/statistics/piechart?activityId={$activityId}&";
|
||||
$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' => $watchDuration, 'url' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, 'url' => '']];
|
||||
// $activityData2 = [['name' => '浏览人数', 'value' => $browse, 'url' => "{$url}type=browse"], ['name' => '预约人数', 'value' => $subscribe, 'url' => "{$url}type=subscribe"]
|
||||
// , ['name' => '观看人数', 'value' => $watch, 'url' => "{$url}type=watch"], ['name' => '订单数', 'value' => $order, 'url' => "{$url}type=order"]
|
||||
// , ['name' => '直播时长', 'value' => $duration, 'url' => ''], ['name' => '观看次数', 'value' => $livePV, 'url' => ''], ['name' => '人均观看', 'value' => $watchDuration, '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 = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type = 0 AND kpi = 'subscribe')";
|
||||
$watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch', $id_in => null]);
|
||||
$order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, '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, 'areaData' => $areaData
|
||||
, 'bizData' => $bizData, 'consultantData' => $consultantData, 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe];
|
||||
$this->return_response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:活动团队统计
|
||||
* Created on: 2022/10/24 10:02
|
||||
* Created by: dengbw
|
||||
* @param null $activityId
|
||||
*/
|
||||
public function statistics_team_get($activityId = null)
|
||||
{
|
||||
$activityId = intval($activityId);
|
||||
if (!$activityId) {
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
||||
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
||||
$this->load->model('live/Live_polyv_session_model', 'mdPolyvSession');
|
||||
$this->load->model('live/Live_polyv_viewlog_model', 'mdPolyvViewlog');
|
||||
$title = '';
|
||||
$activityData1 = $activityData2 = $teamData = $consultantData = $funnel = $allTeamIds = [];
|
||||
$browse = $subscribe = $watch = $order = 0;
|
||||
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
||||
if ($re) {
|
||||
$title = $re['title'];
|
||||
$channelId = $re['channelId'];
|
||||
$res_biz = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'browse desc');
|
||||
foreach ($res_biz as $k => $v) {
|
||||
$area_id = intval($v['teamId1']);
|
||||
$biz_id = intval($v['teamId2']);
|
||||
$re_team = $this->mdSyliveTeam->get(['teamId' => $biz_id]);
|
||||
if ($re_team) {
|
||||
$consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId], 'distinct(cf_uid)');
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId, '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.uid", 'left')
|
||||
->where(['a.biz_id' => $biz_id, 'a.type' => 1, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
//统计顾问
|
||||
$allConsultant = 0;
|
||||
if ($area_id) {
|
||||
if (!in_array($area_id, $allTeamIds)) {
|
||||
$allTeamIds[] = $area_id;
|
||||
}
|
||||
}
|
||||
if ($biz_id) {
|
||||
$allTeamIds[] = $biz_id;
|
||||
$consultants = [];
|
||||
$consultants[] = $biz_id;
|
||||
$res_org = $this->mdSyliveTeam->select(['parentId' => $biz_id, '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[] = ['area_id' => $area_id, 'biz_id' => $biz_id,
|
||||
'teamName' => $re_team['teamName'], 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
|
||||
, 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
$res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId, 'type' => 1], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id');
|
||||
foreach ($res_user as $k => $v) {
|
||||
$userId = intval($v['userId']);
|
||||
$re_user = $this->mdSyliveUser->get(['userId' => $userId]);
|
||||
if ($re_user) {
|
||||
$consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
||||
$re_team = $this->mdSyliveTeam->get(['teamId' => $v['biz_id']]);
|
||||
$re_team && $consultantName .= "({$re_team['teamName']})";
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, '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.uid", 'left')
|
||||
->where(['a.cf_uid' => $userId, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch
|
||||
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'order']);
|
||||
$duration = $livePV = $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);
|
||||
$livePV = $re_livePV['livePV'];
|
||||
$watchDuration = round($duration / $livePV);
|
||||
$pvDuration = round($livePV / $re_liveUV['liveUV'], 1);
|
||||
}
|
||||
}
|
||||
$allConsultant = 0;
|
||||
$consultant = count($res_user);
|
||||
if ($allTeamIds) {
|
||||
$str_allTeamIds = implode(',', array_unique($allTeamIds));
|
||||
$allConsultant = $this->mdSyliveUser->count(["teamId in({$str_allTeamIds})" => null, 'status>=' => 0, 'teamId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$activityData1 = [['name' => '参与团队数', 'value' => count($teamData)]
|
||||
, ['name' => '参与/全部团员数', 'value' => $consultant . '/' . $allConsultant]];
|
||||
$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' => $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 = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type=1 AND kpi = 'subscribe')";
|
||||
$watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch', $id_in => null]);
|
||||
$order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $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];
|
||||
$this->return_response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:获取区域饼状数据
|
||||
|
||||
@@ -0,0 +1,533 @@
|
||||
<?php
|
||||
defined('BASEPATH') OR exit('No direct script access allowed');
|
||||
require_once APPPATH . 'controllers/api/BaseController.php';
|
||||
|
||||
/**
|
||||
* Notes:私域直播_统计
|
||||
* Created on: 2022/10/27 17:15
|
||||
* Created by: dengbw
|
||||
*/
|
||||
class Statistics extends BaseController
|
||||
{
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
parent::__construct();
|
||||
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
|
||||
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
||||
$this->load->model('market/Market_sylive_activity_biz_model', 'mdSyliveActivityBiz');
|
||||
$this->load->model('market/Market_sylive_team_model', 'mdSyliveTeam');
|
||||
$this->load->model('market/Market_sylive_activity_team_model', 'mdSyliveActivityTeam');
|
||||
$this->load->model('market/Market_sylive_organization_model', 'mdSyliveOrganization');
|
||||
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
||||
$this->load->model('live/Live_polyv_session_model', 'mdPolyvSession');
|
||||
$this->load->model('live/Live_polyv_viewlog_model', 'mdPolyvViewlog');
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:机构数据统计主页
|
||||
* Created on: 2022/10/27 16:39
|
||||
* Created by: dengbw
|
||||
* @param null $activityId
|
||||
*/
|
||||
public function biz_get($activityId = null)
|
||||
{
|
||||
$activityId = intval($activityId);
|
||||
if (!$activityId) {
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
$title = '';
|
||||
$activityData1 = $activityData2 = $areaData = $bizData = $consultantData = $areaAry = $funnel = $allOrganizationIds = [];
|
||||
$browse = $subscribe = $watch = $order = 0;
|
||||
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
||||
if ($re) {
|
||||
$title = $re['title'];
|
||||
$channelId = $re['channelId'];
|
||||
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0], 'browse desc');
|
||||
foreach ($res_biz as $k => $v) {
|
||||
$areaId = intval($v['areaId']);
|
||||
$bizId = intval($v['bizId']);
|
||||
$re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId]);
|
||||
if ($re_biz) {
|
||||
$consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)');
|
||||
$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.uid", 'left')
|
||||
->where(['a.biz_id' => $bizId, 'a.type' => 0, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
//统计顾问
|
||||
$allConsultant = 0;
|
||||
if ($areaId) {
|
||||
if (!in_array($areaId, $allOrganizationIds)) {
|
||||
$allOrganizationIds[] = $areaId;
|
||||
}
|
||||
}
|
||||
if ($bizId) {
|
||||
$allOrganizationIds[] = $bizId;
|
||||
$areaAry[$areaId]['biz'][] = $bizId;
|
||||
$consultants = [];
|
||||
$consultants[] = $bizId;
|
||||
$res_org = $this->mdSyliveOrganization->select(['parentId' => $bizId, 'status>=' => 0], 'organizationId desc', 0, 0, 'organizationId');
|
||||
foreach ($res_org as $k2 => $v2) {
|
||||
$allOrganizationIds[] = $v2['organizationId'];
|
||||
$areaAry[$areaId]['sales'][] = $v2['organizationId'];
|
||||
$consultants[] = $v2['organizationId'];
|
||||
}
|
||||
$str_organizationIds = implode(',', array_unique($consultants));
|
||||
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$bizData[] = ['areaId' => $areaId, 'bizId' => $bizId,
|
||||
'bizName' => $re_biz['organizationName'], 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe']
|
||||
, 'watch' => $v['watch'], 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
foreach ($areaAry as $k => $v) {
|
||||
$areaId = intval($k);
|
||||
$re_area = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
|
||||
if ($re_area) {
|
||||
$consultant = $this->mdSyliveActivityKpidata->count(['area_id' => $areaId, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)');
|
||||
$browse = $this->mdSyliveActivityBiz->sum('browse', ['areaId' => $areaId, 'status>=' => 0, 'activityId' => $activityId]);
|
||||
$subscribe = $this->mdSyliveActivityBiz->sum('subscribe', ['areaId' => $areaId, 'status>=' => 0, 'activityId' => $activityId]);
|
||||
$watch = $this->mdSyliveActivityBiz->sum('watch', ['areaId' => $areaId, 'status>=' => 0, 'activityId' => $activityId]);
|
||||
$orderTotal = $this->mdSyliveActivityBiz->sum('orderTotal', ['areaId' => $areaId, 'status>=' => 0, 'activityId' => $activityId]);
|
||||
$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.uid", 'left')
|
||||
->where(['a.area_id' => $areaId, 'a.type' => 0, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$allConsultant = 0;
|
||||
if ($v['biz']) {
|
||||
$organizationIds = $v['sales'] ? array_merge($v['biz'], $v['sales']) : $v['biz'];
|
||||
$str_organizationIds = implode(',', array_unique($organizationIds));
|
||||
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$areaData[] = ['areaName' => $re_area['organizationName'], 'biz' => count($v['biz']), 'consultant' => $consultant . '/' . $allConsultant
|
||||
, 'browse' => $browse['browse'], 'subscribe' => $subscribe['subscribe'], 'watch' => $watch['watch'], 'order' => $orderTotal['orderTotal']
|
||||
, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
$res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id');
|
||||
foreach ($res_user as $k => $v) {
|
||||
$userId = intval($v['userId']);
|
||||
$re_user = $this->mdSyliveUser->get(['userId' => $userId]);
|
||||
if ($re_user) {
|
||||
$consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
||||
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $v['biz_id']]);
|
||||
$re_org && $consultantName .= "({$re_org['organizationName']})";
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, '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.uid", 'left')
|
||||
->where(['a.cf_uid' => $userId, 'a.a_id' => $activityId, 'a.type' => 0, '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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch
|
||||
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'order']);
|
||||
$duration = $livePV = $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);
|
||||
$livePV = $re_livePV['livePV'];
|
||||
$watchDuration = round($duration / $livePV);
|
||||
$pvDuration = round($livePV / $re_liveUV['liveUV'], 1);
|
||||
}
|
||||
}
|
||||
$allConsultant = 0;
|
||||
$consultant = count($res_user);
|
||||
if ($allOrganizationIds) {
|
||||
$str_organizationIds = implode(',', array_unique($allOrganizationIds));
|
||||
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$activityData1 = [['name' => '参与区域数', 'value' => count($areaData)], ['name' => '参与门店数', 'value' => count($bizData)]
|
||||
, ['name' => '参与/全部顾问数', 'value' => $consultant . '/' . $allConsultant]];
|
||||
$url = "/sylive/activity/statistics/piechart?activityId={$activityId}&";
|
||||
$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' => $watchDuration, 'url' => ''], ['name' => '人均观看(次)', 'value' => $pvDuration, 'url' => '']];
|
||||
// $activityData2 = [['name' => '浏览人数', 'value' => $browse, 'url' => "{$url}type=browse"], ['name' => '预约人数', 'value' => $subscribe, 'url' => "{$url}type=subscribe"]
|
||||
// , ['name' => '观看人数', 'value' => $watch, 'url' => "{$url}type=watch"], ['name' => '订单数', 'value' => $order, 'url' => "{$url}type=order"]
|
||||
// , ['name' => '直播时长', 'value' => $duration, 'url' => ''], ['name' => '观看次数', 'value' => $livePV, 'url' => ''], ['name' => '人均观看', 'value' => $watchDuration, '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 = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type = 0 AND kpi = 'subscribe')";
|
||||
$watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'kpi' => 'watch', $id_in => null]);
|
||||
$order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, '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, 'areaData' => $areaData
|
||||
, 'bizData' => $bizData, 'consultantData' => $consultantData, 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe];
|
||||
$this->return_response($data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:机构门店统计列表
|
||||
* Created on: 2022/10/27 14:48
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function page_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');
|
||||
!$page && $page = 1;
|
||||
!$limit && $limit = 10;
|
||||
$list = [];
|
||||
$count = 0;
|
||||
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
||||
if ($re) {
|
||||
$channelId = intval($re['channelId']);
|
||||
$sort_order = 'browse desc,id desc';
|
||||
if ($sort && $order) {
|
||||
$sort_order = $sort . ' ' . $order;
|
||||
}
|
||||
$where = ['activityId' => $activityId, 'status' => 0];
|
||||
$count = $this->mdSyliveActivityBiz->count($where);
|
||||
if ($count) {
|
||||
$res = $this->mdSyliveActivityBiz->select($where, $sort_order, $page, $limit);
|
||||
foreach ($res as $v) {
|
||||
$allConsultant = 0;
|
||||
$bizId = intval($v['bizId']);
|
||||
$re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId]);
|
||||
$bizName = $re_biz ? $re_biz['organizationName'] : '-';
|
||||
$consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $bizId, 'type' => 0, 'a_id' => $activityId], 'distinct(cf_uid)');
|
||||
if ($bizId) {//统计顾问数
|
||||
$consultants = [];
|
||||
$consultants[] = $bizId;
|
||||
$res_org = $this->mdSyliveOrganization->select(['parentId' => $bizId, 'status>=' => 0], 'organizationId desc', 0, 0, 'organizationId');
|
||||
foreach ($res_org as $k2 => $v2) {
|
||||
$consultants[] = $v2['organizationId'];
|
||||
}
|
||||
$str_organizationIds = implode(',', array_unique($consultants));
|
||||
$allConsultant = $this->mdSyliveUser->count(["organizationId in({$str_organizationIds})" => null, 'status>=' => 0, 'organizationId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$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.uid", 'left')
|
||||
->where(['a.biz_id' => $bizId, 'a.type' => 0, 'a.a_id' => $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' => $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/27 14:48
|
||||
* Created by: dengbw
|
||||
*/
|
||||
public function page_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');
|
||||
!$page && $page = 1;
|
||||
!$limit && $limit = 10;
|
||||
$list = [];
|
||||
$count = 0;
|
||||
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
||||
if ($re) {
|
||||
$channelId = intval($re['channelId']);
|
||||
$sort_order = 'id desc';
|
||||
if ($sort && $order) {
|
||||
$sort_order = $sort . ' ' . $order;
|
||||
}
|
||||
$where = ['a_id' => $activityId];
|
||||
$count = $this->mdSyliveActivityKpidata->count($where, 'distinct(cf_uid)');
|
||||
if ($count) {
|
||||
$res = $this->mdSyliveActivityKpidata->select($where, $sort_order, $page, $limit, 'distinct(cf_uid) as userId,biz_id');
|
||||
foreach ($res as $v) {
|
||||
$userId = intval($v['userId']);
|
||||
$re_user = $this->mdSyliveUser->get(['userId' => $userId]);
|
||||
$consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
||||
$re_org = $this->mdSyliveOrganization->get(['organizationId' => $v['biz_id']]);
|
||||
$re_org && $consultantName .= "({$re_org['organizationName']})";
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 0, 'cf_uid' => $userId, '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.uid", 'left')
|
||||
->where(['a.cf_uid' => $userId, 'a.a_id' => $activityId, 'a.type' => 0, '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];
|
||||
}
|
||||
$edit = array_column($list, 'browse');
|
||||
array_multisort($edit, SORT_DESC, $list);
|
||||
}
|
||||
}
|
||||
$date = ['list' => $list, 'count' => $count];
|
||||
$this->return_response_list($date);
|
||||
}
|
||||
|
||||
/**
|
||||
* Notes:团队数据统计主页
|
||||
* Created on: 2022/10/27 10:02
|
||||
* Created by: dengbw
|
||||
* @param null $activityId
|
||||
*/
|
||||
public function team_get($activityId = null)
|
||||
{
|
||||
$activityId = intval($activityId);
|
||||
if (!$activityId) {
|
||||
$this->return_json('参数错误');
|
||||
}
|
||||
$title = '';
|
||||
$activityData1 = $activityData2 = $teamData = $consultantData = $funnel = $allTeamIds = [];
|
||||
$browse = $subscribe = $watch = $order = 0;
|
||||
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
||||
if ($re) {
|
||||
$title = $re['title'];
|
||||
$channelId = $re['channelId'];
|
||||
$res_biz = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status' => 0], 'browse desc');
|
||||
foreach ($res_biz as $k => $v) {
|
||||
$area_id = intval($v['teamId1']);
|
||||
$biz_id = intval($v['teamId2']);
|
||||
$re_team = $this->mdSyliveTeam->get(['teamId' => $biz_id]);
|
||||
if ($re_team) {
|
||||
$consultant = $this->mdSyliveActivityKpidata->count(['biz_id' => $biz_id, 'type' => 1, 'a_id' => $activityId], 'distinct(cf_uid)');
|
||||
$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.uid", 'left')
|
||||
->where(['a.biz_id' => $biz_id, 'a.type' => 1, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
//统计顾问
|
||||
$allConsultant = 0;
|
||||
if ($area_id) {
|
||||
if (!in_array($area_id, $allTeamIds)) {
|
||||
$allTeamIds[] = $area_id;
|
||||
}
|
||||
}
|
||||
if ($biz_id) {
|
||||
$allTeamIds[] = $biz_id;
|
||||
$consultants = [];
|
||||
$consultants[] = $biz_id;
|
||||
$res_org = $this->mdSyliveTeam->select(['parentId' => $biz_id, '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[] = ['area_id' => $area_id, 'biz_id' => $biz_id,
|
||||
'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(['a_id' => $activityId, 'type' => 1], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id');
|
||||
foreach ($res_user as $k => $v) {
|
||||
$userId = intval($v['userId']);
|
||||
$re_user = $this->mdSyliveUser->get(['userId' => $userId]);
|
||||
if ($re_user) {
|
||||
$consultantName = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
||||
$re_team = $this->mdSyliveTeam->get(['teamId' => $v['biz_id']]);
|
||||
$re_team && $consultantName .= "({$re_team['teamName']})";
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'cf_uid' => $userId, '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.uid", 'left')
|
||||
->where(['a.cf_uid' => $userId, 'a.a_id' => $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);
|
||||
}
|
||||
}
|
||||
}
|
||||
$consultantData[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch
|
||||
, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
||||
}
|
||||
}
|
||||
$browse = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'browse']);
|
||||
$subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'subscribe']);
|
||||
$watch = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch']);
|
||||
$order = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'order']);
|
||||
$duration = $livePV = $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);
|
||||
$livePV = $re_livePV['livePV'];
|
||||
$watchDuration = round($duration / $livePV);
|
||||
$pvDuration = round($livePV / $re_liveUV['liveUV'], 1);
|
||||
}
|
||||
}
|
||||
$allConsultant = 0;
|
||||
$consultant = count($res_user);
|
||||
if ($allTeamIds) {
|
||||
$str_allTeamIds = implode(',', array_unique($allTeamIds));
|
||||
$allConsultant = $this->mdSyliveUser->count(["teamId in({$str_allTeamIds})" => null, 'status>=' => 0, 'teamId>' => 0]);
|
||||
}
|
||||
$consultant > $allConsultant && $allConsultant = $consultant;
|
||||
$activityData1 = [['name' => '参与团队数', 'value' => count($teamData)]
|
||||
, ['name' => '参与/全部团员数', 'value' => $consultant . '/' . $allConsultant]];
|
||||
$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' => $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 = "uid in(select uid from lc_market_sylive_activity_kpidata where a_id = {$activityId} AND type=1 AND kpi = 'subscribe')";
|
||||
$watch_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'type' => 1, 'kpi' => 'watch', $id_in => null]);
|
||||
$order_subscribe = $this->mdSyliveActivityKpidata->count(['a_id' => $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];
|
||||
$this->return_response($data);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user