diff --git a/market/controllers/api/sylive/GroupsStatistics.php b/market/controllers/api/sylive/GroupsStatistics.php index 558cb468..98b25574 100644 --- a/market/controllers/api/sylive/GroupsStatistics.php +++ b/market/controllers/api/sylive/GroupsStatistics.php @@ -640,146 +640,173 @@ class GroupsStatistics extends BaseController !$page && $page = 1; !$limit && $limit = 10; $list = []; - !$sort && $sort = 'browse'; - !$order && $order = 'desc'; - if ($sort == 'order' && !$day) { - $sort_order = 'orderTotal ' . $order; - } else { - $sort_order = $sort . ' ' . $order; - } - if ($day) { - $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 - , "cfUserId,levelId1,levelId2,levelId3,bizId,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['bizId'] && !in_array($v['bizId'], $groups_ids)) { - $groups_ids[] = $v['bizId']; - } - $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]); - foreach ($res as $v) { - $cfUserId = intval($v['cfUserId']); - $levelName1 = $levelName2 = $levelName3 = $bizName = $consultantName = '-'; - $map_groups[$v['levelId1']] && $levelName1 = $map_groups[$v['levelId1']]; - $map_groups[$v['levelId2']] && $levelName2 = $map_groups[$v['levelId2']]; - $map_groups[$v['levelId3']] && $levelName3 = $map_groups[$v['levelId3']]; - $map_groups[$v['bizId']] && $bizName = $map_groups[$v['bizId']]; - $map_user[$cfUserId] && $consultantName = $map_user[$cfUserId]; - $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[] = ['levelName1' => $levelName1, 'levelName2' => $levelName2, 'levelName3' => $levelName3, - 'bizName' => $bizName, 'consultantName' => $consultantName, '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'); + $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 { - $where = ['activityId' => $activityId, 'status>=' => 0]; - $count = $this->mdSyliveGroupsUser->count($where); + $sort_order = $sort . ' ' . $order; } - if ($count) { + 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 + , "cfUserId,levelId1,levelId2,levelId3,bizId,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['bizId'] && !in_array($v['bizId'], $groups_ids)) { + $groups_ids[] = $v['bizId']; + } + $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]); + foreach ($res as $v) { + $cfUserId = intval($v['cfUserId']); + $levelName1 = $levelName2 = $levelName3 = $bizName = $consultantName = '-'; + $map_groups[$v['levelId1']] && $levelName1 = $map_groups[$v['levelId1']]; + $map_groups[$v['levelId2']] && $levelName2 = $map_groups[$v['levelId2']]; + $map_groups[$v['levelId3']] && $levelName3 = $map_groups[$v['levelId3']]; + $map_groups[$v['bizId']] && $bizName = $map_groups[$v['bizId']]; + $map_user[$cfUserId] && $consultantName = $map_user[$cfUserId]; + $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); + } + $livePV = $watchDuration = 0; + if ($limit == 10000 && $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[] = ['levelName1' => $levelName1, 'levelName2' => $levelName2, 'levelName3' => $levelName3, + 'bizName' => $bizName, 'consultantName' => $consultantName, 'browse' => $browse, + 'subscribe' => $subscribe, 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; + } + } + } else { if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索 - $res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "orderTotal {$order},id desc" - , $page, $limit, "cfUserId,levelId1,levelId2,levelId3,bizId,count(id) as orderTotal"); + $where = ['activityId' => $activityId, 'itemId' => $itemId, 'cfUserId>' => 0, 'kpi' => $sort]; + $count = $this->mdSyliveActivityKpidata->count($where, 'cfUserId'); } else { - $res = $this->mdSyliveGroupsUser->select($where, "{$sort_order},groupsUserId desc", $page, $limit, - 'userId as cfUserId,levelId1,levelId2,levelId3,bizId,browse,subscribe,orderTotal,watch'); + $where = ['activityId' => $activityId, 'status>=' => 0]; + $count = $this->mdSyliveGroupsUser->count($where); } - $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['bizId'] && !in_array($v['bizId'], $groups_ids)) { - $groups_ids[] = $v['bizId']; - } - $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]); - foreach ($res as $v) { - $cfUserId = intval($v['cfUserId']); - $levelName1 = $levelName2 = $levelName3 = $bizName = $consultantName = '-'; - $map_groups[$v['levelId1']] && $levelName1 = $map_groups[$v['levelId1']]; - $map_groups[$v['levelId2']] && $levelName2 = $map_groups[$v['levelId2']]; - $map_groups[$v['levelId3']] && $levelName3 = $map_groups[$v['levelId3']]; - $map_groups[$v['bizId']] && $bizName = $map_groups[$v['bizId']]; - $map_user[$cfUserId] && $consultantName = $map_user[$cfUserId]; - if ($sort != 'order' && $itemId) {//有商品id,区分订单 - $order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'cfUserId' => $cfUserId, 'itemId' => $itemId, 'activityId' => $activityId]); + if ($count) { + if ($sort == 'order' && $itemId) {//有订单排序与商品id,区分订单搜索 + $res = $this->mdSyliveActivityKpidata->select_groupby('cfUserId', $where, "orderTotal {$order},id desc" + , $page, $limit, "cfUserId,levelId1,levelId2,levelId3,bizId,count(id) as orderTotal"); } else { - $order = $v['orderTotal']; + $res = $this->mdSyliveGroupsUser->select($where, "{$sort_order},groupsUserId desc", $page, $limit, + 'userId as cfUserId,levelId1,levelId2,levelId3,bizId,browse,subscribe,orderTotal,watch'); } - if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变 - $re = $this->mdSyliveGroupsUser->get(['userId' => $cfUserId, 'activityId' => $activityId], 'browse,subscribe,watch'); - $v['browse'] = intval($re['browse']); - $v['subscribe'] = intval($re['subscribe']); - $v['watch'] = intval($re['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['bizId'] && !in_array($v['bizId'], $groups_ids)) { + $groups_ids[] = $v['bizId']; + } + $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]); + foreach ($res as $v) { + $cfUserId = intval($v['cfUserId']); + $levelName1 = $levelName2 = $levelName3 = $bizName = $consultantName = '-'; + $map_groups[$v['levelId1']] && $levelName1 = $map_groups[$v['levelId1']]; + $map_groups[$v['levelId2']] && $levelName2 = $map_groups[$v['levelId2']]; + $map_groups[$v['levelId3']] && $levelName3 = $map_groups[$v['levelId3']]; + $map_groups[$v['bizId']] && $bizName = $map_groups[$v['bizId']]; + $map_user[$cfUserId] && $consultantName = $map_user[$cfUserId]; + if ($sort != 'order' && $itemId) {//有商品id,区分订单 + $order = $this->mdSyliveActivityKpidata->count(['kpi' => 'order', 'cfUserId' => $cfUserId, 'itemId' => $itemId, 'activityId' => $activityId]); + } else { + $order = $v['orderTotal']; + } + if ($sort == 'order' && $itemId) {//只改变订单数值,其它不变 + $re = $this->mdSyliveGroupsUser->get(['userId' => $cfUserId, 'activityId' => $activityId], 'browse,subscribe,watch'); + $v['browse'] = intval($re['browse']); + $v['subscribe'] = intval($re['subscribe']); + $v['watch'] = intval($re['watch']); + } + $browse = intval($v['browse']); + $subscribe = intval($v['subscribe']); + $watch = intval($v['watch']); + $order = intval($order); + $livePV = $watchDuration = 0; + if ($limit == 10000 && $channelId) {//导出 + $livePV = $this->mdSyliveViewlog->count(['cfUserId' => $cfUserId, 'activityId' => $activityId]); + $re_sum = $this->mdSyliveViewlog->sum('playDuration', ['cfUserId' => $cfUserId, 'activityId' => $activityId]); + if ($re_sum['playDuration']) { + $playDuration = ceil($re_sum['playDuration'] / 60); + $watchDuration = round($playDuration / $livePV); + } + } + $list[] = ['levelName1' => $levelName1, 'levelName2' => $levelName2, 'levelName3' => $levelName3, + 'bizName' => $bizName, 'consultantName' => $consultantName, 'browse' => $browse, + 'subscribe' => $subscribe, 'watch' => $watch, 'order' => $order, 'livePV' => $livePV, 'watchDuration' => $watchDuration]; } - $browse = intval($v['browse']); - $subscribe = intval($v['subscribe']); - $watch = intval($v['watch']); - $order = intval($order); - $list[] = ['levelName1' => $levelName1, 'levelName2' => $levelName2, 'levelName3' => $levelName3, - 'bizName' => $bizName, 'consultantName' => $consultantName, 'browse' => $browse, - 'subscribe' => $subscribe, 'watch' => $watch, 'order' => $order]; } } } diff --git a/market/controllers/api/sylive/GroupsUser.php b/market/controllers/api/sylive/GroupsUser.php index ba360608..75625250 100644 --- a/market/controllers/api/sylive/GroupsUser.php +++ b/market/controllers/api/sylive/GroupsUser.php @@ -65,7 +65,7 @@ class GroupsUser extends BaseController $roleName = '管理员'; } $list[] = [ - 'groupsUserId' => $v['groupsUserId'], 'uname' => $uname, 'nickname' => $nickname, 'mobile' => $mobile + 'groupsUserId' => $v['groupsUserId'], 'userId' => $v['userId'],'uname' => $uname, 'nickname' => $nickname, 'mobile' => $mobile , 'groupsId' => $groupsId, 'roleName' => $roleName, 'status' => $status, 'createTime' => $createTime]; } } diff --git a/market/controllers/api/sylive/Team.php b/market/controllers/api/sylive/Team.php index 443639f0..d365bceb 100644 --- a/market/controllers/api/sylive/Team.php +++ b/market/controllers/api/sylive/Team.php @@ -57,7 +57,7 @@ class Team extends BaseController $res[$k]['teamId'] = intval($v['teamId']); $res[$k]['parentId'] = intval($v['parentId']); $res[$k]['sortNumber'] = intval($v['sortNumber']); - $res[$k]['organizationId'] = $v['organizationId'] ? $v['organizationId'] : ''; + $res[$k]['organizationId'] = $v['organizationId'] ? intval($v['organizationId']) : ''; $city = $logo = []; if ($v['cityId']) { $city[] = $v['provinceId'];