776 lines
45 KiB
PHP
776 lines
45 KiB
PHP
<?php
|
|
defined('BASEPATH') OR exit('No direct script access allowed');
|
|
require_once APPPATH . 'controllers/api/BaseController.php';
|
|
|
|
/**
|
|
* Notes:私域直播_分组数据统计
|
|
* Created on: 2022/12/05 17:15
|
|
* Created by: dengbw
|
|
*/
|
|
class GroupsStatistics extends BaseController
|
|
{
|
|
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('market/Market_sylive_groups_model', 'mdSyliveGroups');
|
|
$this->load->model('market/Market_sylive_groups_user_model', 'mdSyliveGroupsUser');
|
|
$this->load->model('market/Market_sylive_user_model', 'mdSyliveUser');
|
|
$this->load->model('market/Market_sylive_activity_kpidata_model', 'mdSyliveActivityKpidata');
|
|
$this->load->model('market/Market_sylive_activity_model', 'mdSyliveActivity');
|
|
$this->load->model('market/Market_sylive_order_model', 'mdSyliveOrder');
|
|
$this->load->model('market/Market_sylive_items_model', 'mdSyliveItems');
|
|
$this->load->model('market/Market_sylive_viewlog_model', 'mdSyliveViewlog');
|
|
$this->load->model('live/Live_polyv_session_model', 'mdPolyvSession');
|
|
}
|
|
|
|
/**
|
|
* Notes:分组数据统计主页
|
|
* Created on: 2022/12/05 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function index_get($activityId = null)
|
|
{
|
|
$activityId = intval($activityId);
|
|
if (!$activityId) {
|
|
$this->return_json('参数错误');
|
|
}
|
|
$title = '';
|
|
$activityData1 = $activityData2 = $areaAry = $funnel = $allOrganizationIds = $levelData = [];
|
|
$days[] = ['name' => '全部日期', 'value' => ''];
|
|
$goods[] = ['name' => '全部订单', 'value' => ''];
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
if ($re) {
|
|
$res_item = $this->mdSyliveItems->select(['status>=' => 0, 'activityId' => $activityId], 'sort asc,itemId desc'
|
|
, 0, 0, 'itemId,title');
|
|
foreach ($res_item as $k => $v) {
|
|
$goods[] = ['name' => $v['title'], 'value' => intval($v['itemId'])];
|
|
}
|
|
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'];
|
|
$browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'browse']);
|
|
$subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'subscribe']);
|
|
$watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch']);
|
|
$order = $this->mdSyliveOrder->count(['activityId' => $activityId, '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);
|
|
}
|
|
}
|
|
$consultant = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId], 'cfUserId');
|
|
$allConsultant = $this->mdSyliveGroupsUser->count(['activityId' => $activityId, 'status>=' => 0]);
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$bizs = $this->mdSyliveGroups->count(['activityId' => $activityId, 'ifBiz' => 1, 'status>=' => 0]);
|
|
$activityData1 = [['name' => '参与门店数', 'value' => $bizs]
|
|
, ['name' => '参与/全部顾问数', 'value' => $consultant . '/' . $allConsultant]];
|
|
$watch_un = 0;
|
|
if ($liveUV) {
|
|
$watch_un = $watch - $liveUV;
|
|
$watch_un < 0 && $watch_un = 0;
|
|
}
|
|
$activityData2 = [['name' => '浏览数(人)', 'value' => $browse, 'url' => ''], ['name' => '预约数(人)', 'value' => $subscribe, 'url' => '']
|
|
, ['name' => '订单数(单)', 'value' => $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' => '']];
|
|
}
|
|
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'parentId' => 0, 'status>=' => 0]);
|
|
if ($re_gro['statisticsType']) {
|
|
$this->load->model('market/Market_sys_dictionary_data_model', 'mdSysDictionaryData');
|
|
$res_dit = $this->mdSysDictionaryData->select(['status>=' => 0, 'dictId' => $re_gro['statisticsType']], 'sortNumber asc,dictDataId desc'
|
|
, 0, 0, 'dictDataCode,dictDataName');
|
|
foreach ($res_dit as $k => $v) {
|
|
$groupsLevel = intval($v['dictDataCode']);
|
|
$re_gro = $this->mdSyliveGroups->get(['activityId' => $activityId, 'groupsLevel' => $groupsLevel, 'status>=' => 0]);
|
|
if ($re_gro) {
|
|
$levelData[] = ['title' => $v['dictDataName'] . '统计', 'value' => $groupsLevel];
|
|
}
|
|
}
|
|
}
|
|
$data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => ['list' => $activityData1, 'style' => 'width: 50%']
|
|
, 'activityData2' => ['list' => $activityData2, 'style' => 'width: 11.1%'], 'tableData' => ['days' => $days, 'goods' => $goods]
|
|
, 'levelData' => $levelData
|
|
];
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:分组等级数据统计
|
|
* Created on: 2022/12/5 17:50
|
|
* Created by: dengbw
|
|
*/
|
|
public function level_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$sort = $this->input_param('sort');
|
|
$order = $this->input_param('order');
|
|
$day = $this->input_param('day');//日期
|
|
$itemId = intval($this->input_param('itemId'));//商品
|
|
$groupsLevel = intval($this->input_param('level'));//等级
|
|
$levelId = "levelId" . $groupsLevel;
|
|
$list = [];
|
|
$count = 0;
|
|
$page = 1;
|
|
$limit = 50;
|
|
$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) {//按天搜索
|
|
$createTimeStart = strtotime($day . ' 00:00:00');
|
|
$createTimeEnd = strtotime($day . ' 23:59:59');
|
|
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, "$levelId>" => 0, 'kpi' => $sort];
|
|
if ($sort == 'order') {
|
|
$itemId && $where['itemId'] = $itemId;
|
|
}
|
|
$count = $this->mdSyliveActivityKpidata->count($where, $levelId);
|
|
if ($count) {
|
|
$res = $this->mdSyliveActivityKpidata->select_groupby($levelId, $where, "total {$order},id desc", $page, $limit, "$levelId,count(id) as total");
|
|
foreach ($res as $v) {
|
|
$groupsId = intval($v[$levelId]);
|
|
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$groupsName = $re_gro ? $re_gro['groupsName'] : '-';
|
|
$where_sort[$levelId] = $groupsId;
|
|
if ($sort == 'browse') {
|
|
$browse = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'browse';
|
|
$browse = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'subscribe') {
|
|
$subscribe = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'subscribe';
|
|
$subscribe = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'watch') {
|
|
$watch = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'watch';
|
|
$watch = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'order') {
|
|
$orderTotal = $v['total'];
|
|
} else {
|
|
$where_order['kpi'] = 'order';
|
|
$where_order[$levelId] = $groupsId;
|
|
$itemId && $where_order['itemId'] = $itemId;
|
|
$orderTotal = $this->mdSyliveActivityKpidata->count($where_order);
|
|
}
|
|
$consultant = $this->mdSyliveActivityKpidata->count([$levelId => $groupsId, 'activityId' => $activityId], 'cfUserId');
|
|
$allConsultant = $this->mdSyliveGroupsUser->count([$levelId => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$livePV = $watchDuration = 0;
|
|
if ($channelId) {
|
|
$livePV = $this->mdSyliveViewlog->count([$levelId => $groupsId, 'activityId' => $activityId
|
|
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
|
|
$re_sum = $this->mdSyliveViewlog->sum('playDuration', [$levelId => $groupsId, 'activityId' => $activityId
|
|
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
|
|
if ($re_sum['playDuration']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
$biz = $this->getBiz($groupsId);
|
|
$list[] = [
|
|
'groupsName' => $groupsName, 'biz' => $biz, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
|
|
, 'watch' => $watch, 'order' => $orderTotal, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
} else {
|
|
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
|
|
$where = ['activityId' => $activityId, 'itemId' => $itemId, "$levelId>" => 0, 'kpi' => $sort];
|
|
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
|
|
} else {
|
|
$where = ['activityId' => $activityId, 'status>=' => 0, 'groupsLevel' => $groupsLevel];
|
|
$count = $this->mdSyliveGroups->count($where);
|
|
}
|
|
if ($count) {
|
|
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
|
|
$res = $this->mdSyliveActivityKpidata->select_groupby($levelId, $where, "orderTotal {$order},id desc"
|
|
, $page, $limit, "$levelId,count(id) as orderTotal");
|
|
} else {
|
|
$res = $this->mdSyliveGroups->select($where, "{$sort_order},groupsId desc", $page, $limit,
|
|
'groupsId,groupsName,browse,subscribe,watch,orderTotal');
|
|
}
|
|
foreach ($res as $v) {
|
|
if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变
|
|
$groupsId = intval($v[$levelId]);
|
|
$re_gro = $this->mdSyliveGroups->get(['groupsId' => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$groupsName = $re_gro ? $re_gro['groupsName'] : '-';
|
|
$v['browse'] = intval($re_gro['browse']);
|
|
$v['subscribe'] = intval($re_gro['subscribe']);
|
|
$v['watch'] = intval($re_gro['watch']);
|
|
} else {
|
|
$groupsId = intval($v['groupsId']);
|
|
$groupsName = $v['groupsName'] ? $v['groupsName'] : '-';
|
|
}
|
|
$consultant = $this->mdSyliveActivityKpidata->count([$levelId => $groupsId, 'activityId' => $activityId], 'cfUserId');
|
|
$allConsultant = $this->mdSyliveGroupsUser->count([$levelId => $groupsId, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$livePV = $watchDuration = 0;
|
|
if ($channelId) {
|
|
$livePV = $this->mdSyliveViewlog->count([$levelId => $groupsId, 'activityId' => $activityId]);
|
|
$re_sum = $this->mdSyliveViewlog->sum('playDuration', [$levelId => $groupsId, 'activityId' => $activityId]);
|
|
if ($re_sum['playDuration']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
if ($sort != 'order' && $itemId) {//有商品id,区分订单
|
|
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', $levelId => $groupsId, 'itemId' => $itemId, 'activityId' => $activityId]);
|
|
} else {
|
|
$order = $v['orderTotal'];
|
|
}
|
|
$biz = $this->getBiz($groupsId);
|
|
$list[] = [
|
|
'groupsName' => $groupsName, 'biz' => $biz, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe']
|
|
, 'watch' => $v['watch'], 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$date = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:分组门店统计
|
|
* Created on: 2022/12/05 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function 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');
|
|
$itemId = intval($this->input_param('itemId'));//商品
|
|
!$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;
|
|
}
|
|
//一级分组
|
|
$map_level1 = $this->mdSyliveGroups->map('groupsId', 'groupsName', ['groupsLevel' => 1, 'status>=' => 0]);
|
|
$map_biz = [];
|
|
if ($day) {//按天搜索
|
|
$createTimeStart = strtotime($day . ' 00:00:00');
|
|
$createTimeEnd = strtotime($day . ' 23:59:59');
|
|
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'bizId>' => 0, 'kpi' => $sort];
|
|
if ($sort == 'order') {
|
|
$itemId && $where['itemId'] = $itemId;
|
|
}
|
|
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
|
|
if ($count) {
|
|
$res = $this->mdSyliveActivityKpidata->select_groupby('bizId', $where, "total {$order},id desc",
|
|
$page, $limit, "bizId,levelId1,count(id) as total");
|
|
$str_biz = implode(',', array_column($res, 'bizId'));
|
|
$map_biz = $this->mdSyliveGroups->map('groupsId', 'groupsName',
|
|
["groupsId in({$str_biz})" => null, 'activityId' => $activityId, 'status>=' => 0]);
|
|
foreach ($res as $v) {
|
|
$bizId = intval($v['bizId']);
|
|
$levelId1 = intval($v['levelId1']);
|
|
$bizName = '';
|
|
if ($map_level1[$levelId1]) {
|
|
$bizName = $map_level1[$levelId1];
|
|
}
|
|
if ($map_biz[$bizId]) {
|
|
$bizName = $bizName ? $bizName . ' ' . $map_biz[$bizId] : $map_biz[$bizId];
|
|
}
|
|
$where_sort['bizId'] = $bizId;
|
|
if ($sort == 'browse') {
|
|
$browse = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'browse';
|
|
$browse = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'subscribe') {
|
|
$subscribe = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'subscribe';
|
|
$subscribe = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'watch') {
|
|
$watch = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'watch';
|
|
$watch = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'order') {
|
|
$orderTotal = $v['total'];
|
|
} else {
|
|
$where_order['kpi'] = 'order';
|
|
$where_order['bizId'] = $bizId;
|
|
$itemId && $where_order['itemId'] = $itemId;
|
|
$orderTotal = $this->mdSyliveActivityKpidata->count($where_order);
|
|
}
|
|
$consultant = $this->mdSyliveActivityKpidata->count(['bizId' => $bizId, 'activityId' => $activityId], 'cfUserId');
|
|
$allConsultant = $this->mdSyliveGroupsUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$livePV = $watchDuration = 0;
|
|
if ($channelId) {
|
|
$livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId
|
|
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
|
|
$re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId
|
|
, 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]);
|
|
if ($re_sum['playDuration']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
$list[] = [
|
|
'bizName' => $bizName, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $browse, 'subscribe' => $subscribe
|
|
, 'watch' => $watch, 'order' => $orderTotal, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
} else {
|
|
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
|
|
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'bizId>' => 0, 'kpi' => $sort];
|
|
$count = $this->mdSyliveActivityKpidata->count($where, 'bizId');
|
|
} else {
|
|
$where = ['activityId' => $activityId, 'status>=' => 0, 'ifBiz' => 1];
|
|
$count = $this->mdSyliveGroups->count($where);
|
|
}
|
|
if ($count) {
|
|
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
|
|
$res = $this->mdSyliveActivityKpidata->select_groupby('bizId', $where, "orderTotal {$order},id desc"
|
|
, $page, $limit, "bizId,levelId1,count(id) as orderTotal");
|
|
$str_biz = implode(',', array_column($res, 'bizId'));
|
|
$map_biz = $this->mdSyliveGroups->map('groupsId', 'groupsName',
|
|
["groupsId in({$str_biz})" => null, 'activityId' => $activityId, 'status>=' => 0]);
|
|
} else {
|
|
$res = $this->mdSyliveGroups->select($where, "{$sort_order},groupsId desc", $page, $limit,
|
|
'groupsId,groupsName,browse,subscribe,watch,orderTotal');
|
|
}
|
|
foreach ($res as $v) {
|
|
$bizName = '';
|
|
if ($sort == 'order' && $itemId) {
|
|
$bizId = intval($v['bizId']);
|
|
$levelId1 = intval($v['levelId1']);
|
|
if ($map_level1[$levelId1]) {
|
|
$bizName = $map_level1[$levelId1];
|
|
}
|
|
if ($map_biz[$bizId]) {
|
|
$bizName = $bizName ? $bizName . ' ' . $map_biz[$bizId] : $map_biz[$bizId];
|
|
}
|
|
} else {
|
|
$bizId = intval($v['groupsId']);
|
|
$re_use = $this->mdSyliveGroupsUser->get(["bizId" => $bizId, 'activityId' => $activityId, 'status>=' => 0]);
|
|
if ($re_use['levelId1']) {//根据用户找1级
|
|
$levelId1 = intval($re_use['levelId1']);
|
|
if ($map_level1[$levelId1]) {
|
|
$bizName = $map_level1[$levelId1];
|
|
}
|
|
}
|
|
if (!$bizName && $bizId) {//根据门店向上找1级
|
|
$bizName = $this->getLevelName($bizId, 1, '');
|
|
}
|
|
if ($v['groupsName']) {
|
|
$bizName = $bizName ? $bizName . ' ' . $v['groupsName'] : $v['groupsName'];
|
|
}
|
|
}
|
|
$consultant = $this->mdSyliveActivityKpidata->count(['bizId' => $bizId, 'activityId' => $activityId], 'cfUserId');
|
|
$allConsultant = $this->mdSyliveGroupsUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$consultant > $allConsultant && $allConsultant = $consultant;
|
|
$livePV = $watchDuration = 0;
|
|
if ($channelId) {
|
|
$livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId]);
|
|
$re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId]);
|
|
if ($re_sum['playDuration']) {
|
|
$playDuration = ceil($re_sum['playDuration'] / 60);
|
|
$watchDuration = round($playDuration / $livePV);
|
|
}
|
|
}
|
|
if ($sort != 'order' && $itemId) {//有商品id,区分订单
|
|
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'bizId' => $bizId, 'itemId' => $itemId, 'activityId' => $activityId]);
|
|
} else {
|
|
$order = $v['orderTotal'];
|
|
}
|
|
if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变
|
|
$re = $this->mdSyliveGroups->get(['groupsId' => $bizId, 'activityId' => $activityId, 'status>=' => 0], 'browse,subscribe,watch');
|
|
$v['browse'] = intval($re['browse']);
|
|
$v['subscribe'] = intval($re['subscribe']);
|
|
$v['watch'] = intval($re['watch']);
|
|
}
|
|
$list[] = [
|
|
'bizName' => $bizName, 'consultant' => $consultant, 'allConsultant' => $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe']
|
|
, 'watch' => $v['watch'], 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$date = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:分组顾问统计
|
|
* Created on: 2022/12/05 14:48
|
|
* Created by: dengbw
|
|
*/
|
|
public function 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');
|
|
$itemId = intval($this->input_param('itemId'));//商品
|
|
!$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) {
|
|
$createTimeStart = strtotime($day . ' 00:00:00');
|
|
$createTimeEnd = strtotime($day . ' 23:59:59');
|
|
$where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'cfUserId>' => 0, 'kpi' => $sort];
|
|
if ($sort == 'order') {
|
|
$itemId && $where['itemId'] = $itemId;
|
|
}
|
|
$count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId');
|
|
if ($count) {
|
|
$res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "total {$order},id desc", $page, $limit
|
|
, "levelId1,levelId2,levelId3,bizId as groupsId,cfUserId,count(id) as total");
|
|
$groups_ids = $userIds = [];
|
|
foreach ($res as $v) {
|
|
if ($v['levelId1'] && !in_array($v['levelId1'], $groups_ids)) {
|
|
$groups_ids[] = $v['levelId1'];
|
|
}
|
|
if ($v['levelId2'] && !in_array($v['levelId2'], $groups_ids)) {
|
|
$groups_ids[] = $v['levelId2'];
|
|
}
|
|
if ($v['levelId3'] && !in_array($v['levelId3'], $groups_ids)) {
|
|
$groups_ids[] = $v['levelId3'];
|
|
}
|
|
if ($v['groupsId'] && !in_array($v['groupsId'], $groups_ids)) {
|
|
$groups_ids[] = $v['groupsId'];
|
|
}
|
|
$userIds[] = $v['cfUserId'];
|
|
}
|
|
$str_groups = $groups_ids ? implode(',', $groups_ids) : -1;
|
|
$map_groups = $this->mdSyliveGroups->map('groupsId', 'groupsName',
|
|
["groupsId in({$str_groups})" => null, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$str_user = $userIds ? implode(',', $userIds) : -1;
|
|
$map_user = $this->mdSyliveUser->map('userId', 'uname,nickname', ["userId in({$str_user})" => null, 'status>=' => 0]);
|
|
foreach ($res as $v) {
|
|
$cfUserId = intval($v['cfUserId']);
|
|
$bizName = $uname = '';
|
|
$map_groups[$v['levelId1']] && $bizName = $map_groups[$v['levelId1']] . ' ';
|
|
$map_groups[$v['levelId2']] && $bizName .= $map_groups[$v['levelId2']] . ' ';
|
|
$map_groups[$v['levelId3']] && $bizName .= $map_groups[$v['levelId3']] . ' ';
|
|
if ($map_groups[$v['groupsId']]) {
|
|
$groupsName = $map_groups[$v['groupsId']] . ' ';
|
|
if ($bizName != $groupsName) {
|
|
$bizName .= $groupsName;
|
|
}
|
|
}
|
|
$uname = $map_user[$cfUserId]['uname'] ? $map_user[$cfUserId]['uname'] : $map_user[$cfUserId]['nickname'];
|
|
$where_sort['cfUserId'] = $cfUserId;
|
|
if ($sort == 'browse') {
|
|
$browse = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'browse';
|
|
$browse = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'subscribe') {
|
|
$subscribe = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'subscribe';
|
|
$subscribe = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'watch') {
|
|
$watch = $v['total'];
|
|
} else {
|
|
$where_sort['kpi'] = 'watch';
|
|
$watch = $this->mdSyliveActivityKpidata->count($where_sort);
|
|
}
|
|
if ($sort == 'order') {
|
|
$order = $v['total'];
|
|
} else {
|
|
$where_order['kpi'] = 'order';
|
|
$where_order['cfUserId'] = $cfUserId;
|
|
$itemId && $where_order['itemId'] = $itemId;
|
|
$order = $this->mdSyliveActivityKpidata->count($where_order);
|
|
}
|
|
$list[] = ['consultantName' => $bizName . $uname, 'browse' => $browse, 'subscribe' => $subscribe
|
|
, 'watch' => $watch, 'order' => $order];
|
|
}
|
|
}
|
|
} else {
|
|
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
|
|
$where = ['activityId' => $activityId, 'itemId' => $itemId, 'cfUserId>' => 0, 'kpi' => $sort];
|
|
$count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId');
|
|
} else {
|
|
$where = ['activityId' => $activityId, 'status>=' => 0];
|
|
$count = $this->mdSyliveGroupsUser->count($where);
|
|
}
|
|
if ($count) {
|
|
if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索
|
|
$res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "orderTotal {$order},id desc"
|
|
, $page, $limit, "cfUserId as userId,levelId1,levelId2,levelId3,bizId as groupsId,count(id) as orderTotal");
|
|
} else {
|
|
$res = $this->mdSyliveGroupsUser->select($where, "{$sort_order},groupsUserId desc", $page, $limit,
|
|
'userId,levelId1,levelId2,levelId3,groupsId,browse,subscribe,orderTotal,watch');
|
|
}
|
|
$groups_ids = $userIds = [];
|
|
foreach ($res as $v) {
|
|
if ($v['levelId1'] && !in_array($v['levelId1'], $groups_ids)) {
|
|
$groups_ids[] = $v['levelId1'];
|
|
}
|
|
if ($v['levelId2'] && !in_array($v['levelId2'], $groups_ids)) {
|
|
$groups_ids[] = $v['levelId2'];
|
|
}
|
|
if ($v['levelId3'] && !in_array($v['levelId3'], $groups_ids)) {
|
|
$groups_ids[] = $v['levelId3'];
|
|
}
|
|
if ($v['groupsId'] && !in_array($v['groupsId'], $groups_ids)) {
|
|
$groups_ids[] = $v['groupsId'];
|
|
}
|
|
$userIds[] = $v['userId'];
|
|
}
|
|
$str_groups = $groups_ids ? implode(',', $groups_ids) : -1;
|
|
$map_groups = $this->mdSyliveGroups->map('groupsId', 'groupsName',
|
|
["groupsId in({$str_groups})" => null, 'activityId' => $activityId, 'status>=' => 0]);
|
|
$str_user = $userIds ? implode(',', $userIds) : -1;
|
|
$map_user = $this->mdSyliveUser->map('userId', 'uname,nickname', ["userId in({$str_user})" => null, 'status>=' => 0]);
|
|
foreach ($res as $v) {
|
|
$userId = intval($v['userId']);
|
|
$bizName = $uname = '';
|
|
$map_groups[$v['levelId1']] && $bizName = $map_groups[$v['levelId1']] . ' ';
|
|
$map_groups[$v['levelId2']] && $bizName .= $map_groups[$v['levelId2']] . ' ';
|
|
$map_groups[$v['levelId3']] && $bizName .= $map_groups[$v['levelId3']] . ' ';
|
|
if ($map_groups[$v['groupsId']]) {
|
|
$groupsName = $map_groups[$v['groupsId']] . ' ';
|
|
if ($bizName != $groupsName) {
|
|
$bizName .= $groupsName;
|
|
}
|
|
}
|
|
$uname = $map_user[$userId]['uname'] ? $map_user[$userId]['uname'] : $map_user[$userId]['nickname'];
|
|
if ($sort != 'order' && $itemId) {//有商品id,区分订单
|
|
$order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'cfUserId' => $userId, 'itemId' => $itemId, 'activityId' => $activityId]);
|
|
} else {
|
|
$order = $v['orderTotal'];
|
|
}
|
|
if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变
|
|
$re = $this->mdSyliveGroupsUser->get(['userId' => $userId, 'activityId' => $activityId], 'browse,subscribe,watch');
|
|
$v['browse'] = intval($re['browse']);
|
|
$v['subscribe'] = intval($re['subscribe']);
|
|
$v['watch'] = intval($re['watch']);
|
|
}
|
|
$list[] = ['consultantName' => $bizName . $uname, 'browse' => $v['browse'], 'subscribe' => $v['subscribe']
|
|
, 'watch' => $v['watch'], 'order' => $order];
|
|
}
|
|
}
|
|
}
|
|
}
|
|
$date = ['list' => $list, 'count' => $count];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:漏头数据
|
|
* Created on: 2022/12/05 14:17
|
|
* Created by: dengbw
|
|
*/
|
|
public function funnel_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$itemId = intval($this->input_param('itemId'));//商品
|
|
$show = $this->input_param('show');
|
|
$funnel_preheating = $funnel_live = [];
|
|
$timeStart = 0;
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
$re['timeStart'] && $timeStart = strtotime($re['timeStart']);
|
|
if ($show == 'left' || !$show) {//预热阶段
|
|
$left_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND kpi = 'browse' AND createTime < {$timeStart})";
|
|
$left_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'browse', 'createTime<' => $timeStart]);
|
|
$left_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'subscribe', 'createTime<' => $timeStart]);
|
|
$left_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch', $left_browse_where => null]);
|
|
if ($itemId) {
|
|
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'kpi' => 'order', $left_browse_where => null]);
|
|
} else {
|
|
$left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, '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_preheating = ['title' => '浏览转化漏斗((预热阶段)', 'expectedData' => $left_expected_data, 'actualData' => $left_actual_data];
|
|
}
|
|
if ($show == 'right' || !$show) {//直播阶段
|
|
$right_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND kpi = 'browse' AND createTime >= {$timeStart})";
|
|
$right_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'browse', 'createTime>=' => $timeStart]);
|
|
$right_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'kpi' => 'watch', $right_browse_where => null]);
|
|
if ($itemId) {
|
|
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'itemId' => $itemId, 'kpi' => 'order', $right_browse_where => null]);
|
|
} else {
|
|
$right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, '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_live = ['title' => '浏览转化漏斗(直播阶段)', 'expectedData' => $right_expected_data, 'actualData' => $right_actual_data];
|
|
}
|
|
$data['funnelPreheating'] = $funnel_preheating;
|
|
$data['funnelLive'] = $funnel_live;
|
|
$this->return_response($data);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取观看数/订单数区域折线图数据
|
|
* Created on: 2022/12/06 10:54
|
|
* Created by: dengbw
|
|
*/
|
|
public function stacked_watchOrder_get()
|
|
{
|
|
$activityId = intval($this->input_param('activityId'));
|
|
$re = $this->mdSyliveActivity->get(['activityId' => $activityId]);
|
|
$times = $legendData = $yAxisSeries = $xAxisData = [];
|
|
if ($re) {
|
|
$timeStart = $re['timeStart'];
|
|
$timeEnd = $re['timeEnd'];
|
|
if ($timeStart != '0000-00-00 00:00:00' && (date('Y-m-d H:i:s') > $timeStart)) {
|
|
$start_Time = strtotime($timeStart);
|
|
$end_Time = strtotime($timeEnd);
|
|
$legend_data = [['name' => date('Y-m-d', $start_Time) . '的观看数', 'value' => 'watch'],
|
|
['name' => date('Y-m-d', $start_Time) . '的订单数', 'value' => 'order']];
|
|
$add_time = '+1 hour';
|
|
$diff = abs($start_Time - $end_Time); // 获取时间差
|
|
$hour = ceil($diff / 3600); // 获取相差小时数
|
|
$hour < 6 && $add_time = '+30 minute';//转分钟显示
|
|
$ii = 0;
|
|
while ($start_Time < $end_Time) {
|
|
$start = date('Y-m-d H:i:s', $start_Time);
|
|
$ii > 0 && $start = date('Y-m-d H:i:s', $start_Time + 60);
|
|
$name_start = date('H:i', $start_Time);
|
|
$start_Time = strtotime($add_time, $start_Time);
|
|
$name = $name_start . '-' . date('H:i', $start_Time);
|
|
$end = date('Y-m-d H:i:s', $start_Time + 59);
|
|
$times[] = ['name' => $name, 'start' => $start, 'end' => $end];
|
|
$xAxisData[] = $name;
|
|
$ii++;
|
|
}
|
|
foreach ($legend_data as $v) {
|
|
$legendData[] = $v['name'];
|
|
$counts = [];
|
|
foreach ($times as $v2) {
|
|
$start = strtotime($v2['start']);
|
|
$end = strtotime($v2['end']);
|
|
$counts[] = $this->mdSyliveActivityKpidata->count(['kpi' => $v['value'], 'createTime >=' => $start,
|
|
'createTime <=' => $end, 'activityId' => $activityId]);
|
|
}
|
|
$yAxisSeries[] = ['name' => $v['name'], 'type' => 'line', 'data' => $counts];
|
|
}
|
|
}
|
|
}
|
|
$date = ['legendData' => $legendData, 'xAxisData' => $xAxisData, 'yAxisSeries' => $yAxisSeries];
|
|
$this->return_response_list($date);
|
|
}
|
|
|
|
/**
|
|
* Notes:获取门店数
|
|
* Created on: 2022/12/6 14:48
|
|
* Created by: dengbw
|
|
* @param $groupsId
|
|
* @return int
|
|
*/
|
|
private function getBiz($groupsId)
|
|
{
|
|
$groupsIds = '';
|
|
$res1 = $this->mdSyliveGroups->select(['parentId' => $groupsId, 'status>=' => 0], "groupsId desc", 0, 0, 'groupsId');
|
|
if ($res1) {
|
|
$groupsIds = implode(',', array_column($res1, 'groupsId'));
|
|
$res2 = $this->mdSyliveGroups->select(["parentId in({$groupsIds})" => null, 'status>=' => 0]
|
|
, "groupsId desc", 0, 0, 'groupsId');
|
|
if ($res2) {
|
|
$groupsIds = implode(',', array_column($res2, 'groupsId'));
|
|
$res3 = $this->mdSyliveGroups->select(["parentId in({$groupsIds})" => null, 'status>=' => 0]
|
|
, "groupsId desc", 0, 0, 'groupsId');
|
|
if ($res3) {
|
|
$groupsIds = implode(',', array_column($res3, 'groupsId'));
|
|
}
|
|
}
|
|
}
|
|
$biz = 0;
|
|
if ($groupsIds) {
|
|
$biz = $this->mdSyliveGroups->count(["groupsId in({$groupsIds})" => null, 'status>=' => 0]);
|
|
}
|
|
return $biz;
|
|
}
|
|
|
|
/**
|
|
* Notes:根据等级找名字
|
|
* Created on: 2022/12/10 13:56
|
|
* Created by: dengbw
|
|
* @param $groupsId
|
|
* @param $groupsLevel
|
|
* @param string $groupsName
|
|
* @return string
|
|
*/
|
|
private function getLevelName($groupsId, $groupsLevel, $groupsName = '')
|
|
{
|
|
$re = $this->mdSyliveGroups->get(['groupsId' => $groupsId], 'groupsName,parentId,groupsLevel');
|
|
if (!$re) {
|
|
return $groupsName;
|
|
} else {
|
|
if ($re['groupsLevel'] == $groupsLevel) {
|
|
$groupsName = $re['groupsName'];
|
|
}
|
|
if (!$groupsName && $re['parentId']) {
|
|
return $this->getLevelName($re['parentId'], $groupsLevel, $groupsName);
|
|
} else {
|
|
return $groupsName;
|
|
}
|
|
}
|
|
}
|
|
|
|
} |