913 lines
58 KiB
PHP
913 lines
58 KiB
PHP
<?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_user_model', 'mdSyliveActivityUser');
|
|
$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_order_model', 'mdSyliveOrder');
|
|
$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 = $areaAry = $funnel = $allOrganizationIds = [];
|
|
$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->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0], 'browse desc');
|
|
foreach ($res_biz as $k => $v) {
|
|
$areaId = intval($v['areaId']);
|
|
$bizId = intval($v['bizId']);
|
|
if ($areaId) {
|
|
if (!in_array($areaId, $areaAry)) {
|
|
$areaAry[] = $areaId;
|
|
}
|
|
if (!in_array($areaId, $allOrganizationIds)) {
|
|
$allOrganizationIds[] = $areaId;
|
|
}
|
|
}
|
|
if ($bizId) {
|
|
$allOrganizationIds[] = $bizId;
|
|
$res_org = $this->mdSyliveOrganization->select(['parentId' => $bizId, 'status>=' => 0], 'organizationId desc', 0, 0, 'organizationId');
|
|
foreach ($res_org as $k2 => $v2) {
|
|
$allOrganizationIds[] = $v2['organizationId'];
|
|
}
|
|
}
|
|
}
|
|
$browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveOrder->count(['itemId' => $activityId, 'cfrom' => 0, '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_livePV = $this->mdPolyvSession->sum('livePV', ['channelId' => $channelId]);
|
|
$re_liveUV = $this->mdPolyvSession->sum('liveUV', ['channelId' => $channelId]);
|
|
$livePV = $re_livePV['livePV'];
|
|
$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 = $this->mdSyliveActivityUser->count(['activityId' => $activityId, 'organizationId>' => 0, 'userId>' => 0]);
|
|
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;
|
|
$biz = $this->mdSyliveActivityBiz->count(['activityId' => $activityId, 'status>=' => 0, 'bizId>' => 0]);
|
|
$activityData1 = [['name' => '参与区域数', 'value' => count($areaAry)], ['name' => '参与门店数', 'value' => $biz]
|
|
, ['name' => '参与/全部顾问数', 'value' => $consultant . '/' . $allConsultant]];
|
|
$url = "/sylive/activity/statistics/piechart?activityId={$activityId}&";
|
|
$watch_un = $watch - $liveUV;
|
|
$watch_un < 0 && $watch_un = 0;
|
|
$activityData2 = [['name' => '浏览数(人)', 'value' => $browse, 'url' => ''], ['name' => '预约数(人)', 'value' => $subscribe, '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' => '']];
|
|
}
|
|
$timeStart = strtotime($re['timeStart']);//直播开始时间
|
|
$left_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND type = 0 AND kpi = 'browse' AND createTime < {$timeStart})";
|
|
$left_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'browse', 'createTime<' => $timeStart]);
|
|
$left_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'subscribe']);
|
|
$left_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'watch', $left_browse_where => null]);
|
|
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, '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 = 0 AND kpi = 'browse' AND createTime >= {$timeStart})";
|
|
$right_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'browse', 'createTime>=' => $timeStart]);
|
|
$right_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, 'kpi' => 'watch', $right_browse_where => null]);
|
|
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 0, '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: 33.3%'], 'activityData2' => ['list' => $activityData2, 'style' => 'width: 11.1%']
|
|
, 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe, 'days' => $days];
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:区域统计列表
|
|
* Created on: 2022/11/7 16:30
|
|
* Created by: dengbw
|
|
*/
|
|
public function page_area_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 = [];
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
if ($re) {
|
|
$areaAry = [];
|
|
$res_biz = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0, 'bizId>=' => 0], 'browse desc');
|
|
foreach ($res_biz as $k => $v) {
|
|
$areaId = intval($v['areaId']);
|
|
$bizId = intval($v['bizId']);
|
|
$areaAry[$areaId]['biz'][] = $bizId;
|
|
$res_org = $this->mdSyliveOrganization->select(['parentId' => $bizId, 'status>=' => 0], 'organizationId desc', 0, 0, 'organizationId');
|
|
foreach ($res_org as $k2 => $v2) {
|
|
$areaAry[$areaId]['sales'][] = $v2['organizationId'];
|
|
}
|
|
}
|
|
$channelId = intval($re['channelId']);
|
|
!$sort && $sort = 'browse';
|
|
!$order && $order = 'desc';
|
|
if ($day) {//按天搜索
|
|
foreach ($areaAry as $k => $v) {
|
|
$areaId = intval($k);
|
|
$re_area = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
|
|
if ($re_area) {
|
|
$consultant = $this->mdSyliveActivityKpidata->count(['areaId' => $areaId, 'type' => 0, 'day' => $day, 'activityId' => $activityId], 'distinct(cfUserId)');
|
|
$browse = $this->mdSyliveActivityKpidata->count(['kpi' => 'browse', 'areaId' => $areaId, 'type' => 0, 'day' => $day, 'activityId' => $activityId]);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['kpi' => 'subscribe', 'areaId' => $areaId, 'type' => 0, 'day' => $day, 'activityId' => $activityId]);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['kpi' => 'watch', 'areaId' => $areaId, 'type' => 0, 'day' => $day, 'activityId' => $activityId]);
|
|
$orderTotal = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'areaId' => $areaId, 'type' => 0, 'day' => $day, '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.userId", 'left')
|
|
->where(['a.areaId' => $areaId, 'a.type' => 0, '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);
|
|
}
|
|
}
|
|
}
|
|
$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;
|
|
$list[] = ['areaName' => $re_area['organizationName'], 'biz' => count($v['biz']), 'consultant' => $consultant . '/' . $allConsultant
|
|
, 'browse' => $browse, 'subscribe' => $subscribe, 'watch' => $watch, 'order' => $orderTotal
|
|
, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
} else {
|
|
foreach ($areaAry as $k => $v) {
|
|
$areaId = intval($k);
|
|
$re_area = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
|
|
if ($re_area) {
|
|
//$consultant = $this->mdSyliveActivityKpidata->count(['areaId' => $areaId, 'type' => 0, 'activityId' => $activityId], 'distinct(cfUserId)');
|
|
//$browse = $this->mdSyliveActivityKpidata->count(['kpi' => 'browse', 'areaId' => $areaId, 'type' => 0, 'activityId' => $activityId]);
|
|
$consultant = $this->mdSyliveActivityUser->count(['areaId' => $areaId, 'activityId' => $activityId, 'organizationId>' => 0, 'userId>' => 0]);
|
|
$browse = $this->mdSyliveActivityBiz->sum('browse', ['areaId' => $areaId, 'activityId' => $activityId]);
|
|
$subscribe = $this->mdSyliveActivityBiz->sum('subscribe', ['areaId' => $areaId, 'activityId' => $activityId]);
|
|
$watch = $this->mdSyliveActivityBiz->sum('watch', ['areaId' => $areaId, 'activityId' => $activityId]);
|
|
$orderTotal = $this->mdSyliveActivityBiz->sum('orderTotal', ['areaId' => $areaId, '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.userId", 'left')
|
|
->where(['a.areaId' => $areaId, 'a.type' => 0, '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);
|
|
}
|
|
}
|
|
}
|
|
$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;
|
|
$list[] = ['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];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$order = $order == 'desc' ? SORT_DESC : SORT_ASC;
|
|
$sortKey = array_column($list, $sort);
|
|
array_multisort($sortKey, $order, $list);
|
|
$count = count($list);
|
|
$list = array_splice($list, 0, $limit);
|
|
$date = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* 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');
|
|
$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' => 0, '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->mdSyliveOrganization->get(['organizationId' => $bizId, 'status>=' => 0]);
|
|
$bizName = $re_biz ? $re_biz['organizationName'] : '-';
|
|
$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, 'organizationId>' => 0, 'userId>' => 0]);
|
|
$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]);
|
|
$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' => 0, '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, 'bizId>' => 0];
|
|
$count = $this->mdSyliveActivityBiz->count($where);
|
|
if ($count) {
|
|
$res = $this->mdSyliveActivityBiz->select($where, "{$sort_order},id desc", $page, $limit);
|
|
foreach ($res as $v) {
|
|
$bizId = intval($v['bizId']);
|
|
$re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId, 'status>=' => 0]);
|
|
$bizName = $re_biz ? $re_biz['organizationName'] : '-';
|
|
//$consultant = $this->mdSyliveActivityKpidata->count(['bizId' => $bizId, 'type' => 0, 'activityId' => $activityId], 'distinct(cfUserId)');
|
|
$consultant = $this->mdSyliveActivityUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'organizationId>' => 0, 'userId>' => 0]);
|
|
//统计顾问数
|
|
$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.userId", 'left')
|
|
->where(['a.bizId' => $bizId, 'a.type' => 0, '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' => $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');
|
|
$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' => 0, '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->mdSyliveOrganization->get(['organizationId' => $v['bizId'], 'status>=' => 0]);
|
|
$organizationName = $re_org['organizationName'] ? $re_org['organizationName'] : '-';
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $cfUserId, 'status>=' => 0]);
|
|
$uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
|
$consultantName = $organizationName . ' ' . $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' => 0, '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, 'organizationId>' => 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->mdSyliveOrganization->get(['organizationId' => $v['bizId'], 'status>=' => 0]);
|
|
$organizationName = $re_org['organizationName'] ? $re_org['organizationName'] : '-';
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $userId, 'status>=' => 0]);
|
|
$uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
|
$consultantName = $organizationName . ' ' . $uname;
|
|
$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' => $userId, 'a.activityId' => $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' => $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 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) {
|
|
$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);
|
|
}
|
|
}
|
|
}
|
|
//统计顾问
|
|
$allConsultant = 0;
|
|
if ($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);
|
|
}
|
|
}
|
|
}
|
|
$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;
|
|
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;
|
|
$url = "/sylive/activity/statistics/piechart?activityId={$activityId}&type=1&";
|
|
$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' => '']];
|
|
// $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];
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取区域饼状数据
|
|
* Created on: 2022/10/9 17:21
|
|
* Created by: dengbw
|
|
*/
|
|
public function piechart_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$type = intval($this->input_param('type'));
|
|
$kpi = $this->input_param('kpi');
|
|
if (!$activityId || !$kpi) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$data = [];
|
|
if ($type == 1) {
|
|
$res = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status>=' => 0], 'browse desc', 0, 0, 'distinct(teamId1) as areaId');
|
|
foreach ($res as $k => $v) {
|
|
$areaId = intval($v['areaId']);
|
|
$re = $this->mdSyliveTeam->get(['teamId' => $areaId]);
|
|
$name = $re['teamName'] ? $re['teamName'] : '-';
|
|
$re_kpi = $this->mdSyliveActivityTeam->sum($kpi, ['teamId1' => $areaId, 'status>=' => 0, 'activityId' => $activityId]);
|
|
$data[] = ['name' => $name, 'value' => $re_kpi[$kpi] ? $re_kpi[$kpi] : '0'
|
|
, 'url' => "/sylive/activity/statistics/barchart?activityId={$activityId}&areaId={$areaId}&kpi={$kpi}&type={$type}"];
|
|
}
|
|
} else {
|
|
$res = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0], 'browse desc', 0, 0, 'distinct(areaId)');
|
|
foreach ($res as $k => $v) {
|
|
$areaId = intval($v['areaId']);
|
|
$re = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
|
|
$name = $re['organizationName'] ? $re['organizationName'] : '-';
|
|
$re_kpi = $this->mdSyliveActivityBiz->sum($kpi, ['areaId' => $areaId, 'status>=' => 0, 'activityId' => $activityId]);
|
|
$data[] = ['name' => $name, 'value' => $re_kpi[$kpi] ? $re_kpi[$kpi] : '0'
|
|
, 'url' => "/sylive/activity/statistics/barchart?activityId={$activityId}&areaId={$areaId}&kpi={$kpi}&type={$type}"];
|
|
}
|
|
}
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取门店柱状数据
|
|
* Created on: 2022/10/9 17:30
|
|
* Created by: dengbw
|
|
*/
|
|
public function barchart_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$areaId = intval($this->input_param('areaId'));
|
|
$type = intval($this->input_param('type'));
|
|
$kpi = $this->input_param('kpi');
|
|
if (!$activityId || !$areaId || !$kpi) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$data = $dataTitle = $dataValue = $dataUrl = [];
|
|
if ($type == 1) {
|
|
$res = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'teamId1' => $areaId, 'status>=' => 0]);
|
|
foreach ($res as $k => $v) {
|
|
$bizId = intval($v['teamId2']);
|
|
$re = $this->mdSyliveTeam->get(['teamId' => $bizId]);
|
|
$name = $re['teamName'] ? $re['teamName'] : '-';
|
|
$value = $v[$kpi] ? $v[$kpi] : '0';
|
|
$url = "/sylive/activity/statistics/storebarchart?activityId={$activityId}&bizId={$bizId}&kpi={$kpi}&type={$type}";
|
|
$data[] = ['name' => $name, 'value' => $value, 'url' => $url];
|
|
}
|
|
} else {
|
|
$res = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'areaId' => $areaId, 'status>=' => 0]);
|
|
foreach ($res as $k => $v) {
|
|
$bizId = intval($v['bizId']);
|
|
$re = $this->mdSyliveOrganization->get(['organizationId' => $bizId]);
|
|
$name = $re['organizationName'] ? $re['organizationName'] : '-';
|
|
$value = $v[$kpi] ? $v[$kpi] : '0';
|
|
$url = "/sylive/activity/statistics/storebarchart?activityId={$activityId}&bizId={$bizId}&kpi={$kpi}&type={$type}";
|
|
$data[] = ['name' => $name, 'value' => $value, 'url' => $url];
|
|
}
|
|
}
|
|
if ($data) {
|
|
$edit = array_column($data, 'value');
|
|
array_multisort($edit, SORT_ASC, $data);
|
|
foreach ($data as $k => $v) {
|
|
$dataTitle[] = $v['name'];
|
|
$dataValue[] = $v['value'];
|
|
$dataUrl[] = $v['url'];
|
|
}
|
|
}
|
|
$data['dataTitle'] = $dataTitle;
|
|
$data['dataValue'] = $dataValue;
|
|
$data['dataUrl'] = $dataUrl;
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取顾问柱状数据
|
|
* Created on: 2022/10/10 10:08
|
|
* Created by: dengbw
|
|
*/
|
|
public function storebarchart_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$bizId = intval($this->input_param('bizId'));
|
|
$type = intval($this->input_param('type'));
|
|
$kpi = $this->input_param('kpi');
|
|
if (!$activityId || !$bizId || !$kpi) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$data = $dataTitle = $dataValue = [];
|
|
$res_user = $this->mdSyliveActivityKpidata->select(['activityId' => $activityId, 'bizId' => $bizId, 'type' => $type]
|
|
, 'id desc', 0, 0, 'distinct(cfUserId)');
|
|
foreach ($res_user as $k => $v) {
|
|
$cfUserId = intval($v['cfUserId']);
|
|
$re_user = $this->mdSyliveUser->get(['userId' => $cfUserId]);
|
|
if ($re_user) {
|
|
$name = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname'];
|
|
$value = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'cfUserId' => $cfUserId, 'type' => $type, 'kpi' => $kpi]);
|
|
$data[] = ['name' => $name ? $name : '-', 'value' => $value];
|
|
}
|
|
}
|
|
if ($data) {
|
|
$edit = array_column($data, 'value');
|
|
array_multisort($edit, SORT_DESC, $data);
|
|
foreach ($data as $k => $v) {
|
|
$dataTitle[] = $v['name'];
|
|
$dataValue[] = $v['value'];
|
|
}
|
|
}
|
|
$data['dataTitle'] = $dataTitle;
|
|
$data['dataValue'] = $dataValue;
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:查询排名
|
|
* Created on: 2022/11/3 19:45
|
|
* Created by: dengbw
|
|
*/
|
|
public function ranking_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$type = intval($this->input_param('type'));
|
|
$kpi = $this->input_param('kpi');
|
|
$area = $biz = $consultant = [];
|
|
$kpi == 'order' && $kpi = 'orderTotal';
|
|
if ($type == 1) {
|
|
|
|
} else {
|
|
//大区排名
|
|
$res = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0, 'bizId>=' => 0], "id desc", 0, 0, 'distinct(areaId)');
|
|
foreach ($res as $k => $v) {
|
|
$areaId = intval($v['areaId']);
|
|
$re = $this->mdSyliveOrganization->get(['organizationId' => $areaId]);
|
|
$name = $re['organizationName'] ? $re['organizationName'] : '-';
|
|
$value = $this->mdSyliveActivityBiz->sum($kpi, ['areaId' => $areaId, 'activityId' => $activityId]);
|
|
$area[] = ['name' => $name, 'value' => $value[$kpi], 'percent' => 0];
|
|
}
|
|
if ($res) {
|
|
$edit = array_column($area, 'value');
|
|
array_multisort($edit, SORT_DESC, $area);
|
|
$areaMax = $area[0]['value'];
|
|
foreach ($area as $k => $v) {
|
|
$percent = ceil(($v['value'] / $areaMax) * 100);
|
|
$area[$k]['percent'] = $percent;
|
|
}
|
|
$area = array_splice($area, 0, 10);
|
|
}
|
|
//门店排名
|
|
$res = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0]
|
|
, "{$kpi} desc,id desc", 1, 10, "{$kpi},bizId");
|
|
if ($res) {
|
|
$bizMax = $res[0][$kpi];
|
|
foreach ($res as $k => $v) {
|
|
$bizId = intval($v['bizId']);
|
|
$re = $this->mdSyliveOrganization->get(['organizationId' => $bizId]);
|
|
$name = $re['organizationName'] ? $re['organizationName'] : '-';
|
|
$percent = ceil(($v[$kpi] / $bizMax) * 100);
|
|
$biz[] = ['name' => $name, 'value' => $v[$kpi], 'percent' => $percent];
|
|
}
|
|
}
|
|
//顾问排名
|
|
$res = $this->mdSyliveActivityUser->select_groupby('userId', ['activityId' => $activityId, 'organizationId>' => 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->mdSyliveOrganization->get(['organizationId' => $v['bizId'], 'status>=' => 0]);
|
|
$re_org && $name .= "({$re_org['organizationName']})";
|
|
$percent = ceil(($v[$kpi] / $consultantMax) * 100);
|
|
$consultant[] = ['name' => $name, 'value' => $v[$kpi], 'percent' => $percent];
|
|
}
|
|
}
|
|
}
|
|
$data['area'] = $area;
|
|
$data['biz'] = $biz;
|
|
$data['consultant'] = $consultant;
|
|
$this->return_response($data);
|
|
}
|
|
|
|
} |