diff --git a/market/controllers/api/sylive/GroupsStatistics.php b/market/controllers/api/sylive/GroupsStatistics.php index 734cdad0..be68d11e 100644 --- a/market/controllers/api/sylive/GroupsStatistics.php +++ b/market/controllers/api/sylive/GroupsStatistics.php @@ -474,14 +474,37 @@ class GroupsStatistics extends BaseController } $count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId'); if ($count) { - $res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "total {$order},id desc", $page, $limit, "bizId as groupsId,cfUserId,count(id) as total"); + $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']; + } + !in_array($v['cfUserId'], $userIds) && $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', ["userId in({$str_user})" => null, 'status>=' => 0]); foreach ($res as $v) { $cfUserId = intval($v['cfUserId']); - $re_org = $this->mdSyliveGroups->get(['groupsId' => $v['groupsId'], 'status>=' => 0]); - $bizName = $re_org['groupsName'] ? $re_org['groupsName'] : '-'; - $re_user = $this->mdSyliveUser->get(['userId' => $cfUserId, 'status>=' => 0]); - $uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; - $consultantName = $bizName . ' ' . $uname; + $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']] . ' '; + $map_groups[$v['groupsId']] && $bizName .= $map_groups[$v['groupsId']] . ' '; + $map_user[$cfUserId] && $uname = $map_user[$cfUserId]; $where_sort['cfUserId'] = $cfUserId; if ($sort == 'browse') { $browse = $v['total']; @@ -509,19 +532,8 @@ class GroupsStatistics extends BaseController $itemId && $where_order['itemId'] = $itemId; $order = $this->mdSyliveActivityKpidata->count($where_order); } - $livePV = $watchDuration = 0; - if ($channelId) { - $livePV = $this->mdSyliveViewlog->count(['cfUserId' => $cfUserId, 'activityId' => $activityId - , 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]); - $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $cfUserId, 'activityId' => $activityId - , 'createTime>=' => $createTimeStart, 'createTime<=' => $createTimeEnd]); - 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]; + $list[] = ['consultantName' => $bizName . $uname, 'browse' => $browse, 'subscribe' => $subscribe + , 'watch' => $watch, 'order' => $order]; } } } else { @@ -535,27 +547,40 @@ class GroupsStatistics extends BaseController if ($count) { if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索 $res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "orderTotal {$order},id desc" - , $page, $limit, "cfUserId as userId,bizId as groupsId,count(id) as orderTotal"); + , $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,groupsId,browse,subscribe,orderTotal,watch'); + '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']; + } + !in_array($v['userId'], $userIds) && $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', ["userId in({$str_user})" => null, 'status>=' => 0]); foreach ($res as $v) { $userId = intval($v['userId']); - $re_org = $this->mdSyliveGroups->get(['groupsId' => $v['groupsId'], 'status>=' => 0]); - $bizName = $re_org['groupsName'] ? $re_org['groupsName'] : '-'; - $re_user = $this->mdSyliveUser->get(['userId' => $userId, 'status>=' => 0]); - $uname = $re_user['uname'] ? $re_user['uname'] : $re_user['nickname']; - $consultantName = $bizName . ' ' . $uname; - $livePV = $watchDuration = 0; - if ($channelId) { - $livePV = $this->mdSyliveViewlog->count(['cfUserId' => $userId, 'activityId' => $activityId]); - $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $userId, 'activityId' => $activityId]); - if ($re_sum['playDuration']) { - $playDuration = ceil($re_sum['playDuration'] / 60); - $watchDuration = round($playDuration / $livePV); - } - } + $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']] . ' '; + $map_groups[$v['groupsId']] && $bizName .= $map_groups[$v['groupsId']] . ' '; + $map_user[$userId] && $uname = $map_user[$userId]; if ($sort != 'order' && $itemId) {//有商品id,区分订单 $order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'cfUserId' => $userId, 'itemId' => $itemId, 'activityId' => $activityId]); } else { @@ -567,8 +592,8 @@ class GroupsStatistics extends BaseController $v['subscribe'] = intval($re['subscribe']); $v['watch'] = intval($re['watch']); } - $list[] = ['consultantName' => $consultantName, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'], 'watch' => $v['watch'] - , 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + $list[] = ['consultantName' => $bizName . $uname, 'browse' => $v['browse'], 'subscribe' => $v['subscribe'] + , 'watch' => $v['watch'], 'order' => $order]; } } }