From 8bee183945455030695fc6f5e5f805a4b268bad4 Mon Sep 17 00:00:00 2001 From: dengbw Date: Fri, 28 Oct 2022 16:54:27 +0800 Subject: [PATCH] market_statistics_1028_2 --- market/controllers/api/sylive/Statistics.php | 70 ++++++++++++++++---- 1 file changed, 56 insertions(+), 14 deletions(-) diff --git a/market/controllers/api/sylive/Statistics.php b/market/controllers/api/sylive/Statistics.php index cc3f031a..ce59ef40 100644 --- a/market/controllers/api/sylive/Statistics.php +++ b/market/controllers/api/sylive/Statistics.php @@ -138,7 +138,7 @@ class Statistics extends BaseController , 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } } - $res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id'); + $res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId, 'type' => 0], 'id desc', 0, 0, 'distinct(cf_uid) as userId,biz_id'); foreach ($res_user as $k => $v) { $userId = intval($v['userId']); $re_user = $this->mdSyliveUser->get(['userId' => $userId]); @@ -328,7 +328,7 @@ class Statistics extends BaseController if ($sort && $order) { $sort_order = $sort . ' ' . $order; } - $where = ['a_id' => $activityId]; + $where = ['a_id' => $activityId, 'type' => 0]; $count = $this->mdSyliveActivityKpidata->count($where, 'distinct(cf_uid)'); if ($count) { $res = $this->mdSyliveActivityKpidata->select($where, $sort_order, $page, $limit, 'distinct(cf_uid) as userId,biz_id'); @@ -557,7 +557,7 @@ class Statistics extends BaseController $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 + $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 { @@ -567,7 +567,7 @@ class Statistics extends BaseController $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 + $data[] = ['name' => $name, 'value' => $re_kpi[$kpi] ? $re_kpi[$kpi] : '0' , 'url' => "/sylive/activity/statistics/barchart?activityId={$activityId}&areaId={$areaId}&kpi={$kpi}&type={$type}"]; } } @@ -588,24 +588,35 @@ class Statistics extends BaseController if (!$activityId || !$areaId || !$kpi) { $this->return_json('参数错误'); } - $dataTitle = $dataValue = $dataUrl = []; + $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]); - $dataTitle[] = $re['teamName'] ? $re['teamName'] : '-'; - $dataValue[] = $v[$kpi] ? $v[$kpi] : 0; - $dataUrl[] = "/sylive/activity/statistics/storebarchart?activityId={$activityId}&bizId={$bizId}&kpi={$kpi}&type={$type}"; + $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]); - $dataTitle[] = $re['organizationName'] ? $re['organizationName'] : '-'; - $dataValue[] = $v[$kpi] ? $v[$kpi] : 0; - $dataUrl[] = "/sylive/activity/statistics/storebarchart?activityId={$activityId}&bizId={$bizId}&kpi={$kpi}&type={$type}"; + $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; @@ -628,15 +639,24 @@ class Statistics extends BaseController if (!$activityId || !$bizId || !$kpi) { $this->return_json('参数错误'); } - $dataTitle = $dataValue = []; + $data = $dataTitle = $dataValue = []; $res_user = $this->mdSyliveActivityKpidata->select(['a_id' => $activityId, 'biz_id' => $bizId, 'type' => $type] , 'id desc', 0, 0, 'distinct(cf_uid) as userId'); foreach ($res_user as $k => $v) { $userId = intval($v['userId']); $re_user = $this->mdSyliveUser->get(['userId' => $userId]); if ($re_user) { - $dataTitle[] = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; - $dataValue[] = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'type' => $type, 'kpi' => $kpi]); + $name = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; + $value = $this->mdSyliveActivityKpidata->count(['a_id' => $activityId, 'cf_uid' => $userId, 'type' => $type, 'kpi' => $kpi]); + $data[] = ['name' => $name ? $name : '-', 'value' => $value]; + } + } + if ($data) { + $edit = array_column($data, 'value'); + array_multisort($edit, SORT_ASC, $data); + foreach ($data as $k => $v) { + $dataTitle[] = $v['name']; + $dataValue[] = $v['value']; } } $data['dataTitle'] = $dataTitle; @@ -644,4 +664,26 @@ class Statistics extends BaseController $this->return_response($data); } + + public function ranking_get() + { + $activityId = intval($this->input_param('activityId')); + $type = intval($this->input_param('type')); + $kpi = $this->input_param('kpi'); + $areaRank = $bizRank = $consultantRank = []; + if ($type == 1) { + + } else { + $res = $this->mdSyliveActivityBiz->select(['activityId' => $activityId, 'status>=' => 0], 'browse desc', 0, 0, 'distinct(areaId) as 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]); + $areaRank[] = ['name' => $name, 'value' => $re_kpi[$kpi] ? $re_kpi[$kpi] : 0]; + } + } + + } + } \ No newline at end of file