diff --git a/market/controllers/api/sylive/Statistics.php b/market/controllers/api/sylive/Statistics.php index 60253a90..e8a0664c 100644 --- a/market/controllers/api/sylive/Statistics.php +++ b/market/controllers/api/sylive/Statistics.php @@ -39,9 +39,17 @@ class Statistics extends BaseController $this->return_json('参数错误'); } $title = ''; - $activityData1 = $activityData2 = $areaData = $areaAry = $funnel = $allOrganizationIds = []; + $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'); @@ -49,67 +57,21 @@ class Statistics extends BaseController $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; - $areaAry[$areaId]['biz'][] = $bizId; $res_org = $this->mdSyliveOrganization->select(['parentId' => $bizId, 'status>=' => 0], 'organizationId desc', 0, 0, 'organizationId'); foreach ($res_org as $k2 => $v2) { $allOrganizationIds[] = $v2['organizationId']; - $areaAry[$areaId]['sales'][] = $v2['organizationId']; } } } - 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], 'distinct(userId)'); - $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; - $areaData[] = ['areaName' => $re_area['organizationName'], 'biz' => count($v['biz']), 'consultant' => $consultant . '/' . $allConsultant - , 'browse' => $browse['browse'], 'subscribe' => $subscribe['subscribe'], 'watch' => $watch['watch'], 'order' => $orderTotal['orderTotal'] - , 'livePV' => $livePV, 'watchDuration' => $watchDuration]; - } - } - if ($areaData) { - $edit = array_column($areaData, 'browse'); - array_multisort($edit, SORT_DESC, $areaData); - } $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']); @@ -130,14 +92,14 @@ class Statistics extends BaseController } } $allConsultant = 0; - $consultant = $this->mdSyliveActivityUser->count(['activityId' => $activityId, 'organizationId>' => 0], 'userId'); + $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($areaData)], ['name' => '参与门店数', 'value' => $biz] + $activityData1 = [['name' => '参与区域数', 'value' => count($areaAry)], ['name' => '参与门店数', 'value' => $biz] , ['name' => '参与/全部顾问数', 'value' => $consultant . '/' . $allConsultant]]; $url = "/sylive/activity/statistics/piechart?activityId={$activityId}&"; $watch_un = $watch - $liveUV; @@ -177,10 +139,140 @@ class Statistics extends BaseController $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%'] - , 'areaData' => $areaData, 'funnelBrowse' => $funnel_browse, 'funnelSubscribe' => $funnel_subscribe]; + , '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 = []; + $count = 0; + $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]); + $order = $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' => $order + , '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 == 'asc' ? SORT_ASC : SORT_DESC; + $edit = array_column($list, $sort); + array_multisort($edit, $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 @@ -193,6 +285,7 @@ class Statistics extends BaseController $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 = []; @@ -200,26 +293,48 @@ class Statistics extends BaseController $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); if ($re) { $channelId = intval($re['channelId']); - $sort_order = 'browse desc,id desc'; - if ($sort && $order) { - if ($sort == 'order') { - $sort_order = 'orderTotal ' . $order; - } else { - $sort_order = $sort . ' ' . $order; - } + !$sort && $sort = 'browse'; + !$order && $order = 'desc'; + if ($sort == 'order' && !$day) { + $sort_order = 'orderTotal ' . $order; + } else { + $sort_order = $sort . ' ' . $order; } - $where = ['activityId' => $activityId, 'status>=' => 0, 'bizId>' => 0]; - $count = $this->mdSyliveActivityBiz->count($where); - if ($count) { - $res = $this->mdSyliveActivityBiz->select($where, $sort_order, $page, $limit); - foreach ($res as $v) { - $allConsultant = 0; - $bizId = intval($v['bizId']); - $re_biz = $this->mdSyliveOrganization->get(['organizationId' => $bizId, '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], 'distinct(userId)'); - if ($bizId) {//统计顾问数 + 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'); @@ -228,31 +343,76 @@ class Statistics extends BaseController } $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); + $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]; } - $list[] = [ - 'bizName' => $bizName, 'consultant' => $consultant . '/' . $allConsultant, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'] - , 'watch' => $v['watch'], 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } } @@ -272,6 +432,7 @@ class Statistics extends BaseController $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 = []; @@ -279,48 +440,110 @@ class Statistics extends BaseController $re = $this->mdSyliveActivity->get(['activityId' => $activityId]); if ($re) { $channelId = intval($re['channelId']); - $sort_order = 'browse desc,id desc'; - if ($sort && $order) { - if ($sort == 'order') { - $sort_order = 'orderTotal ' . $order; - } else { - $sort_order = $sort . ' ' . $order; - } + !$sort && $sort = 'browse'; + !$order && $order = 'desc'; + if ($sort == 'order' && !$day) { + $sort_order = 'orderTotal ' . $order; + } else { + $sort_order = $sort . ' ' . $order; } - $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, $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); + 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]; } - $list[] = ['consultantName' => $consultantName, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'], 'watch' => $v['watch'] - , 'order' => $v['orderTotal'], 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } } @@ -648,7 +871,7 @@ class Statistics extends BaseController array_multisort($edit, SORT_DESC, $area); $areaMax = $area[0]['value']; foreach ($area as $k => $v) { - $percent = number_format_com(($v['value'] / $areaMax) * 100, 1, ''); + $percent = ceil(($v['value'] / $areaMax) * 100); $area[$k]['percent'] = $percent; } } @@ -661,7 +884,7 @@ class Statistics extends BaseController $bizId = intval($v['bizId']); $re = $this->mdSyliveOrganization->get(['organizationId' => $bizId]); $name = $re['organizationName'] ? $re['organizationName'] : '-'; - $percent = number_format_com(($v[$kpi] / $bizMax) * 100, 1, ''); + $percent = ceil(($v[$kpi] / $bizMax) * 100); $biz[] = ['name' => $name, 'value' => $v[$kpi], 'percent' => $percent]; } } @@ -676,7 +899,7 @@ class Statistics extends BaseController $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 = number_format_com(($v[$kpi] / $consultantMax) * 100, 1, ''); + $percent = ceil(($v[$kpi] / $consultantMax) * 100); $consultant[] = ['name' => $name, 'value' => $v[$kpi], 'percent' => $percent]; } }