From 8b8cdbbcfbfae35cccd6ed2effad227881639526 Mon Sep 17 00:00:00 2001 From: dengbw Date: Fri, 18 Nov 2022 15:15:38 +0800 Subject: [PATCH] market_statistics_1118 --- market/controllers/api/sylive/Statistics.php | 262 +++++++++++-------- 1 file changed, 150 insertions(+), 112 deletions(-) diff --git a/market/controllers/api/sylive/Statistics.php b/market/controllers/api/sylive/Statistics.php index 90d02c8a..1a1205cf 100644 --- a/market/controllers/api/sylive/Statistics.php +++ b/market/controllers/api/sylive/Statistics.php @@ -40,6 +40,7 @@ class Statistics extends BaseController if (!$activityId) { $this->return_json('参数错误'); } + $type = 0; $title = ''; $timeStart = '0000-00-00 00:00:00'; $activityData1 = $activityData2 = $areaAry = $funnel = $allOrganizationIds = []; @@ -82,10 +83,10 @@ class Statistics extends BaseController } } } - $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(['activityId' => $activityId, 'cfrom' => 0, 'status' => 1]); + $browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => $type, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => $type, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => $type, 'kpi' => 'watch']); + $order = $this->mdSyliveOrder->count(['activityId' => $activityId, 'cfrom' => $type, 'status' => 1]); $duration_min = $livePV = $liveUV = $watchDuration = $watchDuration = $pvDuration = 0; if ($channelId) { $re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]); @@ -378,7 +379,7 @@ class Statistics extends BaseController $livePV = $watchDuration = 0; if ($channelId) { $livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId, 'type' => $type]); - $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId, 'type' => 0]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId, 'type' => $type]); if ($re_sum['playDuration']) { $playDuration = ceil($re_sum['playDuration'] / 60); $watchDuration = round($playDuration / $livePV); @@ -531,7 +532,7 @@ class Statistics extends BaseController $order = $v['orderTotal']; } if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变 - $re = $this->mdSyliveActivityUser->get(['userId' => $userId, 'activityId' => $activityId], 'browse,subscribe,watch'); + $re = $this->mdSyliveActivityUser->get(['userId' => $userId, 'activityId' => $activityId, 'organizationId>' => 0], 'browse,subscribe,watch'); $v['browse'] = intval($re['browse']); $v['subscribe'] = intval($re['subscribe']); $v['watch'] = intval($re['watch']); @@ -558,11 +559,19 @@ class Statistics extends BaseController if (!$activityId) { $this->return_json('参数错误'); } + $type = 1; $title = ''; + $timeStart = '0000-00-00 00:00:00'; $activityData1 = $activityData2 = $areaAry = $funnel = $allTeamIds = []; $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--) { @@ -571,6 +580,7 @@ class Statistics extends BaseController } } $title = $re['title']; + $timeStart = $re['timeStart']; $channelId = $re['channelId']; $res_biz = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status>=' => 0], 'browse desc'); foreach ($res_biz as $k => $v) { @@ -592,10 +602,10 @@ class Statistics extends BaseController } } } - $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->mdSyliveOrder->count(['activityId' => $activityId, 'cfrom' => 1, 'status' => 1]); + $browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => $type, 'kpi' => 'browse']); + $subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => $type, 'kpi' => 'subscribe']); + $watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => $type, 'kpi' => 'watch']); + $order = $this->mdSyliveOrder->count(['activityId' => $activityId, 'cfrom' => $type, 'status' => 1]); $duration_min = $livePV = $liveUV = $watchDuration = $watchDuration = $pvDuration = 0; if ($channelId) { $re_duration = $this->mdPolyvSession->sum('duration', ['channelId' => $channelId]); @@ -620,7 +630,7 @@ class Statistics extends BaseController $consultant > $allConsultant && $allConsultant = $consultant; $activityData1 = [['name' => '参与团队数', 'value' => count($areaAry)] , ['name' => '参与/全部团员数', 'value' => $consultant . '/' . $allConsultant]]; - $url = "/sylive/activity/statistics/piechart?activityId={$activityId}&type=1&"; + $url = "/sylive/activity/statistics/piechart?activityId={$activityId}&type={$type}&"; $watch_un = 0; if ($liveUV) { $watch_un = $watch - $liveUV; @@ -635,36 +645,12 @@ class Statistics extends BaseController // , ['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 = 1 AND kpi = 'browse' AND createTime < {$timeStart})"; - $left_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'browse', 'createTime<' => $timeStart]); - $left_subscribe = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'subscribe']); - $left_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'watch', $left_browse_where => null]); - $left_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'order', $left_browse_where => null]); - $left_subscribe_per = number_format_com($left_subscribe / $left_browse * 100, 1, ''); - $left_watch_per = number_format_com($left_watch / $left_subscribe * 100, 1, ''); - $left_order_per = number_format_com($left_order / $left_watch * 100, 1, ''); - $left_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "预约人数({$left_subscribe_per}%)", 'value' => 75] - , ['name' => "观看人数({$left_watch_per}%)", 'value' => 50], ['name' => "订单数({$left_order_per}%)", 'value' => 25]]; - $left_actual_data = [['name' => '浏览人数', 'value' => $left_browse], ['name' => '预约人数', 'value' => $left_subscribe] - , ['name' => '观看人数', 'value' => $left_watch], ['name' => '订单数', 'value' => $left_order]]; - $funnel_browse = ['title' => '浏览转化漏斗((预热阶段)', 'expected_data' => $left_expected_data, 'actual_data' => $left_actual_data]; - - $right_browse_where = "userId in(select userId from lc_market_sylive_activity_kpidata where activityId = {$activityId} AND type = 1 AND kpi = 'browse' AND createTime >= {$timeStart})"; - $right_browse = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'browse', 'createTime>=' => $timeStart]); - $right_watch = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'watch', $right_browse_where => null]); - $right_order = $this->mdSyliveActivityKpidata->count(['activityId' => $activityId, 'type' => 1, 'kpi' => 'order', $right_browse_where => null]); - $right_watch_per = number_format_com($right_watch / $right_browse * 100, 1, ''); - $right_order_per = number_format_com($right_order / $right_watch * 100, 1, ''); - $right_expected_data = [['name' => "浏览人数100%", 'value' => 100], ['name' => "观看人数({$right_watch_per}%)", 'value' => 66.7], ['name' => "订单数({$right_order_per}%)", 'value' => 33.3]]; - $right_actual_data = [['name' => '浏览人数_' . $right_browse, 'value' => $right_browse], ['name' => '观看人数', 'value' => $right_watch], ['name' => '订单数', 'value' => $right_order]]; - $funnel_subscribe = ['title' => '浏览转化漏斗(直播阶段)', 'expected_data' => $right_expected_data, 'actual_data' => $right_actual_data]; - - $data = ['activityId' => $activityId, 'title' => $title, 'activityData1' => ['list' => $activityData1, 'style' => 'width: 50%'], 'activityData2' => ['list' => $activityData2, 'style' => 'width: 11.1%'] - , 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe, 'days' => $days]; + $data = ['activityId' => $activityId, 'title' => $title, 'timeStart' => strtotime($timeStart), 'activityData1' => ['list' => $activityData1, 'style' => 'width: 50%'] + , 'activityData2' => ['list' => $activityData2, 'style' => 'width: 11.1%'], 'tableData' => ['days' => $days, 'goods' => $goods]]; $this->return_response($data); } + /** * Notes:团队统计列表 * Created on: 2022/10/27 14:48 @@ -678,12 +664,14 @@ class Statistics extends BaseController $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) { + $type = 1; $channelId = intval($re['channelId']); !$sort && $sort = 'browse'; !$order && $order = 'desc'; @@ -693,7 +681,12 @@ class Statistics extends BaseController $sort_order = $sort . ' ' . $order; } if ($day) {//按天搜索 - $where = ['activityId' => $activityId, 'day' => $day, 'type' => 1, 'bizId>' => 0, 'kpi' => $sort]; + $createTimeStart = strtotime($day . ' 00:00:00'); + $createTimeEnd = strtotime($day . ' 23:59:59'); + $where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'type' => $type, '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,count(id) as total"); @@ -701,30 +694,32 @@ class Statistics extends BaseController $bizId = intval($v['bizId']); $re_biz = $this->mdSyliveTeam->get(['teamId' => $bizId, 'status>=' => 0]); $bizName = $re_biz ? $re_biz['teamName'] : '-'; - $where['bizId'] = $bizId; + $where_sort['bizId'] = $bizId; if ($sort == 'browse') { $browse = $v['total']; } else { - $where['kpi'] = 'browse'; - $browse = $this->mdSyliveActivityKpidata->count($where); + $where_sort['kpi'] = 'browse'; + $browse = $this->mdSyliveActivityKpidata->count($where_sort); } if ($sort == 'subscribe') { $subscribe = $v['total']; } else { - $where['kpi'] = 'subscribe'; - $subscribe = $this->mdSyliveActivityKpidata->count($where); + $where_sort['kpi'] = 'subscribe'; + $subscribe = $this->mdSyliveActivityKpidata->count($where_sort); } if ($sort == 'watch') { $watch = $v['total']; } else { - $where['kpi'] = 'watch'; - $watch = $this->mdSyliveActivityKpidata->count($where); + $where_sort['kpi'] = 'watch'; + $watch = $this->mdSyliveActivityKpidata->count($where_sort); } if ($sort == 'order') { - $order = $v['total']; + $orderTotal = $v['total']; } else { - $where['kpi'] = 'order'; - $order = $this->mdSyliveActivityKpidata->count($where); + $where_order['kpi'] = 'order'; + $where_order['bizId'] = $bizId; + $itemId && $where_order['itemId'] = $itemId; + $orderTotal = $this->mdSyliveActivityKpidata->count($where_order); } $consultant = $this->mdSyliveActivityUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'teamId>' => 0, 'userId>' => 0]); $consultants = []; @@ -737,36 +732,37 @@ class Statistics extends BaseController $allConsultant = $this->mdSyliveUser->count(["teamId in({$str_organizationIds})" => null, 'status>=' => 0, 'teamId>' => 0]); $livePV = $watchDuration = 0; if ($channelId) { - $res_watch = $this->mdSyliveActivityKpidata->db->select('b.unionid') - ->from('lc_market_sylive_activity_kpidata as a') - ->join('lc_market_sylive_user as b', "b.userId=a.userId", 'left') - ->where(['a.bizId' => $bizId, 'a.type' => 1, 'a.day' => $day, 'a.activityId' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) - ->limit(10000, 0) - ->get()->result_array(); - if ($res_watch) { - $str_unionids = implode("','", array_column($res_watch, 'unionid')); - $where_pv = ['channelId' => $channelId, 'param3' => 'live']; - $where_pv["param1 in ('" . $str_unionids . "')"] = null; - $livePV = $this->mdPolyvViewlog->count($where_pv); - $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); - if ($re_sum['playDuration']) { - $playDuration = ceil($re_sum['playDuration'] / 60); - $watchDuration = round($playDuration / $livePV); - } + $livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId + , 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd, 'type' => $type]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId + , 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd, 'type' => $type]); + 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]; + , 'watch' => $watch, 'order' => $orderTotal, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } } else { - $where = ['activityId' => $activityId, 'status>=' => 0, 'teamId2>' => 0]; - $count = $this->mdSyliveActivityTeam->count($where); + if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索 + $where = ['activityId' => $activityId, 'type' => $type, 'itemId' => $itemId, 'bizId>' => 0, 'kpi' => $sort]; + $count = $this->mdSyliveActivityKpidata->count($where, 'bizId'); + } else { + $where = ['activityId' => $activityId, 'status>=' => 0, 'teamId2>' => 0]; + $count = $this->mdSyliveActivityTeam->count($where); + } if ($count) { - $res = $this->mdSyliveActivityTeam->select($where, "{$sort_order},id desc", $page, $limit); + if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索 + $res = $this->mdSyliveActivityKpidata->select_groupby('bizId', $where, "orderTotal {$order},id desc", $page, $limit, "bizId,count(id) as orderTotal"); + } else { + $res = $this->mdSyliveActivityTeam->select($where, "{$sort_order},id desc", $page, $limit + , 'teamId2 as bizId,browse,subscribe,watch,orderTotal'); + } foreach ($res as $v) { - $bizId = intval($v['teamId2']); + $bizId = intval($v['bizId']); $re_biz = $this->mdSyliveTeam->get(['teamId' => $bizId, 'status>=' => 0]); $bizName = $re_biz ? $re_biz['teamName'] : '-'; $consultant = $this->mdSyliveActivityUser->count(['bizId' => $bizId, 'activityId' => $activityId, 'teamId>' => 0, 'userId>' => 0]); @@ -782,16 +778,27 @@ class Statistics extends BaseController $consultant > $allConsultant && $allConsultant = $consultant; $livePV = $watchDuration = 0; if ($channelId) { - $livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId, 'type' => 1]); - $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId, 'type' => 1]); + $livePV = $this->mdSyliveViewlog->count(['bizId' => $bizId, 'activityId' => $activityId, 'type' => $type]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['bizId' => $bizId, 'activityId' => $activityId, 'type' => $type]); 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, 'type' => $type, 'itemId' => $itemId, 'activityId' => $activityId]); + } else { + $order = $v['orderTotal']; + } + if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变 + $re = $this->mdSyliveActivityTeam->get(['teamId2' => $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, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'] - , 'watch' => $v['watch'], 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + , 'watch' => $v['watch'], 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } } @@ -813,12 +820,14 @@ class Statistics extends BaseController $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) { + $type = 1; $channelId = intval($re['channelId']); !$sort && $sort = 'browse'; !$order && $order = 'desc'; @@ -828,60 +837,58 @@ class Statistics extends BaseController $sort_order = $sort . ' ' . $order; } if ($day) { - $where = ['activityId' => $activityId, 'day' => $day, 'type' => 1, 'cfUserId>' => 0, 'kpi' => $sort]; + $createTimeStart = strtotime($day . ' 00:00:00'); + $createTimeEnd = strtotime($day . ' 23:59:59'); + $where = $where_order = $where_sort = ['activityId' => $activityId, 'day' => $day, 'type' => $type, '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, "bizId,cfUserId,count(id) as total"); foreach ($res as $v) { $cfUserId = intval($v['cfUserId']); $re_org = $this->mdSyliveTeam->get(['teamId' => $v['bizId'], 'status>=' => 0]); - $teamName = $re_org['teamName'] ? $re_org['teamName'] : '-'; + $organizationName = $re_org['teamName'] ? $re_org['teamName'] : '-'; $re_user = $this->mdSyliveUser->get(['userId' => $cfUserId, 'status>=' => 0]); $uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; - $consultantName = $teamName . ' ' . $uname; - $where['cfUserId'] = $cfUserId; + $consultantName = $organizationName . ' ' . $uname; + $where_sort['cfUserId'] = $cfUserId; if ($sort == 'browse') { $browse = $v['total']; } else { $where['kpi'] = 'browse'; - $browse = $this->mdSyliveActivityKpidata->count($where); + $browse = $this->mdSyliveActivityKpidata->count($where_sort); } if ($sort == 'subscribe') { $subscribe = $v['total']; } else { $where['kpi'] = 'subscribe'; - $subscribe = $this->mdSyliveActivityKpidata->count($where); + $subscribe = $this->mdSyliveActivityKpidata->count($where_sort); } if ($sort == 'watch') { $watch = $v['total']; } else { $where['kpi'] = 'watch'; - $watch = $this->mdSyliveActivityKpidata->count($where); + $watch = $this->mdSyliveActivityKpidata->count($where_sort); } if ($sort == 'order') { $order = $v['total']; } else { - $where['kpi'] = 'order'; - $order = $this->mdSyliveActivityKpidata->count($where); + $where_order['kpi'] = 'order'; + $where_order['cfUserId'] = $cfUserId; + $itemId && $where_order['itemId'] = $itemId; + $order = $this->mdSyliveActivityKpidata->count($where_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.type' => 1, 'a.day' => $day, 'a.activityId' => $activityId, 'a.kpi' => 'watch', "unionid!=''" => null]) - ->limit(10000, 0) - ->get()->result_array(); - if ($res_watch) { - $str_unionids = implode("','", array_column($res_watch, 'unionid')); - $where_pv = ['channelId' => $channelId, 'param3' => 'live']; - $where_pv["param1 in ('" . $str_unionids . "')"] = null; - $livePV = $this->mdPolyvViewlog->count($where_pv); - $re_sum = $this->mdPolyvViewlog->sum('playDuration', $where_pv); - if ($re_sum['playDuration']) { - $playDuration = ceil($re_sum['playDuration'] / 60); - $watchDuration = round($playDuration / $livePV); - } + $livePV = $this->mdSyliveViewlog->count(['cfUserId' => $cfUserId, 'activityId' => $activityId + , 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd, 'type' => $type]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $cfUserId, 'activityId' => $activityId + , 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd, 'type' => $type]); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); } } $list[] = ['consultantName' => $consultantName, 'browse' => $browse, 'subscribe' => $subscribe @@ -889,29 +896,50 @@ class Statistics extends BaseController } } } else { - $where = ['activityId' => $activityId, 'teamId>' => 0]; - $count = $this->mdSyliveActivityUser->count($where, 'userId'); + if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索 + $where = ['activityId' => $activityId, 'type' => $type, 'itemId' => $itemId, 'cfUserId>' => 0, 'kpi' => $sort]; + $count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId'); + } else { + $where = ['activityId' => $activityId, 'teamId>' => 0]; + $count = $this->mdSyliveActivityUser->count($where, 'userId'); + } if ($count) { - $filed = 'userId,bizId,browse,subscribe,orderTotal,watch'; - $res = $this->mdSyliveActivityUser->select_groupby('userId', $where, "{$sort_order},id desc", $page, $limit, $filed); + if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索 + $res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "orderTotal {$order},id desc" + , $page, $limit, "cfUserId as userId,bizId,count(id) as orderTotal"); + } else { + $res = $this->mdSyliveActivityUser->select_groupby('userId', $where, "{$sort_order},id desc", $page + , $limit, 'userId,bizId,browse,subscribe,orderTotal,watch'); + } foreach ($res as $v) { $userId = intval($v['userId']); $re_org = $this->mdSyliveTeam->get(['teamId' => $v['bizId'], 'status>=' => 0]); - $teamName = $re_org['teamName'] ? $re_org['teamName'] : '-'; + $organizationName = $re_org['teamName'] ? $re_org['teamName'] : '-'; $re_user = $this->mdSyliveUser->get(['userId' => $userId, 'status>=' => 0]); $uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; - $consultantName = $teamName . ' ' . $uname; + $consultantName = $organizationName . ' ' . $uname; $livePV = $watchDuration = 0; if ($channelId) { - $livePV = $this->mdSyliveViewlog->count(['cfUserId' => $userId, 'activityId' => $activityId, 'type' => 1]); - $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $userId, 'activityId' => $activityId, 'type' => 1]); + $livePV = $this->mdSyliveViewlog->count(['cfUserId' => $userId, 'activityId' => $activityId, 'type' => $type]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $userId, 'activityId' => $activityId, 'type' => $type]); 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', 'cfUserId' => $userId, 'type' => $type, 'itemId' => $itemId, 'activityId' => $activityId]); + } else { + $order = $v['orderTotal']; + } + if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变 + $re = $this->mdSyliveActivityUser->get(['userId' => $userId, 'activityId' => $activityId, 'teamId>' => 0], 'browse,subscribe,watch'); + $v['browse'] = intval($re['browse']); + $v['subscribe'] = intval($re['subscribe']); + $v['watch'] = intval($re['watch']); + } $list[] = ['consultantName' => $consultantName, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'], 'watch' => $v['watch'] - , 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + , 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } } @@ -1063,12 +1091,17 @@ class Statistics extends BaseController $kpi == 'order' && $kpi = 'orderTotal'; if ($type == 1) { //团队排名 - $res = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status>=' => 0] - , "{$kpi} desc,id desc", 1, 10, "{$kpi},teamId2"); + if ($kpi == 'orderTotal' && $itemId) { + $where_order = ['activityId' => $activityId, 'type' => $type, 'itemId' => $itemId, 'bizId>' => 0, 'kpi' => 'order']; + $res = $this->mdSyliveActivityKpidata->select_groupby('bizId', $where_order, "orderTotal desc,id desc", 1, 10, "bizId,count(id) as orderTotal"); + } else { + $res = $this->mdSyliveActivityTeam->select(['activityId' => $activityId, 'status>=' => 0] + , "{$kpi} desc,id desc", 1, 10, "{$kpi},teamId2 as bizId"); + } if ($res) { $bizMax = $res[0][$kpi]; foreach ($res as $k => $v) { - $bizId = intval($v['teamId2']); + $bizId = intval($v['bizId']); $re = $this->mdSyliveTeam->get(['teamId' => $bizId]); $name = $re['teamName'] ? $re['teamName'] : '-'; $percent = ceil(($v[$kpi] / $bizMax) * 100); @@ -1076,8 +1109,13 @@ class Statistics extends BaseController } } //顾问排名 - $res = $this->mdSyliveActivityUser->select_groupby('userId', ['activityId' => $activityId, 'teamId>' => 0] - , "{$kpi} desc,id desc", 1, 10, "{$kpi},bizId,userId"); + if ($kpi == 'orderTotal' && $itemId) { + $where_order = ['activityId' => $activityId, 'type' => $type, 'itemId' => $itemId, 'cfUserId>' => 0, 'kpi' => 'order']; + $res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where_order, "orderTotal desc,id desc", 1, 10, "bizId,cfUserId as userId,count(id) as orderTotal"); + } else { + $res = $this->mdSyliveActivityUser->select_groupby('userId', ['activityId' => $activityId, 'teamId>' => 0] + , "{$kpi} desc,id desc", 1, 10, "{$kpi},bizId,userId"); + } if ($res) { $consultantMax = $res[0][$kpi]; foreach ($res as $k => $v) {